[pdm-devel] [PATCH datacenter-manager v2 5/7] ui: tasks: add helper to summarize task categories
Dominik Csapak
d.csapak at proxmox.com
Wed Feb 19 13:28:22 CET 2025
one for mapping UPID worker types to shortahnds that can be used for
pre-filtering via the api (have to filter on the client side a bit more
since we'll return more than what we want with the current filtering
api)
and one for creating a title for each type
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
ui/src/tasks.rs | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/ui/src/tasks.rs b/ui/src/tasks.rs
index 0e7899c..a94cc9a 100644
--- a/ui/src/tasks.rs
+++ b/ui/src/tasks.rs
@@ -120,3 +120,32 @@ pub fn format_optional_remote_upid(upid: &str, include_remote: bool) -> String {
format_upid(&upid)
}
}
+
+/// Map worker types to sensible categories (that can also be used as filter for the api)
+///
+/// Note: if using as filter for the api, the result has to be filtered with this again, since
+/// more records will be returned. E.g. using 'vz' will also return 'vzdump' tasks which are
+/// not desired.
+pub fn map_worker_type(worker_type: &str) -> &str {
+ match worker_type {
+ task_type if task_type.contains("migrate") => "migrate",
+ task_type if task_type.starts_with("qm") => "qm",
+ task_type if task_type.starts_with("vz") && task_type != "vzdump" => "vz",
+ task_type if task_type.starts_with("ceph") => "ceph",
+ task_type if task_type.starts_with("ha") => "ha",
+ other => other,
+ }
+}
+
+/// Map a category from [`map_worker_type`] to a title text.
+pub fn get_type_title(task_type: &str) -> String {
+ match task_type {
+ "migrate" => tr!("Guest Migrations"),
+ "qm" => tr!("Virtual Machine related Tasks"),
+ "vz" => tr!("Container related Tasks"),
+ "ceph" => tr!("Ceph related Tasks"),
+ "vzdump" => tr!("Backup Tasks"),
+ "ha" => tr!("HA related Tasks"),
+ other => other.to_string(),
+ }
+}
--
2.39.5
More information about the pdm-devel
mailing list