diff --git a/pgml-dashboard/Cargo.lock b/pgml-dashboard/Cargo.lock index f28f4db10..daa69f6a5 100644 --- a/pgml-dashboard/Cargo.lock +++ b/pgml-dashboard/Cargo.lock @@ -2464,7 +2464,7 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pgml" -version = "0.10.0" +version = "0.10.1" dependencies = [ "anyhow", "async-trait", @@ -2479,6 +2479,7 @@ dependencies = [ "itertools", "lopdf", "md5", + "parking_lot 0.12.1", "regex", "reqwest", "rust_bridge", diff --git a/pgml-dashboard/src/templates/head.rs b/pgml-dashboard/src/components/layouts/head/mod.rs similarity index 86% rename from pgml-dashboard/src/templates/head.rs rename to pgml-dashboard/src/components/layouts/head/mod.rs index 27eb4e6b6..b7e9dc710 100644 --- a/pgml-dashboard/src/templates/head.rs +++ b/pgml-dashboard/src/components/layouts/head/mod.rs @@ -1,11 +1,14 @@ +use pgml_components::component; use sailfish::TemplateOnce; -#[derive(Clone, Default)] +#[derive(TemplateOnce, Default, Clone)] +#[template(path = "layouts/head/template.html")] pub struct Head { pub title: String, pub description: Option, pub image: Option, pub preloads: Vec, + pub context: Option, } impl Head { @@ -13,7 +16,7 @@ impl Head { Head::default() } - pub fn add_preload(&mut self, preload: &str) -> &mut Self { + pub fn add_preload(mut self, preload: &str) -> Head { self.preloads.push(preload.to_owned()); self } @@ -36,30 +39,14 @@ impl Head { pub fn not_found() -> Head { Head::new().title("404 - Not Found") } -} - -#[derive(TemplateOnce, Default, Clone)] -#[template(path = "layout/head.html")] -pub struct DefaultHeadTemplate { - pub head: Head, -} -impl DefaultHeadTemplate { - pub fn new(head: Option) -> DefaultHeadTemplate { - let head = match head { - Some(head) => head, - None => Head::new(), - }; - - DefaultHeadTemplate { head } + pub fn context(mut self, context: &Option) -> Head { + self.context = context.to_owned(); + self } } -impl From for String { - fn from(layout: DefaultHeadTemplate) -> String { - layout.render_once().unwrap() - } -} +component!(Head); #[cfg(test)] mod head_tests { diff --git a/pgml-dashboard/templates/layout/head.html b/pgml-dashboard/src/components/layouts/head/template.html similarity index 85% rename from pgml-dashboard/templates/layout/head.html rename to pgml-dashboard/src/components/layouts/head/template.html index 89018e26c..5b465ee25 100644 --- a/pgml-dashboard/templates/layout/head.html +++ b/pgml-dashboard/src/components/layouts/head/template.html @@ -5,21 +5,21 @@ - <%= head.title %> – PostgresML + <%= title %> – PostgresML - <% if head.description.is_some() { %> - - - + <% if description.is_some() { %> + + + <% } else { %> <% } %> - <% if head.image.is_some() { %> - - + <% if image.is_some() { %> + + <% } else { %> @@ -27,15 +27,19 @@ - + - + + <% if context.is_some() { %> + <%- context.unwrap() %> + <% } else { %> + + + "> + + + + + + + <% } %> + + <% for link in preloads { %> + type="image/webp"> + <% }; %> - "> + + - - - - @@ -69,10 +83,6 @@ - - - - <% if config::dev_mode() { %> <% } %> - - diff --git a/pgml-dashboard/src/components/layouts/mod.rs b/pgml-dashboard/src/components/layouts/mod.rs new file mode 100644 index 000000000..1669f52e9 --- /dev/null +++ b/pgml-dashboard/src/components/layouts/mod.rs @@ -0,0 +1,6 @@ +// This file is automatically generated. +// You shouldn't modify it manually. + +// src/components/layouts/head +pub mod head; +pub use head::Head; diff --git a/pgml-dashboard/src/components/mod.rs b/pgml-dashboard/src/components/mod.rs index 1054f2d8a..373dbe776 100644 --- a/pgml-dashboard/src/components/mod.rs +++ b/pgml-dashboard/src/components/mod.rs @@ -31,6 +31,9 @@ pub use github_icon::GithubIcon; // src/components/inputs pub mod inputs; +// src/components/layouts +pub mod layouts; + // src/components/left_nav_menu pub mod left_nav_menu; pub use left_nav_menu::LeftNavMenu; diff --git a/pgml-dashboard/src/guards.rs b/pgml-dashboard/src/guards.rs index 14fd3e1d5..b16da5cdc 100644 --- a/pgml-dashboard/src/guards.rs +++ b/pgml-dashboard/src/guards.rs @@ -132,6 +132,7 @@ impl Cluster { }, lower_left_nav: StaticNav::default(), marketing_footer: MarketingFooter::new().render_once().unwrap(), + head_items: None, }, notifications: None, } diff --git a/pgml-dashboard/src/lib.rs b/pgml-dashboard/src/lib.rs index 853761b5c..cefa1d6fa 100644 --- a/pgml-dashboard/src/lib.rs +++ b/pgml-dashboard/src/lib.rs @@ -54,6 +54,7 @@ pub struct Context { pub upper_left_nav: StaticNav, pub lower_left_nav: StaticNav, pub marketing_footer: String, + pub head_items: Option, } #[derive(Debug, Clone, Default)] diff --git a/pgml-dashboard/src/templates/mod.rs b/pgml-dashboard/src/templates/mod.rs index 9d11ab2e8..6d9a6c4fd 100644 --- a/pgml-dashboard/src/templates/mod.rs +++ b/pgml-dashboard/src/templates/mod.rs @@ -14,9 +14,8 @@ use crate::models; use crate::utils::tabs; pub mod docs; -pub mod head; -pub use head::*; +use crate::components::layouts::Head; #[derive(TemplateOnce, Default)] #[template(path = "content/not_found.html")] @@ -44,8 +43,15 @@ pub struct Layout { impl Layout { pub fn new(title: &str, context: Option<&crate::guards::Cluster>) -> Self { + let head = match context.as_ref() { + Some(context) => Head::new() + .title(title) + .context(&context.context.head_items), + None => Head::new().title(title), + }; + Layout { - head: Head::new().title(title), + head, alert_banner: AlertBanner::from_notification(Notification::next_alert(context)), feature_banner: FeatureBanner::from_notification(Notification::next_feature(context)), ..Default::default() @@ -112,7 +118,7 @@ impl From for String { pub struct WebAppBase<'a> { pub content: Option, pub breadcrumbs: Vec>, - pub head: String, + pub head: Head, pub dropdown_nav: StaticNav, pub account_management_nav: StaticNav, pub upper_left_nav: StaticNav, @@ -122,17 +128,10 @@ pub struct WebAppBase<'a> { impl<'a> WebAppBase<'a> { pub fn new(title: &str, context: &crate::Context) -> Self { + let head = Head::new().title(title).context(&context.head_items); + WebAppBase { - head: crate::templates::head::DefaultHeadTemplate::new(Some( - crate::templates::head::Head { - title: title.to_owned(), - description: None, - image: None, - preloads: vec![], - }, - )) - .render_once() - .unwrap(), + head, dropdown_nav: context.dropdown_nav.clone(), account_management_nav: context.account_management_nav.clone(), upper_left_nav: context.upper_left_nav.clone(), @@ -141,11 +140,6 @@ impl<'a> WebAppBase<'a> { } } - pub fn head(&mut self, head: String) -> &mut Self { - self.head = head.to_owned(); - self - } - pub fn breadcrumbs(&mut self, breadcrumbs: Vec>) -> &mut Self { self.breadcrumbs = breadcrumbs.to_owned(); self diff --git a/pgml-dashboard/static/fonts/Inter-Medium.woff2 b/pgml-dashboard/static/fonts/Inter-Medium.woff2 new file mode 100644 index 000000000..0fd2ee737 Binary files /dev/null and b/pgml-dashboard/static/fonts/Inter-Medium.woff2 differ diff --git a/pgml-dashboard/templates/layout/base.html b/pgml-dashboard/templates/layout/base.html index 4a2a785fc..d60caf98d 100644 --- a/pgml-dashboard/templates/layout/base.html +++ b/pgml-dashboard/templates/layout/base.html @@ -4,7 +4,7 @@ - <% include!("head.html"); %> + <%+ head %>
diff --git a/pgml-dashboard/templates/layout/web_app_base.html b/pgml-dashboard/templates/layout/web_app_base.html index da6ba949b..9e311b681 100644 --- a/pgml-dashboard/templates/layout/web_app_base.html +++ b/pgml-dashboard/templates/layout/web_app_base.html @@ -16,7 +16,7 @@ - <%- head %> + <%+ head %> <% for component in body_components { %> <%+ component %>