From 01e01d5619315a6eb96f3bf29cf00b55ad307877 Mon Sep 17 00:00:00 2001 From: Lev Date: Fri, 16 Feb 2024 14:01:25 -0800 Subject: [PATCH] Add support for adding profile picture --- .../src/components/navigation/navbar/web_app/mod.rs | 5 ++++- .../components/navigation/navbar/web_app/template.html | 4 ++-- pgml-dashboard/src/components/profile_icon/mod.rs | 8 +++++--- pgml-dashboard/src/components/profile_icon/template.html | 6 ++++++ pgml-dashboard/src/models.rs | 2 ++ pgml-dashboard/src/templates/mod.rs | 2 ++ pgml-dashboard/static/css/scss/components/_icon.scss | 4 ++-- pgml-dashboard/templates/content/playground.html | 4 ++-- pgml-dashboard/templates/layout/web_app_base.html | 6 +++--- 9 files changed, 28 insertions(+), 13 deletions(-) diff --git a/pgml-dashboard/src/components/navigation/navbar/web_app/mod.rs b/pgml-dashboard/src/components/navigation/navbar/web_app/mod.rs index c4df12a77..7306ce292 100644 --- a/pgml-dashboard/src/components/navigation/navbar/web_app/mod.rs +++ b/pgml-dashboard/src/components/navigation/navbar/web_app/mod.rs @@ -1,4 +1,5 @@ use crate::components::{StaticNav, StaticNavLink}; +use crate::models::User; use crate::utils::config; use pgml_components::component; use sailfish::TemplateOnce; @@ -9,14 +10,16 @@ pub struct WebApp { pub standalone_dashboard: bool, pub links: Vec, pub account_management_nav: StaticNav, + pub user: User, } impl WebApp { - pub fn new(links: Vec, account_management_nav: StaticNav) -> WebApp { + pub fn new(links: Vec, account_management_nav: StaticNav, user: User) -> WebApp { WebApp { standalone_dashboard: config::standalone_dashboard(), links, account_management_nav, + user, } } } diff --git a/pgml-dashboard/src/components/navigation/navbar/web_app/template.html b/pgml-dashboard/src/components/navigation/navbar/web_app/template.html index 2ee5460a0..38dfb57a7 100644 --- a/pgml-dashboard/src/components/navigation/navbar/web_app/template.html +++ b/pgml-dashboard/src/components/navigation/navbar/web_app/template.html @@ -21,7 +21,7 @@ @@ -63,7 +63,7 @@ diff --git a/pgml-dashboard/src/components/profile_icon/mod.rs b/pgml-dashboard/src/components/profile_icon/mod.rs index 6049512c0..1e9da27d2 100644 --- a/pgml-dashboard/src/components/profile_icon/mod.rs +++ b/pgml-dashboard/src/components/profile_icon/mod.rs @@ -3,11 +3,13 @@ use sailfish::TemplateOnce; #[derive(TemplateOnce, Default)] #[template(path = "profile_icon/template.html")] -pub struct ProfileIcon; +pub struct ProfileIcon { + pub profile_picture: Option, +} impl ProfileIcon { - pub fn new() -> ProfileIcon { - ProfileIcon + pub fn new(profile_picture: Option) -> ProfileIcon { + ProfileIcon { profile_picture } } } diff --git a/pgml-dashboard/src/components/profile_icon/template.html b/pgml-dashboard/src/components/profile_icon/template.html index 04fef6804..1a72f2f59 100644 --- a/pgml-dashboard/src/components/profile_icon/template.html +++ b/pgml-dashboard/src/components/profile_icon/template.html @@ -1,3 +1,9 @@ +<% if let Some(profile_picture) = profile_picture { %> + +<% } else { %> + + +<% } %> diff --git a/pgml-dashboard/src/models.rs b/pgml-dashboard/src/models.rs index c26ca363f..f5b7bb5aa 100644 --- a/pgml-dashboard/src/models.rs +++ b/pgml-dashboard/src/models.rs @@ -961,6 +961,7 @@ impl UploadedFile { pub struct User { pub id: i64, pub email: String, + pub profile_picture: Option, } impl Default for User { @@ -968,6 +969,7 @@ impl Default for User { User { id: -1, email: "".to_string(), + profile_picture: None, } } } diff --git a/pgml-dashboard/src/templates/mod.rs b/pgml-dashboard/src/templates/mod.rs index 061cf353c..696664a19 100644 --- a/pgml-dashboard/src/templates/mod.rs +++ b/pgml-dashboard/src/templates/mod.rs @@ -127,6 +127,7 @@ pub struct WebAppBase<'a> { pub upper_left_nav: StaticNav, pub lower_left_nav: StaticNav, pub body_components: Vec, + pub user: models::User, } impl<'a> WebAppBase<'a> { @@ -139,6 +140,7 @@ impl<'a> WebAppBase<'a> { account_management_nav: context.account_management_nav.clone(), upper_left_nav: context.upper_left_nav.clone(), lower_left_nav: context.lower_left_nav.clone(), + user: context.user.clone(), ..Default::default() } } diff --git a/pgml-dashboard/static/css/scss/components/_icon.scss b/pgml-dashboard/static/css/scss/components/_icon.scss index f965304b3..cd8f53cf2 100644 --- a/pgml-dashboard/static/css/scss/components/_icon.scss +++ b/pgml-dashboard/static/css/scss/components/_icon.scss @@ -110,13 +110,13 @@ color: #{$neon-tint-100}; } - svg { + svg,img { border-color: #{$neon-tint-100}; } } - svg { + svg,img { border: 2px solid #{$gray-700}; background-color: #{$gray-500}; } diff --git a/pgml-dashboard/templates/content/playground.html b/pgml-dashboard/templates/content/playground.html index 84248a6eb..a1b776d79 100644 --- a/pgml-dashboard/templates/content/playground.html +++ b/pgml-dashboard/templates/content/playground.html @@ -19,7 +19,7 @@

icons

<%+ GithubIcon::new() %>
- <%+ ProfileIcon %> + <%+ ProfileIcon::new(None) %>

Dropdowns

@@ -33,7 +33,7 @@

Dropdowns

StaticNavLink::new("Starts Active".into(), "#test".into()).active(true) ] ).collapsable() - .icon(ProfileIcon::new().into()) %> + .icon(ProfileIcon::new(None).into()) %>
<%+ Dropdown::nav( diff --git a/pgml-dashboard/templates/layout/web_app_base.html b/pgml-dashboard/templates/layout/web_app_base.html index 9e311b681..b53736d28 100644 --- a/pgml-dashboard/templates/layout/web_app_base.html +++ b/pgml-dashboard/templates/layout/web_app_base.html @@ -24,14 +24,14 @@
- <%+ WebAppNavbar::new(left_nav_links, account_management_nav) %> + <%+ WebAppNavbar::new(left_nav_links, account_management_nav, user) %>
- <%+ WebAppLeftNav::new( upper_left_nav, lower_left_nav, dropdown_nav ) %> + <%+ WebAppLeftNav::new(upper_left_nav, lower_left_nav, dropdown_nav) %>
- <%- Breadcrumbs::render( breadcrumbs ) %> + <%- Breadcrumbs::render(breadcrumbs) %>