update depedencies, changes to support updated authentication-module
[squeep-indie-auther] / src / template / admin-maintenance-html.js
1 'use strict';
2
3 const th = require('./template-helper');
4 const { sessionNavLinks } = require('@squeep/authentication-module');
5
6 function renderAlmanacRow(entry) {
7 const { event, date } = entry;
8 return `<tr>
9 \t<td>${event}</td>
10 \t<td>${th.timeElement(date, { title: 'Occurred' })}</td>
11 </tr>`;
12 }
13
14 function almanacSection(almanac) {
15 return `<section>
16 \t<h2>Almanac</h2>
17 \t<table>
18 \t\t<thead>
19 \t\t\t<th>Event</th>
20 \t\t\t<th>Date</th>
21 \t\t</thead>
22 \t\t<tbody>
23 ${almanac.map((entry) => renderAlmanacRow(entry)).join('\n')}
24 \t\t</tbody>
25 \t<table>
26 </section>`;
27 }
28
29 function renderChoreRow(choreName, choreDetails) {
30 const { intervalMs, nextSchedule } = choreDetails;
31 return `<tr>
32 \t<td>${choreName}</td>
33 \t<td>${th.secondsToPeriod(Math.ceil(intervalMs / 1000))}</td>
34 \t<td>${th.timeElement(nextSchedule)}</td>
35 </tr>`;
36 }
37
38 function choresSection(chores) {
39 return `<section>
40 \t<h2>Chores</h2>
41 \t<table>
42 \t\t<thead>
43 \t\t\t<th>Chore</th>
44 \t\t\t<th>Frequency</th>
45 \t\t\t<th>Next Run</th>
46 \t\t</thead>
47 \t\t<tbody>
48 ${Object.entries(chores).map((chore) => renderChoreRow(...chore)).join('\n')}
49 \t\t</tbody>
50 \t<table>
51 </section>`;
52 }
53
54 /**
55 *
56 * @param {Object} ctx
57 * @param {Object[]} ctx.almanac
58 * @param {Object} ctx.chores
59 * @param {Object} options
60 * @param {Object} options.manager
61 * @param {String} options.manager.pageTitle
62 * @param {String[]} options.manager.footerEntries
63 * @param {String} options.adminContactHTML
64 * @returns {String}
65 */
66 module.exports = (ctx, options) => {
67 const pagePathLevel = 1;
68 const htmlOptions = {
69 pageIdentifier: 'maintenance',
70 pageTitle: options.manager.pageTitle + ' - Maintenance',
71 logoUrl: options.manager.logoUrl,
72 footerEntries: options.manager.footerEntries,
73 };
74 th.navLinks(pagePathLevel, ctx, htmlOptions);
75 sessionNavLinks(pagePathLevel, ctx, htmlOptions);
76 const content = [
77 almanacSection(ctx.almanac || []),
78 choresSection(ctx.chores || {}),
79 ];
80 return th.htmlPage(pagePathLevel, ctx, htmlOptions, content);
81 };