From 006c17e81ed487ddb5b0148aa67c9c9680fc4c49 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Fri, 10 Jan 2025 21:29:51 +0530 Subject: [PATCH] feat: bootstrap billing templates --- web_ui/src/billing/add_bill.rs | 69 ++++++++++++++ web_ui/src/billing/add_line_item.rs | 69 ++++++++++++++ web_ui/src/billing/delete_bill.rs | 68 ++++++++++++++ web_ui/src/billing/delete_line_item.rs | 67 ++++++++++++++ web_ui/src/billing/mod.rs | 25 +++++ web_ui/src/billing/update_bill.rs | 69 ++++++++++++++ web_ui/src/billing/update_line_item.rs | 69 ++++++++++++++ web_ui/src/lib.rs | 1 + web_ui/src/utils.rs | 1 + web_ui/templates/billing/add_bill.html | 17 ++++ web_ui/templates/billing/add_line_item.html | 91 +++++++++++++++++++ web_ui/templates/billing/delete_bill.html | 14 +++ .../templates/billing/delete_line_item.html | 15 +++ web_ui/templates/billing/update_bill.html | 39 ++++++++ .../templates/billing/update_line_item.html | 91 +++++++++++++++++++ 15 files changed, 705 insertions(+) create mode 100644 web_ui/src/billing/add_bill.rs create mode 100644 web_ui/src/billing/add_line_item.rs create mode 100644 web_ui/src/billing/delete_bill.rs create mode 100644 web_ui/src/billing/delete_line_item.rs create mode 100644 web_ui/src/billing/mod.rs create mode 100644 web_ui/src/billing/update_bill.rs create mode 100644 web_ui/src/billing/update_line_item.rs create mode 100644 web_ui/templates/billing/add_bill.html create mode 100644 web_ui/templates/billing/add_line_item.html create mode 100644 web_ui/templates/billing/delete_bill.html create mode 100644 web_ui/templates/billing/delete_line_item.html create mode 100644 web_ui/templates/billing/update_bill.html create mode 100644 web_ui/templates/billing/update_line_item.html diff --git a/web_ui/src/billing/add_bill.rs b/web_ui/src/billing/add_bill.rs new file mode 100644 index 0000000..800ab3c --- /dev/null +++ b/web_ui/src/billing/add_bill.rs @@ -0,0 +1,69 @@ + +// 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_BILL_PAGE: TemplateFile = TemplateFile::new( + "billing.add_bill", + "billing/add_bill.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + ADD_BILL_PAGE + .register(t) + .expect(ADD_BILL_PAGE.name); +} + +pub struct AddBillPage { + ctx: RefCell, +} + +impl AddBillPage { + 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_BILL_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/billing-add_bill.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(AddBillPage::page()) + .build() + .unwrap(); + tw.write(); + } +} + diff --git a/web_ui/src/billing/add_line_item.rs b/web_ui/src/billing/add_line_item.rs new file mode 100644 index 0000000..31653e9 --- /dev/null +++ b/web_ui/src/billing/add_line_item.rs @@ -0,0 +1,69 @@ + +// 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_LINE_ITEM_PAGE: TemplateFile = TemplateFile::new( + "billing.add_line_item", + "billing/add_line_item.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + ADD_LINE_ITEM_PAGE + .register(t) + .expect(ADD_LINE_ITEM_PAGE.name); +} + +pub struct AddLineItemPage { + ctx: RefCell, +} + +impl AddLineItemPage { + 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_LINE_ITEM_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/billing-add_line_item.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(AddLineItemPage::page()) + .build() + .unwrap(); + tw.write(); + } +} + diff --git a/web_ui/src/billing/delete_bill.rs b/web_ui/src/billing/delete_bill.rs new file mode 100644 index 0000000..af87b11 --- /dev/null +++ b/web_ui/src/billing/delete_bill.rs @@ -0,0 +1,68 @@ + +// 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 DELETE_BILL_PAGE: TemplateFile = TemplateFile::new( + "billing.delete_bill", + "billing/delete_bill.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + DELETE_BILL_PAGE + .register(t) + .expect(DELETE_BILL_PAGE.name); +} + +pub struct DeleteBillPage { + ctx: RefCell, +} + +impl DeleteBillPage { + 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(DELETE_BILL_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/billing-delete_bill.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(DeleteBillPage::page()) + .build() + .unwrap(); + tw.write(); + } +} diff --git a/web_ui/src/billing/delete_line_item.rs b/web_ui/src/billing/delete_line_item.rs new file mode 100644 index 0000000..ae5b064 --- /dev/null +++ b/web_ui/src/billing/delete_line_item.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 DELETE_LINE_ITEM_PAGE: TemplateFile = TemplateFile::new( + "billing.delete_line_item", + "billing/delete_line_item.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + DELETE_LINE_ITEM_PAGE + .register(t) + .expect(DELETE_LINE_ITEM_PAGE.name); +} + +pub struct DeleteLineItemPage { + ctx: RefCell, +} + +impl DeleteLineItemPage { + 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(DELETE_LINE_ITEM_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/billing-delete_line_item.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(DeleteLineItemPage::page()) + .build() + .unwrap(); + tw.write(); + } +} diff --git a/web_ui/src/billing/mod.rs b/web_ui/src/billing/mod.rs new file mode 100644 index 0000000..400cefa --- /dev/null +++ b/web_ui/src/billing/mod.rs @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2024 Aravinth Manivannan +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +pub mod add_bill; +pub mod update_bill; +pub mod delete_bill; +pub mod add_line_item; +pub mod update_line_item; +pub mod delete_line_item; + +pub fn register_templates(t: &mut tera::Tera) { + for template in [ + add_bill::ADD_BILL_PAGE, + update_bill::UPDATE_BILL_PAGE, + delete_bill::DELETE_BILL_PAGE, + add_line_item::ADD_LINE_ITEM_PAGE, + update_line_item::UPDATE_LINE_ITEM_PAGE, + delete_line_item::DELETE_LINE_ITEM_PAGE, + ] + .iter() + { + template.register(t).expect(template.name); + } +} diff --git a/web_ui/src/billing/update_bill.rs b/web_ui/src/billing/update_bill.rs new file mode 100644 index 0000000..de1d001 --- /dev/null +++ b/web_ui/src/billing/update_bill.rs @@ -0,0 +1,69 @@ + +// 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_BILL_PAGE: TemplateFile = TemplateFile::new( + "billing.update_bill", + "billing/update_bill.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + UPDATE_BILL_PAGE + .register(t) + .expect(UPDATE_BILL_PAGE.name); +} + +pub struct UpdateBillPage { + ctx: RefCell, +} + +impl UpdateBillPage { + 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_BILL_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/billing-update_bill.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(UpdateBillPage::page()) + .build() + .unwrap(); + tw.write(); + } +} + diff --git a/web_ui/src/billing/update_line_item.rs b/web_ui/src/billing/update_line_item.rs new file mode 100644 index 0000000..d23f80b --- /dev/null +++ b/web_ui/src/billing/update_line_item.rs @@ -0,0 +1,69 @@ + +// 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_LINE_ITEM_PAGE: TemplateFile = TemplateFile::new( + "billing.update_line_item", + "billing/update_line_item.html", +); + +pub fn register_templates(t: &mut tera::Tera) { + UPDATE_LINE_ITEM_PAGE + .register(t) + .expect(UPDATE_LINE_ITEM_PAGE.name); +} + +pub struct UpdateLineItemPage { + ctx: RefCell, +} + +impl UpdateLineItemPage { + 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_LINE_ITEM_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/billing-update_line_item.html"; + + let tw = TestWriterBuilder::default() + .file(FILE.into()) + .contents(UpdateLineItemPage::page()) + .build() + .unwrap(); + tw.write(); + } +} + diff --git a/web_ui/src/lib.rs b/web_ui/src/lib.rs index 1beb522..9e1b0e4 100644 --- a/web_ui/src/lib.rs +++ b/web_ui/src/lib.rs @@ -6,6 +6,7 @@ pub mod identity; pub mod inventory; mod log; mod utils; +pub mod billing; pub fn init() { lazy_static::initialize(&utils::TEMPLATES); diff --git a/web_ui/src/utils.rs b/web_ui/src/utils.rs index b183be3..5fd6108 100644 --- a/web_ui/src/utils.rs +++ b/web_ui/src/utils.rs @@ -48,6 +48,7 @@ lazy_static! { tera.autoescape_on(vec![".html", ".sql"]); crate::identity::register_templates(&mut tera); crate::inventory::register_templates(&mut tera); + crate::billing::register_templates(&mut tera); tera }; } diff --git a/web_ui/templates/billing/add_bill.html b/web_ui/templates/billing/add_bill.html new file mode 100644 index 0000000..86ae4b0 --- /dev/null +++ b/web_ui/templates/billing/add_bill.html @@ -0,0 +1,17 @@ + + + + + + Add Bill | Vanikam + + + Token Refreshed +
+ + +
+ + diff --git a/web_ui/templates/billing/add_line_item.html b/web_ui/templates/billing/add_line_item.html new file mode 100644 index 0000000..792a284 --- /dev/null +++ b/web_ui/templates/billing/add_line_item.html @@ -0,0 +1,91 @@ + + + + + + Add Line Item | Vanikam + + + Token Refreshed +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/web_ui/templates/billing/delete_bill.html b/web_ui/templates/billing/delete_bill.html new file mode 100644 index 0000000..6868117 --- /dev/null +++ b/web_ui/templates/billing/delete_bill.html @@ -0,0 +1,14 @@ + + + + + + Delete Bill | Vanikam + + + Token Refreshed +
+ +
+ + diff --git a/web_ui/templates/billing/delete_line_item.html b/web_ui/templates/billing/delete_line_item.html new file mode 100644 index 0000000..432346f --- /dev/null +++ b/web_ui/templates/billing/delete_line_item.html @@ -0,0 +1,15 @@ + + + + + + Delete Line Item | Vanikam + + + Token Refreshed +
+ + +
+ + diff --git a/web_ui/templates/billing/update_bill.html b/web_ui/templates/billing/update_bill.html new file mode 100644 index 0000000..5feafcd --- /dev/null +++ b/web_ui/templates/billing/update_bill.html @@ -0,0 +1,39 @@ + + + + + + Update Bill | Vanikam + + + Token Refreshed +
+ + + + + + + + + +
+ + diff --git a/web_ui/templates/billing/update_line_item.html b/web_ui/templates/billing/update_line_item.html new file mode 100644 index 0000000..96f1e48 --- /dev/null +++ b/web_ui/templates/billing/update_line_item.html @@ -0,0 +1,91 @@ + + + + + + Update Line Item | Vanikam + + + Token Refreshed +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +