all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pdm-devel] [PATCH datacenter-manager] ui: subscription_info: add subscription counts
@ 2025-11-28 13:51 Dominik Csapak
  0 siblings, 0 replies; only message in thread
From: Dominik Csapak @ 2025-11-28 13:51 UTC (permalink / raw)
  To: pdm-devel

count the subscriptions we know of and show them in a tabular style.
the list is split between PVE and PBS.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
not super sure about the style and positioning, and when one has many
different types of subscriptions, this can get rather large

maybe it would be better as it's own panel?

 ui/src/dashboard/subscription_info.rs | 99 ++++++++++++++++++++++++++-
 1 file changed, 96 insertions(+), 3 deletions(-)

diff --git a/ui/src/dashboard/subscription_info.rs b/ui/src/dashboard/subscription_info.rs
index 6c94b8ef..73c70c0c 100644
--- a/ui/src/dashboard/subscription_info.rs
+++ b/ui/src/dashboard/subscription_info.rs
@@ -1,3 +1,4 @@
+use std::collections::HashMap;
 use std::rc::Rc;
 
 use anyhow::Error;
@@ -7,16 +8,19 @@ use yew::{
 };
 
 use proxmox_yew_comp::Status;
-use pwt::prelude::*;
 use pwt::widget::{Button, Column, Container, Dialog, Fa, Panel, Row};
+use pwt::{css::AlignSelf, prelude::*};
 use pwt::{
     css::{AlignItems, FlexFit, JustifyContent, TextAlign},
     state::SharedState,
 };
 
-use pdm_api_types::subscription::{RemoteSubscriptionState, RemoteSubscriptions};
+use pdm_api_types::remotes::RemoteType;
+use pdm_api_types::subscription::{
+    NodeSubscriptionInfo, RemoteSubscriptionState, RemoteSubscriptions, SubscriptionLevel,
+};
 
-use crate::{dashboard::SubscriptionsList, LoadResult};
+use crate::{dashboard::SubscriptionsList, get_remote_list, LoadResult, RemoteList};
 
 #[derive(Properties, PartialEq)]
 pub struct SubscriptionInfo {
@@ -31,6 +35,92 @@ impl SubscriptionInfo {
 
 struct PdmSubscriptionInfo;
 
+#[derive(Default)]
+struct SubCount {
+    community: u32,
+    basic: u32,
+    standard: u32,
+    premium: u32,
+    none: u32,
+}
+
+impl SubCount {
+    fn count_subs(&mut self, subscriptions: &HashMap<String, Option<NodeSubscriptionInfo>>) {
+        for info in subscriptions.values().flatten() {
+            match info.level {
+                SubscriptionLevel::None => self.none += 1,
+                SubscriptionLevel::Unknown => {}
+                SubscriptionLevel::Community => self.community += 1,
+                SubscriptionLevel::Basic => self.basic += 1,
+                SubscriptionLevel::Standard => self.standard += 1,
+                SubscriptionLevel::Premium => self.premium += 1,
+            }
+        }
+    }
+
+    fn total(&self) -> u32 {
+        self.community + self.basic + self.standard + self.none
+    }
+}
+
+fn render_subscription_list(remotes: RemoteList, subs: &[RemoteSubscriptions]) -> Column {
+    let mut pve = SubCount::default();
+    let mut pbs = SubCount::default();
+
+    for sub in subs {
+        if let Some(remote_type) = remotes
+            .iter()
+            .find_map(|remote| (remote.id == sub.remote).then_some(remote.ty))
+        {
+            if let Some(hash) = sub.node_status.as_ref() {
+                match remote_type {
+                    RemoteType::Pve => pve.count_subs(hash),
+                    RemoteType::Pbs => pbs.count_subs(hash),
+                }
+            }
+        }
+    }
+
+    fn render_row(count: u32, text: impl Into<Html>) -> Option<Row> {
+        (count > 0).then_some(
+            Row::new()
+                .padding_start(2)
+                .gap(2)
+                .with_child(Container::new().with_child(text))
+                .with_flex_spacer()
+                .with_child(Container::new().with_child(count)),
+        )
+    }
+
+    fn render_product(count: SubCount, title: &str) -> Option<Column> {
+        (count.total() > 0).then_some(
+            Column::new()
+                .class(FlexFit)
+                .class(AlignSelf::Stretch)
+                .padding_x(4)
+                .padding_bottom(4)
+                .gap(1)
+                .with_child(
+                    Row::new()
+                        .gap(2)
+                        .with_child(Container::new().with_child(title))
+                        .with_flex_spacer()
+                        .with_child(Container::new().with_child(tr!("Subscriptions"))),
+                )
+                .with_optional_child(render_row(count.community, "Community"))
+                .with_optional_child(render_row(count.basic, "Basic"))
+                .with_optional_child(render_row(count.standard, "Standard"))
+                .with_optional_child(render_row(count.premium, "Premium"))
+                .with_optional_child(render_row(count.none, tr!("None"))),
+        )
+    }
+
+    Column::new()
+        .class(AlignSelf::Stretch)
+        .with_optional_child(render_product(pve, "Proxmox VE"))
+        .with_optional_child(render_product(pbs, "Proxmox Backup Server"))
+}
+
 fn render_subscription_status(subs: &[RemoteSubscriptions]) -> Row {
     let mut none = 0;
     let mut mixed = 0;
@@ -122,6 +212,9 @@ impl Component for PdmSubscriptionInfo {
                     .as_ref()
                     .map(|subs| render_subscription_status(subs)),
             )
+            .with_optional_child(props.subs.as_ref().and_then(|subs| {
+                get_remote_list(ctx.link()).map(|remotes| render_subscription_list(remotes, subs))
+            }))
             .into()
     }
 }
-- 
2.47.3



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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-11-28 13:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-28 13:51 [pdm-devel] [PATCH datacenter-manager] ui: subscription_info: add subscription counts Dominik Csapak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal