add indicator for percent of sucessfully updated subscription to topic details
[websub-hub] / src / template / admin-topic-details-html.js
1 'use strict';
2
3 const th = require('./template-helper');
4
5 /**
6 * Show a topic with all of its subscribers.
7 * @param {Object} ctx
8 * @param {Object} ctx.topic
9 * @param {Object[]} ctx.subscriptions
10 * @param {Object} options
11 * @param {Object} options.manager
12 * @param {String} options.manager.pageTitle
13 * @returns {String}
14 */
15 module.exports = (ctx, options) => {
16 const pageTitle = `${options.manager.pageTitle} - Topic Details`;
17 const logoUrl = options.manager.logoUrl;
18 const navLinks = [
19 {
20 href: '..',
21 text: '↑ All Topics',
22 },
23 ];
24 const footerEntries = options.manager.footerEntries;
25 if (!ctx.subscriptions) {
26 ctx.subscriptions = [];
27 }
28
29 const htmlOptions = {
30 pageTitle,
31 logoUrl,
32 navLinks,
33 footerEntries,
34 };
35
36 const content = [
37 ` <section class="topics">
38 <table>
39 <thead>`,
40 th.renderTopicRowHeader(),
41 ` </thead>
42 <tbody>`,
43 ...(ctx.topic && [ th.renderTopicRow(ctx.topic, ctx.subscriptions, false) ] || []),
44 ` </tbody>
45 </table>
46 </section>`,
47 ` <section class="history">
48 <p>Topic Publish History &mdash; ${ctx.publishCount} updates in the last ${ctx.publishSpan} days</p>
49 <img title="Topic Publish History" src="${ctx.params.topicId}/history.svg">
50 </section>`,
51 ` <section class="subscriptions">
52 <p>${ctx.subscriptions.length ? ctx.subscriptions.length : 'no'} subscription${(ctx.subscriptions.length === 1) ? '' : 's'}</p>`,
53 ...(ctx.subscriptions.length && [`
54 <label for="subscriptions-delivered">
55 Successful Deliveries of Latest Content
56 </label>
57 <progress id="subscriptions-delivered" max="${ctx.subscriptions.length}" value="${ctx.subscriptionsDelivered}">
58 ${ctx.subscriptionsDelivered} of ${ctx.subscriptions.length} (${Math.ceil(100 * ctx.subscriptions.length / ctx.subscriptionsDelivered)}%)
59 </progress>`] || []),
60 ` <table>
61 <thead>`,
62 th.renderSubscriptionRowHeader(),
63 ` </thead>
64 <tbody>`,
65 ...(ctx.subscriptions && ctx.subscriptions.map(th.renderSubscriptionRow)),
66 ` </tbody>
67 </table>
68 </section>`,
69 ];
70
71 return th.htmlPage(2, ctx, htmlOptions, content);
72 };