[pdm-devel] [PATCH datacenter-manager] remove 'per-node-template' from the weburl config

Dominik Csapak d.csapak at proxmox.com
Thu Jan 23 14:27:54 CET 2025


* remove the property from the struct
* remove the second edit field
* adapt url generation code

i left the 'node' parameter in the 'get_deep_url' since we'll want to
add it later again (does not hurt to not use it), but removed the option
from the config again, otherwise a user might set it and wonders why it
doesn't to anything.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 lib/pdm-api-types/src/remotes.rs |  4 ---
 ui/src/lib.rs                    | 50 +++++++++++++-------------------
 ui/src/remotes/edit_remote.rs    | 19 ------------
 3 files changed, 20 insertions(+), 53 deletions(-)

diff --git a/lib/pdm-api-types/src/remotes.rs b/lib/pdm-api-types/src/remotes.rs
index 01ee95a..76e42d9 100644
--- a/lib/pdm-api-types/src/remotes.rs
+++ b/lib/pdm-api-types/src/remotes.rs
@@ -44,10 +44,6 @@ pub struct WebUrl {
     /// A base URL for accessing the remote.
     #[serde(skip_serializing_if = "Option::is_none")]
     pub base_url: Option<String>,
-
-    /// A template for a per node URL. replaces {{nodename}} with the nodename.
-    #[serde(skip_serializing_if = "Option::is_none")]
-    pub per_node_template: Option<String>,
 }
 
 #[api]
diff --git a/ui/src/lib.rs b/ui/src/lib.rs
index cee7791..cf7b15e 100644
--- a/ui/src/lib.rs
+++ b/ui/src/lib.rs
@@ -82,7 +82,7 @@ pub(crate) fn get_remote<C: yew::Component>(
 pub(crate) fn get_deep_url<C: yew::Component>(
     link: &yew::html::Scope<C>,
     remote: &str,
-    node: Option<&str>,
+    _node: Option<&str>,
     id: &str,
 ) -> Option<web_sys::Url> {
     let remote = get_remote(link, remote)?;
@@ -91,37 +91,27 @@ pub(crate) fn get_deep_url<C: yew::Component>(
         (id, pdm_api_types::remotes::RemoteType::Pve) => format!("v1::={id}"),
         (id, pdm_api_types::remotes::RemoteType::Pbs) => format!("DataStore-{id}"),
     };
+    let url = remote
+        .web_url
+        .as_deref()
+        .and_then(|web_url| web_url.base_url.as_deref())
+        .and_then(|url| web_sys::Url::new(url).ok())
+        .or_else(|| {
+            let node = remote.nodes.first()?;
+            let url = web_sys::Url::new(&format!("https://{}/", node.hostname));
+            url.ok().inspect(|url| {
+                if url.port() == "" {
+                    let default_port = match remote.ty {
+                        pdm_api_types::remotes::RemoteType::Pve => "8006",
+                        pdm_api_types::remotes::RemoteType::Pbs => "8007",
+                    };
+                    url.set_port(default_port);
+                }
+            })
+        });
 
-    let url = match remote.web_url {
-        Some(web_url) => match (web_url.per_node_template.as_deref(), node) {
-            (Some(template), Some(node)) => {
-                web_sys::Url::new(&template.replace("{{nodename}}", node)).ok()
-            }
-            _ => web_url
-                .base_url
-                .as_ref()
-                .map(|url| web_sys::Url::new(url).ok())
-                .flatten(),
-        },
-        None => None,
-    }
-    .or_else(|| {
-        let node = remote.nodes.first()?;
-        let url = web_sys::Url::new(&format!("https://{}/", node.hostname));
-        url.ok().map(|url| {
-            if url.port() == "" {
-                let default_port = match remote.ty {
-                    pdm_api_types::remotes::RemoteType::Pve => "8006",
-                    pdm_api_types::remotes::RemoteType::Pbs => "8007",
-                };
-                url.set_port(default_port);
-            }
-            url
-        })
-    });
-    url.map(|url| {
+    url.inspect(|url| {
         url.set_hash(&hash);
-        url
     })
 }
 
diff --git a/ui/src/remotes/edit_remote.rs b/ui/src/remotes/edit_remote.rs
index 3c98fa1..d9c0e6f 100644
--- a/ui/src/remotes/edit_remote.rs
+++ b/ui/src/remotes/edit_remote.rs
@@ -123,25 +123,6 @@ fn edit_remote_input_panel(_form_ctx: &FormContext, remote_id: &str) -> Html {
                 .name("_web-url_base-url")
                 .placeholder(tr!("Use first endpoint.")),
         )
-        .with_field(
-            tr!("per Node URL template"),
-            Field::new()
-                .name("_web-url_per-node-template")
-                .placeholder(tr!("Same as Web Base URL.")),
-        )
-        .with_custom_child(
-            Row::new()
-                .key("hint-text")
-                .gap(2)
-                .with_child(Container::new().with_child(tr!(
-                    "Possible template values for 'per Node URL template' are:"
-                )))
-                .with_child(
-                    Container::new()
-                        .style("font-family", "monospace")
-                        .with_child("{{nodename}}"),
-                ),
-        )
         .with_custom_child(
             Container::new()
                 .key("nodes-title")
-- 
2.39.5





More information about the pdm-devel mailing list