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