From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 218051FF190 for ; Fri, 10 Jan 2025 11:22:32 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 94465290FB; Fri, 10 Jan 2025 11:22:18 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Fri, 10 Jan 2025 11:21:42 +0100 Message-Id: <20250110102142.1212874-7-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110102142.1212874-1-d.csapak@proxmox.com> References: <20250110102142.1212874-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 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 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 5/5] ui: remote edit: add 'web-url' options to the edit panel X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" so users can modify it. Signed-off-by: Dominik Csapak --- ui/src/remotes/edit_remote.rs | 59 ++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/ui/src/remotes/edit_remote.rs b/ui/src/remotes/edit_remote.rs index f9b0356..27c3cb6 100644 --- a/ui/src/remotes/edit_remote.rs +++ b/ui/src/remotes/edit_remote.rs @@ -1,18 +1,24 @@ use std::rc::Rc; +use anyhow::Error; +use serde_json::Value; use yew::html::IntoEventCallback; use yew::virtual_dom::{VComp, VNode}; use pwt::css::FlexFit; use pwt::prelude::*; -use pwt::widget::form::{DisplayField, Field, FormContext, InputType}; -use pwt::widget::{Container, InputPanel}; +use pwt::widget::form::{delete_empty_values, DisplayField, Field, FormContext, InputType}; +use pwt::widget::{Container, InputPanel, Row}; +use proxmox_yew_comp::form::{flatten_property_string, property_string_from_parts}; use proxmox_yew_comp::percent_encoding::percent_encode_component; use proxmox_yew_comp::{EditWindow, SchemaValidation}; +use proxmox_client::ApiResponseData; use proxmox_schema::ApiType; +use pdm_api_types::remotes::WebUrl; + use super::NodeUrlList; use pwt_macros::builder; @@ -37,6 +43,14 @@ impl EditRemote { pub struct PdmEditRemote {} +async fn load_remote(url: AttrValue) -> Result, Error> { + let mut resp: ApiResponseData = proxmox_yew_comp::http_get_full(&*url, None).await?; + + flatten_property_string(&mut resp.data, "web-url", &WebUrl::API_SCHEMA); + + Ok(resp) +} + impl Component for PdmEditRemote { type Message = (); type Properties = EditRemote; @@ -47,14 +61,15 @@ impl Component for PdmEditRemote { fn view(&self, ctx: &Context) -> Html { let props = ctx.props(); + let url = format!( + "/remotes/{}/config", + percent_encode_component(&props.remote_id) + ); EditWindow::new(tr!("Edit") + ": " + &tr!("Remote")) .width(800) .min_height(400) .on_done(props.on_done.clone()) - .loader(format!( - "/remotes/{}/config", - percent_encode_component(&props.remote_id) - )) + .loader((load_remote, url)) .renderer({ let remote_id = props.remote_id.clone(); move |form_ctx| edit_remote_input_panel(form_ctx, &remote_id) @@ -64,7 +79,12 @@ impl Component for PdmEditRemote { move |form_ctx: FormContext| { let url = url.clone(); async move { - let data = form_ctx.get_submit_data(); + let mut data = form_ctx.get_submit_data(); + + property_string_from_parts::(&mut data, "web-url", true); + + let data = delete_empty_values(&data, &["web-url"], true); + proxmox_yew_comp::http_put(&url, Some(data)).await } } @@ -97,6 +117,31 @@ fn edit_remote_input_panel(_form_ctx: &FormContext, remote_id: &str) -> Html { .input_type(InputType::Password) .required(false), ) + .with_field( + tr!("Web Base URL"), + Field::new() + .name("_web-url_base-url") + .placeholder(tr!("Automatically generate from first connection.")), + ) + .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