Use default Nunjucks template if necessary.

If the survey configuration does not itself have a template
we will use the one in etc/defaults/templates/sequence.html.njk.

It is not very likely that the template will be changed all that
often and it avoids issues when people forget to copy it across
to a new survey, etc.
This commit is contained in:
D. Berge
2021-05-20 20:38:39 +02:00
parent e7661bfd1c
commit 39d85a692b
2 changed files with 9 additions and 4 deletions

View File

@@ -2,14 +2,17 @@ const { configuration } = require('../../../../lib/db');
const { transform, prepare } = require('../../../../lib/sse');
const render = require('../../../../lib/render');
// FIXME Refactor when able
const defaultTemplatePath = require('path').resolve(__dirname, "../../../../../../../etc/default/templates/sequence.html.njk");
const html = async function (req, res, next) {
try {
const query = req.query;
query.sequence = req.params.sequence;
const {events, sequences} = await prepare(req.params.project, query);
const seis = transform(events, sequences, {projectId: req.params.project});
const templates = await configuration.get(req.params.project, "sse/templates");
const template = templates[0].template;
const template = (await configuration.get(req.params.project, "sse/templates/0/template")) || defaultTemplatePath;
console.log("TEMPLATE", template);
const response = await render(seis, template);