X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=src%2Ftemplate%2Fadmin-html.js;h=f72102f27f8bf09883b930b2eeed054d4f5f6735;hb=f0bf29c75b0fd405ff92fa76f058e61162b87e43;hp=4fee8e74298e9de7fc22713f700060f1f87d2a9d;hpb=fba42a499fe1af051b0982c1f3e8b3873c9ed2fb;p=squeep-indie-auther
diff --git a/src/template/admin-html.js b/src/template/admin-html.js
index 4fee8e7..f72102f 100644
--- a/src/template/admin-html.js
+++ b/src/template/admin-html.js
@@ -10,49 +10,79 @@ const th = require('./template-helper');
const { sessionNavLinks } = require('@squeep/authentication-module');
+/**
+ *
+ * @param {string} profile profile
+ * @returns {string} li
+ */
function renderProfileLI(profile) {
- return `\t
${profile}`;
+ return `\t${profile}`;
}
+/**
+ *
+ * @param {string} profile profile
+ * @param {string} scope scope
+ * @param {boolean} selected is selected
+ * @returns {string} td
+ */
function renderProfileScopeIndicator(profile, scope, selected) {
const checked = selected ? ' checked' : '';
return `\t\t
-\t\t\t
+\t\t\t
\t\t | `;
}
+/**
+ *
+ * @param {string} scope scope
+ * @param {object} details details
+ * @param {string[]} profiles profiles
+ * @returns {string} tr
+ */
function renderScopeRow(scope, details, profiles) {
return `\t
${(profiles || []).map((profile) => renderProfileScopeIndicator(profile, scope, details.profiles.includes(profile))).join('\n')}
-\t\t |
+\t\t${scope} |
\t\t${details.description} |
\t\t${details.application} |
\t\t` +
(details.isManuallyAdded ? `
-\t\t\t
+\t\t\t
` : '') + `
\t\t |
\t
`;
}
+/**
+ *
+ * @param {string} profile profile
+ * @returns {string} th
+ */
function renderProfileHeader(profile) {
- return `
+ return ` |
\t\t${profile}
| `;
}
+/**
+ *
+ * @param {object} scopeIndex scopes
+ * @param {string[]} profiles profiles
+ * @returns {string} table
+ */
function scopeIndexTable(scopeIndex, profiles) {
return `
\t
${(profiles || []).map((profile) => renderProfileHeader(profile)).join('\n')}
-\t\tScope |
-\t\tDescription |
-\t\tApplication |
-\t\t |
+\t\tScope |
+\t\tDescription |
+\t\tApplication |
+\t\t |
\t
@@ -61,6 +91,11 @@ ${Object.entries(scopeIndex).sort(th.scopeCompare).map(([scope, details]) => ren
`;
}
+/**
+ *
+ * @param {object} token token
+ * @returns {string} type
+ */
function _tokenType(token) {
if (token.resource) {
return 'ticket-token';
@@ -71,6 +106,11 @@ function _tokenType(token) {
return 'token';
}
+/**
+ *
+ * @param {object} token token
+ * @returns {string} tr
+ */
function renderTokenRow(token) {
const createdTitle = token.refreshed ? 'Refreshed At' : 'Created At';
const createdDate = token.refreshed ? token.refreshed : token.created;
@@ -86,47 +126,63 @@ function renderTokenRow(token) {
${token.resource ? token.resource : ''} |
\t\t\t` + (
token.isRevoked ? '' : `
-\t\t\t\t`) + `
+\t\t\t\t`) + `
\t\t\t |
\t\t`;
}
+/**
+ * @returns {string} tr
+ */
function noTokensRows() {
return [`\t\t
-\t\t\t(No active or recent tokens.) |
+\t\t\t(No active or recent tokens.) |
\t\t
`];
}
+/**
+ *
+ * @param {object} tokens tokens
+ * @returns {string} table
+ */
function tokenTable(tokens) {
const tokenRows = tokens?.length ? tokens.map((token) => renderTokenRow(token)) : noTokensRows();
- return `
+ const formOpen = tokens?.length ? '' : '';
+ return `${formOpen}
\t
\t\t
-Type |
-\t\t\tClient Identifier / Ticket Subject |
-\t\t\tProfile |
-Scopes |
-\t\t\tCode |
-\t\t\tCreated or Refreshed |
-\t\t\tExpires |
-\t\t\tRevoked |
-Resource |
-\t\t\t |
+\t\t\tType |
+\t\t\tClient Identifier / Ticket Subject |
+\t\t\tProfile |
+\t\t\tScopes |
+\t\t\tCode |
+\t\t\tCreated or Refreshed |
+\t\t\tExpires |
+\t\t\tRevoked |
+\t\t\tResource |
+\t\t\t |
\t\t
\t
\t
${tokenRows.join('\n')}
\t
-
`;
+
${formClose}`;
}
+/**
+ *
+ * @param {object} ctx context
+ * @returns {string} section
+ */
function mainContent(ctx) {
+ const profileList = (ctx.profilesScopes?.profiles || []).map((p) => renderProfileLI(p)).join('\n');
return `
\tProfiles
\t
-\t${(ctx.profilesScopes?.profiles || []).map((p) => renderProfileLI(p)).join('\n')}
+${profileList}
\t
-\t