From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pdm-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id C1D041FF16B
	for <inbox@lore.proxmox.com>; Thu, 23 Jan 2025 14:28:31 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id B0D64C767;
	Thu, 23 Jan 2025 14:28:27 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Thu, 23 Jan 2025 14:27:54 +0100
Message-Id: <20250123132754.3271555-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.39.5
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.018 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pdm-devel] [PATCH datacenter-manager] remove 'per-node-template'
 from the weburl config
X-BeenThere: pdm-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Datacenter Manager development discussion
 <pdm-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/>
List-Post: <mailto:pdm-devel@lists.proxmox.com>
List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Datacenter Manager development discussion
 <pdm-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pdm-devel-bounces@lists.proxmox.com
Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com>

* 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@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



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel