This commit is contained in:
2023-08-29 21:34:00 +02:00
parent 0f66ec80ac
commit 6fb11545d5
8 changed files with 120 additions and 96 deletions

1194
rust/src/view/trip/mod.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,198 @@
use maud::{html, Markup};
use uuid::Uuid;
use crate::models;
pub struct TripPackageListRow;
impl TripPackageListRow {
pub fn build(trip_id: Uuid, item: &models::TripItem) -> Markup {
html!(
li
."flex"
."flex-row"
."justify-between"
."items-stretch"
."bg-green-50"[item.packed]
."bg-red-50"[!item.packed]
."hover:bg-white"[!item.packed]
."h-full"
{
span
."p-2"
{
(item.item.name)
}
@if item.packed {
a
href={
"/trips/" (trip_id)
"/items/" (item.item.id)
"/unpack"
}
hx-post={
"/trips/" (trip_id)
"/packagelist/item/"
(item.item.id) "/unpack"
}
hx-target="closest li"
hx-swap="outerHTML"
."flex"
."flex-row"
."aspect-square"
{
span
."mdi"
."m-auto"
."text-xl"
."mdi-check"
{}
}
} @else {
a
href={
"/trips/" (trip_id)
"/items/" (item.item.id)
"/pack"
}
hx-post={
"/trips/" (trip_id)
"/packagelist/item/"
(item.item.id) "/pack"
}
hx-target="closest li"
hx-swap="outerHTML"
."flex"
."flex-row"
."aspect-square"
{
span
."mdi"
."m-auto"
."text-xl"
."mdi-checkbox-blank-outline"
{}
}
}
}
)
}
}
pub struct TripPackageListCategoryBlock;
impl TripPackageListCategoryBlock {
pub fn build(trip: &models::Trip, category: &models::TripCategory) -> Markup {
let empty = !category
.items
.as_ref()
.unwrap()
.iter()
.any(|item| item.picked);
html!(
div
."inline-block"
."w-full"
."mb-5"
."border"
."border-2"
."border-gray-300"
."opacity-30"[empty]
{
div
."bg-gray-100"
."border-b-2"
."border-gray-300"
."p-3"
{
h3 { (category.category.name) }
}
@if empty {
div
."flex"
."p-1"
{
span
."text-sm"
."m-auto"
{
"no items picked"
}
}
} @else {
ul
."flex"
."flex-col"
{
@for item in category.items.as_ref().unwrap() {
(TripPackageListRow::build(trip.id, item))
}
}
}
}
)
}
}
pub struct TripPackageList;
impl TripPackageList {
pub fn build(trip: &models::Trip) -> Markup {
// let all_packed = trip.categories().iter().all(|category| {
// category
// .items
// .as_ref()
// .unwrap()
// .iter()
// .all(|item| !item.picked || item.packed)
// });
html!(
div
."p-8"
."flex"
."flex-col"
."gap-8"
{
div
."flex"
."flex-row"
."justify-between"
{
h1 ."text-xl" {
"Package list for "
a
href={"/trips/" (trip.id) "/"}
hx-boost="true"
."font-bold"
{
(trip.name)
}
}
a
href={"/trips/" (trip.id) "/packagelist/"}
hx-boost="true"
// disabled[!all_packed]
// ."opacity-50"[!all_packed]
."p-2"
."border-2"
."border-gray-500"
."rounded-md"
."bg-blue-200"
."hover:bg-blue-200"
{
"Finish packing"
}
}
div
."columns-3"
."gap-5"
{
@for category in trip.categories() {
(TripPackageListCategoryBlock::build(trip, category))
}
}
}
)
}
}

168
rust/src/view/trip/types.rs Normal file
View File

@@ -0,0 +1,168 @@
use crate::models;
use crate::ClientState;
use maud::{html, Markup};
pub struct TypeList;
impl TypeList {
pub fn build(state: &ClientState, trip_types: Vec<models::TripsType>) -> Markup {
html!(
div ."p-8" ."flex" ."flex-col" ."gap-8" {
h1 ."text-2xl" {"Trip Types"}
ul
."flex"
."flex-col"
."items-stretch"
."border-t"
."border-l"
."h-full"
{
@for trip_type in trip_types {
li
."border-b"
."border-r"
."flex"
."flex-row"
."justify-between"
."items-stretch"
{
@if state.trip_type_edit.map_or(false, |id| id == trip_type.id) {
form
."hidden"
id="edit-trip-type"
action={ (trip_type.id) "/edit/name/submit" }
hx-boost="true"
target="_self"
method="post"
{}
div
."bg-blue-200"
."p-2"
."grow"
{
input
."bg-blue-100"
."hover:bg-white"
."w-full"
type="text"
name="new-value"
form="edit-trip-type"
value=(trip_type.name)
{}
}
div
."flex"
."flex-row"
{
a
href="."
hx-boost="true"
."bg-red-200"
."hover:bg-red-300"
."w-8"
."flex"
{
span
."mdi"
."mdi-cancel"
."text-xl"
."m-auto"
{}
}
button
type="submit"
form="edit-trip-type"
."bg-green-200"
."hover:bg-green-300"
."w-8"
{
span
."mdi"
."mdi-content-save"
."text-xl"
{}
}
}
} @else {
span
."p-2"
{
(trip_type.name)
}
div
."bg-blue-100"
."hover:bg-blue-200"
."p-0"
."w-8"
{
a
href={ "?edit=" (trip_type.id) }
hx-boost="true"
.flex
."w-full"
."h-full"
{
span
."m-auto"
."mdi"
."mdi-pencil"
."text-xl"
{}
}
}
}
}
}
}
form
name="new-trip-type"
action="/trips/types/"
target="_self"
method="post"
hx-boost="true"
."mt-8" ."p-5" ."border-2" ."border-gray-200"
{
div ."mb-5" ."flex" ."flex-row" {
span ."mdi" ."mdi-playlist-plus" ."text-2xl" ."mr-4" {}
p ."inline" ."text-xl" { "Add new trip type" }
}
div ."w-11/12" ."m-auto" {
div ."mx-auto" ."pb-8" {
div ."flex" ."flex-row" ."justify-center" {
label for="new-trip-type-name" ."font-bold" ."w-1/2" ."p-2" ."text-center" { "Name" }
span ."w-1/2" {
input
type="text"
id="new-trip-type-name"
name="new-trip-type-name"
."block"
."w-full"
."p-2"
."bg-gray-50"
."border-2"
."rounded"
."focus:outline-none"
."focus:bg-white"
{}
}
}
}
input
type="submit"
value="Add"
."py-2"
."border-2"
."rounded"
."border-gray-300"
."mx-auto"
."w-full"
{}
}
}
}
)
}
}