X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Ftemplate-helper.js;h=7f7021ae010f2a58be394f17e23ea4120a4570d7;hb=55ff163110484141dd9eb7f55e49a85bad082378;hp=c72e0ed348415d2c8adf6f1366b1639330819f65;hpb=77dea84c13c1dd92c1b3a1257f1d82909e9bda74;p=squeep-html-template-helper
diff --git a/lib/template-helper.js b/lib/template-helper.js
index c72e0ed..7f7021a 100644
--- a/lib/template-helper.js
+++ b/lib/template-helper.js
@@ -15,7 +15,7 @@ const { lazy } = require('@squeep/lazy-property');
const initContext = (ctx) => {
ctx.errors = [];
ctx.notifications = [];
-}
+};
/**
* Some fields may have values outside normal dates, handle them here.
@@ -100,7 +100,7 @@ const timeElement = (date, options = {}) => {
dateFormat(date, pInf, nInf, otherwise),
'',
].join('');
-}
+};
/**
@@ -118,7 +118,7 @@ const secondsToPeriod = (seconds) => {
result.push(`${r} ${label}${r != 1 ? 's' : ''}`);
}
value = factor ? Math.floor(value / factor) : value;
- }
+ };
nextResult(60, 'second');
nextResult(60, 'minute');
@@ -232,6 +232,7 @@ ${spacer}` : '';
* @param {Object} ctx
* @param {Object} options
* @param {String[]=} options.logoUrl
+ * @param {String[]=} options.logoAlt
* @param {String[]=} options.pageTitle
* @returns {String}
*/
@@ -239,9 +240,10 @@ function htmlHeader(pagePathLevel, ctx, options) {
const rootPathPfx = '../'.repeat(pagePathLevel);
const {
logoUrl = '',
+ logoAlt = 'logo',
pageTitle = '',
} = options;
- const logoImg = logoUrl ? `
` : '';
+ const logoImg = logoUrl ? `
` : '';
return `\t\t
\t\t\t${logoImg}${pageTitle}
${htmlNav(ctx, options)}
@@ -338,16 +340,16 @@ ${spacer}`;
* @param {String[]=} options.notificationContent
*/
function htmlMessages(ctx, options) {
- const errorHeading = options && options.errorHeading ? `
+ const errorHeading = options?.errorHeading ? `
\t${options.errorHeading}
` : '';
- const errorContent = options && options.errorContent && options.errorContent.length ? '\n' + options.errorContent.map(((content) => `\t${content}`)).join('\n') : '';
- const notificationHeading = options && options.notificationHeading ? `\n\t${options.notificationHeading}
` : '';
- const notificationContent = options && options.notificationContent && options.notificationContent.length ? '\n' + options.notificationContent.map(((content) => `\t${content}`)).join('\n') : '';
- const errors = ctx && ctx.errors && ctx.errors.length ? `
+ const errorContent = options?.errorContent?.length ? '\n' + options.errorContent.map(((content) => `\t${content}`)).join('\n') : '';
+ const notificationHeading = options?.notificationHeading ? `\n\t${options.notificationHeading}
` : '';
+ const notificationContent = options?.notificationContent?.length ? '\n' + options.notificationContent.map(((content) => `\t${content}`)).join('\n') : '';
+ const errors = ctx?.errors?.length ? `
${errorHeading}${errorContent}
${UL(ctx.errors, 1)}
` : '';
- const notifications = ctx && ctx.notifications && ctx.notifications.length ? `
+ const notifications = ctx?.notifications?.length ? `
${notificationHeading}${notificationContent}
${UL(ctx.notifications, 1)}
` : '';
@@ -356,17 +358,15 @@ ${UL(ctx.notifications, 1)}
/**
- * Render all parts of an HTML page. Adds user logout nav link automatically.
+ * Render all parts of an HTML page.
* @param {Number} pagePathLevel - relative path-distance to base
* @param {Object} ctx
- * @param {Object=} ctx.session
- * @param {String=} ctx.session.authenticatedIdentifier
- * @param {String=} ctx.session.authenticatedProfile
* @param {String[]=} ctx.errors
* @param {String[]=} ctx.notifications
* @param {Object} options
* @param {String=} options.pageTitle
* @param {String=} options.logoUrl
+ * @param {String=} options.logoAlt
* @param {Object[]=} options.bodyAttributes
* @param {String[]=} options.headElements
* @param {Object[]=} options.navLinks
@@ -379,19 +379,6 @@ ${UL(ctx.notifications, 1)}
* @returns {String}
*/
function htmlPage(pagePathLevel, ctx, options, main = []) {
- const user = (ctx && ctx.session && ctx.session.authenticatedProfile) || (ctx && ctx.session && ctx.session.authenticatedIdentifier);
- if (user) {
- if (!options.navLinks) {
- options.navLinks = [];
- }
- const logoutRedirect = ctx && ctx.url ? `?r=${encodeURIComponent(ctx.url)}` : '';
- const logoutPath = (pagePathLevel > 0) ? `${'../'.repeat(pagePathLevel - 1)}` : 'admin/';
- options.navLinks.push({
- text: `Logout (${user})`,
- href: `${logoutPath}logout${logoutRedirect}`,
- });
- }
-
return [
'',
'',