From b6350f2225f240643b129ce86e8d05d4701ebc7a Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 10 Jan 2025 21:13:40 +0530 Subject: [PATCH] feat: bootstrap inventory templates --- web_ui/src/inventory/add_category.rs | 63 ++++++++++++++ web_ui/src/inventory/add_customization.rs | 67 +++++++++++++++ web_ui/src/inventory/add_product.rs | 63 ++++++++++++++ web_ui/src/inventory/mod.rs | 25 ++++++ web_ui/src/inventory/update_category.rs | 67 +++++++++++++++ web_ui/src/inventory/update_customization.rs | 67 +++++++++++++++ web_ui/src/inventory/update_product.rs | 65 +++++++++++++++ web_ui/src/lib.rs | 1 + web_ui/src/utils.rs | 1 + web_ui/templates/inventory/add_category.html | 25 ++++++ .../inventory/add_customization.html | 21 +++++ web_ui/templates/inventory/add_product.html | 83 +++++++++++++++++++ .../templates/inventory/update_category.html | 25 ++++++ .../inventory/update_customization.html | 21 +++++ .../templates/inventory/update_product.html | 83 +++++++++++++++++++ 15 files changed, 677 insertions(+) create mode 100644 web_ui/src/inventory/add_category.rs create mode 100644 web_ui/src/inventory/add_customization.rs create mode 100644 web_ui/src/inventory/add_product.rs create mode 100644 web_ui/src/inventory/mod.rs create mode 100644 web_ui/src/inventory/update_category.rs create mode 100644 web_ui/src/inventory/update_customization.rs create mode 100644 web_ui/src/inventory/update_product.rs create mode 100644 web_ui/templates/inventory/add_category.html create mode 100644 web_ui/templates/inventory/add_customization.html create mode 100644 web_ui/templates/inventory/add_product.html create mode 100644 web_ui/templates/inventory/update_category.html create mode 100644 web_ui/templates/inventory/update_customization.html create mode 100644 web_ui/templates/inventory/update_product.html diff --git a/web_ui/src/inventory/add_category.rs b/web_ui/src/inventory/add_category.rs new file mode 100644 index 0000000..ed6841e --- /dev/null +++ b/web_ui/src/inventory/add_category.rs @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later +use std::cell::RefCell; + +use derive_builder::*; +use derive_more::*; +use serde::*; +use tera::Context; +use url::Url; + +pub use super::*; +use crate::utils::*; + +pub const ADD_CATEGORY_PAGE: TemplateFile = + TemplateFile::new("inventory.add_category", "inventory/add_category.html"); + +pub fn register_templates(t: &mut tera::Tera) { + ADD_CATEGORY_PAGE.register(t).expect(ADD_CATEGORY_PAGE.name); +} + +pub struct AddCategoryPage { + ctx: RefCell, +} + +impl AddCategoryPage { + pub fn new() -> Self { + let mut ctx = context(); + + //ctx.insert(PAYLOAD_KEY, p); + + let ctx = RefCell::new(ctx); + Self { ctx } + } + + pub fn render(&self) -> String { + TEMPLATES + .render(ADD_CATEGORY_PAGE.name, &self.ctx.borrow()) + .unwrap() + } + + pub fn page() -> String { + let p = Self::new(); + p.render() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn render_page_and_write() { + const FILE: &str = "./tmp/inventory-add_category.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(AddCategoryPage::page()) + .build() + .unwrap(); + tw.write(); + } +} diff --git a/web_ui/src/inventory/add_customization.rs b/web_ui/src/inventory/add_customization.rs new file mode 100644 index 0000000..97e8d7a --- /dev/null +++ b/web_ui/src/inventory/add_customization.rs @@ -0,0 +1,67 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later +use std::cell::RefCell; + +use derive_builder::*; +use derive_more::*; +use serde::*; +use tera::Context; +use url::Url; + +pub use super::*; +use crate::utils::*; + +pub const ADD_CUSTOMIZATION_PAGE: TemplateFile = TemplateFile::new( + "inventory.add_customization", + "inventory/add_customization.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + ADD_CUSTOMIZATION_PAGE + .register(t) + .expect(ADD_CUSTOMIZATION_PAGE.name); +} + +pub struct AddCustomizationPage { + ctx: RefCell, +} + +impl AddCustomizationPage { + pub fn new() -> Self { + let mut ctx = context(); + + //ctx.insert(PAYLOAD_KEY, p); + + let ctx = RefCell::new(ctx); + Self { ctx } + } + + pub fn render(&self) -> String { + TEMPLATES + .render(ADD_CUSTOMIZATION_PAGE.name, &self.ctx.borrow()) + .unwrap() + } + + pub fn page() -> String { + let p = Self::new(); + p.render() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn render_page_and_write() { + const FILE: &str = "./tmp/inventory-add_customization.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(AddCustomizationPage::page()) + .build() + .unwrap(); + tw.write(); + } +} diff --git a/web_ui/src/inventory/add_product.rs b/web_ui/src/inventory/add_product.rs new file mode 100644 index 0000000..b596f6c --- /dev/null +++ b/web_ui/src/inventory/add_product.rs @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later +use std::cell::RefCell; + +use derive_builder::*; +use derive_more::*; +use serde::*; +use tera::Context; +use url::Url; + +pub use super::*; +use crate::utils::*; + +pub const ADD_PRODUCT_PAGE: TemplateFile = + TemplateFile::new("inventory.add_product", "inventory/add_product.html"); + +pub fn register_templates(t: &mut tera::Tera) { + ADD_PRODUCT_PAGE.register(t).expect(ADD_PRODUCT_PAGE.name); +} + +pub struct AddProductPage { + ctx: RefCell, +} + +impl AddProductPage { + pub fn new() -> Self { + let mut ctx = context(); + + //ctx.insert(PAYLOAD_KEY, p); + + let ctx = RefCell::new(ctx); + Self { ctx } + } + + pub fn render(&self) -> String { + TEMPLATES + .render(ADD_PRODUCT_PAGE.name, &self.ctx.borrow()) + .unwrap() + } + + pub fn page() -> String { + let p = Self::new(); + p.render() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn render_page_and_write() { + const FILE: &str = "./tmp/inventory-add_product.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(AddProductPage::page()) + .build() + .unwrap(); + tw.write(); + } +} diff --git a/web_ui/src/inventory/mod.rs b/web_ui/src/inventory/mod.rs new file mode 100644 index 0000000..67f0951 --- /dev/null +++ b/web_ui/src/inventory/mod.rs @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +pub mod add_category; +pub mod add_customization; +pub mod add_product; +pub mod update_category; +pub mod update_customization; +pub mod update_product; + +pub fn register_templates(t: &mut tera::Tera) { + for template in [ + add_category::ADD_CATEGORY_PAGE, + update_category::UPDATE_CATEGORY_PAGE, + add_product::ADD_PRODUCT_PAGE, + update_product::UPDATE_PRODUCT_PAGE, + add_customization::ADD_CUSTOMIZATION_PAGE, + update_customization::UPDATE_CUSTOMIZATION_PAGE, + ] + .iter() + { + template.register(t).expect(template.name); + } +} diff --git a/web_ui/src/inventory/update_category.rs b/web_ui/src/inventory/update_category.rs new file mode 100644 index 0000000..8fc78fa --- /dev/null +++ b/web_ui/src/inventory/update_category.rs @@ -0,0 +1,67 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later +use std::cell::RefCell; + +use derive_builder::*; +use derive_more::*; +use serde::*; +use tera::Context; +use url::Url; + +pub use super::*; +use crate::utils::*; + +pub const UPDATE_CATEGORY_PAGE: TemplateFile = TemplateFile::new( + "inventory.update_category", + "inventory/update_category.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + UPDATE_CATEGORY_PAGE + .register(t) + .expect(UPDATE_CATEGORY_PAGE.name); +} + +pub struct UpdateCategoryPage { + ctx: RefCell, +} + +impl UpdateCategoryPage { + pub fn new() -> Self { + let mut ctx = context(); + + //ctx.insert(PAYLOAD_KEY, p); + + let ctx = RefCell::new(ctx); + Self { ctx } + } + + pub fn render(&self) -> String { + TEMPLATES + .render(UPDATE_CATEGORY_PAGE.name, &self.ctx.borrow()) + .unwrap() + } + + pub fn page() -> String { + let p = Self::new(); + p.render() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn render_page_and_write() { + const FILE: &str = "./tmp/inventory-update_category.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(UpdateCategoryPage::page()) + .build() + .unwrap(); + tw.write(); + } +} diff --git a/web_ui/src/inventory/update_customization.rs b/web_ui/src/inventory/update_customization.rs new file mode 100644 index 0000000..2fce280 --- /dev/null +++ b/web_ui/src/inventory/update_customization.rs @@ -0,0 +1,67 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later +use std::cell::RefCell; + +use derive_builder::*; +use derive_more::*; +use serde::*; +use tera::Context; +use url::Url; + +pub use super::*; +use crate::utils::*; + +pub const UPDATE_CUSTOMIZATION_PAGE: TemplateFile = TemplateFile::new( + "inventory.update_customization", + "inventory/update_customization.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + UPDATE_CUSTOMIZATION_PAGE + .register(t) + .expect(UPDATE_CUSTOMIZATION_PAGE.name); +} + +pub struct UpdateCustomizationPage { + ctx: RefCell, +} + +impl UpdateCustomizationPage { + pub fn new() -> Self { + let mut ctx = context(); + + //ctx.insert(PAYLOAD_KEY, p); + + let ctx = RefCell::new(ctx); + Self { ctx } + } + + pub fn render(&self) -> String { + TEMPLATES + .render(UPDATE_CUSTOMIZATION_PAGE.name, &self.ctx.borrow()) + .unwrap() + } + + pub fn page() -> String { + let p = Self::new(); + p.render() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn render_page_and_write() { + const FILE: &str = "./tmp/inventory-update_customization.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(UpdateCustomizationPage::page()) + .build() + .unwrap(); + tw.write(); + } +} diff --git a/web_ui/src/inventory/update_product.rs b/web_ui/src/inventory/update_product.rs new file mode 100644 index 0000000..5c479ed --- /dev/null +++ b/web_ui/src/inventory/update_product.rs @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later +use std::cell::RefCell; + +use derive_builder::*; +use derive_more::*; +use serde::*; +use tera::Context; +use url::Url; + +pub use super::*; +use crate::utils::*; + +pub const UPDATE_PRODUCT_PAGE: TemplateFile = + TemplateFile::new("inventory.update_product", "inventory/update_product.html"); + +pub fn register_templates(t: &mut tera::Tera) { + UPDATE_PRODUCT_PAGE + .register(t) + .expect(UPDATE_PRODUCT_PAGE.name); +} + +pub struct UpdateProductPage { + ctx: RefCell, +} + +impl UpdateProductPage { + pub fn new() -> Self { + let mut ctx = context(); + + //ctx.insert(PAYLOAD_KEY, p); + + let ctx = RefCell::new(ctx); + Self { ctx } + } + + pub fn render(&self) -> String { + TEMPLATES + .render(UPDATE_PRODUCT_PAGE.name, &self.ctx.borrow()) + .unwrap() + } + + pub fn page() -> String { + let p = Self::new(); + p.render() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn render_page_and_write() { + const FILE: &str = "./tmp/inventory-update_product.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(UpdateProductPage::page()) + .build() + .unwrap(); + tw.write(); + } +} diff --git a/web_ui/src/lib.rs b/web_ui/src/lib.rs index d02df30..1beb522 100644 --- a/web_ui/src/lib.rs +++ b/web_ui/src/lib.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later pub mod identity; +pub mod inventory; mod log; mod utils; diff --git a/web_ui/src/utils.rs b/web_ui/src/utils.rs index a2412d5..b183be3 100644 --- a/web_ui/src/utils.rs +++ b/web_ui/src/utils.rs @@ -47,6 +47,7 @@ lazy_static! { } tera.autoescape_on(vec![".html", ".sql"]); crate::identity::register_templates(&mut tera); + crate::inventory::register_templates(&mut tera); tera }; } diff --git a/web_ui/templates/inventory/add_category.html b/web_ui/templates/inventory/add_category.html new file mode 100644 index 0000000..83e9411 --- /dev/null +++ b/web_ui/templates/inventory/add_category.html @@ -0,0 +1,25 @@ + + + + + + Create Category | Vanikam + + + +
+ + + + + +
+ + + diff --git a/web_ui/templates/inventory/add_customization.html b/web_ui/templates/inventory/add_customization.html new file mode 100644 index 0000000..5f9a0d8 --- /dev/null +++ b/web_ui/templates/inventory/add_customization.html @@ -0,0 +1,21 @@ + + + + + + Add Customization | Vanikam + + + +
+ + + + +
+ + + diff --git a/web_ui/templates/inventory/add_product.html b/web_ui/templates/inventory/add_product.html new file mode 100644 index 0000000..a75765c --- /dev/null +++ b/web_ui/templates/inventory/add_product.html @@ -0,0 +1,83 @@ + + + + + + Add Product | Vanikam + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + diff --git a/web_ui/templates/inventory/update_category.html b/web_ui/templates/inventory/update_category.html new file mode 100644 index 0000000..1fbc54f --- /dev/null +++ b/web_ui/templates/inventory/update_category.html @@ -0,0 +1,25 @@ + + + + + + Update Category | Vanikam + + + +
+ + + + + +
+ + + diff --git a/web_ui/templates/inventory/update_customization.html b/web_ui/templates/inventory/update_customization.html new file mode 100644 index 0000000..248e25b --- /dev/null +++ b/web_ui/templates/inventory/update_customization.html @@ -0,0 +1,21 @@ + + + + + + Update Customization | Vanikam + + + +
+ + + + +
+ + + diff --git a/web_ui/templates/inventory/update_product.html b/web_ui/templates/inventory/update_product.html new file mode 100644 index 0000000..fde8c68 --- /dev/null +++ b/web_ui/templates/inventory/update_product.html @@ -0,0 +1,83 @@ + + + + + + Update Product | Vanikam + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +