Merge branch 'v1.3-dev'
[websub-hub] / src / template / admin-overview-html.js
index b86f7af600e741e25805a89923f2a898d1127161..948bdbb0083fa77917a7f5b96dc61eb94557be92 100644 (file)
@@ -1,24 +1,36 @@
 'use strict';
 
 const th = require('./template-helper');
+const { sessionNavLinks } = require('@squeep/authentication-module');
 
 /**
  * Show a summary of all topics.
- * @param {Object} ctx
- * @param {Object[]} ctx.topics
- * @param {Object} options
- * @param {Object} options.manager
- * @param {String} options.manager.pageTitle
- * @returns {String}
+ * @param {object} ctx context
+ * @param {object[]} ctx.topics topics
+ * @param {object} options options
+ * @param {object} options.manager manager options
+ * @param {string} options.manager.pageTitle page title
+ * @returns {string} html
  */
 module.exports = (ctx, options) => {
+  const pagePathLevel = 1;
   const pageTitle = `${options.manager.pageTitle} - Topics`;
-  const headElements = [];
-  const navLinks = [];
+  const logoUrl = options.manager.logoUrl;
+  const footerEntries = options.manager.footerEntries;
   if (!ctx.topics) {
     ctx.topics = [];
   }
-  return th.htmlTemplate(1, pageTitle, headElements, navLinks, [
+
+  const htmlOptions = {
+    pageIdentifier: 'admin',
+    pageTitle,
+    logoUrl,
+    footerEntries,
+  };
+  th.navLinks(pagePathLevel, ctx, htmlOptions);
+  sessionNavLinks(pagePathLevel, ctx, htmlOptions);
+
+  const content = [
     `      <section class="topics">
         <p>${ctx.topics.length ? ctx.topics.length : 'no'} topic${(ctx.topics.length === 1) ? '' : 's'}</p>
         <table>
@@ -26,9 +38,11 @@ module.exports = (ctx, options) => {
     th.renderTopicRowHeader(),
     `          </thead>
         <tbody>`,
-    ...(ctx.topics && ctx.topics.map((topic) => th.renderTopicRow(topic, { length: topic.subscribers }))),
+    ...((ctx?.topics || []).map((topic) => th.renderTopicRow(topic, { length: topic.subscribers }))),
     `        </tbody>
         </table>
       </section>`,
-  ]);
+  ];
+
+  return th.htmlPage(pagePathLevel, ctx, htmlOptions, content);
 };
\ No newline at end of file