Initial release
[websub-hub] / src / template / admin-overview-html.js
diff --git a/src/template/admin-overview-html.js b/src/template/admin-overview-html.js
new file mode 100644 (file)
index 0000000..b86f7af
--- /dev/null
@@ -0,0 +1,34 @@
+'use strict';
+
+const th = require('./template-helper');
+
+/**
+ * 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}
+ */
+module.exports = (ctx, options) => {
+  const pageTitle = `${options.manager.pageTitle} - Topics`;
+  const headElements = [];
+  const navLinks = [];
+  if (!ctx.topics) {
+    ctx.topics = [];
+  }
+  return th.htmlTemplate(1, pageTitle, headElements, navLinks, [
+    `      <section class="topics">
+        <p>${ctx.topics.length ? ctx.topics.length : 'no'} topic${(ctx.topics.length === 1) ? '' : 's'}</p>
+        <table>
+          <thead>`,
+    th.renderTopicRowHeader(),
+    `          </thead>
+        <tbody>`,
+    ...(ctx.topics && ctx.topics.map((topic) => th.renderTopicRow(topic, { length: topic.subscribers }))),
+    `        </tbody>
+        </table>
+      </section>`,
+  ]);
+};
\ No newline at end of file