492c40d1dfc3d4fba87a0936cff1883359ed8cc1
[squeep-indie-auther] / src / template / admin-ticket-html.js
1 'use strict';
2
3 /**
4 * This renders the interface for submitting a ticket proffer to a third-party.
5 */
6
7 const th = require('./template-helper');
8
9
10 function renderProfileOption(profile) {
11 return `<option value="${profile}">${profile}</option>`;
12 }
13
14 function renderScopeCheckboxTR(scope) {
15 const defaultChecked = ['read'];
16 const checked = defaultChecked.includes(scope) ? ' checked' : '';
17 return `<tr class="scope">
18 \t<td><input type="checkbox" id="scopes-${scope}" name="scopes" value="${scope}"${checked}></td>
19 \t<td>${scope}</td>
20 </tr>`;
21 }
22
23 function mainContent(ctx) {
24 const profileOptions = th.indented(4, (ctx?.profilesScopes?.profiles || []).map((profile) => renderProfileOption(profile)))
25 .join('\n');
26 const elideScopes = ['profile', 'email'];
27 const allScopes = Object.keys(ctx?.profilesScopes?.scopeIndex || {});
28 const displayScopes = (allScopes).filter((scope) => !elideScopes.includes(scope));
29 const scopesCheckboxRows = th.indented(4, displayScopes.map((scope) => renderScopeCheckboxTR(scope)))
30 .join('\n');
31 return `<section>
32 \t<form action="" method="POST">
33 \t\t<div>
34 \t\t\tYou may proactively send a ticket to a third-party site,
35 \t\t\twhich they may redeem for an access token which grants additional
36 \t\t\taccess to the specified resource.
37 \t\t</div>
38 \t\t<br>
39 \t\t<fieldset>
40 \t\t\t<legend>Proffer A Ticket</legend>
41 \t\t\t<label for="profile-select">Profile Granting this Ticket</label>
42 \t\t\t<select id="profile-select" name="profile">
43 ${profileOptions}
44 \t\t\t</select>
45 \t\t\t<br>
46 \t\t\t<label for="resource-url">Resource URL:</label>
47 \t\t\t<input type="url" id="resource-url" name="resource" size="96">
48 \t\t\t<br>
49 \t\t\t<label for="recipient-url">Recipient URL:</label>
50 \t\t\t<input type="url" id="recipient-url" name="subject" size="96">
51 \t\t\t<br>
52 <fieldset>
53 <legend>Scopes</legend>
54 \t\t\t<table>
55 ${scopesCheckboxRows}
56 \t\t\t</table>
57 </fieldset>
58 \t\t\t<br>
59 \t\t\t<label for="scopes-adhoc">Additional Scopes (space separated):</label>
60 \t\t\t<input type="text" id="scopes-adhoc" name="adhoc" size="96">
61 \t\t\t<br>
62 \t\t\t<button name="action" value="proffer-ticket">Send Ticket</button>
63 \t\t</fieldset>
64 \t</form>
65 </section>`;
66 }
67
68
69 /**
70 *
71 * @param {Object} ctx
72 * @param {Object} ctx.profilesScopes.scopeIndex
73 * @param {String[]} ctx.profileScopes.profiles
74 * @param {Object} options
75 * @param {Object} options.manager
76 * @param {String} options.manager.pageTitle
77 * @param {String} options.manager.logoUrl
78 * @param {String[]} options.manager.footerEntries
79 * @returns {String}
80 */
81 module.exports = (ctx, options) => {
82 const htmlOptions = {
83 pageTitle: options.manager.pageTitle + ' - Ticket Proffer',
84 logoUrl: options.manager.logoUrl,
85 footerEntries: options.manager.footerEntries,
86 navLinks: [
87 {
88 text: 'Admin',
89 href: '../admin/',
90 },
91 ],
92 errorContent: ['Unable to send ticket.'],
93 };
94 const content = [
95 mainContent(ctx),
96 ];
97 return th.htmlPage(2, ctx, htmlOptions, content);
98 };