update dependencies and devDependencies, address lint issues
[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 /**
7 *
8 * @param {object} entry entry
9 * @returns {string} tr
10 */
11 function renderAlmanacRow(entry) {
12 const { event, date } = entry;
13 return `<tr>
14 \t<td>${event}</td>
15 \t<td>${th.timeElement(date, { title: 'Occurred' })}</td>
16 </tr>`;
17 }
18
19 /**
20 *
21 * @param {object[]} almanac entries
22 * @returns {string} section
23 */
24 function almanacSection(almanac) {
25 return `<section>
26 \t<h2>Almanac</h2>
27 \t<table>
28 \t\t<thead>
29 \t\t\t\t<tr>
30 \t\t\t\t<th scope="col">Event</th>
31 \t\t\t\t<th scope="col">Date</th>
32 \t\t\t</tr>
33 \t\t</thead>
34 \t\t<tbody>
35 ${almanac.map((entry) => renderAlmanacRow(entry)).join('\n')}
36 \t\t</tbody>
37 \t</table>
38 </section>`;
39 }
40
41 /**
42 *
43 * @param {string} choreName name
44 * @param {object} choreDetails details
45 * @returns {string} tr
46 */
47 function renderChoreRow(choreName, choreDetails) {
48 const { intervalMs, nextSchedule } = choreDetails;
49 return `<tr>
50 \t<td>${choreName}</td>
51 \t<td>${th.secondsToPeriod(Math.ceil(intervalMs / 1000))}</td>
52 \t<td>${th.timeElement(nextSchedule)}</td>
53 </tr>`;
54 }
55
56 /**
57 *
58 * @param {object} chores chores
59 * @returns {string} section
60 */
61 function choresSection(chores) {
62 return `<section>
63 \t<h2>Chores</h2>
64 \t<table>
65 \t\t<thead>
66 \t\t\t<tr>
67 \t\t\t\t<th scope="col">Chore</th>
68 \t\t\t\t<th scope="col">Frequency</th>
69 \t\t\t\t<th scope="col">Next Run</th>
70 \t\t\t</tr>
71 \t\t</thead>
72 \t\t<tbody>
73 ${Object.entries(chores).map((chore) => renderChoreRow(...chore)).join('\n')}
74 \t\t</tbody>
75 \t</table>
76 </section>`;
77 }
78
79 /**
80 *
81 * @param {object} ctx context
82 * @param {object[]} ctx.almanac entries
83 * @param {object} ctx.chores chores
84 * @param {object} options options
85 * @param {object} options.manager manager options
86 * @param {string} options.manager.pageTitle page title
87 * @param {string[]} options.manager.footerEntries footer entires
88 * @returns {string} page
89 */
90 module.exports = (ctx, options) => {
91 const pagePathLevel = 1;
92 const htmlOptions = {
93 pageIdentifier: 'maintenance',
94 pageTitle: options.manager.pageTitle + ' - Maintenance',
95 logoUrl: options.manager.logoUrl,
96 footerEntries: options.manager.footerEntries,
97 };
98 th.navLinks(pagePathLevel, ctx, htmlOptions);
99 sessionNavLinks(pagePathLevel, ctx, htmlOptions);
100 const content = [
101 almanacSection(ctx.almanac || []),
102 choresSection(ctx.chores || {}),
103 ];
104 return th.htmlPage(pagePathLevel, ctx, htmlOptions, content);
105 };