all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH datacenter-manager v2 3/6] ui: add 'My Settings' dialog with xterm.js and noVNC settings
Date: Fri, 27 Nov 2026 18:09:24 +0100	[thread overview]
Message-ID: <20261127170941.4183880-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261127170941.4183880-1-d.csapak@proxmox.com>

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





  parent reply	other threads:[~2026-11-27 17:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127170941.4183880-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal