From f2c7cb8a253f92f7cc1faf2bef58c1c645f16d0d Mon Sep 17 00:00:00 2001 From: Kevin Zimmerman <4733573+kczimm@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:15:41 -0500 Subject: [PATCH 1/3] remove unused deps --- pgml-dashboard/Cargo.lock | 308 +------------------------------------- pgml-dashboard/Cargo.toml | 7 +- 2 files changed, 8 insertions(+), 307 deletions(-) diff --git a/pgml-dashboard/Cargo.lock b/pgml-dashboard/Cargo.lock index 0acfe1334..7dfaccf6e 100644 --- a/pgml-dashboard/Cargo.lock +++ b/pgml-dashboard/Cargo.lock @@ -52,17 +52,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "ahash" version = "0.8.7" @@ -76,15 +65,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "aho-corasick" -version = "0.7.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" -dependencies = [ - "memchr", -] - [[package]] name = "aho-corasick" version = "1.1.2" @@ -173,12 +153,6 @@ dependencies = [ "backtrace", ] -[[package]] -name = "arc-swap" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" - [[package]] name = "async-stream" version = "0.3.5" @@ -383,15 +357,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitpacking" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8c7d2ac73c167c06af4a5f37e6e59d84148d57ccbe4480b76f0273eefea82d7" -dependencies = [ - "crunchy", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -436,12 +401,6 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" -[[package]] -name = "census" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fafee10a5dd1cffcb5cc560e0d0df8803d7355a2b12272e3557dee57314cb6e" - [[package]] name = "cfg-if" version = "1.0.0" @@ -532,15 +491,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "combine" -version = "4.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" -dependencies = [ - "memchr", -] - [[package]] name = "comrak" version = "0.17.1" @@ -769,12 +719,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "crypto-common" version = "0.1.6" @@ -1033,12 +977,6 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" -[[package]] -name = "downcast-rs" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" - [[package]] name = "dtoa" version = "1.0.9" @@ -1153,17 +1091,6 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" -[[package]] -name = "fail" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe5e43d0f78a42ad591453aedb1d7ae631ce7ee445c7643691055a9ed8d3b01c" -dependencies = [ - "log", - "once_cell", - "rand", -] - [[package]] name = "fallible-iterator" version = "0.2.0" @@ -1180,26 +1107,6 @@ dependencies = [ "regex", ] -[[package]] -name = "fastdivide" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25c7df09945d65ea8d70b3321547ed414bbc540aad5bac6883d021b970f35b04" - -[[package]] -name = "fastfield_codecs" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374a3a53c1bd5fb31b10084229290eafb0a05f260ec90f1f726afffda4877a8a" -dependencies = [ - "fastdivide", - "itertools", - "log", - "ownedbytes", - "tantivy-bitpacker", - "tantivy-common", -] - [[package]] name = "fastrand" version = "2.0.0" @@ -1295,16 +1202,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "futf" version = "0.1.5" @@ -1513,9 +1410,6 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -dependencies = [ - "ahash 0.7.6", -] [[package]] name = "hashbrown" @@ -1523,7 +1417,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" dependencies = [ - "ahash 0.8.7", + "ahash", "allocator-api2", ] @@ -1622,12 +1516,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "htmlescape" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9025058dae765dee5070ec375f591e2ba14638c63feff74f13805a72e523163" - [[package]] name = "http" version = "0.2.9" @@ -1840,9 +1728,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", ] [[package]] @@ -1912,12 +1797,6 @@ dependencies = [ "spin 0.5.2", ] -[[package]] -name = "levenshtein_automata" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c2cdeb66e45e9f36bfad5bbdb4d2384e70936afbee843c6f6543f0c551ebb25" - [[package]] name = "libc" version = "0.2.147" @@ -1992,7 +1871,6 @@ checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" dependencies = [ "cfg-if", "generator", - "pin-utils", "scoped-tls", "serde", "serde_json", @@ -2019,21 +1897,6 @@ dependencies = [ "weezl", ] -[[package]] -name = "lru" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999beba7b6e8345721bd280141ed958096a2e4abdf74f67ff4ce49b4b54e47a" -dependencies = [ - "hashbrown 0.12.3", -] - -[[package]] -name = "lz4_flex" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a8cbbb2831780bc3b9c15a41f5b49222ef756b6730a95f3decfdd15903eb5a3" - [[package]] name = "mac" version = "0.1.1" @@ -2099,31 +1962,12 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" -[[package]] -name = "measure_time" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56220900f1a0923789ecd6bf25fbae8af3b2f1ff3e9e297fc9b6b8674dd4d852" -dependencies = [ - "instant", - "log", -] - [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memmap2" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" -dependencies = [ - "libc", -] - [[package]] name = "memoffset" version = "0.9.0" @@ -2186,15 +2030,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "murmurhash32" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d736ff882f0e85fe9689fb23db229616c4c00aee2b3ac282f666d8f20eb25d4a" -dependencies = [ - "byteorder", -] - [[package]] name = "native-tls" version = "0.2.11" @@ -2349,15 +2184,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "oneshot" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc22d22931513428ea6cc089e942d38600e3d00976eef8c86de6b8a3aadec6eb" -dependencies = [ - "loom", -] - [[package]] name = "onig" version = "6.4.0" @@ -2457,15 +2283,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" -[[package]] -name = "ownedbytes" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e957eaa64a299f39755416e5b3128c505e9d63a91d0453771ad2ccd3907f8db" -dependencies = [ - "stable_deref_trait", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -2579,9 +2396,7 @@ dependencies = [ name = "pgml-dashboard" version = "2.7.12" dependencies = [ - "aho-corasick 0.7.20", "anyhow", - "base64 0.21.4", "chrono", "comrak", "console-subscriber", @@ -2615,7 +2430,6 @@ dependencies = [ "serde_json", "sqlparser", "sqlx", - "tantivy", "time", "tokio", "url", @@ -3034,7 +2848,7 @@ version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ - "aho-corasick 1.1.2", + "aho-corasick", "memchr", "regex-automata 0.3.7", "regex-syntax 0.7.5", @@ -3055,7 +2869,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" dependencies = [ - "aho-corasick 1.1.2", + "aho-corasick", "memchr", "regex-syntax 0.7.5", ] @@ -3247,28 +3061,12 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rust-stemmers" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e46a2036019fdb888131db7a4c847a1063a7493f971ed94ea82c67eada63ca54" -dependencies = [ - "serde", - "serde_derive", -] - [[package]] name = "rustc-demangle" version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc_version" version = "0.4.0" @@ -3427,7 +3225,7 @@ version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c95a930e03325234c18c7071fd2b60118307e025d6fff3e12745ffbf63a3d29c" dependencies = [ - "ahash 0.8.7", + "ahash", "cssparser", "ego-tree", "getopts", @@ -3957,7 +3755,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d84b0a3c3739e220d94b3239fd69fb1f74bc36e16643423bd99de3b43c21bfbd" dependencies = [ - "ahash 0.8.7", + "ahash", "atoi", "bigdecimal", "byteorder", @@ -4301,96 +4099,6 @@ dependencies = [ "libc", ] -[[package]] -name = "tantivy" -version = "0.19.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb26a6b22c84d8be41d99a14016d6f04d30d8d31a2ea411a8ab553af5cc490d" -dependencies = [ - "aho-corasick 0.7.20", - "arc-swap", - "async-trait", - "base64 0.13.1", - "bitpacking", - "byteorder", - "census", - "crc32fast", - "crossbeam-channel", - "downcast-rs", - "fail", - "fastdivide", - "fastfield_codecs", - "fs2", - "htmlescape", - "itertools", - "levenshtein_automata", - "log", - "lru", - "lz4_flex", - "measure_time", - "memmap2", - "murmurhash32", - "num_cpus", - "once_cell", - "oneshot", - "ownedbytes", - "rayon", - "regex", - "rust-stemmers", - "rustc-hash", - "serde", - "serde_json", - "smallvec", - "stable_deref_trait", - "tantivy-bitpacker", - "tantivy-common", - "tantivy-fst", - "tantivy-query-grammar", - "tempfile", - "thiserror", - "time", - "uuid", - "winapi", -] - -[[package]] -name = "tantivy-bitpacker" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e71a0c95b82d4292b097a09b989a6380d28c3a86800c841a2d03bae1fc8b9fa6" - -[[package]] -name = "tantivy-common" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14fef4182bb60df9a4b92cd8ecab39ba2e50a05542934af17eef1f49660705cb" -dependencies = [ - "byteorder", - "ownedbytes", -] - -[[package]] -name = "tantivy-fst" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc3c506b1a8443a3a65352df6382a1fb6a7afe1a02e871cee0d25e2c3d5f3944" -dependencies = [ - "byteorder", - "regex-syntax 0.6.29", - "utf8-ranges", -] - -[[package]] -name = "tantivy-query-grammar" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343e3ada4c1c480953f6960f8a21ce9c76611480ffdd4f4e230fdddce0fc5331" -dependencies = [ - "combine", - "once_cell", - "regex", -] - [[package]] name = "tempfile" version = "3.7.0" @@ -4965,12 +4673,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "utf8-ranges" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcfc827f90e53a02eaef5e535ee14266c1d569214c6aa70133a624d8a3164ba" - [[package]] name = "utf8parse" version = "0.2.1" diff --git a/pgml-dashboard/Cargo.toml b/pgml-dashboard/Cargo.toml index 1c1b7aa8a..6734f3134 100644 --- a/pgml-dashboard/Cargo.toml +++ b/pgml-dashboard/Cargo.toml @@ -12,8 +12,6 @@ default-run = "pgml-dashboard" [dependencies] anyhow = "1" -aho-corasick = "0.7" -base64 = "0.21" comrak = "0.17" chrono = { version = "0.4", features = ["serde"] } csv-async = "1" @@ -37,7 +35,6 @@ regex = "1.9" reqwest = { version = "0.11", features = ["json"] } rocket = { git = "https://github.com/SergioBenitez/Rocket", features = ["secrets", "json"] } sailfish = "0.8.0" # 0.8.1 has breaking changes -scraper = "0.17" serde = "1" sentry = "0.31" sentry-log = "0.31" @@ -45,7 +42,6 @@ sentry-anyhow = "0.31" serde_json = "1" sqlparser = "0.38" sqlx = { version = "0.7.3", features = [ "runtime-tokio-rustls", "postgres", "json", "migrate", "time", "uuid", "bigdecimal"] } -tantivy = "0.19" time = "0.3" tokio = { version = "1", features = ["full"] } url = "2.4" @@ -54,5 +50,8 @@ zoomies = { git="https://github.com/HyperparamAI/zoomies.git", branch="master" } ws = { package = "rocket_ws", git = "https://github.com/SergioBenitez/Rocket" } futures = "0.3.29" +[dev-dependencies] +scraper = "0.17" + [build-dependencies] glob = "*" From 847e8c57d58ee83161fcfe503e448c6f5273ec1b Mon Sep 17 00:00:00 2001 From: Kevin Zimmerman <4733573+kczimm@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:56:15 -0500 Subject: [PATCH 2/3] refactor main and lib into new mods --- pgml-dashboard/src/catchers.rs | 23 + .../src/components/inputs/radio/mod.rs | 2 +- .../components/layouts/marketing/base/mod.rs | 2 +- .../src/components/navigation/toc/mod.rs | 2 +- .../marketing/alert_banner/mod.rs | 3 +- .../marketing/alert_banner/template.html | 45 +- .../marketing/feature_banner/mod.rs | 3 +- .../marketing/feature_banner/template.html | 71 +- .../product/product_banner/mod.rs | 6 +- .../product/product_banner/template.html | 170 ++-- .../src/components/pages/article/index/mod.rs | 2 +- .../components/pages/blog/landing_page/mod.rs | 2 +- .../pages/careers/landing_page/mod.rs | 2 +- .../src/components/pages/docs/article/mod.rs | 4 +- .../components/pages/docs/landing_page/mod.rs | 2 +- .../src/components/pagination/mod.rs | 2 +- pgml-dashboard/src/context.rs | 15 + pgml-dashboard/src/guards.rs | 4 +- pgml-dashboard/src/lib.rs | 943 +++++------------- pgml-dashboard/src/main.rs | 452 ++++----- pgml-dashboard/src/notifications.rs | 216 ++++ pgml-dashboard/src/routes.rs | 282 ++++++ pgml-dashboard/src/sentry.rs | 44 + pgml-dashboard/src/templates/mod.rs | 2 +- 24 files changed, 1157 insertions(+), 1142 deletions(-) create mode 100644 pgml-dashboard/src/catchers.rs create mode 100644 pgml-dashboard/src/context.rs create mode 100644 pgml-dashboard/src/notifications.rs create mode 100644 pgml-dashboard/src/routes.rs create mode 100644 pgml-dashboard/src/sentry.rs diff --git a/pgml-dashboard/src/catchers.rs b/pgml-dashboard/src/catchers.rs new file mode 100644 index 000000000..05da2ea5b --- /dev/null +++ b/pgml-dashboard/src/catchers.rs @@ -0,0 +1,23 @@ +use rocket::{catch, http::Status, request::Request, response::Redirect}; + +use crate::responses::{self, BadRequest, Response}; + +#[catch(403)] +pub async fn not_authorized_catcher(_status: Status, _request: &Request<'_>) -> Redirect { + Redirect::to("/login") +} + +#[catch(404)] +pub async fn not_found_handler(_status: Status, _request: &Request<'_>) -> Response { + Response::not_found() +} + +#[catch(default)] +pub async fn error_catcher(status: Status, request: &Request<'_>) -> Result { + Err(responses::Error(anyhow::anyhow!( + "{} {}\n{:?}", + status.code, + status.reason().unwrap(), + request + ))) +} diff --git a/pgml-dashboard/src/components/inputs/radio/mod.rs b/pgml-dashboard/src/components/inputs/radio/mod.rs index 9816d07fc..25bd7abc1 100644 --- a/pgml-dashboard/src/components/inputs/radio/mod.rs +++ b/pgml-dashboard/src/components/inputs/radio/mod.rs @@ -16,7 +16,7 @@ pub struct RadioOption { impl RadioOption { pub fn new(label: Component, value: impl ToString) -> Self { RadioOption { - label: label, + label, value: value.to_string(), checked: false, actions: StimulusActions::default(), diff --git a/pgml-dashboard/src/components/layouts/marketing/base/mod.rs b/pgml-dashboard/src/components/layouts/marketing/base/mod.rs index 5d1ee0d36..ea105bbaf 100644 --- a/pgml-dashboard/src/components/layouts/marketing/base/mod.rs +++ b/pgml-dashboard/src/components/layouts/marketing/base/mod.rs @@ -2,7 +2,7 @@ use crate::components::layouts::Head; use crate::components::notifications::marketing::AlertBanner; use crate::guards::Cluster; use crate::models::User; -use crate::Notification; +use crate::notifications::Notification; use pgml_components::component; use sailfish::TemplateOnce; use std::fmt; diff --git a/pgml-dashboard/src/components/navigation/toc/mod.rs b/pgml-dashboard/src/components/navigation/toc/mod.rs index 2ebf6e158..969dfa528 100644 --- a/pgml-dashboard/src/components/navigation/toc/mod.rs +++ b/pgml-dashboard/src/components/navigation/toc/mod.rs @@ -1,4 +1,4 @@ -use crate::docs::TocLink; +use crate::templates::docs::TocLink; use pgml_components::component; use sailfish::TemplateOnce; diff --git a/pgml-dashboard/src/components/notifications/marketing/alert_banner/mod.rs b/pgml-dashboard/src/components/notifications/marketing/alert_banner/mod.rs index bf7a1612a..7ff89b320 100644 --- a/pgml-dashboard/src/components/notifications/marketing/alert_banner/mod.rs +++ b/pgml-dashboard/src/components/notifications/marketing/alert_banner/mod.rs @@ -1,7 +1,8 @@ -use crate::Notification; use pgml_components::component; use sailfish::TemplateOnce; +use crate::notifications::Notification; + #[derive(TemplateOnce, Default, Clone)] #[template(path = "notifications/marketing/alert_banner/template.html")] pub struct AlertBanner { diff --git a/pgml-dashboard/src/components/notifications/marketing/alert_banner/template.html b/pgml-dashboard/src/components/notifications/marketing/alert_banner/template.html index 5724f2884..22b8d6c5d 100644 --- a/pgml-dashboard/src/components/notifications/marketing/alert_banner/template.html +++ b/pgml-dashboard/src/components/notifications/marketing/alert_banner/template.html @@ -1,24 +1,27 @@ -<% use crate::NotificationLevel; %> - - <% if notification.is_some() {%> - <% let notification = notification.unwrap(); %> -
-
- - <% } %> - + \ No newline at end of file diff --git a/pgml-dashboard/src/components/notifications/marketing/feature_banner/mod.rs b/pgml-dashboard/src/components/notifications/marketing/feature_banner/mod.rs index 34d136869..566974517 100644 --- a/pgml-dashboard/src/components/notifications/marketing/feature_banner/mod.rs +++ b/pgml-dashboard/src/components/notifications/marketing/feature_banner/mod.rs @@ -1,7 +1,8 @@ -use crate::Notification; use pgml_components::component; use sailfish::TemplateOnce; +use crate::notifications::Notification; + #[derive(TemplateOnce, Default, Clone)] #[template(path = "notifications/marketing/feature_banner/template.html")] pub struct FeatureBanner { diff --git a/pgml-dashboard/src/components/notifications/marketing/feature_banner/template.html b/pgml-dashboard/src/components/notifications/marketing/feature_banner/template.html index b0d9b0225..f4ba6e7d9 100644 --- a/pgml-dashboard/src/components/notifications/marketing/feature_banner/template.html +++ b/pgml-dashboard/src/components/notifications/marketing/feature_banner/template.html @@ -1,37 +1,42 @@ -<% use crate::NotificationLevel; %> - - <% if notification.is_some() {%> - <% let notification = notification.unwrap(); %> -
+<% use crate::notifications::NotificationLevel; %> + + <% if notification.is_some() {%> + <% let notification=notification.unwrap(); %> +
-
- <% } %> -
-
-
- <% } %> -
+ \ No newline at end of file diff --git a/pgml-dashboard/src/components/notifications/product/product_banner/mod.rs b/pgml-dashboard/src/components/notifications/product/product_banner/mod.rs index aecede1ab..d5b5a4962 100644 --- a/pgml-dashboard/src/components/notifications/product/product_banner/mod.rs +++ b/pgml-dashboard/src/components/notifications/product/product_banner/mod.rs @@ -1,5 +1,7 @@ -use crate::utils::random_string; -use crate::{Notification, NotificationLevel}; +use crate::{ + notifications::{Notification, NotificationLevel}, + utils::random_string, +}; use pgml_components::component; use sailfish::TemplateOnce; diff --git a/pgml-dashboard/src/components/notifications/product/product_banner/template.html b/pgml-dashboard/src/components/notifications/product/product_banner/template.html index 152ce347a..3c5493688 100644 --- a/pgml-dashboard/src/components/notifications/product/product_banner/template.html +++ b/pgml-dashboard/src/components/notifications/product/product_banner/template.html @@ -1,98 +1,84 @@ -<% - use crate::NotificationLevel; - use crate::components::Modal; -%> +<% use crate::notifications::NotificationLevel; use crate::components::Modal; %> -
- <% if notification.is_some() {%> - <% - let notification = notification.unwrap(); - let modal_id = format!("modal-{}", notification.id); - let show_modal = notification.trigger_modal && show_modal_on_load; - %> -
- data-action=" - hide.bs.modal->notifications-product-product-banner#updateModalCookie - turbo:load@window->notifications-product-product-banner#showModal - " - <% } %> - data-notifications-product-product-banner-notification-id-value="<%- notification.id %>" - data-notifications-product-product-banner-modal-value="<%- modal_id %>"> - <% - let icon = { - if notification.level == NotificationLevel::ProductHigh { - "error" - } else if notification.level == NotificationLevel::ProductMedium { - "notifications" - } else { - "lightbulb" - } - }; - %> -
- - <% if show_modal {%> - <% - let title = if notification.title.is_some() { - format!(r#"
{}
"#, notification.title.unwrap())} else {String::from("")}; - %> +
+ <% if notification.is_some() {%> + <% let notification=notification.unwrap(); let modal_id=format!("modal-{}", notification.id); let + show_modal=notification.trigger_modal && show_modal_on_load; %> +
+ data-action=" + hide.bs.modal->notifications-product-product-banner#updateModalCookie + turbo:load@window->notifications-product-product-banner#showModal + " + <% } %> + data-notifications-product-product-banner-notification-id-value="<%- notification.id %>" + data-notifications-product-product-banner-modal-value="<%- modal_id %>"> + <% let icon={ if notification.level==NotificationLevel::ProductHigh { "error" } else if + notification.level==NotificationLevel::ProductMedium { "notifications" } else { "lightbulb" } }; %> +
+ - "#, - display = if notification.preset_icon { "d-block" } else { "d-none" }, - icon = icon, - title = title, - message = notification.message - ) - .into()).id(&modal_id) - .set_static_backdrop(true) %> - <% } %> -
<% } %> -
+
\ No newline at end of file diff --git a/pgml-dashboard/src/components/pages/article/index/mod.rs b/pgml-dashboard/src/components/pages/article/index/mod.rs index 07350c35a..593ac4abf 100644 --- a/pgml-dashboard/src/components/pages/article/index/mod.rs +++ b/pgml-dashboard/src/components/pages/article/index/mod.rs @@ -5,7 +5,7 @@ use crate::components::cards::blog::ArticlePreview; use crate::components::notifications::marketing::FeatureBanner; use crate::components::sections::related_articles::RelatedArticles; use crate::guards::Cluster; -use crate::Notification; +use crate::notifications::Notification; use pgml_components::component; use sailfish::TemplateOnce; diff --git a/pgml-dashboard/src/components/pages/blog/landing_page/mod.rs b/pgml-dashboard/src/components/pages/blog/landing_page/mod.rs index 3b37769c0..3c95b021b 100644 --- a/pgml-dashboard/src/components/pages/blog/landing_page/mod.rs +++ b/pgml-dashboard/src/components/pages/blog/landing_page/mod.rs @@ -1,7 +1,7 @@ use crate::components::cards::blog::article_preview::DocMeta; use crate::components::notifications::marketing::FeatureBanner; use crate::guards::Cluster; -use crate::Notification; +use crate::notifications::Notification; use pgml_components::component; use sailfish::TemplateOnce; diff --git a/pgml-dashboard/src/components/pages/careers/landing_page/mod.rs b/pgml-dashboard/src/components/pages/careers/landing_page/mod.rs index 79ebf6f68..e7c556c54 100644 --- a/pgml-dashboard/src/components/pages/careers/landing_page/mod.rs +++ b/pgml-dashboard/src/components/pages/careers/landing_page/mod.rs @@ -1,7 +1,7 @@ use crate::api::cms::Collection; use crate::components::notifications::marketing::FeatureBanner; use crate::guards::Cluster; -use crate::Notification; +use crate::notifications::Notification; use pgml_components::component; use sailfish::TemplateOnce; diff --git a/pgml-dashboard/src/components/pages/docs/article/mod.rs b/pgml-dashboard/src/components/pages/docs/article/mod.rs index 454e90834..0ff27794b 100644 --- a/pgml-dashboard/src/components/pages/docs/article/mod.rs +++ b/pgml-dashboard/src/components/pages/docs/article/mod.rs @@ -1,7 +1,7 @@ use crate::components::notifications::marketing::FeatureBanner; -use crate::docs::TocLink; use crate::guards::Cluster; -use crate::Notification; +use crate::notifications::Notification; +use crate::templates::docs::TocLink; use pgml_components::component; use sailfish::TemplateOnce; diff --git a/pgml-dashboard/src/components/pages/docs/landing_page/mod.rs b/pgml-dashboard/src/components/pages/docs/landing_page/mod.rs index 05b429a41..1542a8ed0 100644 --- a/pgml-dashboard/src/components/pages/docs/landing_page/mod.rs +++ b/pgml-dashboard/src/components/pages/docs/landing_page/mod.rs @@ -2,7 +2,7 @@ use crate::api::cms::{Document, DOCS}; use crate::components::cms::IndexLink; use crate::components::notifications::marketing::FeatureBanner; use crate::guards::Cluster; -use crate::Notification; +use crate::notifications::Notification; use lazy_static::lazy_static; use pgml_components::component; use sailfish::TemplateOnce; diff --git a/pgml-dashboard/src/components/pagination/mod.rs b/pgml-dashboard/src/components/pagination/mod.rs index f82d3568a..c315c768b 100644 --- a/pgml-dashboard/src/components/pagination/mod.rs +++ b/pgml-dashboard/src/components/pagination/mod.rs @@ -16,7 +16,7 @@ impl Pagination { Pagination { count, timed: false, - identifier: identifier, + identifier, active_index: None, clickable: true, } diff --git a/pgml-dashboard/src/context.rs b/pgml-dashboard/src/context.rs new file mode 100644 index 000000000..81c6abbaf --- /dev/null +++ b/pgml-dashboard/src/context.rs @@ -0,0 +1,15 @@ +use crate::{models, templates::StaticNav}; + +/// This struct contains information specific to the cluster being displayed in the dashboard. +/// +/// The dashboard is built to manage multiple clusters, but the server itself by design is stateless. +/// This gives it a bit of shared state that allows the dashboard to display cluster-specific information. +#[derive(Debug, Default, Clone)] +pub struct Context { + pub user: models::User, + pub cluster: models::Cluster, + pub dropdown_nav: StaticNav, + pub product_left_nav: StaticNav, + pub marketing_footer: String, + pub head_items: Option, +} diff --git a/pgml-dashboard/src/guards.rs b/pgml-dashboard/src/guards.rs index 3e8d4fb94..c34658320 100644 --- a/pgml-dashboard/src/guards.rs +++ b/pgml-dashboard/src/guards.rs @@ -1,4 +1,6 @@ use crate::components::sections::footers::marketing_footer::MarketingFooter; +use crate::context::Context; +use crate::notifications::Notification; use crate::templates::components::{StaticNav, StaticNavLink}; use crate::utils::urls; use once_cell::sync::OnceCell; @@ -9,7 +11,7 @@ use sqlx::{postgres::PgPoolOptions, Executor, PgPool}; static POOL: OnceCell = OnceCell::new(); -use crate::{models, utils::config, Context, Notification}; +use crate::{models, utils::config}; #[derive(Debug, Clone, Default)] pub struct Cluster { diff --git a/pgml-dashboard/src/lib.rs b/pgml-dashboard/src/lib.rs index 0ac7994fd..e470e3b8b 100644 --- a/pgml-dashboard/src/lib.rs +++ b/pgml-dashboard/src/lib.rs @@ -3,37 +3,24 @@ #[macro_use] extern crate rocket; -use rocket::http::CookieJar; -use rocket::response::Redirect; -use rocket::route::Route; -use sailfish::TemplateOnce; use sqlx::PgPool; pub mod api; +pub mod catchers; pub mod components; +pub mod context; pub mod fairings; pub mod forms; pub mod guards; pub mod models; +pub mod notifications; pub mod responses; +pub mod routes; +pub mod sentry; pub mod templates; pub mod types; pub mod utils; -use components::notifications::marketing::{AlertBanner, FeatureBanner}; -use components::notifications::product::ProductBanner; -use guards::Cluster; -use responses::{Error, Response, ResponseOk}; -use templates::{components::StaticNav, *}; - -use crate::components::tables::serverless_models::{ServerlessModels, ServerlessModelsTurbo}; -use crate::components::tables::serverless_pricing::{ServerlessPricing, ServerlessPricingTurbo}; -use crate::utils::cookies::{NotificationCookie, Notifications}; -use crate::utils::urls; -use chrono; -use std::collections::hash_map::DefaultHasher; -use std::hash::{Hash, Hasher}; - #[derive(Debug, Default, Clone)] pub struct ClustersSettings { pub max_connections: u32, @@ -41,705 +28,229 @@ pub struct ClustersSettings { pub min_connections: u32, } -/// This struct contains information specific to the cluster being displayed in the dashboard. -/// -/// The dashboard is built to manage multiple clusters, but the server itself by design is stateless. -/// This gives it a bit of shared state that allows the dashboard to display cluster-specific information. -#[derive(Debug, Default, Clone)] -pub struct Context { - pub user: models::User, - pub cluster: models::Cluster, - pub dropdown_nav: StaticNav, - pub product_left_nav: StaticNav, - pub marketing_footer: String, - pub head_items: Option, -} - -#[derive(Debug, Clone, Default)] -pub struct Notification { - pub message: String, - pub level: NotificationLevel, - pub id: String, - pub dismissible: bool, - pub viewed: bool, - pub link: Option, - pub deployment: Option, - pub preset_icon: bool, - pub title: Option, - pub modal_show_interval: i64, - pub notification_show_interval: i64, - pub trigger_modal: bool, -} -impl Notification { - pub fn new(message: &str) -> Notification { - let mut s = DefaultHasher::new(); - message.hash(&mut s); - - Notification { - message: message.to_string(), - level: NotificationLevel::Level1, - id: s.finish().to_string(), - dismissible: true, - viewed: false, - link: None, - deployment: None, - preset_icon: false, - title: None, - modal_show_interval: 90, // If modal dismissed, show again in 90 days. - notification_show_interval: 90, // If notification dismissed, show again in 90 days. - trigger_modal: false, - } - } - - pub fn set_level(mut self, level: &NotificationLevel) -> Notification { - self.level = level.clone(); - self - } - - pub fn set_dismissible(mut self, dismissible: bool) -> Notification { - self.dismissible = dismissible; - self - } - - pub fn set_link(mut self, link: &str) -> Notification { - self.link = Some(link.into()); - self - } - - pub fn set_viewed(mut self, viewed: bool) -> Notification { - self.viewed = viewed; - self - } - - pub fn set_deployment(mut self, deployment: &str) -> Notification { - self.deployment = Some(deployment.into()); - 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 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, - _ => false, - } - } - - pub fn is_feature(level: &NotificationLevel) -> bool { - match level { - NotificationLevel::Feature1 | NotificationLevel::Feature2 | NotificationLevel::Feature3 => true, - _ => false, - } - } - - pub fn next_alert(context: Option<&crate::guards::Cluster>) -> Option<&Notification> { - match context.as_ref() { - Some(context) => match &context.notifications { - Some(notifications) => { - match notifications - .into_iter() - .filter(|n| Notification::is_alert(&n.level)) - .next() - { - Some(notification) => return Some(notification), - None => return None, - } - } - None => return None, - }, - None => return None, - }; - } - - pub fn next_feature(context: Option<&crate::guards::Cluster>) -> Option<&Notification> { - match context.as_ref() { - Some(context) => match &context.notifications { - Some(notifications) => { - match notifications - .into_iter() - .filter(|n| Notification::is_feature(&n.level)) - .next() - { - Some(notification) => return Some(notification), - None => return None, - } - } - None => return None, - }, - None => return None, - }; - } - - pub fn next_product_of_level( - context: &crate::guards::Cluster, - desired_level: NotificationLevel, - ) -> Option<&Notification> { - match &context.notifications { - Some(notifications) => { - match notifications - .into_iter() - .filter(|n| { - Notification::product_filter( - n, - desired_level.clone(), - Some(context.context.cluster.id.clone().to_string()), - ) - }) - .next() - { - Some(notification) => return Some(notification), - None => return None, - } - } - None => return None, - } - } - - // Determine if product notification matches desired level and deployment id. - pub fn product_filter( - notification: &Notification, - desired_level: NotificationLevel, - deployment_id: Option, - ) -> bool { - match notification.level { - NotificationLevel::ProductHigh => notification.level == desired_level && notification.viewed == false, - NotificationLevel::ProductMedium => { - notification.level == desired_level - && notification.deployment == deployment_id - && notification.viewed == false - } - NotificationLevel::ProductMarketing => notification.level == desired_level && notification.viewed == false, - _ => false, - } - } -} - -impl std::fmt::Display for NotificationLevel { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - NotificationLevel::Level1 => write!(f, "level1"), - NotificationLevel::Level2 => write!(f, "level2"), - NotificationLevel::Level3 => write!(f, "level3"), - NotificationLevel::Feature1 => write!(f, "feature1"), - NotificationLevel::Feature2 => write!(f, "feature2"), - NotificationLevel::Feature3 => write!(f, "feature3"), - NotificationLevel::ProductHigh => write!(f, "product_high"), - NotificationLevel::ProductMedium => write!(f, "product_medium"), - NotificationLevel::ProductMarketing => write!(f, "product_marketing"), - } - } -} - -#[derive(Debug, Clone, Default, PartialEq)] -pub enum NotificationLevel { - #[default] - // global - Level1, - Level2, - Level3, - // marketing - Feature1, - Feature2, - Feature3, - // product - ProductHigh, - ProductMedium, - ProductMarketing, -} - -#[get("/serverless_models/turboframe?