525337dc5ad6e76b3591d6d6297717009cc0d1e4
[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 logoUrl = options.manager.logoUrl;
17 const footerEntries = options.manager.footerEntries;
18 if (!ctx.topics) {
19 ctx.topics = [];
20 }
21
22 const htmlOptions = {
23 pageTitle,
24 logoUrl,
25 footerEntries,
26 };
27
28 const content = [
29 '<script>0</script>', // This fixes a layout rendering flash on load in FF; do not know why this works but it does.
30 ` <section class="topics">
31 <p>${ctx.topics.length ? ctx.topics.length : 'no'} topic${(ctx.topics.length === 1) ? '' : 's'}</p>
32 <table>
33 <thead>`,
34 th.renderTopicRowHeader(),
35 ` </thead>
36 <tbody>`,
37 ...(ctx.topics && ctx.topics.map((topic) => th.renderTopicRow(topic, { length: topic.subscribers }))),
38 ` </tbody>
39 </table>
40 </section>`,
41 ];
42
43 return th.htmlPage(1, ctx, htmlOptions, content);
44 };