display history of topic updates on topic details page
[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 <table>
54 <thead>`,
55 th.renderSubscriptionRowHeader(),
56 ` </thead>
57 <tbody>`,
58 ...(ctx.subscriptions && ctx.subscriptions.map(th.renderSubscriptionRow)),
59 ` </tbody>
60 </table>
61 </section>`,
62 ];
63
64 return th.htmlPage(2, ctx, htmlOptions, content);
65 };