Skip to content

Add support for adding profile picture #1319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::components::{StaticNav, StaticNavLink};
use crate::models::User;
use crate::utils::config;
use pgml_components::component;
use sailfish::TemplateOnce;
Expand All @@ -9,14 +10,16 @@ pub struct WebApp {
pub standalone_dashboard: bool,
pub links: Vec<StaticNavLink>,
pub account_management_nav: StaticNav,
pub user: User,
}

impl WebApp {
pub fn new(links: Vec<StaticNavLink>, account_management_nav: StaticNav) -> WebApp {
pub fn new(links: Vec<StaticNavLink>, account_management_nav: StaticNav, user: User) -> WebApp {
WebApp {
standalone_dashboard: config::standalone_dashboard(),
links,
account_management_nav,
user,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<!-- Button to toggle collapsed menu for less than lg screens -->
<button class="navbar-toggler collapsed topnav-controlls" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<%+ ProfileIcon::new() %>
<%+ ProfileIcon::new(user.profile_picture.clone()) %>
</button>
</div>

Expand Down Expand Up @@ -63,7 +63,7 @@
<li class="d-none d-lg-flex nav-item align-items-center">
<%+
Dropdown::nav(account_management_nav.links.clone())
.icon(ProfileIcon::new().into())
.icon(ProfileIcon::new(user.profile_picture.clone()).into())
.expandable()
%>
</li>
Expand Down
8 changes: 5 additions & 3 deletions pgml-dashboard/src/components/profile_icon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

impl ProfileIcon {
pub fn new() -> ProfileIcon {
ProfileIcon
pub fn new(profile_picture: Option<String>) -> ProfileIcon {
ProfileIcon { profile_picture }
}
}

Expand Down
6 changes: 6 additions & 0 deletions pgml-dashboard/src/components/profile_icon/template.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<% if let Some(profile_picture) = profile_picture { %>
<img src="<%- profile_picture %>" width="44" height="44" class="rounded-circle">
<% } else { %>

<svg class="rounded-circle" width="44" height="44" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 20V19C5 16.2386 7.23858 14 10 14H14C16.7614 14 19 16.2386 19 19V20M16 7C16 9.20914 14.2091 11 12 11C9.79086 11 8 9.20914 8 7C8 4.79086 9.79086 3 12 3C14.2091 3 16 4.79086 16 7Z" stroke="black" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

<% } %>
2 changes: 2 additions & 0 deletions pgml-dashboard/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,13 +961,15 @@ impl UploadedFile {
pub struct User {
pub id: i64,
pub email: String,
pub profile_picture: Option<String>,
}

impl Default for User {
fn default() -> User {
User {
id: -1,
email: "".to_string(),
profile_picture: None,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions pgml-dashboard/src/templates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub struct WebAppBase<'a> {
pub upper_left_nav: StaticNav,
pub lower_left_nav: StaticNav,
pub body_components: Vec<Component>,
pub user: models::User,
}

impl<'a> WebAppBase<'a> {
Expand All @@ -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()
}
}
Expand Down
4 changes: 2 additions & 2 deletions pgml-dashboard/static/css/scss/components/_icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down
4 changes: 2 additions & 2 deletions pgml-dashboard/templates/content/playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h3 class="h3">icons</h3>
<%+ GithubIcon::new() %>
</div>
<div class="mb-3">
<%+ ProfileIcon %>
<%+ ProfileIcon::new(None) %>
</div>

<h3 class="h3">Dropdowns</h3>
Expand All @@ -33,7 +33,7 @@ <h3 class="h3">Dropdowns</h3>
StaticNavLink::new("Starts Active".into(), "#test".into()).active(true)
]
).collapsable()
.icon(ProfileIcon::new().into()) %>
.icon(ProfileIcon::new(None).into()) %>
</div>
<div class="col-6" style="min-height: 400px;">
<%+ Dropdown::nav(
Expand Down
6 changes: 3 additions & 3 deletions pgml-dashboard/templates/layout/web_app_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
<main>
<div class="container-fluid p-0 min-vh-lg-100">
<div class="row gx-0 min-vh-lg-100 gy-0">
<%+ WebAppNavbar::new(left_nav_links, account_management_nav) %>
<%+ WebAppNavbar::new(left_nav_links, account_management_nav, user) %>

<div class="d-flex">
<%+ WebAppLeftNav::new( upper_left_nav, lower_left_nav, dropdown_nav ) %>
<%+ WebAppLeftNav::new(upper_left_nav, lower_left_nav, dropdown_nav) %>

<div class="clear-from-under-navbar flex-grow-1 min-vw-0">
<div class="px-4 px-sm-5 py-3" style="position: absolute">
<%- Breadcrumbs::render( breadcrumbs ) %>
<%- Breadcrumbs::render(breadcrumbs) %>
</div>

<div class="px-xs-2 px-md-5 overflow-hidden" style="padding-top: 57px;">
Expand Down