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 [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 200931FF16E
	for <inbox@lore.proxmox.com>; Mon, 20 Jan 2025 10:30:18 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 234F416198;
	Mon, 20 Jan 2025 10:30:16 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Mon, 20 Jan 2025 10:29:57 +0100
Message-Id: <20250120093006.927014-8-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250120093006.927014-1-d.csapak@proxmox.com>
References: <20250120093006.927014-1-d.csapak@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -1.233 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
 URIBL_DBL_SPAM 2.5 Contains a spam URL listed in the Spamhaus DBL blocklist
 [tasks.rs]
Subject: [pdm-devel] [PATCH yew-comp 7/7] tasks: make the 'show task' action
 configurable
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>

we sometimes want to use a different base url for a task (e.g. remote
tasks on PDM)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/tasks.rs | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/src/tasks.rs b/src/tasks.rs
index bb6eb1d..56da7dd 100644
--- a/src/tasks.rs
+++ b/src/tasks.rs
@@ -7,6 +7,7 @@ use anyhow::Error;
 use pwt::widget::form::{Field, Form, FormContext, InputType};
 
 use gloo_timers::callback::Timeout;
+use html::IntoEventCallback;
 use serde_json::Map;
 use yew::html::IntoPropValue;
 use yew::virtual_dom::{VComp, VNode};
@@ -50,6 +51,11 @@ pub struct Tasks {
     #[builder(IntoPropValue, into_prop_value)]
     pub base_url: Option<AttrValue>,
 
+    #[builder_cb(IntoEventCallback, into_event_callback, (String, Option<i64>))]
+    #[prop_or_default]
+    /// Called when the task is opened
+    pub on_show_task: Option<Callback<(String, Option<i64>)>>,
+
     #[builder(IntoPropValue, into_prop_value)]
     #[prop_or_default]
     /// An optional column configuration that overwrites the default one.
@@ -88,6 +94,7 @@ pub enum Msg {
     ToggleFilter,
     LoadBatch(u64), // start
     UpdateFilter,
+    ShowTask,
 }
 pub struct ProxmoxTasks {
     selection: Selection,
@@ -270,6 +277,22 @@ impl LoadableComponent for ProxmoxTasks {
                 }));
                 false
             }
+            Msg::ShowTask => {
+                if let Some(on_show_task) = &ctx.props().on_show_task {
+                    let selected_item = self
+                        .selection
+                        .selected_key()
+                        .and_then(|key| self.store.read().lookup_record(&key).cloned());
+                    let selected_item = match selected_item {
+                        Some(item) => item,
+                        None => return false,
+                    };
+                    on_show_task.emit((selected_item.upid, selected_item.endtime));
+                } else {
+                    ctx.link().change_view(Some(ViewDialog::TaskViewer));
+                }
+                false
+            }
         }
     }
 
@@ -292,10 +315,9 @@ impl LoadableComponent for ProxmoxTasks {
             .class("pwt-overflow-hidden")
             .class("pwt-border-bottom")
             .with_child(
-                Button::new(tr!("View")).disabled(disabled).onclick(
-                    ctx.link()
-                        .change_view_callback(|_| Some(ViewDialog::TaskViewer)),
-                ),
+                Button::new(tr!("View"))
+                    .disabled(disabled)
+                    .onclick(ctx.link().callback(|_| Msg::ShowTask)),
             )
             .with_flex_spacer()
             .with_child({
@@ -373,7 +395,7 @@ impl LoadableComponent for ProxmoxTasks {
             .class("pwt-flex-fit")
             .selection(self.selection.clone())
             .on_row_dblclick(move |_: &mut _| {
-                link.change_view(Some(ViewDialog::TaskViewer));
+                link.send_message(Msg::ShowTask);
             })
             .row_render_callback(self.row_render_callback.clone())
             .into()
-- 
2.39.5



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