X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Ftemplate%2Ftemplate-helper.js;h=0ff90772ec7ebd2479344979b08e7d4c075fdb01;hb=5618c8b62b18564ea4262cd089dcf54af72afc10;hp=f36829d7bd1f9bd0eeb7adfe9daf956babce954f;hpb=9915fd047ecd95692e53d93ddb3ad25ae1680925;p=websub-hub
diff --git a/src/template/template-helper.js b/src/template/template-helper.js
index f36829d..0ff9077 100644
--- a/src/template/template-helper.js
+++ b/src/template/template-helper.js
@@ -61,6 +61,11 @@ const secondsToPeriod = (seconds) => {
* @returns {String}
*/
function renderTopicRow(topic, subscribers, detailsLink = true) {
+ if (!topic) {
+ return `
+ (topic not found) |
+
`;
+ }
return `
${detailsLink ? '' : ''}${topic.url}${detailsLink ? '' : ''} |
${subscribers.length} |
@@ -112,6 +117,11 @@ function renderTopicRowHeader() {
* @returns {String}
*/
function renderSubscriptionRow(subscription) {
+ if (!subscription) {
+ return `
+ (topic not found) |
+
`;
+ }
return `
${subscription.callback} |
${dateOrNot(subscription.created, 'Unknown')} |
@@ -162,7 +172,7 @@ function renderSubscriptionRowHeader() {
function htmlHead(pagePathLevel, pageTitle, headElements = []) {
const rootPathPfx = '../'.repeat(pagePathLevel);
return `
-
` +
headElements.map((e) => `${' '.repeat(2)}${e}`).join('\n') + `
@@ -236,7 +246,8 @@ function htmlFooter(footerEntries = []) {
/**
- * Render all parts of an HTML page.
+ * Render all parts of an HTML page. Adds user logout nav link automatically.
+ * @param {Object} ctx
* @param {Number} pagePathLevel
* @param {String} pageTitle
* @param {String[]} headElements
@@ -245,7 +256,20 @@ function htmlFooter(footerEntries = []) {
* @param {String[]} footerEntries
* @returns {String}
*/
-function htmlTemplate(pagePathLevel, pageTitle, headElements = [], navLinks = [], main = [], footerEntries = []) {
+function htmlTemplate(ctx, pagePathLevel, pageTitle, headElements = [], navLinks = [], main = [], footerEntries = []) {
+ const user = (ctx && ctx.session && ctx.session.authenticatedProfile) || (ctx && ctx.session && ctx.session.authenticatedIdentifier);
+ if (user) {
+ let logoutPath;
+ if (pagePathLevel > 0) {
+ logoutPath = `${'../'.repeat(pagePathLevel - 1)}`;
+ } else {
+ logoutPath = 'admin/';
+ }
+ navLinks.push({
+ text: `Logout (${user})`,
+ href: `${logoutPath}logout`,
+ });
+ }
return [
htmlHead(pagePathLevel, pageTitle, headElements),
htmlHeader(pageTitle, navLinks),