From c2c139575dec74fc6a707e63a3bfc5a567c42cda Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sat, 31 Dec 2022 01:27:03 +0530 Subject: [PATCH] feat: link to the forms associated with a deployment --- Cargo.lock | 1 + Cargo.toml | 1 + src/pages/dash/sites/view.rs | 3 ++ src/pages/routes.rs | 49 +++++++++++++++++++++++++++- templates/pages/dash/sites/view.html | 5 +++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index ca21040..42d7774 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1479,6 +1479,7 @@ dependencies = [ "sha2", "sqlx", "tera", + "time", "tokio", "toml", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 17f7984..9a3a68f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,6 +57,7 @@ reqwest = { version = "0.11.13", features = ["json"] } sha2 = "0.10.6" hmac = "0.12.1" hex= "0.4.3" +time = { version = "0.3.17", features = ["formatting"] } [dependencies.cache-buster] git = "https://github.com/realaravinth/cache-buster" diff --git a/src/pages/dash/sites/view.rs b/src/pages/dash/sites/view.rs index 93f06ae..a1dc3c1 100644 --- a/src/pages/dash/sites/view.rs +++ b/src/pages/dash/sites/view.rs @@ -73,6 +73,7 @@ impl View { pub struct TemplateSiteWithEvents { pub site: Site, pub view: String, + pub forms: String, pub delete: String, pub last_update: Option, pub events: Vec, @@ -86,10 +87,12 @@ impl TemplateSiteWithEvents { ) -> Self { let view = PAGES.dash.site.get_view(site.pub_id); let delete = PAGES.dash.site.get_delete(site.pub_id); + let forms = PAGES.dash.site.forms.get_list_host(&site.hostname); Self { site, last_update, view, + forms, delete, events, } diff --git a/src/pages/routes.rs b/src/pages/routes.rs index 67875e4..6069113 100644 --- a/src/pages/routes.rs +++ b/src/pages/routes.rs @@ -114,6 +114,44 @@ impl ForgejoWebhook { } } +#[derive(Serialize)] +/// Dashboard Site routes +pub struct DashSiteForms { + /// view form submission route + pub view: &'static str, + /// delete form submission route + pub delete: &'static str, + + /// list forms belonging to hostname + pub list_forms: &'static str, +} + +impl DashSiteForms { + /// create new instance of DashSiteForms route + pub const fn new() -> DashSiteForms { + let view = "/dash/site/forms/submission/view"; + let delete = "/dash/site/forms/submission/delete"; + let list_forms = "/dash/site/forms/list"; + DashSiteForms { + view, + delete, + list_forms, + } + } + + pub fn get_list_host(&self, host: &str) -> String { + format!("{}?host={}", self.list_forms, host) + } + + pub fn get_view(&self, page: usize, host: &str, path: &str) -> String { + format!("{}?host={}&path={}&page={}", self.view, host, path, page) + } + + pub fn get_delete(&self, id: usize, host: &str, path: &str) -> String { + format!("{}?host={}&path={}&id={}", self.view, host, path, id) + } +} + #[derive(Serialize)] /// Dashboard Site routes pub struct DashSite { @@ -123,6 +161,9 @@ pub struct DashSite { pub view: &'static str, /// delete site route pub delete: &'static str, + + /// forms routes + pub forms: DashSiteForms, } impl DashSite { @@ -131,7 +172,13 @@ impl DashSite { let add = "/dash/site/add"; let view = "/dash/site/view/{deployment_pub_id}"; let delete = "/dash/site/delete/{deployment_pub_id}"; - DashSite { add, view, delete } + let forms = DashSiteForms::new(); + DashSite { + add, + view, + delete, + forms, + } } pub fn get_view(&self, deployment_pub_id: Uuid) -> String { diff --git a/templates/pages/dash/sites/view.html b/templates/pages/dash/sites/view.html index bd8aec3..2ab8597 100644 --- a/templates/pages/dash/sites/view.html +++ b/templates/pages/dash/sites/view.html @@ -28,6 +28,11 @@ + + Forms + See forms + + Branch {{ payload.site.branch }}