X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=src%2Ftemplate%2Ftemplate-helper.js;fp=src%2Ftemplate%2Ftemplate-helper.js;h=c633e41542505c17c091d8e2e6866276e1bf8372;hb=d0444b4b0ee8166d911e6b227218d110eb7eddf1;hp=f36829d7bd1f9bd0eeb7adfe9daf956babce954f;hpb=728dc0686aa5282e7fc9473c92fbbc617a2b93d7;p=websub-hub
diff --git a/src/template/template-helper.js b/src/template/template-helper.js
index f36829d..c633e41 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')} |
@@ -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),