Merge branch 'v1.2-dev' as v1.2.0
[websub-hub] / src / template / admin-overview-html.js
1 'use strict';
2
3 const th = require('./template-helper');
4
5 /**
6 * Show a summary of all topics.
7 * @param {Object} ctx
8 * @param {Object[]} ctx.topics
9 * @param {Object} options
10 * @param {Object} options.manager
11 * @param {String} options.manager.pageTitle
12 * @returns {String}
13 */
14 module.exports = (ctx, options) => {
15 const pageTitle = `${options.manager.pageTitle} - Topics`;
16 const headElements = [];
17 const navLinks = [];
18 const footerEntries = options.manager.footerEntries;
19 if (!ctx.topics) {
20 ctx.topics = [];
21 }
22 return th.htmlTemplate(1, pageTitle, headElements, navLinks, [
23 ` <section class="topics">
24 <p>${ctx.topics.length ? ctx.topics.length : 'no'} topic${(ctx.topics.length === 1) ? '' : 's'}</p>
25 <table>
26 <thead>`,
27 th.renderTopicRowHeader(),
28 ` </thead>
29 <tbody>`,
30 ...(ctx.topics && ctx.topics.map((topic) => th.renderTopicRow(topic, { length: topic.subscribers }))),
31 ` </tbody>
32 </table>
33 </section>`,
34 ], footerEntries);
35 };