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 AF3031FF16E
	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 2186016216;
	Mon, 20 Jan 2025 10:30:17 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Mon, 20 Jan 2025 10:30:06 +0100
Message-Id: <20250120093006.927014-17-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 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
 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 9/9] ui: also show running
 remote tasks in 'running tasks' list
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>

by doing a second api call for the remote tasks, and mixing in the
results into the list.

To correctly show the remote tasks in the list, use the 'render'
property to render the remote tasks differently.

On the OpenTask viewstate, use a different baseurl for the task viewer
for remote tasks.

To determine if a UPID is a remote one, try to parse it as a
`RemoteUpid`.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/main.rs        | 19 ++++++++++++++-
 ui/src/top_nav_bar.rs | 54 +++++++++++++++++++++++++++++++++++++------
 2 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/ui/src/main.rs b/ui/src/main.rs
index 42257a9..6e2c9b2 100644
--- a/ui/src/main.rs
+++ b/ui/src/main.rs
@@ -1,5 +1,6 @@
 use anyhow::Error;
 use gloo_timers::callback::Timeout;
+use serde_json::json;
 use wasm_bindgen::JsCast;
 use web_sys::HtmlElement;
 
@@ -135,7 +136,23 @@ impl Component for DatacenterManagerApp {
 
         let running_tasks = Loader::new()
             .on_change(ctx.link().callback(|_| Msg::TaskChanged))
-            .loader("/nodes/localhost/tasks?running=1&limit=100");
+            .loader((
+                |url: AttrValue| async move {
+                    // TODO replace with pdm client call
+                    let params = Some(json!({
+                        "limit": 100,
+                        "running": true,
+                    }));
+                    let mut res: Vec<TaskListItem> =
+                        http_get(url.to_string(), params.clone()).await?;
+
+                    let res2: Vec<_> = http_get("/remote-tasks/list", params).await?;
+                    res.extend_from_slice(&res2);
+
+                    Ok(res.into_iter().take(100).collect())
+                },
+                "/nodes/localhost/tasks",
+            ));
 
         let login_info = authentication_from_cookie(&proxmox_yew_comp::ExistingProduct::PDM);
 
diff --git a/ui/src/top_nav_bar.rs b/ui/src/top_nav_bar.rs
index 70ba524..07b3b23 100644
--- a/ui/src/top_nav_bar.rs
+++ b/ui/src/top_nav_bar.rs
@@ -13,11 +13,15 @@ use pwt::state::{Loader, Theme, ThemeObserver};
 use pwt::widget::{Button, Container, Row, ThemeModeSelector, Tooltip};
 
 use proxmox_yew_comp::common_api_types::TaskListItem;
+use proxmox_yew_comp::utils::{format_task_description, format_upid, set_location_href};
 use proxmox_yew_comp::RunningTasksButton;
 use proxmox_yew_comp::{http_get, HelpButton, LanguageDialog, TaskViewer, ThemeDialog};
 
 use pwt_macros::builder;
 
+use pdm_api_types::RemoteUpid;
+use pdm_client::types::PveUpid;
+
 use crate::widget::SearchBox;
 
 #[derive(Deserialize)]
@@ -185,10 +189,38 @@ impl Component for PdmTopNavBar {
 
         if let Some(username) = &props.username {
             button_group.add_child(
-                RunningTasksButton::new(props.running_tasks.clone()).on_show_task(
-                    ctx.link()
-                        .callback(|info| Msg::ChangeView(Some(ViewState::OpenTask(info)))),
-                ),
+                RunningTasksButton::new(props.running_tasks.clone())
+                    .on_show_task(
+                        ctx.link()
+                            .callback(|info| Msg::ChangeView(Some(ViewState::OpenTask(info)))),
+                    )
+                    .buttons(vec![
+                        Button::new(tr!("Show Local Tasks"))
+                            .class(ColorScheme::Primary)
+                            .onclick(move |_| {
+                                set_location_href("#/administration/tasks");
+                            }),
+                        Button::new(tr!("Show Remote Tasks"))
+                            .class(ColorScheme::Primary)
+                            .onclick(move |_| {
+                                set_location_href("#/remotes/tasks");
+                            }),
+                    ])
+                    .render(|item: &TaskListItem| {
+                        if let Ok(remote_upid) = (&item.upid).parse::<RemoteUpid>() {
+                            let description = match remote_upid.upid.parse::<PveUpid>() {
+                                Ok(upid) => format_task_description(
+                                    &upid.worker_type,
+                                    upid.worker_id.as_deref(),
+                                ),
+                                Err(_) => format_upid(&remote_upid.upid),
+                            };
+                            format!("{} - {}", remote_upid.remote(), description)
+                        } else {
+                            format_upid(&item.upid)
+                        }
+                        .into()
+                    }),
             );
 
             button_group.add_child(
@@ -207,9 +239,17 @@ impl Component for PdmTopNavBar {
             ViewState::ThemeDialog => ThemeDialog::new()
                 .on_close(ctx.link().callback(|_| Msg::ChangeView(None)))
                 .into(),
-            ViewState::OpenTask((task_id, _endtime)) => TaskViewer::new(task_id)
-                .on_close(ctx.link().callback(|_| Msg::ChangeView(None)))
-                .into(),
+            ViewState::OpenTask((task_id, _endtime)) => {
+                // TODO PBS
+                let base_url = task_id
+                    .parse::<RemoteUpid>()
+                    .ok()
+                    .map(|upid| format!("/pve/remotes/{}/tasks", upid.remote()));
+                TaskViewer::new(task_id)
+                    .base_url(base_url.unwrap_or("/nodes/localhost/tasks".to_string()))
+                    .on_close(ctx.link().callback(|_| Msg::ChangeView(None)))
+                    .into()
+            }
         });
 
         let src = if self.dark_mode {
-- 
2.39.5



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