public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager 1/4] ui: subscription_info: add subscription counts
Date: Tue,  2 Dec 2025 11:00:02 +0100	[thread overview]
Message-ID: <20251202100012.1328096-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251202100012.1328096-1-d.csapak@proxmox.com>

count the subscriptions we know of and show them in a tabular style.
Showing each product as a single line with each subscription type as a
column.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 ui/src/dashboard/subscription_info.rs | 109 ++++++++++++++++++++++++--
 1 file changed, 103 insertions(+), 6 deletions(-)

diff --git a/ui/src/dashboard/subscription_info.rs b/ui/src/dashboard/subscription_info.rs
index 6c94b8ef..f9e8c33f 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,18 @@ use yew::{
 };
 
 use proxmox_yew_comp::Status;
+use pwt::css::{AlignItems, AlignSelf, Display, FlexFit, JustifyContent, TextAlign};
 use pwt::prelude::*;
+use pwt::props::PwtSpace;
+use pwt::state::SharedState;
 use pwt::widget::{Button, Column, Container, Dialog, Fa, Panel, Row};
-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 +34,97 @@ 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]) -> Container {
+    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_right_aligned(text: impl Into<Html>) -> Container {
+        Container::new().class(TextAlign::Right).with_child(text)
+    }
+
+    fn render_product(count: SubCount, title: &str) -> Vec<Container> {
+        vec![
+            Container::new().with_child(title),
+            render_right_aligned(count.community),
+            render_right_aligned(count.basic),
+            render_right_aligned(count.standard),
+            render_right_aligned(count.premium),
+            render_right_aligned(count.none),
+        ]
+    }
+
+    let mut list = vec![
+        Container::new().with_child(tr!("Product")),
+        render_right_aligned("Community"),
+        render_right_aligned("Basic"),
+        render_right_aligned("Standard"),
+        render_right_aligned("Premium"),
+        render_right_aligned(tr!("None")),
+    ];
+
+    if pve.total() > 0 {
+        list.append(&mut render_product(pve, "Proxmox VE"));
+    }
+    if pbs.total() > 0 {
+        list.append(&mut render_product(pbs, "Proxmox Backup Server"));
+    }
+
+    if list.is_empty() {
+        return Container::new();
+    }
+
+    Container::new()
+        .padding_x(4)
+        .padding_bottom(4)
+        .class(Display::Grid)
+        .class(AlignSelf::Stretch)
+        .style("grid-template-columns", "1fr repeat(5, 100px)")
+        .style("gap", PwtSpace::Pwt(2))
+        .children(list.into_iter().map(|c| c.into()))
+}
+
 fn render_subscription_status(subs: &[RemoteSubscriptions]) -> Row {
     let mut none = 0;
     let mut mixed = 0;
@@ -122,6 +216,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


  parent reply	other threads:[~2025-12-02 10:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02  9:59 [pdm-devel] [PATCH datacenter-manager/yew-comp 0/6] add basic version guarding for pve guests Dominik Csapak
2025-12-02 10:00 ` [pdm-devel] [PATCH yew-comp 1/2] qemu: options/hardware: prepare and use version feature gating Dominik Csapak
2025-12-02 10:32   ` Thomas Lamprecht
2025-12-02 10:53     ` Dominik Csapak
2025-12-02 10:00 ` [pdm-devel] [PATCH yew-comp 2/2] pve: lxc panels: prepare/add " Dominik Csapak
2025-12-02 10:00 ` Dominik Csapak [this message]
2025-12-02 10:00 ` [pdm-devel] [PATCH datacenter-manager 2/4] lib/server: pve: add api call to get the cached version info from remotes Dominik Csapak
2025-12-02 10:00 ` [pdm-devel] [PATCH datacenter-manager 3/4] ui: pve: qemu: load and pass the pve-manager version to panels Dominik Csapak
2025-12-02 10:00 ` [pdm-devel] [PATCH datacenter-manager 4/4] ui: pve: lxc: " Dominik Csapak
2025-12-02 11:18 ` [pdm-devel] superseded: [PATCH datacenter-manager/yew-comp 0/6] add basic version guarding for pve guests Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251202100012.1328096-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal