update dependencies, fixes to support new authentication features
[websub-hub] / src / template / admin-overview-html.js
1 'use strict';
2
3 const th = require('./template-helper');
4 const { sessionNavLinks } = require('@squeep/authentication-module');
5
6 /**
7 * Show a summary of all topics.
8 * @param {object} ctx context
9 * @param {object[]} ctx.topics topics
10 * @param {object} options options
11 * @param {object} options.manager manager options
12 * @param {string} options.manager.pageTitle page title
13 * @returns {string} html
14 */
15 module.exports = (ctx, options) => {
16 const pagePathLevel = 1;
17 const pageTitle = `${options.manager.pageTitle} - Topics`;
18 const logoUrl = options.manager.logoUrl;
19 const footerEntries = options.manager.footerEntries;
20 if (!ctx.topics) {
21 ctx.topics = [];
22 }
23
24 const htmlOptions = {
25 pageIdentifier: 'admin',
26 pageTitle,
27 logoUrl,
28 footerEntries,
29 };
30 th.navLinks(pagePathLevel, ctx, htmlOptions);
31 sessionNavLinks(pagePathLevel, ctx, htmlOptions);
32
33 const content = [
34 ` <section class="topics">
35 <p>${ctx.topics.length ? ctx.topics.length : 'no'} topic${(ctx.topics.length === 1) ? '' : 's'}</p>
36 <table>
37 <thead>`,
38 th.renderTopicRowHeader(),
39 ` </thead>
40 <tbody>`,
41 ...((ctx?.topics || []).map((topic) => th.renderTopicRow(topic, { length: topic.subscribers }))),
42 ` </tbody>
43 </table>
44 </section>`,
45 ];
46
47 return th.htmlPage(pagePathLevel, ctx, htmlOptions, content);
48 };