Skip to content

Commit 847e8c5

Browse files
committed
refactor main and lib into new mods
1 parent f2c7cb8 commit 847e8c5

File tree

24 files changed

+1157
-1142
lines changed

24 files changed

+1157
-1142
lines changed

pgml-dashboard/src/catchers.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use rocket::{catch, http::Status, request::Request, response::Redirect};
2+
3+
use crate::responses::{self, BadRequest, Response};
4+
5+
#[catch(403)]
6+
pub async fn not_authorized_catcher(_status: Status, _request: &Request<'_>) -> Redirect {
7+
Redirect::to("/login")
8+
}
9+
10+
#[catch(404)]
11+
pub async fn not_found_handler(_status: Status, _request: &Request<'_>) -> Response {
12+
Response::not_found()
13+
}
14+
15+
#[catch(default)]
16+
pub async fn error_catcher(status: Status, request: &Request<'_>) -> Result<BadRequest, responses::Error> {
17+
Err(responses::Error(anyhow::anyhow!(
18+
"{} {}\n{:?}",
19+
status.code,
20+
status.reason().unwrap(),
21+
request
22+
)))
23+
}

pgml-dashboard/src/components/inputs/radio/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct RadioOption {
1616
impl RadioOption {
1717
pub fn new(label: Component, value: impl ToString) -> Self {
1818
RadioOption {
19-
label: label,
19+
label,
2020
value: value.to_string(),
2121
checked: false,
2222
actions: StimulusActions::default(),

pgml-dashboard/src/components/layouts/marketing/base/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::components::layouts::Head;
22
use crate::components::notifications::marketing::AlertBanner;
33
use crate::guards::Cluster;
44
use crate::models::User;
5-
use crate::Notification;
5+
use crate::notifications::Notification;
66
use pgml_components::component;
77
use sailfish::TemplateOnce;
88
use std::fmt;

pgml-dashboard/src/components/navigation/toc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::docs::TocLink;
1+
use crate::templates::docs::TocLink;
22
use pgml_components::component;
33
use sailfish::TemplateOnce;
44

pgml-dashboard/src/components/notifications/marketing/alert_banner/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::Notification;
21
use pgml_components::component;
32
use sailfish::TemplateOnce;
43

4+
use crate::notifications::Notification;
5+
56
#[derive(TemplateOnce, Default, Clone)]
67
#[template(path = "notifications/marketing/alert_banner/template.html")]
78
pub struct AlertBanner {
Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
<% use crate::NotificationLevel; %>
2-
<turbo-frame id="notifications-banner" class="position-relative d-block">
3-
<% if notification.is_some() {%>
4-
<% let notification = notification.unwrap(); %>
5-
<div data-controller="notifications-marketing-alert-banner">
6-
<div class="<%- notification.level.to_string() %> W-100">
7-
<div class="banner d-flex container p-1">
8-
<div 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">
9-
<div class="mx-3 overflow-hidden" style="max-width: 80%;">
10-
<p class="m-0 text-center"><%- notification.message %></p>
1+
<% use crate::notifications::NotificationLevel; %>
2+
<turbo-frame id="notifications-banner" class="position-relative d-block">
3+
<% if notification.is_some() {%>
4+
<% let notification=notification.unwrap(); %>
5+
<div data-controller="notifications-marketing-alert-banner">
6+
<div class="<%- notification.level.to_string() %> W-100">
7+
<div class="banner d-flex container p-1">
8+
<div
9+
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">
10+
<div class="mx-3 overflow-hidden" style="max-width: 80%;">
11+
<p class="m-0 text-center"><%- notification.message %></p>
12+
</div>
13+
</div>
14+
15+
<% if notification.dismissible && notification.level !=NotificationLevel::Level3 {%>
16+
<a class="w-0 overflow-visible d-flex align-items-center" style="right: 4vw"
17+
href="/dashboard/notifications/remove_banner?id=<%- notification.id%>&notification_type=alert">
18+
<span
19+
class="material-symbols-outlined <% if notification.level == NotificationLevel::Level2 {%>close-light<% } else {%>close-dark<% } %>">
20+
close
21+
</span></a>
22+
<% } %>
23+
</div>
1124
</div>
1225
</div>
13-
14-
<% if notification.dismissible && notification.level != NotificationLevel::Level3 {%>
15-
<a class="w-0 overflow-visible d-flex align-items-center" style="right: 4vw" href="/dashboard/notifications/remove_banner?id=<%- notification.id%>&notification_type=alert">
16-
<span class="material-symbols-outlined <% if notification.level == NotificationLevel::Level2 {%>close-light<% } else {%>close-dark<% } %>">
17-
close
18-
</span></a>
1926
<% } %>
20-
</div>
21-
</div>
22-
</div>
23-
<% } %>
24-
</turbo-frame>
27+
</turbo-frame>

pgml-dashboard/src/components/notifications/marketing/feature_banner/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::Notification;
21
use pgml_components::component;
32
use sailfish::TemplateOnce;
43

4+
use crate::notifications::Notification;
5+
56
#[derive(TemplateOnce, Default, Clone)]
67
#[template(path = "notifications/marketing/feature_banner/template.html")]
78
pub struct FeatureBanner {
Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
1-
<% use crate::NotificationLevel; %>
2-
<turbo-frame id="marketing-notifications-banner-feature" class="position-relative z-1">
3-
<% if notification.is_some() {%>
4-
<% let notification = notification.unwrap(); %>
5-
<div data-controller="notifications-marketing-feature-banner">
1+
<% use crate::notifications::NotificationLevel; %>
2+
<turbo-frame id="marketing-notifications-banner-feature" class="position-relative z-1">
3+
<% if notification.is_some() {%>
4+
<% let notification=notification.unwrap(); %>
5+
<div data-controller="notifications-marketing-feature-banner">
66

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

10-
<% let content = format!(
11-
r#"
12-
<{} 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">
13-
<div class="px-3 py-3 py-sm-0 overflow-hidden">
14-
<p class="m-0 text-center">{} {}</p>
15-
</div>
16-
</{}>
17-
"#,
18-
if notification.link.is_some() { format!(r#"a href="{}" data-turbo="false" "#, notification.link.clone().unwrap()) } else { "div".to_string() },
19-
if notification.link.is_some() { "btn btn-tertiary p-0 goto-arrow-hover-trigger" } else { "" },
20-
notification.message,
21-
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 { "" },
22-
if notification.link.is_some() { "a" } else { "div" },
23-
); %>
24-
25-
<%- content %>
11+
<% let content=format!( r#" <{}
12+
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">
13+
<div class="px-3 py-3 py-sm-0 overflow-hidden">
14+
<p class="m-0 text-center">{} {}</p>
15+
</div>
16+
</{}>
17+
"#,
18+
if notification.link.is_some() { format!(r#"a href="{}" data-turbo="false" "#,
19+
notification.link.clone().unwrap()) } else { "div".to_string() },
20+
if notification.link.is_some() { "btn btn-tertiary p-0 goto-arrow-hover-trigger" } else { "" },
21+
notification.message,
22+
if notification.link.is_some() { r#"<span
23+
class="material-symbols-outlined more-info position-relative goto-arrow-shift-animation"
24+
style="top: 2px;">arrow_forward</span>"# } else { "" },
25+
if notification.link.is_some() { "a" } else { "div" },
26+
); %>
27+
28+
<%- content %>
2629

27-
<% if notification.dismissible {%>
28-
<a class="w-0 btn btn-tertiary overflow-visible d-flex align-items-start p-2" style="height: fit-content" href="/dashboard/notifications/remove_banner?id=<%- notification.id%>&notification_type=feature">
29-
<span class="material-symbols-outlined close">
30-
close
31-
</span></a>
30+
<% if notification.dismissible {%>
31+
<a class="w-0 btn btn-tertiary overflow-visible d-flex align-items-start p-2"
32+
style="height: fit-content"
33+
href="/dashboard/notifications/remove_banner?id=<%- notification.id%>&notification_type=feature">
34+
<span class="material-symbols-outlined close">
35+
close
36+
</span></a>
37+
<% } %>
38+
</div>
39+
</div>
40+
</div>
3241
<% } %>
33-
</div>
34-
</div>
35-
</div>
36-
<% } %>
37-
</turbo-frame>
42+
</turbo-frame>

pgml-dashboard/src/components/notifications/product/product_banner/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use crate::utils::random_string;
2-
use crate::{Notification, NotificationLevel};
1+
use crate::{
2+
notifications::{Notification, NotificationLevel},
3+
utils::random_string,
4+
};
35
use pgml_components::component;
46
use sailfish::TemplateOnce;
57

Lines changed: 78 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,84 @@
1-
<%
2-
use crate::NotificationLevel;
3-
use crate::components::Modal;
4-
%>
1+
<% use crate::notifications::NotificationLevel; use crate::components::Modal; %>
52

6-
<div class="<%- location_id %>">
7-
<% if notification.is_some() {%>
8-
<%
9-
let notification = notification.unwrap();
10-
let modal_id = format!("modal-{}", notification.id);
11-
let show_modal = notification.trigger_modal && show_modal_on_load;
12-
%>
13-
<div
14-
data-controller="notifications-product-product-banner"
15-
<% if show_modal {%>
16-
data-action="
17-
hide.bs.modal->notifications-product-product-banner#updateModalCookie
18-
turbo:load@window->notifications-product-product-banner#showModal
19-
"
20-
<% } %>
21-
data-notifications-product-product-banner-notification-id-value="<%- notification.id %>"
22-
data-notifications-product-product-banner-modal-value="<%- modal_id %>">
23-
<%
24-
let icon = {
25-
if notification.level == NotificationLevel::ProductHigh {
26-
"error"
27-
} else if notification.level == NotificationLevel::ProductMedium {
28-
"notifications"
29-
} else {
30-
"lightbulb"
31-
}
32-
};
33-
%>
34-
<div class="rounded-2 W-100 <%- notification.level.to_string() %>">
35-
<div class="banner d-flex container">
36-
<%
37-
let title = if notification.title.is_some() {
38-
format!(r#"<p class="title m-0">{}</p>"#, notification.title.clone().unwrap())} else {String::from("")};
39-
%>
40-
41-
<% let content = format!(
42-
r#"
43-
<{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">
44-
<div class="px-3 py-3 py-sm-1 overflow-hidden text-container d-flex flex-row gap-2">
45-
<span class="material-symbols-outlined {display} preset-icon">{icon}</span>
46-
<div>
47-
{title}
48-
<p class="m-0">{message}</p>
49-
</div>
50-
</div>
51-
</{close_tag}>
52-
"#,
53-
if notification.link.is_some() { "btn btn-tertiary p-0" } else { "" },
54-
display = if notification.preset_icon { "d-block" } else { "d-none" },
55-
icon = icon,
56-
title = title,
57-
message = notification.message,
58-
open_tag = if notification.link.is_some() { format!(r#"a href="{}" data-turbo="false" "#, notification.link.clone().unwrap()) } else { "div".to_string() },
59-
close_tag = if notification.link.is_some() { "a" } else { "div" },
60-
); %>
61-
62-
<%- content %>
63-
64-
<% if notification.dismissible {%>
65-
<a class="w-0 btn btn-tertiary overflow-visible d-flex align-items-start p-2" style="height: fit-content" href="<%- url %>" >
66-
<span class="material-symbols-outlined close">
67-
close
68-
</span>
69-
</a>
70-
<% } %>
71-
</div>
72-
<% if show_modal {%>
73-
<%
74-
let title = if notification.title.is_some() {
75-
format!(r#"<h6 data-action="click->notifications-product-product-banner#followModalLink">{}</h6>"#, notification.title.unwrap())} else {String::from("")};
76-
%>
3+
<div class="<%- location_id %>">
4+
<% if notification.is_some() {%>
5+
<% let notification=notification.unwrap(); let modal_id=format!("modal-{}", notification.id); let
6+
show_modal=notification.trigger_modal && show_modal_on_load; %>
7+
<div data-controller="notifications-product-product-banner" <% if show_modal {%>
8+
data-action="
9+
hide.bs.modal->notifications-product-product-banner#updateModalCookie
10+
turbo:load@window->notifications-product-product-banner#showModal
11+
"
12+
<% } %>
13+
data-notifications-product-product-banner-notification-id-value="<%- notification.id %>"
14+
data-notifications-product-product-banner-modal-value="<%- modal_id %>">
15+
<% let icon={ if notification.level==NotificationLevel::ProductHigh { "error" } else if
16+
notification.level==NotificationLevel::ProductMedium { "notifications" } else { "lightbulb" } }; %>
17+
<div class="rounded-2 W-100 <%- notification.level.to_string() %>">
18+
<div class="banner d-flex container">
19+
<% let title=if notification.title.is_some() { format!(r#"<p class="title m-0">{}</p>"#,
20+
notification.title.clone().unwrap())} else {String::from("")};
21+
%>
7722

78-
<%+ Modal::new(format!(r#"
79-
<div class="d-flex flex-column gap-4 align-items-center text-center">
80-
<a class="btn btn-tertiary position-absolute top-0 end-0" data-action="click->notifications-product-product-banner#hideModal"><span class="material-symbols-outlined close m-2">close</span></a>
81-
<span class="material-symbols-outlined {display} preset-icon" style="font-size: 44px">{icon}</span>
82-
{title}
83-
<p class="m-0" data-action="click->notifications-product-product-banner#followModalLink">{message}</p>
23+
<% let content=format!( r#" <{open_tag}
24+
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">
25+
<div class="px-3 py-3 py-sm-1 overflow-hidden text-container d-flex flex-row gap-2">
26+
<span class="material-symbols-outlined {display} preset-icon">{icon}</span>
27+
<div>
28+
{title}
29+
<p class="m-0">{message}</p>
30+
</div>
31+
</div>
32+
</{close_tag}>
33+
"#,
34+
if notification.link.is_some() { "btn btn-tertiary p-0" } else { "" },
35+
display = if notification.preset_icon { "d-block" } else { "d-none" },
36+
icon = icon,
37+
title = title,
38+
message = notification.message,
39+
open_tag = if notification.link.is_some() { format!(r#"a href="{}" data-turbo="false" "#,
40+
notification.link.clone().unwrap()) } else { "div".to_string() },
41+
close_tag = if notification.link.is_some() { "a" } else { "div" },
42+
); %>
43+
44+
<%- content %>
45+
46+
<% if notification.dismissible {%>
47+
<a class="w-0 btn btn-tertiary overflow-visible d-flex align-items-start p-2"
48+
style="height: fit-content" href="<%- url %>">
49+
<span class="material-symbols-outlined close">
50+
close
51+
</span>
52+
</a>
53+
<% } %>
54+
</div>
55+
<% if show_modal {%>
56+
<% let title=if notification.title.is_some() { format!(r#"<h6
57+
data-action="click->notifications-product-product-banner#followModalLink">{}</h6>"#,
58+
notification.title.unwrap())} else {String::from("")};
59+
%>
60+
61+
<%+ Modal::new(format!(r#" <div class="d-flex flex-column gap-4 align-items-center text-center">
62+
<a class="btn btn-tertiary position-absolute top-0 end-0"
63+
data-action="click->notifications-product-product-banner#hideModal"><span
64+
class="material-symbols-outlined close m-2">close</span></a>
65+
<span class="material-symbols-outlined {display} preset-icon"
66+
style="font-size: 44px">{icon}</span>
67+
{title}
68+
<p class="m-0" data-action="click->notifications-product-product-banner#followModalLink">
69+
{message}</p>
70+
</div>
71+
"#,
72+
display = if notification.preset_icon { "d-block" } else { "d-none" },
73+
icon = icon,
74+
title = title,
75+
message = notification.message
76+
)
77+
.into()).id(&modal_id)
78+
.set_static_backdrop(true) %>
79+
<% } %>
8480
</div>
85-
"#,
86-
display = if notification.preset_icon { "d-block" } else { "d-none" },
87-
icon = icon,
88-
title = title,
89-
message = notification.message
90-
)
91-
.into()).id(&modal_id)
92-
.set_static_backdrop(true) %>
93-
<% } %>
94-
</div>
9581
</div>
9682

9783
<% } %>
98-
</div>
84+
</div>

pgml-dashboard/src/components/pages/article/index/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::components::cards::blog::ArticlePreview;
55
use crate::components::notifications::marketing::FeatureBanner;
66
use crate::components::sections::related_articles::RelatedArticles;
77
use crate::guards::Cluster;
8-
use crate::Notification;
8+
use crate::notifications::Notification;
99
use pgml_components::component;
1010
use sailfish::TemplateOnce;
1111

0 commit comments

Comments
 (0)