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