From 90fb07086b3705a7cfd84a775adec905e5b6dc5f Mon Sep 17 00:00:00 2001
From: Justin Wind <justin.wind+git@gmail.com>
Date: Thu, 3 Nov 2022 15:17:36 -0700
Subject: [PATCH] add indicator for percent of sucessfully updated subscription
 to topic details

---
 src/manager.js                           |  8 +++++---
 src/template/admin-topic-details-html.js | 11 +++++++++--
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/manager.js b/src/manager.js
index b6d2ccb..74730c2 100644
--- a/src/manager.js
+++ b/src/manager.js
@@ -579,7 +579,7 @@ class Manager {
    * @param {object} ctx
    */
   async getHistorySVG(res, ctx) {
-    const _scope = _fileScope('getHist');
+    const _scope = _fileScope('getHistorySVG');
     this.logger.debug(_scope, 'called', { ctx });
 
     const days = Math.min(parseInt(ctx.queryParams.days) || this.options.manager.publishHistoryDays, 365);
@@ -658,8 +658,7 @@ class Manager {
     const _scope = _fileScope('getTopicDetails');
     this.logger.debug(_scope, 'called', { ctx });
 
-
-    ctx.publishSpan = 60;
+    ctx.publishSpan = 60; // FIXME: configurable
     const topicId = ctx.params.topicId;
     let publishHistory;
     await this.db.context(async (dbCtx) => {
@@ -668,6 +667,9 @@ class Manager {
       publishHistory = await this.db.topicPublishHistory(dbCtx, topicId, ctx.publishSpan);
     });
     ctx.publishCount = publishHistory.reduce((a, b) => a + b, 0);
+    ctx.subscriptionsDelivered = ctx.subscriptions.filter((subscription) => {
+      return subscription.latestContentDelivered >= ctx.topic.contentUpdated;
+    }).length;
     this.logger.debug(_scope, 'got topic details', { topic: ctx.topic, subscriptions: ctx.subscriptions, updates: ctx.publishCount });
 
     // Profile users can only see related topics.
diff --git a/src/template/admin-topic-details-html.js b/src/template/admin-topic-details-html.js
index abf441a..1d0add0 100644
--- a/src/template/admin-topic-details-html.js
+++ b/src/template/admin-topic-details-html.js
@@ -49,8 +49,15 @@ module.exports = (ctx, options) => {
         <img title="Topic Publish History" src="${ctx.params.topicId}/history.svg">
       </section>`,
     `      <section class="subscriptions">
-        <p>${ctx.subscriptions.length ? ctx.subscriptions.length : 'no'} subscription${(ctx.subscriptions.length === 1) ? '' : 's'}</p>
-        <table>
+        <p>${ctx.subscriptions.length ? ctx.subscriptions.length : 'no'} subscription${(ctx.subscriptions.length === 1) ? '' : 's'}</p>`,
+    ...(ctx.subscriptions.length && [`
+        <label for="subscriptions-delivered">
+          Successful Deliveries of Latest Content
+        </label>
+        <progress id="subscriptions-delivered" max="${ctx.subscriptions.length}" value="${ctx.subscriptionsDelivered}">
+          ${ctx.subscriptionsDelivered} of ${ctx.subscriptions.length} (${Math.ceil(100 * ctx.subscriptions.length / ctx.subscriptionsDelivered)}%)
+        </progress>`] || []),
+    `        <table>
           <thead>`,
     th.renderSubscriptionRowHeader(),
     `          </thead>
-- 
2.49.0