simplify
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
use maud::{html, Markup};
|
||||
|
||||
pub struct Home {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct Home;
|
||||
|
||||
impl Home {
|
||||
pub fn build() -> Self {
|
||||
let doc: Markup = html!(
|
||||
pub fn build() -> Markup {
|
||||
html!(
|
||||
div id="home" class={"p-8" "max-w-xl"} {
|
||||
p {
|
||||
a href="/inventory/" { "Inventory" }
|
||||
@@ -15,14 +13,6 @@ impl Home {
|
||||
a href="/trips/" { "Trips" }
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Home> for Markup {
|
||||
fn from(val: Home) -> Self {
|
||||
val.doc
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,15 @@ use crate::models::*;
|
||||
use crate::ClientState;
|
||||
use uuid::{uuid, Uuid};
|
||||
|
||||
pub struct Inventory {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct Inventory;
|
||||
|
||||
impl Inventory {
|
||||
pub async fn build(state: ClientState, categories: Vec<Category>) -> Result<Self, Error> {
|
||||
pub async fn build(state: ClientState, categories: Vec<Category>) -> Result<Markup, Error> {
|
||||
let doc = html!(
|
||||
div id="pkglist-item-manager" {
|
||||
div ."p-8" ."grid" ."grid-cols-4" ."gap-3" {
|
||||
div ."col-span-2" {
|
||||
(InventoryCategoryList::build(&state, &categories).into_markup())
|
||||
(InventoryCategoryList::build(&state, &categories))
|
||||
}
|
||||
div ."col-span-2" {
|
||||
h1 ."text-2xl" ."mb-5" ."text-center" { "Items" }
|
||||
@@ -22,37 +20,29 @@ impl Inventory {
|
||||
(InventoryItemList::build(&state, categories.iter().find(|category| category.id == active_category_id)
|
||||
.ok_or(Error::NotFoundError { description: format!("no category with id {}", active_category_id) })?
|
||||
.items())
|
||||
.into_markup())
|
||||
)
|
||||
}
|
||||
(InventoryNewItemForm::build(&state, &categories).into_markup())
|
||||
(InventoryNewItemForm::build(&state, &categories))
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Ok(Self { doc })
|
||||
Ok(doc)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Inventory> for Markup {
|
||||
fn from(val: Inventory) -> Self {
|
||||
val.doc
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InventoryCategoryList {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct InventoryCategoryList;
|
||||
|
||||
impl InventoryCategoryList {
|
||||
pub fn build(state: &ClientState, categories: &Vec<Category>) -> Self {
|
||||
pub fn build(state: &ClientState, categories: &Vec<Category>) -> Markup {
|
||||
let biggest_category_weight: u32 = categories
|
||||
.iter()
|
||||
.map(Category::total_weight)
|
||||
.max()
|
||||
.unwrap_or(1);
|
||||
|
||||
let doc = html!(
|
||||
html!(
|
||||
div {
|
||||
h1 ."text-2xl" ."mb-5" ."text-center" { "Categories" }
|
||||
table
|
||||
@@ -146,30 +136,16 @@ impl InventoryCategoryList {
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
|
||||
fn into_markup(self) -> Markup {
|
||||
self.doc
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InventoryCategoryList> for Markup {
|
||||
fn from(val: InventoryCategoryList) -> Self {
|
||||
val.doc
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InventoryItemList {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct InventoryItemList;
|
||||
|
||||
impl InventoryItemList {
|
||||
pub fn build(state: &ClientState, items: &Vec<Item>) -> Self {
|
||||
pub fn build(state: &ClientState, items: &Vec<Item>) -> Markup {
|
||||
let biggest_item_weight: u32 = items.iter().map(|item| item.weight).max().unwrap_or(1);
|
||||
let doc = html!(
|
||||
html!(
|
||||
div #items {
|
||||
@if items.is_empty() {
|
||||
p ."text-lg" ."text-center" ."py-5" ."text-gray-400" { "[Empty]" }
|
||||
@@ -305,30 +281,15 @@ impl InventoryItemList {
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
|
||||
fn into_markup(self) -> Markup {
|
||||
self.doc
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InventoryItemList> for Markup {
|
||||
fn from(val: InventoryItemList) -> Self {
|
||||
val.doc
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InventoryNewItemForm {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct InventoryNewItemForm;
|
||||
|
||||
impl InventoryNewItemForm {
|
||||
pub fn build(state: &ClientState, categories: &Vec<Category>) -> Self {
|
||||
let doc = html!(
|
||||
|
||||
pub fn build(state: &ClientState, categories: &Vec<Category>) -> Markup {
|
||||
html!(
|
||||
form
|
||||
name="new-item"
|
||||
id="new-item"
|
||||
@@ -417,24 +378,6 @@ impl InventoryNewItemForm {
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
|
||||
fn into_markup(self) -> Markup {
|
||||
self.doc
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InventoryNewItemForm> for Markup {
|
||||
fn from(val: InventoryNewItemForm) -> Self {
|
||||
val.doc
|
||||
}
|
||||
}
|
||||
// impl InventoryItemList {
|
||||
// pub fn to_string(self) -> String {
|
||||
// self.doc.into_string()
|
||||
// }
|
||||
// }
|
||||
//ItemList
|
||||
|
||||
@@ -8,9 +8,7 @@ pub use home::*;
|
||||
pub use inventory::*;
|
||||
pub use trip::*;
|
||||
|
||||
pub struct Root {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct Root;
|
||||
|
||||
pub enum TopLevelPage {
|
||||
Inventory,
|
||||
@@ -19,8 +17,8 @@ pub enum TopLevelPage {
|
||||
}
|
||||
|
||||
impl Root {
|
||||
pub fn build(body: Markup, active_page: &TopLevelPage) -> Self {
|
||||
let doc = html!(
|
||||
pub fn build(body: Markup, active_page: &TopLevelPage) -> Markup {
|
||||
html!(
|
||||
(DOCTYPE)
|
||||
html {
|
||||
head {
|
||||
@@ -61,12 +59,20 @@ impl Root {
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> String {
|
||||
self.doc.into_string()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ErrorPage;
|
||||
|
||||
impl ErrorPage {
|
||||
pub fn build(message: &str) -> Markup {
|
||||
Root::build(
|
||||
html!(
|
||||
h1 { "Error" }
|
||||
p { (message) }
|
||||
),
|
||||
&TopLevelPage::None,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,36 +3,24 @@ use crate::models::*;
|
||||
|
||||
use maud::{html, Markup};
|
||||
|
||||
pub struct TripManager {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct TripManager;
|
||||
|
||||
impl TripManager {
|
||||
pub fn build(trips: Vec<models::Trip>) -> Self {
|
||||
let doc = html!(
|
||||
pub fn build(trips: Vec<models::Trip>) -> Markup {
|
||||
html!(
|
||||
div ."p-8" {
|
||||
(TripTable::build(trips).into_markup())
|
||||
(NewTrip::build().into_markup())
|
||||
(TripTable::build(trips))
|
||||
(NewTrip::build())
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TripTable {
|
||||
doc: Markup,
|
||||
}
|
||||
|
||||
impl From<TripManager> for Markup {
|
||||
fn from(val: TripManager) -> Self {
|
||||
val.doc
|
||||
}
|
||||
}
|
||||
pub struct TripTable;
|
||||
|
||||
impl TripTable {
|
||||
pub fn build(trips: Vec<models::Trip>) -> Self {
|
||||
let doc = html!(
|
||||
pub fn build(trips: Vec<models::Trip>) -> Markup {
|
||||
html!(
|
||||
h1 ."text-2xl" ."mb-5" {"Trips"}
|
||||
table
|
||||
."table"
|
||||
@@ -83,23 +71,15 @@ impl TripTable {
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
|
||||
pub fn into_markup(self) -> Markup {
|
||||
self.doc
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NewTrip {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct NewTrip;
|
||||
|
||||
impl NewTrip {
|
||||
pub fn build() -> Self {
|
||||
let doc = html!(
|
||||
pub fn build() -> Markup {
|
||||
html!(
|
||||
form
|
||||
name="new_trip"
|
||||
action="/trip/"
|
||||
@@ -190,48 +170,32 @@ impl NewTrip {
|
||||
{}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
|
||||
pub fn into_markup(self) -> Markup {
|
||||
self.doc
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Trip {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct Trip;
|
||||
|
||||
impl Trip {
|
||||
pub fn build(trip: &models::Trip) -> Self {
|
||||
let doc = html!(
|
||||
pub fn build(trip: &models::Trip) -> Markup {
|
||||
html!(
|
||||
div ."p-8" {
|
||||
div ."flex" ."flex-row" ."items-center" ."gap-x-3" {
|
||||
h1 ."text-2xl" ."font-semibold"{ (trip.name) }
|
||||
}
|
||||
div ."my-6" {
|
||||
(TripInfo::build(&trip).into_markup())
|
||||
(TripInfo::build(&trip))
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
|
||||
pub fn into_markup(self) -> Markup {
|
||||
self.doc
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TripInfo {
|
||||
doc: Markup,
|
||||
}
|
||||
pub struct TripInfo;
|
||||
|
||||
impl TripInfo {
|
||||
pub fn build(trip: &models::Trip) -> Self {
|
||||
let doc = html!(
|
||||
pub fn build(trip: &models::Trip) -> Markup {
|
||||
html!(
|
||||
table
|
||||
."table"
|
||||
."table-auto"
|
||||
@@ -338,12 +302,6 @@ impl TripInfo {
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Self { doc }
|
||||
}
|
||||
|
||||
pub fn into_markup(self) -> Markup {
|
||||
self.doc
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user