[pdm-devel] [PATCH datacenter-manager v4 8/8] ui: dashboard: make task summary time range configurable
Dominik Csapak
d.csapak at proxmox.com
Tue Aug 26 12:15:18 CEST 2025
in the browsers local storage.
We already have now an interface to configure this, so use it to store
the timeframe to check for tasks
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v3:
* deduplicate hours/since calculation
* remove hours/since from the StatisticsOptions since it's saved in the
dashboard_config
ui/src/dashboard/mod.rs | 56 ++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 20 deletions(-)
diff --git a/ui/src/dashboard/mod.rs b/ui/src/dashboard/mod.rs
index 502332a..cc62870 100644
--- a/ui/src/dashboard/mod.rs
+++ b/ui/src/dashboard/mod.rs
@@ -59,6 +59,9 @@ pub const DEFAULT_MAX_AGE_S: u64 = 60;
/// The default refresh interval
pub const DEFAULT_REFRESH_INTERVAL_S: u64 = DEFAULT_MAX_AGE_S / 2;
+/// The default hours to show for task summaries
+pub const DEFAULT_TASK_SUMMARY_HOURS: u32 = 24;
+
#[derive(Properties, PartialEq)]
pub struct Dashboard {}
@@ -81,6 +84,8 @@ pub struct DashboardConfig {
refresh_interval: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
max_age: Option<u64>,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ task_last_hours: Option<u32>,
}
pub type LoadingResult = (
@@ -99,8 +104,6 @@ pub enum Msg {
}
struct StatisticsOptions {
- hours: u32,
- since: i64,
data: Option<TaskStatistics>,
error: Option<Error>,
}
@@ -194,13 +197,10 @@ impl PdmDashboard {
statistics: &StatisticsOptions,
remotes: Option<u32>,
) -> Panel {
+ let (hours, since) = Self::get_task_options(&self.config);
let title = match remotes {
- Some(count) => tr!(
- "Task Summary for Top {0} Remotes (Last {1}h)",
- count,
- statistics.hours
- ),
- None => tr!("Task Summary by Category (Last {0}h)", statistics.hours),
+ Some(count) => tr!("Task Summary for Top {0} Remotes (Last {1}h)", count, hours),
+ None => tr!("Task Summary by Category (Last {0}h)", hours),
};
Panel::new()
.flex(1.0)
@@ -215,7 +215,7 @@ impl PdmDashboard {
statistics
.data
.clone()
- .map(|data| TaskSummary::new(data, statistics.since, remotes)),
+ .map(|data| TaskSummary::new(data, since, remotes)),
)
.with_optional_child(
(statistics.error.is_none() && statistics.data.is_none())
@@ -257,6 +257,7 @@ impl PdmDashboard {
fn reload(&mut self, ctx: &yew::Context<Self>) {
let link = ctx.link().clone();
let max_age = self.config.max_age.unwrap_or(DEFAULT_MAX_AGE_S);
+ let (_, since) = Self::get_task_options(&self.config);
self.load_finished_time = None;
self.async_pool.spawn(async move {
@@ -265,7 +266,6 @@ impl PdmDashboard {
let top_entities_future = client.get_top_entities();
let status_future = http_get("/resources/status", Some(json!({"max-age": max_age})));
- let since = (Date::now() / 1000.0) as i64 - (24 * 60 * 60);
let params = Some(json!({
"since": since,
"limit": 0,
@@ -284,6 +284,12 @@ impl PdmDashboard {
)));
});
}
+
+ fn get_task_options(config: &PersistentState<DashboardConfig>) -> (u32, i64) {
+ let hours = config.task_last_hours.unwrap_or(DEFAULT_TASK_SUMMARY_HOURS);
+ let since = (Date::now() / 1000.0) as i64 - (hours * 60 * 60) as i64;
+ (hours, since)
+ }
}
impl Component for PdmDashboard {
@@ -291,7 +297,8 @@ impl Component for PdmDashboard {
type Properties = Dashboard;
fn create(ctx: &yew::Context<Self>) -> Self {
- let config = PersistentState::new(StorageLocation::local("dashboard-config"));
+ let config: PersistentState<DashboardConfig> =
+ PersistentState::new(StorageLocation::local("dashboard-config"));
let async_pool = AsyncPool::new();
let (remote_list, _context_listener) = ctx
@@ -299,20 +306,15 @@ impl Component for PdmDashboard {
.context(ctx.link().callback(Msg::RemoteListChanged))
.expect("No Remote list context provided");
- let since = (Date::now() / 1000.0) as i64 - (24 * 60 * 60);
- let statistics = StatisticsOptions {
- hours: 24,
- since,
- data: None,
- error: None,
- };
-
let mut this = Self {
status: ResourcesStatus::default(),
last_error: None,
top_entities: None,
last_top_entities_error: None,
- statistics,
+ statistics: StatisticsOptions {
+ data: None,
+ error: None,
+ },
loading: true,
load_finished_time: None,
remote_list,
@@ -374,7 +376,14 @@ impl Component for PdmDashboard {
true
}
Msg::UpdateConfig(dashboard_config) => {
+ let (old_hours, _) = Self::get_task_options(&self.config);
self.config.update(dashboard_config);
+ let (new_hours, _) = Self::get_task_options(&self.config);
+
+ if old_hours != new_hours {
+ self.reload(ctx);
+ }
+
self.show_config_window = false;
true
}
@@ -592,6 +601,13 @@ impl Component for PdmDashboard {
DisplayField::new()
.key("max-age-explanation")
.value(tr!("If a response from a remote is older than 'Max Age', it will be updated on the next refresh.")))
+ .with_field(
+ tr!("Task Summary Time Range (last hours)"),
+ Number::new()
+ .name("task-last-hours")
+ .min(0u64)
+ .placeholder(DEFAULT_TASK_SUMMARY_HOURS.to_string()),
+ )
.into()
})
.on_close(ctx.link().callback(|_| Msg::ConfigWindow(false)))
--
2.47.2
More information about the pdm-devel
mailing list