feat: link to the forms associated with a deployment

This commit is contained in:
Aravinth Manivannan 2022-12-31 01:27:03 +05:30
parent efc8ce5a27
commit c2c139575d
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
5 changed files with 58 additions and 1 deletions

1
Cargo.lock generated
View file

@ -1479,6 +1479,7 @@ dependencies = [
"sha2", "sha2",
"sqlx", "sqlx",
"tera", "tera",
"time",
"tokio", "tokio",
"toml", "toml",
"tracing", "tracing",

View file

@ -57,6 +57,7 @@ reqwest = { version = "0.11.13", features = ["json"] }
sha2 = "0.10.6" sha2 = "0.10.6"
hmac = "0.12.1" hmac = "0.12.1"
hex= "0.4.3" hex= "0.4.3"
time = { version = "0.3.17", features = ["formatting"] }
[dependencies.cache-buster] [dependencies.cache-buster]
git = "https://github.com/realaravinth/cache-buster" git = "https://github.com/realaravinth/cache-buster"

View file

@ -73,6 +73,7 @@ impl View {
pub struct TemplateSiteWithEvents { pub struct TemplateSiteWithEvents {
pub site: Site, pub site: Site,
pub view: String, pub view: String,
pub forms: String,
pub delete: String, pub delete: String,
pub last_update: Option<TemplateSiteEvent>, pub last_update: Option<TemplateSiteEvent>,
pub events: Vec<TemplateSiteEvent>, pub events: Vec<TemplateSiteEvent>,
@ -86,10 +87,12 @@ impl TemplateSiteWithEvents {
) -> Self { ) -> Self {
let view = PAGES.dash.site.get_view(site.pub_id); let view = PAGES.dash.site.get_view(site.pub_id);
let delete = PAGES.dash.site.get_delete(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 { Self {
site, site,
last_update, last_update,
view, view,
forms,
delete, delete,
events, events,
} }

View file

@ -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)] #[derive(Serialize)]
/// Dashboard Site routes /// Dashboard Site routes
pub struct DashSite { pub struct DashSite {
@ -123,6 +161,9 @@ pub struct DashSite {
pub view: &'static str, pub view: &'static str,
/// delete site route /// delete site route
pub delete: &'static str, pub delete: &'static str,
/// forms routes
pub forms: DashSiteForms,
} }
impl DashSite { impl DashSite {
@ -131,7 +172,13 @@ impl DashSite {
let add = "/dash/site/add"; let add = "/dash/site/add";
let view = "/dash/site/view/{deployment_pub_id}"; let view = "/dash/site/view/{deployment_pub_id}";
let delete = "/dash/site/delete/{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 { pub fn get_view(&self, deployment_pub_id: Uuid) -> String {

View file

@ -28,6 +28,11 @@
</td> </td>
</tr> </tr>
<tr>
<th>Forms</th>
<td><a href="{{ payload.forms }}" >See forms</a></td>
</tr>
<tr> <tr>
<th>Branch</th> <th>Branch</th>
<td>{{ payload.site.branch }}</td> <td>{{ payload.site.branch }}</td>