Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Dan product notifications#1524

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
chillenberger merged 13 commits intomasterfromdan-product-notifications
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
a2a4ce2
checkpoint product notifications
chillenbergerJun 7, 2024
a555f4e
Merge branch 'master' into dan-product-notifications
chillenbergerJun 11, 2024
c9fefe0
checkpoint
chillenbergerJun 12, 2024
c432f03
Merge branch 'master' into dan-product-notifications
chillenbergerJun 12, 2024
495de99
backend working, front end design working
chillenbergerJun 12, 2024
c5b9932
add top level notices to layout
chillenbergerJun 12, 2024
4f5fdb2
add ability to show/hide modal with events and use this feature
chillenbergerJun 12, 2024
11c455b
all for many high level notifications
chillenbergerJun 14, 2024
aa26bc3
clean up code, prevent modal collision
chillenbergerJun 14, 2024
d6c598c
fmt
chillenbergerJun 14, 2024
ff02bb7
Merge branch 'master' into dan-product-notifications
chillenbergerJun 14, 2024
270032a
add product marketing banner to layout
chillenbergerJun 14, 2024
2a67b62
adn new line
chillenbergerJun 14, 2024
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
PrevPrevious commit
NextNext commit
checkpoint
  • Loading branch information
@chillenberger
chillenberger committedJun 12, 2024
commitc9fefe05a2f61c97012c461199e78697b161ad5d
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,10 +41,6 @@ div[data-controller="notifications-marketing-feature-banner"] {
color: #{$slate-shade-100}
}
}

.feature1, .feature2, .feature3 {
border-radius: $border-radius-xl;
}

.message-area {
max-width: 75vw;
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@
<% let notification = notification.unwrap(); %>
<div data-controller="notifications-marketing-feature-banner">

<div class="<%- notification.level.to_string() %> <% if notification.level == NotificationLevel::Feature3 {%>main-gradient-border-card<% } %> rounded-2 W-100">
<div class="<%- notification.level.to_string() %> <% if notification.level == NotificationLevel::Feature3 {%>main-gradient-border-card<% } %> rounded-3 W-100">
<div class="banner d-flex container">

<% let content = format!(
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ pub struct ProductBanner {
pub notification: Option<Notification>,
pub location_id: String,
pub url: String,
pub show_modal: bool,
}

impl ProductBanner {
Expand All@@ -32,13 +33,15 @@ impl ProductBanner {
notification: Some(notification.clone()),
location_id,
url,
show_modal: false,
}
}
None => {
return ProductBanner {
notification: None,
location_id,
url,
show_modal: false,
}
}
}
Expand All@@ -51,6 +54,10 @@ impl ProductBanner {
pub fn get_url(&self) -> String {
self.url.clone()
}

pub fn set_show_modal(&mut self, show_modal: bool) {
self.show_modal = show_modal;
}
}

component!(ProductBanner);
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,33 @@ div[data-controller="notifications-product-product-banner"] {
margin-top: 3rem;
margin-bottom: 3rem;

.product1, .product2, .product3 {
.product_high, .product_medium, .product_marketing {
background-color: #{$gray-600};
margin: 2px 0px;
}

.product_high {
border: 2px solid #{$alert-notification-high};
.title, .preset-icon {
color: #{$alert-notification-high};
}
}

.product_medium {
border: 2px solid #{$alert-notification-medium};
.title, .preset-icon {
color: #{$alert-notification-medium};
}

}

.product_marketing {
border: 2px solid #{$alert-notification-marketing};
.title, .preset-icon {
color: #{$alert-notification-marketing};
}
}

.close {
color: #{$gray-100};
}
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = [];
static outlets = [];
static values = {
modal: String,
showModal: Boolean
};

initialize() {
console.log("Initialized notifications-product-product-banner");

initialize() {}

connect() {
if (this.showModalValue) {
const myModal = new bootstrap.Modal(document.getElementById(this.modalValue), {})
myModal.show();
}
}

connect() {}
updateModalCookie() {
console.log("updating cookie")
}

disconnect() {}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
<%
use crate::NotificationLevel;
use crate::components::Modal;
%>

<div class="<%- location_id %>">
<% if notification.is_some() {%>
<% let notification = notification.unwrap(); %>
<div data-controller="notifications-product-product-banner">
<div
data-controller="notifications-product-product-banner"
data-action="hide.bs.modal->notifications-product-product-banner#updateModalCookie"
data-notifications-product-product-banner-modal-value="<%- location_id %>"
data-notifications-product-product-banner-show-modal-value="<%- notification.modal && notification.trigger_modal %>">
<%
letborder_color = {
leticon = {
if notification.level == NotificationLevel::ProductHigh {
"red-gradient-border-card"
"error"
} else if notification.level == NotificationLevel::ProductMedium {
"orange-gradient-border-card"
"notifications"
} else {
"green-gradient-border-card"
"lightbulb"
}
};
%>
<div class="<%- border_color %>rounded-2 W-100">
<div class="rounded-2 W-100 <%- notification.level.to_string() %>">
<div class="banner d-flex container">

<%
let title = if notification.title.is_some() {
format!(r#"<p class="title m-0">{}</p>"#, notification.title.unwrap())} else {String::from("")};
%>

<% let content = format!(
r#"
<{} class="{} flex-grow-1 d-flex flex-column flex-md-row justify-content-center align-items-center row-gap-0 column-gap-3 fw-semibold overflow-hidden">
<div class="px-3 py-3 py-sm-0 overflow-hidden">
<p class="m-0 text-center">{} {}</p>
<{open_tag} class="{} flex-grow-1 d-flex flex-column flex-md-row justify-content-start align-items-center row-gap-0 column-gap-3 fw-semibold overflow-hidden">
<div class="px-3 py-3 py-sm-1 overflow-hidden text-container d-flex flex-row gap-2">
<span class="material-symbols-outlined {display} preset-icon">{icon}</span>
<div>
{title}
<p class="m-0">{message}</p>
</div>
</div>
</{}>
</{close_tag}>
"#,
if notification.link.is_some() { format!(r#"a href="{}" data-turbo="false" "#, notification.link.clone().unwrap()) } else { "div".to_string() },
if notification.link.is_some() { "btn btn-tertiary p-0 goto-arrow-hover-trigger" } else { "" },
notification.message,
if notification.link.is_some() { r#"<span class="material-symbols-outlined more-info position-relative goto-arrow-shift-animation" style="top: 2px;">arrow_forward</span>"# } else { "" },
if notification.link.is_some() { "a" } else { "div" },
if notification.link.is_some() { "btn btn-tertiary p-0" } else { "" },
display = if notification.preset_icon { "d-block" } else { "d-none" },
icon = icon,
title = title,
message = notification.message,
open_tag = if notification.link.is_some() { format!(r#"a href="{}" data-turbo="false" "#, notification.link.clone().unwrap()) } else { "div".to_string() },
close_tag = if notification.link.is_some() { "a" } else { "div" },
); %>

<%- content %>
Expand All@@ -48,5 +64,9 @@
</div>
</div>

<% if notification.modal {%>
<% println!("modal is on the screen"); %>
<%+ Modal::new("we need to say something".into()).id(&location_id) %>
<% } %>
<% } %>
</div>
111 changes: 83 additions & 28 deletionspgml-dashboard/src/lib.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,8 +28,9 @@ use templates::{components::StaticNav, *};

use crate::components::tables::serverless_models::{ServerlessModels, ServerlessModelsTurbo};
use crate::components::tables::serverless_pricing::{ServerlessPricing, ServerlessPricingTurbo};
use crate::utils::cookies::Notifications;
use crate::utils::cookies::{NotificationCookie,Notifications};
use crate::utils::urls;
use chrono;
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

Expand DownExpand Up@@ -63,6 +64,12 @@ pub struct Notification {
pub viewed: bool,
pub link: Option<String>,
pub deployment: Option<String>,
pub preset_icon: bool,
pub title: Option<String>,
pub modal_show_interval: i64,
pub notification_show_interval: i64,
pub modal: bool,
pub trigger_modal: bool,
}
impl Notification {
pub fn new(message: &str) -> Notification {
Expand All@@ -77,6 +84,12 @@ impl Notification {
viewed: false,
link: None,
deployment: None,
preset_icon: false,
title: None,
modal_show_interval: 90,
notification_show_interval: 90,
modal: false,
trigger_modal: false,
}
}

Expand DownExpand Up@@ -105,6 +118,36 @@ impl Notification {
self
}

pub fn has_preset_icon(mut self, show_icon: bool) -> Notification {
self.preset_icon = show_icon;
self
}

pub fn set_title(mut self, title: &str) -> Notification {
self.title = Some(title.into());
self
}

pub fn set_modal_show_interval(mut self, interval: i64) -> Notification {
self.modal_show_interval = interval;
self
}

pub fn set_notification_show_interval(mut self, interval: i64) -> Notification {
self.notification_show_interval = interval;
self
}

pub fn has_modal(mut self, modal: bool) -> Notification {
self.modal = modal;
self
}

pub fn set_trigger_modal(mut self, trigger_modal: bool) -> Notification {
self.trigger_modal = trigger_modal;
self
}

pub fn is_alert(level: &NotificationLevel) -> bool {
match level {
NotificationLevel::Level1 | NotificationLevel::Level2 | NotificationLevel::Level3 => true,
Expand DownExpand Up@@ -191,15 +234,6 @@ impl Notification {
match notification.level {
NotificationLevel::ProductHigh => notification.level == desired_level && notification.viewed == false,
NotificationLevel::ProductMedium => {
println!(
"{} == {} && {:?} == {:?} && {} == {}",
notification.level,
desired_level,
notification.deployment,
deployment_id.clone(),
notification.viewed,
false
);
notification.level == desired_level
&& notification.deployment == deployment_id
&& notification.viewed == false
Expand DownExpand Up@@ -317,21 +351,39 @@ pub async fn playground(cluster: &Cluster) -> Result<ResponseOk, Error> {
pub fn remove_banner(id: String, notification_type: String, cookies: &CookieJar<'_>, context: &Cluster) -> ResponseOk {
let mut viewed = Notifications::get_viewed(cookies);

viewed.push(id);
viewed.push(NotificationCookie {
id: id.clone(),
time_viewed: Some(chrono::Utc::now()),
time_modal_viewed: None,
});
Notifications::update_viewed(&viewed, cookies);

let notification = match context.notifications.as_ref() {
Some(notifications) => {
if notification_type == "alert" {
notifications
.into_iter()
.filter(|n: &&Notification| -> bool { Notification::is_alert(&n.level) && !viewed.contains(&n.id) })
.filter(|n: &&Notification| -> bool {
Notification::is_alert(&n.level)
&& !viewed
.clone()
.into_iter()
.map(|x| x.id)
.collect::<Vec<String>>()
.contains(&n.id)
})
.next()
} else if notification_type == "feature" {
notifications
.into_iter()
.filter(|n: &&Notification| -> bool {
Notification::is_feature(&n.level) && !viewed.contains(&n.id)
Notification::is_feature(&n.level)
&& !viewed
.clone()
.into_iter()
.map(|x| x.id)
.collect::<Vec<String>>()
.contains(&n.id)
})
.next()
} else {
Expand All@@ -358,7 +410,11 @@ pub fn remove_banner_product(
) -> Result<Response, Error> {
let mut all_viewed = Notifications::get_viewed(cookies);

all_viewed.push(id.clone());
all_viewed.push(NotificationCookie {
id: id.clone(),
time_viewed: Some(chrono::Utc::now()),
time_modal_viewed: None,
});
Notifications::update_viewed(&all_viewed, cookies);

// Get the notification that triggered this call.
Expand DownExpand Up@@ -402,17 +458,16 @@ pub fn remove_banner_product(
return Ok(Response::turbo_stream(turbo_stream));
}

pub fn routes() -> Vec<Route> {
routes![
dashboard,
remove_banner,
playground,
serverless_models_turboframe,
serverless_pricing_turboframe,
remove_banner_product
]
}

pub async fn migrate(pool: &PgPool) -> anyhow::Result<()> {
Ok(sqlx::migrate!("./migrations").run(pool).await?)
}
// Update cookie to inidicate the user has viewed the modal.
// #[get("/notifications/product/modal/remove_modal?<id>&<deployment_id>")]
// pub fn remove_modal_product(
// id: String,
// deployment_id: Option<String>,
// cookies: &CookieJar<'_>,
// context: &Cluster,
// ) {
// let mut all_viewed = Notifications::get_viewed(cookies);

// all_viewed.push(NotificationCookie{id: id.clone(), time_viewed: None, time_modal_viewed: Some(chrono::Utc::now())});
// Notifications::update_viewed(&all_viewed, cookies);
// }
1 change: 1 addition & 0 deletionspgml-dashboard/src/templates/mod.rs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ pub use crate::components::{self, cms::index_link::IndexLink, NavLink, StaticNav
use crate::{Notification, NotificationLevel};
use components::notifications::marketing::{AlertBanner, FeatureBanner};
use components::notifications::product::ProductBanner;
use rocket::http::CookieJar;

use crate::models::Cluster;
use sailfish::TemplateOnce;
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp