From 292ebabb0a6c3dce8030525d43304fc4080e024e Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Tue, 5 Sep 2023 15:13:30 -0700 Subject: [PATCH 1/4] Add tabs & table --- pgml-dashboard/.editorconfig | 2 +- pgml-dashboard/build.rs | 1 - pgml-dashboard/src/components/mod.rs | 7 +- .../src/components/navigation/mod.rs | 5 ++ .../src/components/navigation/tabs/mod.rs | 10 +++ .../src/components/navigation/tabs/tab/mod.rs | 65 +++++++++++++++++++ .../components/navigation/tabs/tab/tab.scss | 0 .../navigation/tabs/tab/template.html | 3 + .../components/navigation/tabs/tabs/mod.rs | 27 ++++++++ .../components/navigation/tabs/tabs/tabs.scss | 21 ++++++ .../navigation/tabs/tabs/template.html | 17 +++++ .../src/components/tables/large/mod.rs | 10 +++ .../src/components/tables/large/row/mod.rs | 19 ++++++ .../src/components/tables/large/row/row.scss | 37 +++++++++++ .../tables/large/row/row_controller.js | 14 ++++ .../components/tables/large/row/template.html | 9 +++ .../src/components/tables/large/table/mod.rs | 21 ++++++ .../components/tables/large/table/table.scss | 19 ++++++ .../tables/large/table/table_controller.js | 14 ++++ .../tables/large/table/template.html | 14 ++++ pgml-dashboard/src/components/tables/mod.rs | 5 ++ pgml-dashboard/src/utils/markdown.rs | 2 +- pgml-dashboard/static/css/modules.scss | 4 ++ .../static/css/scss/abstracts/variables.scss | 5 ++ .../static/css/scss/components/_navs.scss | 12 ---- .../templates/content/playground.html | 23 +++++++ 26 files changed, 350 insertions(+), 16 deletions(-) create mode 100644 pgml-dashboard/src/components/navigation/mod.rs create mode 100644 pgml-dashboard/src/components/navigation/tabs/mod.rs create mode 100644 pgml-dashboard/src/components/navigation/tabs/tab/mod.rs create mode 100644 pgml-dashboard/src/components/navigation/tabs/tab/tab.scss create mode 100644 pgml-dashboard/src/components/navigation/tabs/tab/template.html create mode 100644 pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs create mode 100644 pgml-dashboard/src/components/navigation/tabs/tabs/tabs.scss create mode 100644 pgml-dashboard/src/components/navigation/tabs/tabs/template.html create mode 100644 pgml-dashboard/src/components/tables/large/mod.rs create mode 100644 pgml-dashboard/src/components/tables/large/row/mod.rs create mode 100644 pgml-dashboard/src/components/tables/large/row/row.scss create mode 100644 pgml-dashboard/src/components/tables/large/row/row_controller.js create mode 100644 pgml-dashboard/src/components/tables/large/row/template.html create mode 100644 pgml-dashboard/src/components/tables/large/table/mod.rs create mode 100644 pgml-dashboard/src/components/tables/large/table/table.scss create mode 100644 pgml-dashboard/src/components/tables/large/table/table_controller.js create mode 100644 pgml-dashboard/src/components/tables/large/table/template.html create mode 100644 pgml-dashboard/src/components/tables/mod.rs diff --git a/pgml-dashboard/.editorconfig b/pgml-dashboard/.editorconfig index 8b67e0f71..88b69042e 100644 --- a/pgml-dashboard/.editorconfig +++ b/pgml-dashboard/.editorconfig @@ -13,4 +13,4 @@ indent_size = 4 [*.html] ident_style = space -indent_size = 4 +indent_size = 2 diff --git a/pgml-dashboard/build.rs b/pgml-dashboard/build.rs index d76aa7923..0c9604dee 100644 --- a/pgml-dashboard/build.rs +++ b/pgml-dashboard/build.rs @@ -3,7 +3,6 @@ use std::process::Command; fn main() { println!("cargo:rerun-if-changed=migrations"); - println!("cargo:rerun-if-changed=src"); let output = Command::new("git") .args(&["rev-parse", "HEAD"]) diff --git a/pgml-dashboard/src/components/mod.rs b/pgml-dashboard/src/components/mod.rs index fd6a206da..40205f3c2 100644 --- a/pgml-dashboard/src/components/mod.rs +++ b/pgml-dashboard/src/components/mod.rs @@ -4,7 +4,6 @@ mod component; pub(crate) use component::{component, Component}; - // src/components/breadcrumbs pub mod breadcrumbs; pub use breadcrumbs::Breadcrumbs; @@ -49,6 +48,9 @@ pub use navbar::Navbar; pub mod navbar_web_app; pub use navbar_web_app::NavbarWebApp; +// src/components/navigation +pub mod navigation; + // src/components/postgres_logo pub mod postgres_logo; pub use postgres_logo::PostgresLogo; @@ -65,6 +67,9 @@ pub use static_nav::StaticNav; pub mod static_nav_link; pub use static_nav_link::StaticNavLink; +// src/components/tables +pub mod tables; + // src/components/test_component pub mod test_component; pub use test_component::TestComponent; diff --git a/pgml-dashboard/src/components/navigation/mod.rs b/pgml-dashboard/src/components/navigation/mod.rs new file mode 100644 index 000000000..e615f8406 --- /dev/null +++ b/pgml-dashboard/src/components/navigation/mod.rs @@ -0,0 +1,5 @@ +// This file is automatically generated. +// You shouldn't modify it manually. + +// src/components/navigation/tabs +pub mod tabs; diff --git a/pgml-dashboard/src/components/navigation/tabs/mod.rs b/pgml-dashboard/src/components/navigation/tabs/mod.rs new file mode 100644 index 000000000..122d9b659 --- /dev/null +++ b/pgml-dashboard/src/components/navigation/tabs/mod.rs @@ -0,0 +1,10 @@ +// This file is automatically generated. +// You shouldn't modify it manually. + +// src/components/navigation/tabs/tab +pub mod tab; +pub use tab::Tab; + +// src/components/navigation/tabs/tabs +pub mod tabs; +pub use tabs::Tabs; diff --git a/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs b/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs new file mode 100644 index 000000000..f64e6e030 --- /dev/null +++ b/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs @@ -0,0 +1,65 @@ +#![allow(unused_variables)] +use crate::components::component; +use crate::components::component::Component; +use sailfish::TemplateOnce; + +#[derive(TemplateOnce, Default, Clone)] +#[template(path = "navigation/tabs/tab/template.html")] +pub struct Tab { + content: Component, + active: bool, + name: String, +} + +impl Tab { + pub fn new(name: impl ToString, content: Component) -> Tab { + Tab { + content, + active: false, + name: name.to_string(), + } + } + + pub fn button_classes(&self) -> String { + if self.active { + "nav-link active btn btn-tertiary rounded-0".to_string() + } else { + "nav-link btn btn-tertiary rounded-0".to_string() + } + } + + pub fn content_classes(&self) -> String { + if self.active { + "tab-pane my-4 show active".to_string() + } else { + "tab-pane my-4".to_string() + } + } + + pub fn id(&self) -> String { + format!("tab-{}", self.name.to_lowercase().replace(" ", "-")) + } + + pub fn selected(&self) -> String { + if self.active { + "selected".to_string() + } else { + "".to_string() + } + } + + pub fn name(&self) -> String { + self.name.clone() + } + + pub fn active(mut self) -> Self { + self.active = true; + self + } + + pub fn is_active(&self) -> bool { + self.active + } +} + +component!(Tab); diff --git a/pgml-dashboard/src/components/navigation/tabs/tab/tab.scss b/pgml-dashboard/src/components/navigation/tabs/tab/tab.scss new file mode 100644 index 000000000..e69de29bb diff --git a/pgml-dashboard/src/components/navigation/tabs/tab/template.html b/pgml-dashboard/src/components/navigation/tabs/tab/template.html new file mode 100644 index 000000000..3033744fa --- /dev/null +++ b/pgml-dashboard/src/components/navigation/tabs/tab/template.html @@ -0,0 +1,3 @@ +
+ <%+ content %> +
diff --git a/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs b/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs new file mode 100644 index 000000000..e5343bcfb --- /dev/null +++ b/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs @@ -0,0 +1,27 @@ +use crate::components::component; +use crate::components::navigation::tabs::Tab; +use sailfish::TemplateOnce; + +#[derive(TemplateOnce, Default)] +#[template(path = "navigation/tabs/tabs/template.html")] +pub struct Tabs { + tabs: Vec, +} + +impl Tabs { + pub fn new(tabs: &[Tab]) -> Tabs { + // Set the first tab to active if none are. + let mut tabs = tabs.to_vec(); + if tabs.iter().all(|t| !t.is_active()) { + tabs = tabs + .into_iter() + .enumerate() + .map(|(i, tab)| if i == 0 { tab.active() } else { tab }) + .collect(); + } + + Tabs { tabs } + } +} + +component!(Tabs); diff --git a/pgml-dashboard/src/components/navigation/tabs/tabs/tabs.scss b/pgml-dashboard/src/components/navigation/tabs/tabs/tabs.scss new file mode 100644 index 000000000..2da2868c6 --- /dev/null +++ b/pgml-dashboard/src/components/navigation/tabs/tabs/tabs.scss @@ -0,0 +1,21 @@ +.nav-tabs { + // These tabs are used in docs as well, where they are + // generated using Bootstrap. It wasn't obvious to me + // how to replace those with this component yet, so I'm just + // enforcing the font-family here so they look the same. Docs use Roboto by default. + font-family: 'silka', 'Roboto', 'sans-serif'; + + --bs-nav-tabs-border-width: 4px; + + .nav-link { + border: none; + + &.active, &:focus, &:active { + border-bottom: 4px solid #{$slate-tint-700}; + color: #{$slate-tint-700}; + text-shadow: none; + } + + color: #{$slate-tint-100}; + } +} diff --git a/pgml-dashboard/src/components/navigation/tabs/tabs/template.html b/pgml-dashboard/src/components/navigation/tabs/tabs/template.html new file mode 100644 index 000000000..d148c1ad1 --- /dev/null +++ b/pgml-dashboard/src/components/navigation/tabs/tabs/template.html @@ -0,0 +1,17 @@ + +
+ <% for (i, tab) in tabs.into_iter().enumerate() { %> +
+ <%+ tab %> +
+ <% } %> +
diff --git a/pgml-dashboard/src/components/tables/large/mod.rs b/pgml-dashboard/src/components/tables/large/mod.rs new file mode 100644 index 000000000..17fdf1b6f --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/mod.rs @@ -0,0 +1,10 @@ +// This file is automatically generated. +// You shouldn't modify it manually. + +// src/components/tables/large/row +pub mod row; +pub use row::Row; + +// src/components/tables/large/table +pub mod table; +pub use table::Table; diff --git a/pgml-dashboard/src/components/tables/large/row/mod.rs b/pgml-dashboard/src/components/tables/large/row/mod.rs new file mode 100644 index 000000000..eac8a2e65 --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/row/mod.rs @@ -0,0 +1,19 @@ +use crate::components::component; +use crate::components::component::Component; +use sailfish::TemplateOnce; + +#[derive(TemplateOnce, Default, Clone)] +#[template(path = "tables/large/row/template.html")] +pub struct Row { + columns: Vec, +} + +impl Row { + pub fn new(columns: &[Component]) -> Row { + Row { + columns: columns.to_vec(), + } + } +} + +component!(Row); diff --git a/pgml-dashboard/src/components/tables/large/row/row.scss b/pgml-dashboard/src/components/tables/large/row/row.scss new file mode 100644 index 000000000..5a65b7722 --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/row/row.scss @@ -0,0 +1,37 @@ +table.table.table-lg { + tr { + &:first-of-type { + td { + padding-top: 16px; + } + } + + &:hover { + div.table-cell-content { + background: #{$gray-800}; + } + } + + td { + vertical-align: middle; + padding: 8px 0; + + div.table-cell-content { + background: #{$gray-600}; + padding: 20px 0; + } + + &:first-of-type { + div.table-cell-content { + padding-left: 67px; + } + } + + &:last-of-type { + div.table-cell-content { + padding-right: 67px; + } + } + } + } +} diff --git a/pgml-dashboard/src/components/tables/large/row/row_controller.js b/pgml-dashboard/src/components/tables/large/row/row_controller.js new file mode 100644 index 000000000..ed54ee88b --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/row/row_controller.js @@ -0,0 +1,14 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + static targets = [] + static outlets = [] + + initialize() { + console.log('Initialized tables-large-row') + } + + connect() {} + + disconnect() {} +} \ No newline at end of file diff --git a/pgml-dashboard/src/components/tables/large/row/template.html b/pgml-dashboard/src/components/tables/large/row/template.html new file mode 100644 index 000000000..32b9c8714 --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/row/template.html @@ -0,0 +1,9 @@ + + <% for column in columns { %> + +
+ <%+ column %> +
+ + <% } %> + diff --git a/pgml-dashboard/src/components/tables/large/table/mod.rs b/pgml-dashboard/src/components/tables/large/table/mod.rs new file mode 100644 index 000000000..42da7d9fd --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/table/mod.rs @@ -0,0 +1,21 @@ +use crate::components::component; +use crate::components::tables::large::Row; +use sailfish::TemplateOnce; + +#[derive(TemplateOnce, Default)] +#[template(path = "tables/large/table/template.html")] +pub struct Table { + rows: Vec, + headers: Vec, +} + +impl Table { + pub fn new(headers: &[impl ToString], rows: &[Row]) -> Table { + Table { + headers: headers.iter().map(|h| h.to_string()).collect(), + rows: rows.to_vec(), + } + } +} + +component!(Table); diff --git a/pgml-dashboard/src/components/tables/large/table/table.scss b/pgml-dashboard/src/components/tables/large/table/table.scss new file mode 100644 index 000000000..3befa6e55 --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/table/table.scss @@ -0,0 +1,19 @@ +table.table.table-lg { + * { + border-width: 0; + } + + thead { + th { + color: #{$slate-shade-100}; + background: #{$gray-800}; + text-transform: uppercase; + font-size: 0.75rem; + padding: 16px 0; + + &:first-of-type { + padding-left: 67px; + } + } + } +} diff --git a/pgml-dashboard/src/components/tables/large/table/table_controller.js b/pgml-dashboard/src/components/tables/large/table/table_controller.js new file mode 100644 index 000000000..2d0ba2cf1 --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/table/table_controller.js @@ -0,0 +1,14 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + static targets = [] + static outlets = [] + + initialize() { + console.log('Initialized tables-large-table') + } + + connect() {} + + disconnect() {} +} \ No newline at end of file diff --git a/pgml-dashboard/src/components/tables/large/table/template.html b/pgml-dashboard/src/components/tables/large/table/template.html new file mode 100644 index 000000000..6df09000b --- /dev/null +++ b/pgml-dashboard/src/components/tables/large/table/template.html @@ -0,0 +1,14 @@ + + + + <% for header in headers { %> + + <% } %> + + + + <% for row in rows { %> + <%+ row %> + <% } %> + + diff --git a/pgml-dashboard/src/components/tables/mod.rs b/pgml-dashboard/src/components/tables/mod.rs new file mode 100644 index 000000000..48a76b04c --- /dev/null +++ b/pgml-dashboard/src/components/tables/mod.rs @@ -0,0 +1,5 @@ +// This file is automatically generated. +// You shouldn't modify it manually. + +// src/components/tables/large +pub mod large; diff --git a/pgml-dashboard/src/utils/markdown.rs b/pgml-dashboard/src/utils/markdown.rs index 0957e5e39..b13636c6a 100644 --- a/pgml-dashboard/src/utils/markdown.rs +++ b/pgml-dashboard/src/utils/markdown.rs @@ -669,7 +669,7 @@ impl<'a> Tab<'a> { "
  • @@ -10,7 +17,13 @@
    <% for (i, tab) in tabs.into_iter().enumerate() { %> -
    +
    <%+ tab %>
    <% } %> diff --git a/pgml-dashboard/src/components/tables/large/row/row_controller.js b/pgml-dashboard/src/components/tables/large/row/row_controller.js deleted file mode 100644 index ed54ee88b..000000000 --- a/pgml-dashboard/src/components/tables/large/row/row_controller.js +++ /dev/null @@ -1,14 +0,0 @@ -import { Controller } from '@hotwired/stimulus' - -export default class extends Controller { - static targets = [] - static outlets = [] - - initialize() { - console.log('Initialized tables-large-row') - } - - connect() {} - - disconnect() {} -} \ No newline at end of file diff --git a/pgml-dashboard/src/components/tables/large/table/table_controller.js b/pgml-dashboard/src/components/tables/large/table/table_controller.js deleted file mode 100644 index 2d0ba2cf1..000000000 --- a/pgml-dashboard/src/components/tables/large/table/table_controller.js +++ /dev/null @@ -1,14 +0,0 @@ -import { Controller } from '@hotwired/stimulus' - -export default class extends Controller { - static targets = [] - static outlets = [] - - initialize() { - console.log('Initialized tables-large-table') - } - - connect() {} - - disconnect() {} -} \ No newline at end of file diff --git a/pgml-dashboard/src/components/tables/large/table/template.html b/pgml-dashboard/src/components/tables/large/table/template.html index 6df09000b..1aa2a831b 100644 --- a/pgml-dashboard/src/components/tables/large/table/template.html +++ b/pgml-dashboard/src/components/tables/large/table/template.html @@ -1,4 +1,4 @@ -
    <%= header %>
    +
    <% for header in headers { %> From e527f5f6be2a76c24547dd3d4d89323f4aba1d4d Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Tue, 5 Sep 2023 15:17:10 -0700 Subject: [PATCH 3/4] remove comment --- pgml-dashboard/static/css/scss/abstracts/variables.scss | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pgml-dashboard/static/css/scss/abstracts/variables.scss b/pgml-dashboard/static/css/scss/abstracts/variables.scss index 71b9be468..2bd8d0983 100644 --- a/pgml-dashboard/static/css/scss/abstracts/variables.scss +++ b/pgml-dashboard/static/css/scss/abstracts/variables.scss @@ -223,7 +223,3 @@ $breadcrumb-divider: quote(""); // animations $animation-timer: 0.35s; $transition-collapse-width: width 0.35s ease; - -// $table-border-width: 0; -// $table-cell-padding-y: 0; -// $table-cell-padding-x: 0; From 73dbaf8bb8f68ebb65871439f8bc7f86a261aa35 Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Tue, 5 Sep 2023 15:35:22 -0700 Subject: [PATCH 4/4] allow to show active tab --- .../src/components/navigation/tabs/tab/mod.rs | 5 +++++ .../src/components/navigation/tabs/tabs/mod.rs | 17 +++++++++++++++++ .../templates/content/playground.html | 4 ++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs b/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs index f64e6e030..b1e33cc00 100644 --- a/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs +++ b/pgml-dashboard/src/components/navigation/tabs/tab/mod.rs @@ -57,6 +57,11 @@ impl Tab { self } + pub fn inactive(mut self) -> Self { + self.active = false; + self + } + pub fn is_active(&self) -> bool { self.active } diff --git a/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs b/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs index e5343bcfb..21b176837 100644 --- a/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs +++ b/pgml-dashboard/src/components/navigation/tabs/tabs/mod.rs @@ -22,6 +22,23 @@ impl Tabs { Tabs { tabs } } + + pub fn active_tab(mut self, name: impl ToString) -> Self { + let tabs = self + .tabs + .into_iter() + .map(|tab| { + if tab.name() == name.to_string() { + tab.active() + } else { + tab.inactive() + } + }) + .collect(); + + self.tabs = tabs; + self + } } component!(Tabs); diff --git a/pgml-dashboard/templates/content/playground.html b/pgml-dashboard/templates/content/playground.html index 5705a96f7..d7864d13c 100644 --- a/pgml-dashboard/templates/content/playground.html +++ b/pgml-dashboard/templates/content/playground.html @@ -49,8 +49,8 @@

    Playground

    navigation::tabs::Tab::new( "Third active tab", "Hello third tab".into(), - ).active(), - ]) %> + ), + ]).active_tab("Third active tab") %>
    <%+ tables::large::Table::new(&["Date", "Time", "Status"], &vec![ pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy