Initial release
[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 headElements = [];
18 const navLinks = [
19 {
20 href: '..',
21 text: '↑ All Topics',
22 },
23 ];
24 if (!ctx.subscriptions) {
25 ctx.subscriptions = [];
26 }
27 return th.htmlTemplate(2, pageTitle, headElements, navLinks, [
28 ` <section class="topics">
29 <table>
30 <thead>`,
31 th.renderTopicRowHeader(),
32 ` </thead>
33 <tbody>`,
34 ...(ctx.topic && [ th.renderTopicRow(ctx.topic, ctx.subscriptions, false) ]),
35 ` </tbody>
36 </table>
37 </section>`,
38 ` <section class="subscriptions">
39 <p>${ctx.subscriptions.length ? ctx.subscriptions.length : 'no'} subscription${(ctx.subscriptions.length === 1) ? '' : 's'}</p>
40 <table>
41 <thead>`,
42 th.renderSubscriptionRowHeader(),
43 ` </thead>
44 <tbody>`,
45 ...(ctx.subscriptions && ctx.subscriptions.map(th.renderSubscriptionRow)),
46 ` </tbody>
47 </table>
48 </section>`,
49 ]);
50 };