public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog
@ 2026-11-27 17:09 Dominik Csapak
  2026-11-27 17:09 ` [PATCH yew-widget-toolkit v2 1/6] state: event: add helpers for custom DOM events Dominik Csapak
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Dominik Csapak @ 2026-11-27 17:09 UTC (permalink / raw)
  To: pdm-devel

This adds a 'My Settings' dialog like the one in PVE to the user menu of
PDM, and lets users choose one of their views as dashboard there.

Let the user select a view as the dashboard and persist that in the browser
local storage.

Note that for the pdm patches, pwt must be bumped and the new version must be
recorded in Cargo.toml.

changes from v1:
* add my settings window and move the default dashboard selection there
* use '#' for the default dashboard instead of '__dashboard__'
* show a notice if the selected dashboard is not in the view_list


proxmox-yew-widget-toolkit:

Dominik Csapak (2):
  state: event: add helpers for custom DOM events
  state: persistent state: allow listening for updates

 src/state/event.rs            | 24 +++++++++++++++++++++++
 src/state/mod.rs              | 29 ++++++++++++++++++++++-----
 src/state/persistent_state.rs | 37 ++++++++++++++++++++++++++++++++++-
 3 files changed, 84 insertions(+), 6 deletions(-)
 create mode 100644 src/state/event.rs


proxmox-datacenter-manager:

Dominik Csapak (4):
  ui: add 'My Settings' dialog with xterm.js and noVNC settings
  ui: view configuration: fix dismissing of remove confirmation dialog
  ui: view selector: use a placeholder that can't conflict with a view
  ui: make the default dashboard page configurable

 ui/Cargo.toml                       |   2 +-
 ui/src/configuration/views.rs       |   5 +-
 ui/src/dashboard/view.rs            |  18 +-
 ui/src/main.rs                      |   1 +
 ui/src/main_menu.rs                 |  32 +++-
 ui/src/top_nav_bar.rs               |  22 ++-
 ui/src/widget/mod.rs                |   5 +-
 ui/src/widget/my_settings_dialog.rs | 266 ++++++++++++++++++++++++++++
 ui/src/widget/view_selector.rs      |  11 +-
 9 files changed, 347 insertions(+), 15 deletions(-)
 create mode 100644 ui/src/widget/my_settings_dialog.rs


Summary over all repositories:
  12 files changed, 431 insertions(+), 21 deletions(-)

-- 
Generated by murpp 0.11.0




^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH yew-widget-toolkit v2 1/6] state: event: add helpers for custom DOM events
  2026-11-27 17:09 [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
@ 2026-11-27 17:09 ` Dominik Csapak
  2026-11-27 17:09 ` [PATCH yew-widget-toolkit v2 2/6] state: persistent state: allow listening for updates Dominik Csapak
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dominik Csapak @ 2026-11-27 17:09 UTC (permalink / raw)
  To: pdm-devel

Creating and dispatching custom events is currently open coded, e.g. for
the `pwt-theme-changed` event. Provide small wrappers so that further
users do not have to repeat the window/document lookup and the JS error
conversion.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/state/event.rs | 24 ++++++++++++++++++++++++
 src/state/mod.rs   |  3 +++
 2 files changed, 27 insertions(+)
 create mode 100644 src/state/event.rs

diff --git a/src/state/event.rs b/src/state/event.rs
new file mode 100644
index 0000000..8566071
--- /dev/null
+++ b/src/state/event.rs
@@ -0,0 +1,24 @@
+//! Helpers to create and dispatch custom DOM events.
+
+use anyhow::{Error, format_err};
+use web_sys::Event;
+
+/// Create a custom [Event] with the given name.
+pub fn create_custom_event(name: &str) -> Result<Event, Error> {
+    Event::new(name).map_err(crate::convert_js_error)
+}
+
+/// Dispatch a custom event with the given name on the document.
+///
+/// The event is only delivered to listeners in the current document, so listeners in other
+/// browser tabs or windows are not notified.
+pub fn dispatch_custom_event(name: &str) -> Result<(), Error> {
+    let document = web_sys::window()
+        .and_then(|window| window.document())
+        .ok_or_else(|| format_err!("no document available"))?;
+
+    document
+        .dispatch_event(&create_custom_event(name)?)
+        .map(|_| ())
+        .map_err(crate::convert_js_error)
+}
diff --git a/src/state/mod.rs b/src/state/mod.rs
index d98d4db..d473ad2 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -7,6 +7,9 @@ use serde::{Serialize, de::DeserializeOwned};
 mod data_store;
 pub use data_store::{DataNode, DataNodeDerefGuard, DataStore};
 
+mod event;
+pub use event::{create_custom_event, dispatch_custom_event};
+
 mod loader;
 pub use loader::{Loader, LoaderState};
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH yew-widget-toolkit v2 2/6] state: persistent state: allow listening for updates
  2026-11-27 17:09 [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
  2026-11-27 17:09 ` [PATCH yew-widget-toolkit v2 1/6] state: event: add helpers for custom DOM events Dominik Csapak
@ 2026-11-27 17:09 ` Dominik Csapak
  2026-11-27 17:09 ` [PATCH datacenter-manager v2 3/6] ui: add 'My Settings' dialog with xterm.js and noVNC settings Dominik Csapak
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dominik Csapak @ 2026-11-27 17:09 UTC (permalink / raw)
  To: pdm-devel

A `PersistentState` only reads its storage location on construction, so
instances held by unrelated components go stale as soon as another one
writes. Components deep in different subtrees often share nothing but the
storage key, so they cannot be handed a common instance either.

Dispatch a per-location event whenever `store_state` succeeds and let
`PersistentState` subscribe to it. The event carries no payload, as the
callback cannot mutate the instance it belongs to, hence `load` is now
public so that the owner can pick up the new value.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/state/mod.rs              | 26 +++++++++++++++++++-----
 src/state/persistent_state.rs | 37 ++++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/src/state/mod.rs b/src/state/mod.rs
index d473ad2..69fa0f5 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -125,6 +125,15 @@ pub fn load_state<T: 'static + DeserializeOwned>(storage: &StorageLocation) -> O
     None
 }
 
+fn create_storage_event_name(location: &StorageLocation) -> String {
+    let (prefix, name) = match location {
+        StorageLocation::Local(name) => ("local", name),
+        StorageLocation::Session(name) => ("session", name),
+    };
+
+    format!("pwt-storage-{prefix}-{name}")
+}
+
 pub fn store_state<T: 'static + Serialize>(data: &T, storage: &StorageLocation) {
     let (store, state_id) = match storage {
         StorageLocation::Local(state_id) => (local_storage(), state_id),
@@ -132,11 +141,18 @@ pub fn store_state<T: 'static + Serialize>(data: &T, storage: &StorageLocation)
     };
     if let Some(store) = store {
         let item_str = serde_json::to_string(data).unwrap();
-        if let Err(err) = store.set_item(state_id, &item_str) {
-            log::error!(
-                "store persistent state {state_id} failed: {}",
-                crate::convert_js_error(err)
-            )
+        match store.set_item(state_id, &item_str) {
+            Ok(()) => {
+                if let Err(err) = dispatch_custom_event(&create_storage_event_name(storage)) {
+                    log::error!("failed to send storage event: {err}")
+                }
+            }
+            Err(err) => {
+                log::error!(
+                    "store persistent state {state_id} failed: {}",
+                    crate::convert_js_error(err)
+                )
+            }
         }
     }
 }
diff --git a/src/state/persistent_state.rs b/src/state/persistent_state.rs
index 90a54b7..672b0e5 100644
--- a/src/state/persistent_state.rs
+++ b/src/state/persistent_state.rs
@@ -1,7 +1,10 @@
+use gloo_events::EventListener;
 use serde::{Serialize, de::DeserializeOwned};
 use std::ops::Deref;
+use yew::Callback;
 
 use crate::props::StorageLocation;
+use crate::state::create_storage_event_name;
 
 /// Helper to store data persistently using window local [Storage](web_sys::Storage)
 ///
@@ -35,6 +38,7 @@ use crate::props::StorageLocation;
 pub struct PersistentState<T> {
     storage: StorageLocation,
     data: T,
+    listener: Option<EventListener>,
 }
 
 impl<T> Deref for PersistentState<T> {
@@ -51,12 +55,14 @@ impl<T: 'static + Default + Serialize + DeserializeOwned> PersistentState<T> {
         let mut me = Self {
             data: T::default(),
             storage: storage.into(),
+            listener: None,
         };
         me.load();
         me
     }
 
-    fn load(&mut self) {
+    /// Loads the (potentially updated) data again from the given storage
+    pub fn load(&mut self) {
         if let Some(data) = super::load_state(&self.storage) {
             self.data = data;
         }
@@ -80,4 +86,33 @@ impl<T: 'static + Default + Serialize + DeserializeOwned> PersistentState<T> {
     pub fn into_inner(self) -> T {
         self.data
     }
+
+    /// Calls the callback when the data has changed.
+    ///
+    /// CAUTION: this does not update the data, [Self::load] must be called after this event to get
+    /// the current value.
+    ///
+    /// The callback also fires for updates done through this instance, so it must not write back
+    /// unconditionally, otherwise it triggers itself in an endless loop. Only updates from the
+    /// current document are reported, changes made in other browser tabs are not.
+    pub fn set_on_update(&mut self, on_update: impl Into<Callback<()>>) {
+        let on_update = on_update.into();
+        let Some(document) = web_sys::window().and_then(|window| window.document()) else {
+            return;
+        };
+
+        self.listener = Some(EventListener::new(
+            &document,
+            create_storage_event_name(&self.storage),
+            move |_| on_update.emit(()),
+        ));
+    }
+
+    /// Builder style method to set an update callback [Self::set_on_update].
+    /// CAUTION: this does not update the data, [Self::load] must be called after this event to
+    /// get the current value
+    pub fn on_update(mut self, on_update: impl Into<Callback<()>>) -> Self {
+        self.set_on_update(on_update);
+        self
+    }
 }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH datacenter-manager v2 3/6] ui: add 'My Settings' dialog with xterm.js and noVNC settings
  2026-11-27 17:09 [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
  2026-11-27 17:09 ` [PATCH yew-widget-toolkit v2 1/6] state: event: add helpers for custom DOM events Dominik Csapak
  2026-11-27 17:09 ` [PATCH yew-widget-toolkit v2 2/6] state: persistent state: allow listening for updates Dominik Csapak
@ 2026-11-27 17:09 ` Dominik Csapak
  2026-11-27 17:09 ` [PATCH datacenter-manager v2 4/6] ui: view configuration: fix dismissing of remove confirmation dialog Dominik Csapak
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Dominik Csapak @ 2026-11-27 17:09 UTC (permalink / raw)
  To: pdm-devel

like in PVE, reachable from the user menu. For now it only contains
the xterm.js settings (font family, font size, letter spacing and line
height) and the noVNC scaling mode.

The xterm.js settings are saved in the 'pve-xterm-*' entries of the
local browser storage, where the xterm.js console reads them from.

The noVNC scaling mode is saved in 'novnc-scaling', but is not yet
used when opening a console.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/Cargo.toml                       |   2 +-
 ui/src/top_nav_bar.rs               |  16 +-
 ui/src/widget/mod.rs                |   3 +
 ui/src/widget/my_settings_dialog.rs | 242 ++++++++++++++++++++++++++++
 4 files changed, 259 insertions(+), 4 deletions(-)
 create mode 100644 ui/src/widget/my_settings_dialog.rs

diff --git a/ui/Cargo.toml b/ui/Cargo.toml
index b538333b..5ee9489c 100644
--- a/ui/Cargo.toml
+++ b/ui/Cargo.toml
@@ -24,7 +24,7 @@ serde_json = "1.0"
 wasm-bindgen = "0.2.92"
 wasm-bindgen-futures = "0.4"
 wasm-logger = "0.2"
-web-sys = { version = "0.3", features = ["Location", "DataTransfer", "Performance"] }
+web-sys = { version = "0.3", features = ["Location", "DataTransfer", "Performance", "Storage"] }
 yew = { version = "0.21",  features = ["csr"] }
 yew-router = { version = "0.18" }
 
diff --git a/ui/src/top_nav_bar.rs b/ui/src/top_nav_bar.rs
index 99b5bbfd..015b6b13 100644
--- a/ui/src/top_nav_bar.rs
+++ b/ui/src/top_nav_bar.rs
@@ -24,7 +24,7 @@ use pbs_api_types::TaskListItem;
 use pdm_api_types::RemoteUpid;
 
 use crate::tasks::format_optional_remote_upid;
-use crate::widget::SearchBox;
+use crate::widget::{MySettingsDialog, SearchBox};
 
 #[derive(Deserialize)]
 pub struct VersionInfo {
@@ -58,6 +58,7 @@ impl TopNavBar {
 
 #[derive(Clone)]
 pub enum ViewState {
+    MySettingsDialog,
     LanguageDialog,
     ThemeDialog,
     OpenTask((String, Option<i64>)),
@@ -152,8 +153,14 @@ impl Component for PdmTopNavBar {
             .map(|cb| Callback::from(move |_event: MenuEvent| cb.emit(())));
 
         let menu = Menu::new()
-            // FIXME: implement
-            //.with_item(MenuItem::new(tr!("My Settings")).icon_class("fa fa-gear"))
+            .with_item(
+                MenuItem::new(tr!("My Settings"))
+                    .icon_class("fa fa-gear")
+                    .on_select(
+                        ctx.link()
+                            .callback(|_| Msg::ChangeView(Some(ViewState::MySettingsDialog))),
+                    ),
+            )
             .with_item(
                 MenuItem::new(tr!("Language"))
                     .icon_class("fa fa-language")
@@ -231,6 +238,9 @@ impl Component for PdmTopNavBar {
         }
 
         let dialog: Option<Html> = self.view_state.as_ref().map(|view_state| match view_state {
+            ViewState::MySettingsDialog => MySettingsDialog::new()
+                .on_close(ctx.link().callback(|_| Msg::ChangeView(None)))
+                .into(),
             ViewState::LanguageDialog => LanguageDialog::new()
                 .on_close(ctx.link().callback(|_| Msg::ChangeView(None)))
                 .into(),
diff --git a/ui/src/widget/mod.rs b/ui/src/widget/mod.rs
index 07c47e36..888a0e19 100644
--- a/ui/src/widget/mod.rs
+++ b/ui/src/widget/mod.rs
@@ -1,6 +1,9 @@
 mod migrate_window;
 pub use migrate_window::MigrateWindow;
 
+mod my_settings_dialog;
+pub use my_settings_dialog::MySettingsDialog;
+
 mod snapshot_window;
 pub use snapshot_window::SnapshotWindow;
 
diff --git a/ui/src/widget/my_settings_dialog.rs b/ui/src/widget/my_settings_dialog.rs
new file mode 100644
index 00000000..0ec84f71
--- /dev/null
+++ b/ui/src/widget/my_settings_dialog.rs
@@ -0,0 +1,242 @@
+use std::rc::Rc;
+use std::str::FromStr;
+
+use serde::{Deserialize, Serialize};
+use serde_json::json;
+use yew::html::IntoEventCallback;
+use yew::virtual_dom::{VComp, VNode};
+
+use pwt::css::ColorScheme;
+use pwt::prelude::*;
+use pwt::props::StorageLocation;
+use pwt::state::{PersistentState, local_storage};
+use pwt::widget::form::{Combobox, Field, Form, FormContext, Number};
+use pwt::widget::{Button, Container, Dialog, InputPanel, Row};
+
+use pwt_macros::builder;
+
+// The xterm.js console uses the text of its local storage entries as is, so they cannot be saved
+// as (JSON encoded) persistent states.
+fn load_xterm_setting<T: FromStr>(key: &str) -> Option<T> {
+    local_storage()?.get_item(key).ok()??.parse().ok()
+}
+
+fn save_xterm_setting<T: ToString>(key: &str, value: Option<T>) {
+    let Some(store) = local_storage() else {
+        return;
+    };
+    let result = match value {
+        Some(value) => store.set_item(key, &value.to_string()),
+        None => store.remove_item(key),
+    };
+    if let Err(err) = result {
+        log::error!("could not save '{key}': {}", pwt::convert_js_error(err));
+    }
+}
+
+/// The xterm.js settings, named like the fields of the form.
+#[derive(Default, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all = "camelCase")]
+struct XtermSettings {
+    font_family: Option<String>,
+    font_size: Option<u64>,
+    letter_spacing: Option<f64>,
+    line_height: Option<f64>,
+}
+
+impl XtermSettings {
+    fn load() -> Self {
+        Self {
+            font_family: load_xterm_setting("pve-xterm-fontFamily"),
+            font_size: load_xterm_setting("pve-xterm-fontSize"),
+            letter_spacing: load_xterm_setting("pve-xterm-letterSpacing"),
+            line_height: load_xterm_setting("pve-xterm-lineHeight"),
+        }
+    }
+
+    fn save(&self) {
+        save_xterm_setting("pve-xterm-fontFamily", self.font_family.as_ref());
+        save_xterm_setting("pve-xterm-fontSize", self.font_size);
+        save_xterm_setting("pve-xterm-letterSpacing", self.letter_spacing);
+        save_xterm_setting("pve-xterm-lineHeight", self.line_height);
+    }
+}
+
+#[derive(Clone, PartialEq, Properties)]
+#[builder]
+pub struct MySettingsDialog {
+    /// Dialog close callback.
+    #[builder_cb(IntoEventCallback, into_event_callback, ())]
+    #[prop_or_default]
+    pub on_close: Option<Callback<()>>,
+}
+
+impl Default for MySettingsDialog {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl MySettingsDialog {
+    pub fn new() -> Self {
+        yew::props!(Self {})
+    }
+}
+
+pub enum Msg {
+    XtermFormChange,
+    XtermSave,
+    XtermReset,
+    NoVncScaling(String),
+}
+
+#[doc(hidden)]
+pub struct PdmMySettingsDialog {
+    xterm_form: FormContext,
+    xterm_saved: XtermSettings,
+    novnc_scaling: PersistentState<Option<String>>,
+}
+
+impl PdmMySettingsDialog {
+    /// Returns the xterm.js settings as entered in the form, or `None` if they are not valid.
+    fn current_valid_xterm_settings(&self) -> Option<XtermSettings> {
+        let form = self.xterm_form.read();
+        if !form.is_valid() {
+            return None;
+        }
+        serde_json::from_value(form.get_submit_data()).ok()
+    }
+}
+
+impl Component for PdmMySettingsDialog {
+    type Message = Msg;
+    type Properties = MySettingsDialog;
+
+    fn create(ctx: &Context<Self>) -> Self {
+        Self {
+            xterm_form: FormContext::new().on_change(ctx.link().callback(|_| Msg::XtermFormChange)),
+            xterm_saved: XtermSettings::load(),
+            novnc_scaling: PersistentState::new(StorageLocation::local("novnc-scaling")),
+        }
+    }
+
+    fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
+        match msg {
+            Msg::XtermFormChange => true,
+            Msg::XtermSave => {
+                if let Some(settings) = self.current_valid_xterm_settings() {
+                    settings.save();
+                    self.xterm_saved = settings;
+                }
+                true
+            }
+            Msg::XtermReset => {
+                self.xterm_saved = XtermSettings::default();
+                self.xterm_saved.save();
+                self.xterm_form.load_form(json!(self.xterm_saved));
+                true
+            }
+            Msg::NoVncScaling(scaling) => {
+                self.novnc_scaling
+                    .update((!scaling.is_empty()).then_some(scaling));
+                false
+            }
+        }
+    }
+
+    fn view(&self, ctx: &Context<Self>) -> Html {
+        let props = ctx.props();
+        let link = ctx.link();
+
+        let current = self.current_valid_xterm_settings();
+        let can_save = current
+            .as_ref()
+            .is_some_and(|entered| *entered != self.xterm_saved);
+        let can_reset = current != Some(XtermSettings::default());
+
+        let section_title = |title: String| {
+            Container::new()
+                .class("pwt-font-title-medium")
+                .with_child(title)
+        };
+
+        let panel = InputPanel::new()
+            .padding(4)
+            .with_custom_child(section_title(tr!("xterm.js Settings")))
+            .with_field(
+                tr!("Font-Family"),
+                Field::new()
+                    .name("fontFamily")
+                    .placeholder(tr!("Default"))
+                    .default(self.xterm_saved.font_family.clone()),
+            )
+            .with_field(
+                tr!("Font-Size"),
+                Number::<u64>::new()
+                    .name("fontSize")
+                    .min(1)
+                    .placeholder(tr!("Default"))
+                    .default(self.xterm_saved.font_size),
+            )
+            .with_field(
+                tr!("Letter Spacing"),
+                Number::<f64>::new()
+                    .name("letterSpacing")
+                    .placeholder(tr!("Default"))
+                    .default(self.xterm_saved.letter_spacing),
+            )
+            .with_field(
+                tr!("Line Height"),
+                Number::<f64>::new()
+                    .name("lineHeight")
+                    .min(0.1)
+                    .placeholder(tr!("Default"))
+                    .default(self.xterm_saved.line_height),
+            )
+            .with_custom_child(
+                Row::new()
+                    .gap(2)
+                    .with_flex_spacer()
+                    .with_child(
+                        Button::new(tr!("Reset"))
+                            .disabled(!can_reset)
+                            .on_activate(link.callback(|_| Msg::XtermReset)),
+                    )
+                    .with_child(
+                        Button::new(tr!("Save"))
+                            .class(ColorScheme::Primary)
+                            .disabled(!can_save)
+                            .on_activate(link.callback(|_| Msg::XtermSave)),
+                    ),
+            )
+            .with_custom_child(section_title(tr!("noVNC Settings")).padding_top(2))
+            .with_field(
+                tr!("Scaling mode"),
+                Combobox::from_key_value_pairs([
+                    ("scale", tr!("Local Scaling")),
+                    ("remote", tr!("Remote Resizing")),
+                    ("off", tr!("Off")),
+                ])
+                .placeholder(tr!("Default"))
+                .default(self.novnc_scaling.clone())
+                .on_change(link.callback(Msg::NoVncScaling)),
+            );
+
+        Dialog::new(tr!("My Settings"))
+            .min_width(400)
+            .on_close(props.on_close.clone())
+            .with_child(
+                Form::new()
+                    .form_context(self.xterm_form.clone())
+                    .with_child(panel),
+            )
+            .into()
+    }
+}
+
+impl From<MySettingsDialog> for VNode {
+    fn from(val: MySettingsDialog) -> Self {
+        let comp = VComp::new::<PdmMySettingsDialog>(Rc::new(val), None);
+        VNode::from(comp)
+    }
+}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH datacenter-manager v2 4/6] ui: view configuration: fix dismissing of remove confirmation dialog
  2026-11-27 17:09 [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
                   ` (2 preceding siblings ...)
  2026-11-27 17:09 ` [PATCH datacenter-manager v2 3/6] ui: add 'My Settings' dialog with xterm.js and noVNC settings Dominik Csapak
@ 2026-11-27 17:09 ` Dominik Csapak
  2026-11-27 17:09 ` [PATCH datacenter-manager v2 5/6] ui: view selector: use a placeholder that can't conflict with a view Dominik Csapak
  2026-11-27 17:09 ` [PATCH datacenter-manager v2 6/6] ui: make the default dashboard page configurable Dominik Csapak
  5 siblings, 0 replies; 7+ messages in thread
From: Dominik Csapak @ 2026-11-27 17:09 UTC (permalink / raw)
  To: pdm-devel

When dismissing a confirm dialog, we need to reset the `ViewState`,
otherwise the dialog is visible until the user navigates away, or clicks
something that changes the `ViewState`.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/configuration/views.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ui/src/configuration/views.rs b/ui/src/configuration/views.rs
index 8016b6d7..955fbb20 100644
--- a/ui/src/configuration/views.rs
+++ b/ui/src/configuration/views.rs
@@ -325,6 +325,7 @@ impl LoadableComponent for ViewGridComp {
                         link.send_message(Msg::Remove(key.clone()));
                     }
                 })
+                .on_close(ctx.link().change_view_callback(|_| None))
                 .into()
             }),
         }
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH datacenter-manager v2 5/6] ui: view selector: use a placeholder that can't conflict with a view
  2026-11-27 17:09 [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
                   ` (3 preceding siblings ...)
  2026-11-27 17:09 ` [PATCH datacenter-manager v2 4/6] ui: view configuration: fix dismissing of remove confirmation dialog Dominik Csapak
@ 2026-11-27 17:09 ` Dominik Csapak
  2026-11-27 17:09 ` [PATCH datacenter-manager v2 6/6] ui: make the default dashboard page configurable Dominik Csapak
  5 siblings, 0 replies; 7+ messages in thread
From: Dominik Csapak @ 2026-11-27 17:09 UTC (permalink / raw)
  To: pdm-devel

since a view could be named '__dashboard__' too. Use '#' instead,
which is not a valid view ID, and expose it as a constant, so that the
code creating the view can use it too.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/configuration/views.rs  |  4 ++--
 ui/src/widget/mod.rs           |  2 +-
 ui/src/widget/view_selector.rs | 11 +++++++++--
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/ui/src/configuration/views.rs b/ui/src/configuration/views.rs
index 955fbb20..91d2361f 100644
--- a/ui/src/configuration/views.rs
+++ b/ui/src/configuration/views.rs
@@ -24,7 +24,7 @@ use pwt::widget::{Button, ConfirmDialog, InputPanel, Toolbar};
 use pdm_api_types::views::{ViewConfig, ViewLayout, ViewTemplate};
 
 use crate::ViewListContext;
-use crate::widget::{ViewFilterSelector, ViewSelector};
+use crate::widget::{DEFAULT_DASHBOARD_VALUE, ViewFilterSelector, ViewSelector};
 
 async fn create_view(
     base_url: AttrValue,
@@ -38,7 +38,7 @@ async fn create_view(
             description: String::new(),
             layout: ViewLayout::Rows { rows: Vec::new() },
         })?),
-        "__dashboard__" => None,
+        DEFAULT_DASHBOARD_VALUE => None,
         layout => {
             let store = store.read();
             if let Some(config) = store.lookup_record(&Key::from(layout)) {
diff --git a/ui/src/widget/mod.rs b/ui/src/widget/mod.rs
index 888a0e19..57088558 100644
--- a/ui/src/widget/mod.rs
+++ b/ui/src/widget/mod.rs
@@ -34,7 +34,7 @@ pub use remote_selector::RemoteSelector;
 mod remote_endpoint_selector;
 
 mod view_selector;
-pub use view_selector::ViewSelector;
+pub use view_selector::{DEFAULT_DASHBOARD_VALUE, ViewSelector};
 
 mod view_filter_selector;
 pub use view_filter_selector::ViewFilterSelector;
diff --git a/ui/src/widget/view_selector.rs b/ui/src/widget/view_selector.rs
index b48ef4f7..9ea9a065 100644
--- a/ui/src/widget/view_selector.rs
+++ b/ui/src/widget/view_selector.rs
@@ -7,6 +7,13 @@ use pwt_macros::{builder, widget};
 
 use pdm_api_types::views::ViewConfig;
 
+/// A placeholder value to represent the default dashboard.
+///
+/// To not conflict with a real view, this is a value that can't be used
+/// in the backend.
+// '#' is too short and uses a forbidden character.
+pub const DEFAULT_DASHBOARD_VALUE: &str = "#";
+
 #[widget(comp=ViewSelectorComp, @input)]
 #[derive(Clone, Properties, PartialEq)]
 #[builder]
@@ -32,7 +39,7 @@ impl Component for ViewSelectorComp {
     }
 
     fn view(&self, ctx: &Context<Self>) -> Html {
-        let mut list = vec!["__dashboard__".into()];
+        let mut list = vec![DEFAULT_DASHBOARD_VALUE.into()];
         let store = &ctx.props().store;
         for item in store.read().data().iter() {
             list.push(item.id.clone().into());
@@ -43,7 +50,7 @@ impl Component for ViewSelectorComp {
             .on_change(|_| {})
             .render_value({
                 move |value: &AttrValue| {
-                    if value == "__dashboard__" {
+                    if value == DEFAULT_DASHBOARD_VALUE {
                         html! {{tr!("Dashboard")}}
                     } else {
                         html! {{value}}
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH datacenter-manager v2 6/6] ui: make the default dashboard page configurable
  2026-11-27 17:09 [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
                   ` (4 preceding siblings ...)
  2026-11-27 17:09 ` [PATCH datacenter-manager v2 5/6] ui: view selector: use a placeholder that can't conflict with a view Dominik Csapak
@ 2026-11-27 17:09 ` Dominik Csapak
  5 siblings, 0 replies; 7+ messages in thread
From: Dominik Csapak @ 2026-11-27 17:09 UTC (permalink / raw)
  To: pdm-devel

by allowing to set the user any view as their dashboard, saved in their
local browser storage.

The selection is in the 'My Settings' dialog. For that, pass the list
of views from the main app through the top nav bar to the dialog.

If the view is not found in the global view list, show a notice for
that.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/dashboard/view.rs            | 18 ++++++++++++++--
 ui/src/main.rs                      |  1 +
 ui/src/main_menu.rs                 | 32 +++++++++++++++++++++++++----
 ui/src/top_nav_bar.rs               |  6 ++++++
 ui/src/widget/my_settings_dialog.rs | 26 ++++++++++++++++++++++-
 5 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/ui/src/dashboard/view.rs b/ui/src/dashboard/view.rs
index 64480310..24678fed 100644
--- a/ui/src/dashboard/view.rs
+++ b/ui/src/dashboard/view.rs
@@ -60,6 +60,7 @@ pub enum EditingMessage {
 #[derive(Properties, PartialEq)]
 pub struct View {
     view: Option<AttrValue>,
+    not_found: bool,
 }
 
 impl From<View> for VNode {
@@ -70,8 +71,11 @@ impl From<View> for VNode {
 }
 
 impl View {
-    pub fn new(view: impl Into<Option<AttrValue>>) -> Self {
-        Self { view: view.into() }
+    pub fn new(view: impl Into<Option<AttrValue>>, not_found: bool) -> Self {
+        Self {
+            view: view.into(),
+            not_found,
+        }
     }
 }
 
@@ -521,6 +525,16 @@ impl Component for ViewComp {
     fn view(&self, ctx: &yew::Context<Self>) -> yew::Html {
         let props = ctx.props();
         let link = ctx.link();
+        match props.view.clone() {
+            Some(view) if props.not_found => {
+                return empty_state(
+                    "search",
+                    tr!("View not found"),
+                    tr!("The configured view '{0}' was not found.", view),
+                );
+            }
+            _ => {}
+        }
         if !self.template.has_data() {
             return Progress::new().into();
         }
diff --git a/ui/src/main.rs b/ui/src/main.rs
index 009e6a38..7642fb55 100644
--- a/ui/src/main.rs
+++ b/ui/src/main.rs
@@ -307,6 +307,7 @@ impl Component for DatacenterManagerApp {
             .with_child(
                 TopNavBar::new(self.running_tasks.clone())
                     .username(username.clone())
+                    .view_list(self.view_list.clone())
                     .on_logout(ctx.link().callback(|_| Msg::Logout)),
             )
             .with_child({
diff --git a/ui/src/main_menu.rs b/ui/src/main_menu.rs
index 8e36717e..4e85f562 100644
--- a/ui/src/main_menu.rs
+++ b/ui/src/main_menu.rs
@@ -1,11 +1,12 @@
 use std::rc::Rc;
 
 use html::IntoPropValue;
+use pwt::props::StorageLocation;
 use yew::virtual_dom::{Key, VComp, VNode};
 
 use pwt::css::{self, Display, FlexFit};
 use pwt::prelude::*;
-use pwt::state::{NavigationContextExt, Selection};
+use pwt::state::{NavigationContextExt, PersistentState, Selection};
 use pwt::widget::nav::{Menu, MenuItem, NavigationDrawer};
 use pwt::widget::{Container, Panel, Row, SelectionView, SelectionViewRenderInfo};
 
@@ -74,6 +75,7 @@ impl MainMenu {
 pub enum Msg {
     Select(Key),
     UpdateAcl(AclContext),
+    UpdateDefaultDashboard,
 }
 
 pub struct PdmMainMenu {
@@ -81,6 +83,7 @@ pub struct PdmMainMenu {
     menu_selection: Selection,
     acl_context: AclContext,
     _acl_context_listener: ContextHandle<AclContext>,
+    default_dashboard: PersistentState<Option<String>>,
 }
 
 fn register_view(
@@ -129,11 +132,17 @@ impl Component for PdmMainMenu {
             .context(ctx.link().callback(Msg::UpdateAcl))
             .expect("acl context not present");
 
+        let default_dashboard = PersistentState::<Option<String>>::new(StorageLocation::Local(
+            "default-dashboard".into(),
+        ))
+        .on_update(ctx.link().callback(|_| Msg::UpdateDefaultDashboard));
+
         Self {
             active: Key::from("dashboard"),
             menu_selection: Selection::new(),
             acl_context,
             _acl_context_listener: acl_context_listener,
+            default_dashboard,
         }
     }
 
@@ -147,6 +156,10 @@ impl Component for PdmMainMenu {
                 self.acl_context = acl_context;
                 true
             }
+            Msg::UpdateDefaultDashboard => {
+                self.default_dashboard.load();
+                true
+            }
         }
     }
 
@@ -168,13 +181,24 @@ impl Component for PdmMainMenu {
 
         let mut menu = Menu::new();
 
+        let default_dashboard: Option<AttrValue> = self.default_dashboard.clone().map(|s| s.into());
+        let not_found = default_dashboard
+            .as_ref()
+            .map(|dashboard| {
+                !props
+                    .view_list
+                    .iter()
+                    .any(|view| view == dashboard.as_str())
+            })
+            .unwrap_or(false);
+
         register_view(
             &mut menu,
             &mut content,
             tr!("Dashboard"),
             "dashboard",
             Some("fa fa-tachometer"),
-            move |_| View::new(None).into(),
+            move |_| View::new(default_dashboard.clone(), not_found).into(),
         );
 
         let mut views = Menu::new();
@@ -192,7 +216,7 @@ impl Component for PdmMainMenu {
                 view.clone(),
                 &format!("view-{view}"),
                 Some("fa fa-plus-square-o"),
-                move |_| View::new(Some(view.clone().into())).into(),
+                move |_| View::new(Some(view.clone().into()), false).into(),
             );
         }
 
@@ -203,7 +227,7 @@ impl Component for PdmMainMenu {
                 view.clone(),
                 &format!("view-{view}"),
                 Some("fa fa-plus-square-o"),
-                move |_| View::new(Some(view.clone().into())).into(),
+                move |_| View::new(Some(view.clone().into()), false).into(),
             );
         }
 
diff --git a/ui/src/top_nav_bar.rs b/ui/src/top_nav_bar.rs
index 015b6b13..35dc08c6 100644
--- a/ui/src/top_nav_bar.rs
+++ b/ui/src/top_nav_bar.rs
@@ -48,6 +48,11 @@ pub struct TopNavBar {
     #[builder(IntoPropValue, into_prop_value)]
     #[prop_or_default]
     pub username: Option<String>,
+
+    /// The views that can be selected as dashboard in the settings.
+    #[builder]
+    #[prop_or_default]
+    pub view_list: Vec<String>,
 }
 
 impl TopNavBar {
@@ -239,6 +244,7 @@ impl Component for PdmTopNavBar {
 
         let dialog: Option<Html> = self.view_state.as_ref().map(|view_state| match view_state {
             ViewState::MySettingsDialog => MySettingsDialog::new()
+                .view_list(props.view_list.clone())
                 .on_close(ctx.link().callback(|_| Msg::ChangeView(None)))
                 .into(),
             ViewState::LanguageDialog => LanguageDialog::new()
diff --git a/ui/src/widget/my_settings_dialog.rs b/ui/src/widget/my_settings_dialog.rs
index 0ec84f71..ae916a47 100644
--- a/ui/src/widget/my_settings_dialog.rs
+++ b/ui/src/widget/my_settings_dialog.rs
@@ -69,6 +69,11 @@ pub struct MySettingsDialog {
     #[builder_cb(IntoEventCallback, into_event_callback, ())]
     #[prop_or_default]
     pub on_close: Option<Callback<()>>,
+
+    /// The views that can be selected as dashboard.
+    #[builder]
+    #[prop_or_default]
+    pub view_list: Vec<String>,
 }
 
 impl Default for MySettingsDialog {
@@ -84,6 +89,7 @@ impl MySettingsDialog {
 }
 
 pub enum Msg {
+    DefaultDashboard(String),
     XtermFormChange,
     XtermSave,
     XtermReset,
@@ -92,6 +98,7 @@ pub enum Msg {
 
 #[doc(hidden)]
 pub struct PdmMySettingsDialog {
+    default_dashboard: PersistentState<Option<String>>,
     xterm_form: FormContext,
     xterm_saved: XtermSettings,
     novnc_scaling: PersistentState<Option<String>>,
@@ -114,6 +121,7 @@ impl Component for PdmMySettingsDialog {
 
     fn create(ctx: &Context<Self>) -> Self {
         Self {
+            default_dashboard: PersistentState::new(StorageLocation::local("default-dashboard")),
             xterm_form: FormContext::new().on_change(ctx.link().callback(|_| Msg::XtermFormChange)),
             xterm_saved: XtermSettings::load(),
             novnc_scaling: PersistentState::new(StorageLocation::local("novnc-scaling")),
@@ -122,6 +130,11 @@ impl Component for PdmMySettingsDialog {
 
     fn update(&mut self, _ctx: &Context<Self>, msg: Self::Message) -> bool {
         match msg {
+            Msg::DefaultDashboard(view) => {
+                self.default_dashboard
+                    .update((!view.is_empty()).then_some(view));
+                false
+            }
             Msg::XtermFormChange => true,
             Msg::XtermSave => {
                 if let Some(settings) = self.current_valid_xterm_settings() {
@@ -160,9 +173,20 @@ impl Component for PdmMySettingsDialog {
                 .with_child(title)
         };
 
+        let views = props.view_list.iter().map(|view| view.clone().into());
+
         let panel = InputPanel::new()
             .padding(4)
-            .with_custom_child(section_title(tr!("xterm.js Settings")))
+            .with_custom_child(section_title(tr!("Web Interface Settings")))
+            .with_field(
+                tr!("Dashboard"),
+                Combobox::new()
+                    .items(Rc::new(views.collect()))
+                    .placeholder(tr!("Default"))
+                    .default(self.default_dashboard.clone())
+                    .on_change(link.callback(Msg::DefaultDashboard)),
+            )
+            .with_custom_child(section_title(tr!("xterm.js Settings")).padding_top(2))
             .with_field(
                 tr!("Font-Family"),
                 Field::new()
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-27 17:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 17:09 [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
2026-11-27 17:09 ` [PATCH yew-widget-toolkit v2 1/6] state: event: add helpers for custom DOM events Dominik Csapak
2026-11-27 17:09 ` [PATCH yew-widget-toolkit v2 2/6] state: persistent state: allow listening for updates Dominik Csapak
2026-11-27 17:09 ` [PATCH datacenter-manager v2 3/6] ui: add 'My Settings' dialog with xterm.js and noVNC settings Dominik Csapak
2026-11-27 17:09 ` [PATCH datacenter-manager v2 4/6] ui: view configuration: fix dismissing of remove confirmation dialog Dominik Csapak
2026-11-27 17:09 ` [PATCH datacenter-manager v2 5/6] ui: view selector: use a placeholder that can't conflict with a view Dominik Csapak
2026-11-27 17:09 ` [PATCH datacenter-manager v2 6/6] ui: make the default dashboard page configurable Dominik Csapak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal