'use strict';
const th = require('./template-helper');
+const { sessionNavLinks } = require('@squeep/authentication-module');
/**
* Show a topic with all of its subscribers.
- * @param {Object} ctx
- * @param {Object} ctx.topic
- * @param {Object[]} ctx.subscriptions
- * @param {Object} options
- * @param {Object} options.manager
- * @param {String} options.manager.pageTitle
- * @returns {String}
+ * @param {object} ctx context
+ * @param {object} ctx.topic topic
+ * @param {object[]} ctx.subscriptions subscriptions
+ * @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 = 2;
const pageTitle = `${options.manager.pageTitle} - Topic Details`;
- const headElements = [];
+ const logoUrl = options.manager.logoUrl;
const navLinks = [
{
href: '..',
if (!ctx.subscriptions) {
ctx.subscriptions = [];
}
- return th.htmlTemplate(2, pageTitle, headElements, navLinks, [
+
+ const htmlOptions = {
+ pageIdentifier: 'admin',
+ pageTitle,
+ logoUrl,
+ navLinks,
+ footerEntries,
+ };
+ th.navLinks(pagePathLevel, ctx, htmlOptions);
+ sessionNavLinks(pagePathLevel, ctx, htmlOptions);
+
+ const content = [
` <section class="topics">
<table>
<thead>`,
th.renderTopicRowHeader(),
` </thead>
<tbody>`,
- ...(ctx.topic && [ th.renderTopicRow(ctx.topic, ctx.subscriptions, false) ]),
+ ...(ctx.topic && [ th.renderTopicRow(ctx.topic, ctx.subscriptions, false) ] || []),
` </tbody>
</table>
</section>`,
+ ` <section class="history">
+ <p>Topic Publish History — ${ctx.publishCount} updates in the last ${ctx.publishSpan} days</p>
+ <img title="Topic Publish History" src="${ctx.params.topicId}/history.svg" alt="histogram of publish history">
+ </section>`,
` <section class="subscriptions">
- <p>${ctx.subscriptions.length ? ctx.subscriptions.length : 'no'} subscription${(ctx.subscriptions.length === 1) ? '' : 's'}</p>
- <table>
+ <p>${ctx.subscriptions.length ? ctx.subscriptions.length : 'no'} subscription${(ctx.subscriptions.length === 1) ? '' : 's'}</p>`,
+ ...(ctx.subscriptions.length && [`
+ <label for="subscriptions-delivered">
+ Successful Deliveries of Latest Content
+ </label>
+ <progress id="subscriptions-delivered" max="${ctx.subscriptions.length}" value="${ctx.subscriptionsDelivered}">
+ ${ctx.subscriptionsDelivered} of ${ctx.subscriptions.length} (${Math.ceil(100 * ctx.subscriptions.length / ctx.subscriptionsDelivered)}%)
+ </progress>`] || []),
+ ` <table>
<thead>`,
th.renderSubscriptionRowHeader(),
` </thead>
<tbody>`,
- ...(ctx.subscriptions && ctx.subscriptions.map(th.renderSubscriptionRow)),
+ ...((ctx?.subscriptions || []).map(th.renderSubscriptionRow)),
` </tbody>
</table>
</section>`,
- ], footerEntries);
+ ];
+
+ return th.htmlPage(pagePathLevel, ctx, htmlOptions, content);
};
\ No newline at end of file