mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 12:57:08 +00:00
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:
@@ -2,14 +2,17 @@ const { configuration } = require('../../../../lib/db');
|
|||||||
const { transform, prepare } = require('../../../../lib/sse');
|
const { transform, prepare } = require('../../../../lib/sse');
|
||||||
const render = require('../../../../lib/render');
|
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) {
|
const html = async function (req, res, next) {
|
||||||
try {
|
try {
|
||||||
const query = req.query;
|
const query = req.query;
|
||||||
query.sequence = req.params.sequence;
|
query.sequence = req.params.sequence;
|
||||||
const {events, sequences} = await prepare(req.params.project, query);
|
const {events, sequences} = await prepare(req.params.project, query);
|
||||||
const seis = transform(events, sequences, {projectId: req.params.project});
|
const seis = transform(events, sequences, {projectId: req.params.project});
|
||||||
const templates = await configuration.get(req.params.project, "sse/templates");
|
const template = (await configuration.get(req.params.project, "sse/templates/0/template")) || defaultTemplatePath;
|
||||||
const template = templates[0].template;
|
console.log("TEMPLATE", template);
|
||||||
|
|
||||||
const response = await render(seis, template);
|
const response = await render(seis, template);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ const { transform, prepare } = require('../../../../lib/sse');
|
|||||||
const render = require('../../../../lib/render');
|
const render = require('../../../../lib/render');
|
||||||
const { url2pdf } = require('../../../../lib/selenium');
|
const { url2pdf } = require('../../../../lib/selenium');
|
||||||
|
|
||||||
|
// FIXME Refactor when able
|
||||||
|
const defaultTemplatePath = require('path').resolve(__dirname, "../../../../../../../etc/default/templates/sequence.html.njk");
|
||||||
|
|
||||||
function tmpname (tmpdir="/dev/shm") {
|
function tmpname (tmpdir="/dev/shm") {
|
||||||
return Path.join(tmpdir, crypto.randomBytes(16).toString('hex')+".tmp");
|
return Path.join(tmpdir, crypto.randomBytes(16).toString('hex')+".tmp");
|
||||||
}
|
}
|
||||||
@@ -17,8 +20,7 @@ const pdf = async function (req, res, next) {
|
|||||||
query.sequence = req.params.sequence;
|
query.sequence = req.params.sequence;
|
||||||
const {events, sequences} = await prepare(req.params.project, query);
|
const {events, sequences} = await prepare(req.params.project, query);
|
||||||
const seis = transform(events, sequences, {projectId: req.params.project});
|
const seis = transform(events, sequences, {projectId: req.params.project});
|
||||||
const templates = await configuration.get(req.params.project, "sse/templates");
|
const template = (await configuration.get(req.params.project, "sse/templates/0/template")) || defaultTemplatePath;
|
||||||
const template = templates[0].template;
|
|
||||||
|
|
||||||
const html = await render(seis, template);
|
const html = await render(seis, template);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user