restruct
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
use maud::{html, Markup, PreEscaped};
|
use maud::{html, Markup, PreEscaped};
|
||||||
|
|
||||||
use crate::models;
|
use crate::models;
|
||||||
use crate::models::*;
|
|
||||||
use crate::ClientState;
|
use crate::ClientState;
|
||||||
use uuid::{uuid, Uuid};
|
use uuid::{uuid, Uuid};
|
||||||
|
|
||||||
@@ -9,8 +8,8 @@ pub struct Inventory;
|
|||||||
|
|
||||||
impl Inventory {
|
impl Inventory {
|
||||||
pub fn build(
|
pub fn build(
|
||||||
active_category: Option<&Category>,
|
active_category: Option<&models::Category>,
|
||||||
categories: &Vec<Category>,
|
categories: &Vec<models::Category>,
|
||||||
edit_item_id: Option<Uuid>,
|
edit_item_id: Option<Uuid>,
|
||||||
) -> Markup {
|
) -> Markup {
|
||||||
html!(
|
html!(
|
||||||
@@ -26,7 +25,7 @@ impl Inventory {
|
|||||||
@if let Some(active_category) = active_category {
|
@if let Some(active_category) = active_category {
|
||||||
(InventoryItemList::build(edit_item_id, active_category.items()))
|
(InventoryItemList::build(edit_item_id, active_category.items()))
|
||||||
}
|
}
|
||||||
(InventoryNewItemForm::build(active_category, &categories))
|
(InventoryNewItemForm::build(active_category, categories))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,10 +36,13 @@ impl Inventory {
|
|||||||
pub struct InventoryCategoryList;
|
pub struct InventoryCategoryList;
|
||||||
|
|
||||||
impl InventoryCategoryList {
|
impl InventoryCategoryList {
|
||||||
pub fn build(active_category: Option<&Category>, categories: &Vec<Category>) -> Markup {
|
pub fn build(
|
||||||
|
active_category: Option<&models::Category>,
|
||||||
|
categories: &Vec<models::Category>,
|
||||||
|
) -> Markup {
|
||||||
let biggest_category_weight: i64 = categories
|
let biggest_category_weight: i64 = categories
|
||||||
.iter()
|
.iter()
|
||||||
.map(Category::total_weight)
|
.map(models::Category::total_weight)
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or(1);
|
.unwrap_or(1);
|
||||||
|
|
||||||
@@ -127,7 +129,7 @@ impl InventoryCategoryList {
|
|||||||
}
|
}
|
||||||
td ."border" ."p-0" ."m-0" {
|
td ."border" ."p-0" ."m-0" {
|
||||||
p ."p-2" ."m-2" {
|
p ."p-2" ."m-2" {
|
||||||
(categories.iter().map(Category::total_weight).sum::<i64>().to_string())
|
(categories.iter().map(models::Category::total_weight).sum::<i64>().to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,7 +142,7 @@ impl InventoryCategoryList {
|
|||||||
pub struct InventoryItemList;
|
pub struct InventoryItemList;
|
||||||
|
|
||||||
impl InventoryItemList {
|
impl InventoryItemList {
|
||||||
pub fn build(edit_item_id: Option<Uuid>, items: &Vec<Item>) -> Markup {
|
pub fn build(edit_item_id: Option<Uuid>, items: &Vec<models::Item>) -> Markup {
|
||||||
let biggest_item_weight: i64 = items.iter().map(|item| item.weight).max().unwrap_or(1);
|
let biggest_item_weight: i64 = items.iter().map(|item| item.weight).max().unwrap_or(1);
|
||||||
html!(
|
html!(
|
||||||
div #items {
|
div #items {
|
||||||
@@ -411,7 +413,10 @@ impl InventoryNewItemFormWeight {
|
|||||||
pub struct InventoryNewItemFormCategory;
|
pub struct InventoryNewItemFormCategory;
|
||||||
|
|
||||||
impl InventoryNewItemFormCategory {
|
impl InventoryNewItemFormCategory {
|
||||||
pub fn build(active_category: Option<&Category>, categories: &Vec<Category>) -> Markup {
|
pub fn build(
|
||||||
|
active_category: Option<&models::Category>,
|
||||||
|
categories: &Vec<models::Category>,
|
||||||
|
) -> Markup {
|
||||||
html!(
|
html!(
|
||||||
div
|
div
|
||||||
."grid"
|
."grid"
|
||||||
@@ -449,7 +454,10 @@ impl InventoryNewItemFormCategory {
|
|||||||
pub struct InventoryNewItemForm;
|
pub struct InventoryNewItemForm;
|
||||||
|
|
||||||
impl InventoryNewItemForm {
|
impl InventoryNewItemForm {
|
||||||
pub fn build(active_category: Option<&Category>, categories: &Vec<Category>) -> Markup {
|
pub fn build(
|
||||||
|
active_category: Option<&models::Category>,
|
||||||
|
categories: &Vec<models::Category>,
|
||||||
|
) -> Markup {
|
||||||
html!(
|
html!(
|
||||||
form
|
form
|
||||||
x-data="{
|
x-data="{
|
||||||
|
|||||||
@@ -4,10 +4,6 @@ pub mod home;
|
|||||||
pub mod inventory;
|
pub mod inventory;
|
||||||
pub mod trip;
|
pub mod trip;
|
||||||
|
|
||||||
pub use home::*;
|
|
||||||
pub use inventory::*;
|
|
||||||
pub use trip::*;
|
|
||||||
|
|
||||||
pub struct Root;
|
pub struct Root;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::models::*;
|
use crate::models;
|
||||||
use crate::{models, HtmxEvents};
|
use crate::HtmxEvents;
|
||||||
|
|
||||||
use maud::{html, Markup, PreEscaped};
|
use maud::{html, Markup, PreEscaped};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@@ -12,8 +12,6 @@ pub struct TripManager;
|
|||||||
pub mod packagelist;
|
pub mod packagelist;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
pub use types::*;
|
|
||||||
|
|
||||||
impl TripManager {
|
impl TripManager {
|
||||||
pub fn build(trips: Vec<models::Trip>) -> Markup {
|
pub fn build(trips: Vec<models::Trip>) -> Markup {
|
||||||
html!(
|
html!(
|
||||||
@@ -47,14 +45,14 @@ impl From<InputType> for &'static str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trip_state_icon(state: &TripState) -> &'static str {
|
fn trip_state_icon(state: &models::TripState) -> &'static str {
|
||||||
match state {
|
match state {
|
||||||
TripState::Init => "mdi-magic-staff",
|
models::TripState::Init => "mdi-magic-staff",
|
||||||
TripState::Planning => "mdi-text-box-outline",
|
models::TripState::Planning => "mdi-text-box-outline",
|
||||||
TripState::Planned => "mdi-clock-outline",
|
models::TripState::Planned => "mdi-clock-outline",
|
||||||
TripState::Active => "mdi-play",
|
models::TripState::Active => "mdi-play",
|
||||||
TripState::Review => "mdi-magnify",
|
models::TripState::Review => "mdi-magnify",
|
||||||
TripState::Done => "mdi-check",
|
models::TripState::Done => "mdi-check",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,8 +224,8 @@ pub struct Trip;
|
|||||||
impl Trip {
|
impl Trip {
|
||||||
pub fn build(
|
pub fn build(
|
||||||
trip: &models::Trip,
|
trip: &models::Trip,
|
||||||
trip_edit_attribute: Option<TripAttribute>,
|
trip_edit_attribute: Option<models::TripAttribute>,
|
||||||
active_category: Option<&TripCategory>,
|
active_category: Option<&models::TripCategory>,
|
||||||
) -> Markup {
|
) -> Markup {
|
||||||
html!(
|
html!(
|
||||||
div ."p-8" ."flex" ."flex-col" ."gap-8" {
|
div ."p-8" ."flex" ."flex-col" ."gap-8" {
|
||||||
@@ -260,10 +258,10 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
div ."flex" ."flex-row" ."items-center" ."gap-x-3" {
|
div ."flex" ."flex-row" ."items-center" ."gap-x-3" {
|
||||||
@if trip_edit_attribute.as_ref().map_or(false, |a| *a == TripAttribute::Name) {
|
@if trip_edit_attribute.as_ref().map_or(false, |a| *a == models::TripAttribute::Name) {
|
||||||
form
|
form
|
||||||
id="edit-trip"
|
id="edit-trip"
|
||||||
action=(format!("edit/{}/submit", to_variant_name(&TripAttribute::Name).unwrap()))
|
action=(format!("edit/{}/submit", to_variant_name(&models::TripAttribute::Name).unwrap()))
|
||||||
hx-boost="true"
|
hx-boost="true"
|
||||||
target="_self"
|
target="_self"
|
||||||
method="post"
|
method="post"
|
||||||
@@ -319,7 +317,7 @@ impl Trip {
|
|||||||
h1 ."text-2xl" { (trip.name) }
|
h1 ."text-2xl" { (trip.name) }
|
||||||
span {
|
span {
|
||||||
a
|
a
|
||||||
href={"?edit=" (to_variant_name(&TripAttribute::Name).unwrap())}
|
href={"?edit=" (to_variant_name(&models::TripAttribute::Name).unwrap())}
|
||||||
hx-boost="true"
|
hx-boost="true"
|
||||||
{
|
{
|
||||||
span
|
span
|
||||||
@@ -360,8 +358,8 @@ impl TripInfoRow {
|
|||||||
pub fn build(
|
pub fn build(
|
||||||
name: &str,
|
name: &str,
|
||||||
value: Option<impl std::fmt::Display>,
|
value: Option<impl std::fmt::Display>,
|
||||||
attribute_key: &TripAttribute,
|
attribute_key: &models::TripAttribute,
|
||||||
edit_attribute: Option<&TripAttribute>,
|
edit_attribute: Option<&models::TripAttribute>,
|
||||||
input_type: InputType,
|
input_type: InputType,
|
||||||
) -> Markup {
|
) -> Markup {
|
||||||
let edit = edit_attribute.map_or(false, |a| a == attribute_key);
|
let edit = edit_attribute.map_or(false, |a| a == attribute_key);
|
||||||
@@ -508,7 +506,7 @@ impl TripInfoStateRow {
|
|||||||
td ."border" ."p-2" { "State" }
|
td ."border" ."p-2" { "State" }
|
||||||
td ."border" {
|
td ."border" {
|
||||||
span .flex .flex-row .items-center .justify-start ."gap-2" {
|
span .flex .flex-row .items-center .justify-start ."gap-2" {
|
||||||
span ."mdi" .(trip_state_icon(&trip_state)) ."text-2xl" ."pl-2" {}
|
span ."mdi" .(trip_state_icon(trip_state)) ."text-2xl" ."pl-2" {}
|
||||||
span ."pr-2" ."py-2" { (trip_state) }
|
span ."pr-2" ."py-2" { (trip_state) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -604,7 +602,10 @@ impl TripInfoStateRow {
|
|||||||
pub struct TripInfo;
|
pub struct TripInfo;
|
||||||
|
|
||||||
impl TripInfo {
|
impl TripInfo {
|
||||||
pub fn build(trip_edit_attribute: Option<TripAttribute>, trip: &models::Trip) -> Markup {
|
pub fn build(
|
||||||
|
trip_edit_attribute: Option<models::TripAttribute>,
|
||||||
|
trip: &models::Trip,
|
||||||
|
) -> Markup {
|
||||||
html!(
|
html!(
|
||||||
table
|
table
|
||||||
."table"
|
."table"
|
||||||
@@ -617,31 +618,31 @@ impl TripInfo {
|
|||||||
tbody {
|
tbody {
|
||||||
(TripInfoRow::build("Location",
|
(TripInfoRow::build("Location",
|
||||||
trip.location.as_ref(),
|
trip.location.as_ref(),
|
||||||
&TripAttribute::Location,
|
&models::TripAttribute::Location,
|
||||||
trip_edit_attribute.as_ref(),
|
trip_edit_attribute.as_ref(),
|
||||||
InputType::Text,
|
InputType::Text,
|
||||||
))
|
))
|
||||||
(TripInfoRow::build("Start date",
|
(TripInfoRow::build("Start date",
|
||||||
Some(trip.date_start),
|
Some(trip.date_start),
|
||||||
&TripAttribute::DateStart,
|
&models::TripAttribute::DateStart,
|
||||||
trip_edit_attribute.as_ref(),
|
trip_edit_attribute.as_ref(),
|
||||||
InputType::Date,
|
InputType::Date,
|
||||||
))
|
))
|
||||||
(TripInfoRow::build("End date",
|
(TripInfoRow::build("End date",
|
||||||
Some(trip.date_end),
|
Some(trip.date_end),
|
||||||
&TripAttribute::DateEnd,
|
&models::TripAttribute::DateEnd,
|
||||||
trip_edit_attribute.as_ref(),
|
trip_edit_attribute.as_ref(),
|
||||||
InputType::Date,
|
InputType::Date,
|
||||||
))
|
))
|
||||||
(TripInfoRow::build("Temp (min)",
|
(TripInfoRow::build("Temp (min)",
|
||||||
trip.temp_min,
|
trip.temp_min,
|
||||||
&TripAttribute::TempMin,
|
&models::TripAttribute::TempMin,
|
||||||
trip_edit_attribute.as_ref(),
|
trip_edit_attribute.as_ref(),
|
||||||
InputType::Number,
|
InputType::Number,
|
||||||
))
|
))
|
||||||
(TripInfoRow::build("Temp (max)",
|
(TripInfoRow::build("Temp (max)",
|
||||||
trip.temp_max,
|
trip.temp_max,
|
||||||
&TripAttribute::TempMax,
|
&models::TripAttribute::TempMax,
|
||||||
trip_edit_attribute.as_ref(),
|
trip_edit_attribute.as_ref(),
|
||||||
InputType::Number,
|
InputType::Number,
|
||||||
))
|
))
|
||||||
@@ -672,8 +673,8 @@ impl TripInfo {
|
|||||||
// the margins
|
// the margins
|
||||||
{
|
{
|
||||||
@let types = trip.types();
|
@let types = trip.types();
|
||||||
@let active_triptypes = types.iter().filter(|t| t.active).collect::<Vec<&TripType>>();
|
@let active_triptypes = types.iter().filter(|t| t.active).collect::<Vec<&models::TripType>>();
|
||||||
@let inactive_triptypes = types.iter().filter(|t| !t.active).collect::<Vec<&TripType>>();
|
@let inactive_triptypes = types.iter().filter(|t| !t.active).collect::<Vec<&models::TripType>>();
|
||||||
|
|
||||||
@if !active_triptypes.is_empty() {
|
@if !active_triptypes.is_empty() {
|
||||||
div
|
div
|
||||||
@@ -830,7 +831,7 @@ impl TripComment {
|
|||||||
pub struct TripItems;
|
pub struct TripItems;
|
||||||
|
|
||||||
impl TripItems {
|
impl TripItems {
|
||||||
pub fn build(active_category: Option<&TripCategory>, trip: &models::Trip) -> Markup {
|
pub fn build(active_category: Option<&models::TripCategory>, trip: &models::Trip) -> Markup {
|
||||||
html!(
|
html!(
|
||||||
div #trip-items ."grid" ."grid-cols-4" ."gap-3" {
|
div #trip-items ."grid" ."grid-cols-4" ."gap-3" {
|
||||||
div ."col-span-2" {
|
div ."col-span-2" {
|
||||||
@@ -856,7 +857,7 @@ pub struct TripCategoryListRow;
|
|||||||
impl TripCategoryListRow {
|
impl TripCategoryListRow {
|
||||||
pub fn build(
|
pub fn build(
|
||||||
trip_id: Uuid,
|
trip_id: Uuid,
|
||||||
category: &TripCategory,
|
category: &models::TripCategory,
|
||||||
active: bool,
|
active: bool,
|
||||||
biggest_category_weight: i64,
|
biggest_category_weight: i64,
|
||||||
htmx_swap: bool,
|
htmx_swap: bool,
|
||||||
@@ -962,12 +963,12 @@ impl TripCategoryListRow {
|
|||||||
pub struct TripCategoryList;
|
pub struct TripCategoryList;
|
||||||
|
|
||||||
impl TripCategoryList {
|
impl TripCategoryList {
|
||||||
pub fn build(active_category: Option<&TripCategory>, trip: &models::Trip) -> Markup {
|
pub fn build(active_category: Option<&models::TripCategory>, trip: &models::Trip) -> Markup {
|
||||||
let categories = trip.categories();
|
let categories = trip.categories();
|
||||||
|
|
||||||
let biggest_category_weight: i64 = categories
|
let biggest_category_weight: i64 = categories
|
||||||
.iter()
|
.iter()
|
||||||
.map(TripCategory::total_picked_weight)
|
.map(models::TripCategory::total_picked_weight)
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or(1);
|
.unwrap_or(1);
|
||||||
|
|
||||||
@@ -1002,7 +1003,7 @@ impl TripCategoryList {
|
|||||||
}
|
}
|
||||||
td ."border" ."p-0" ."m-0" {
|
td ."border" ."p-0" ."m-0" {
|
||||||
p ."p-2" ."m-2" {
|
p ."p-2" ."m-2" {
|
||||||
(categories.iter().map(TripCategory::total_picked_weight).sum::<i64>().to_string())
|
(categories.iter().map(models::TripCategory::total_picked_weight).sum::<i64>().to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1015,7 +1016,7 @@ impl TripCategoryList {
|
|||||||
pub struct TripItemList;
|
pub struct TripItemList;
|
||||||
|
|
||||||
impl TripItemList {
|
impl TripItemList {
|
||||||
pub fn build(trip_id: Uuid, items: &Vec<TripItem>) -> Markup {
|
pub fn build(trip_id: Uuid, items: &Vec<models::TripItem>) -> Markup {
|
||||||
let biggest_item_weight: i64 = items.iter().map(|item| item.item.weight).max().unwrap_or(1);
|
let biggest_item_weight: i64 = items.iter().map(|item| item.item.weight).max().unwrap_or(1);
|
||||||
|
|
||||||
html!(
|
html!(
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ impl TripPackageListCategoryBlock {
|
|||||||
."flex-col"
|
."flex-col"
|
||||||
{
|
{
|
||||||
@for item in category.items.as_ref().unwrap() {
|
@for item in category.items.as_ref().unwrap() {
|
||||||
(TripPackageListRow::build(trip.id, &item))
|
(TripPackageListRow::build(trip.id, item))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,7 +189,7 @@ impl TripPackageList {
|
|||||||
."gap-5"
|
."gap-5"
|
||||||
{
|
{
|
||||||
@for category in trip.categories() {
|
@for category in trip.categories() {
|
||||||
(TripPackageListCategoryBlock::build(trip, &category))
|
(TripPackageListCategoryBlock::build(trip, category))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
593
rust/src/main.rs
593
rust/src/main.rs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user