Skip to content

Commit

Permalink
Add skips (#36)
Browse files Browse the repository at this point in the history
* added skips

* renamed files

* added print styling

* removed runner code
  • Loading branch information
martyncolmer authored Mar 21, 2022
1 parent c185db2 commit 111fdc7
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 173 deletions.
17 changes: 14 additions & 3 deletions middleware/fetchSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@ const request = require("request-promise-native")

const getQuestionnaireFromURL = async (req, res, next) => {
try {
if (!res.locals.url) {
if (!res.locals.urlAWS && !res.locals.urlGCP) {
throw new Error(`missing url in request`)
}
const options = {
json: true,
uri: res.locals.url
uri: res.locals.urlAWS
}
const response = await request(options)
res.locals.questionnaire = response
next()
}
catch (e) {
res.status(500).send(`Sorry, something went wrong with the url request`)
try {
const options = {
json: true,
uri: res.locals.urlGCP
}
const response = await request(options)
res.locals.questionnaire = response
next()
}
catch (e) {
res.status(500).send(`Sorry, something went wrong with the url request`)
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions middleware/setUrl.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = (req, res, next) => {
const authorUrl = process.env.AUTHOR_SCHEMA_URL || ""
const runnerUrl = process.env.RUNNER_SCHEMA_URL || ""
const authorUrlAWS = process.env.AUTHOR_SCHEMA_URL_AWS || ""
const authorUrlGCP = process.env.AUTHOR_SCHEMA_URL_GCP || ""
if (req.body.author_qid) {
res.locals.url = authorUrl + req.body.author_qid
res.locals.urlAWS = authorUrlAWS + req.body.author_qid
}
if (req.body.runner_qid) {
res.locals.url = runnerUrl + req.body.runner_qid
if (req.body.author_qid) {
res.locals.urlGCP = authorUrlGCP + req.body.author_qid
}
if (!res.locals.url) {
res.locals.url = req.body.url || req.query.url
Expand Down
6 changes: 3 additions & 3 deletions routes/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ router.route('/url')
processAuthorQuestionnaire
)
.get(
renderPage("output-grid-no-buttons.html")
renderPage("questionnaire-no-buttons.html")
)
.post(
renderPage("output-grid.html")
renderPage("questionnaire.html")
)

router.post('/table',
Expand All @@ -29,7 +29,7 @@ router.post('/table',
router.get('/json',
parseQuestionnaire,
processAuthorQuestionnaire,
renderPage("output-grid.html")
renderPage("questionnaire.html")
)

module.exports = router
50 changes: 0 additions & 50 deletions routes/runner.js

This file was deleted.

2 changes: 0 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ const bodyParser = require("body-parser")
const setupFilters = require(`./utils/setupFilters`)
const indexRouter = require(`./routes/index`)
const authorRouter = require(`./routes/author`)
const runnerRouter = require(`./routes/runner`)
const app = express()

app.use(bodyParser.urlencoded({ extended: true, limit: "10mb" }))
app.use(bodyParser.json({ limit: "10mb" }))
app.use(express.static('static'))
app.use('/', indexRouter)
app.use('/author', authorRouter)
app.use('/runner', runnerRouter)

const env = nunjucks.configure("views", {
autoescape: true,
Expand Down
13 changes: 6 additions & 7 deletions static/css/extract.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ ul {
margin-bottom: 0px;
}

.panel-section__header {
background-color: indigo;
}

.panel-section__body {
background-color:darkgrey
}
@media print {
.panel__header {
color: #000;
border: 1px solid;
}
}
37 changes: 37 additions & 0 deletions views/expressionGroup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{%for expression in expressionGroup.expressions %}
<div class="grid__col col-12@m">
{% if loop.first %}
<span class="u-fs-r--b">If </span>
{% else %}
{% if (expressionGroup.operator === "And") %}
<span class="u-fs-r--b">and if </span>
{% else %}
<span class="u-fs-r--b">or if </span>
{% endif %}
{% endif %}
{% if expression.left.answerId %}
<span class="u-fs-r"><a href="#{{ expression.left.answerId }}">Answer</a></span>
{% endif %}
<span class="u-fs-r--b"> {{ expression.condition }}</span>
{% if expression.right.customValue %}
<span class="u-fs-r">{{ expression.right.customValue.number }}</span>
{% endif %}
</div>
{% if expression.right.optionIds %}
{%for option in expression.right.optionIds %}
<div class="grid__col col-12@m">
<ul>
{% if optionLabels[option] %}
<li class="list__item">
<span class="u-fs-r">{{ optionLabels[option] }}</span>
</li>
{% else %}
<li class="list__item">
<span class="u-fs-r">Not found</span>
</li>
{% endif %}
</ul>
</div>
{% endfor %}
{% endif %}
{% endfor %}
39 changes: 0 additions & 39 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,5 @@
</div>
</div>
<br>
<div class="grid">
<div class="grid__col col-6@m">
<form method="POST" enctype="application/x-www-form-urlencoded" id="runner-qid-form">
<div class="field">
<label class="label u-fs-r--b">Enter runner questionnaire id: </label>
<input class="input" type="text" name="runner_qid" required />
</div>
</form>
</div>
</div>
<br>
<div class="grid">
<div class="grid__col col-6@m">
<div class="btn-group">
<button type="submit" class="btn btn--small" form="runner-qid-form" formaction="/runner/url">View questionnaire</button>
<button type="submit" class="btn btn--small" form="runner-qid-form" formaction="/runner/table">Question table</button>
</div>
</div>
</div>
<br>
<div class="grid">
<div class="grid__col col-6@m">
<form method="POST" action="/runner-upload" enctype="multipart/form-data" id="runner-form">
<div class="field">
<label class="label u-fs-r--b">Select runner json file: </label>
<input class="input" type="file" name="jsonFile" required />
</div>
</form>
</div>
</div>
<br>
<div class="grid">
<div class="grid__col col-6@m">
<div class="btn-group">
<button type="submit" class="btn btn--small" form="runner-form" formaction="/runner/upload">View questionnaire</button>
<button type="submit" class="btn btn--small" form="runner-form" formaction="/runner/upload-table">Question table</button>
</div>
</div>
</div>
</div>
{% endblock %}
5 changes: 5 additions & 0 deletions views/question-confirmation.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
</div>
</div>
</div>
{% if (question.confirmation.skipConditions) %}
<div class="u-fs-r-b"><em>Skip this question:</em></div>
{% set skipConditions = question.confirmation.skipConditions %}
{% include "skip.html" %}
{% endif %}
</div>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions views/question.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
{% endfor %}
{% endif %}
{% include "routing.html" %}
{% if (question.skipConditions) or (folder.skipConditions) %}
<div class="u-fs-r-b"><em>Skip this question:</em></div>
{% set skipConditions = question.skipConditions %}
{% include "skip.html" %}
{% set skipConditions = folder.skipConditions %}
{% include "skip.html" %}
{% endif %}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<div class="container">
<div class="grid">
<div class="grid__col col-12@m">
{% include "section.html" %}
{%for section in sections %}
{% include "section.html" %}
{% endfor %}
</div>
</div>
</div>
Expand Down
9 changes: 4 additions & 5 deletions views/output-grid.html → views/questionnaire.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
{% block body %}

<div class="container">
<form id="results-form" method="POST" action="/download">
<input type="hidden" value="{{ questions | dump }}" name="questions" />
</form>
<div class="grid">
<div class="grid__col col-12@m">
<div class="btn-group">
<a href="/"><button class="btn btn-group__btn btn--small" >New questionnaire</button></a>
<a href="/"><button class="btn btn-group__btn btn--small print__hidden" >New questionnaire</button></a>
</div>
</div>
</div>
<br>
<div class="grid">
<div class="grid__col col-12@m">
{% include "section.html" %}
{%for section in sections %}
{% include "section.html" %}
{% endfor %}
</div>
</div>
</div>
Expand Down
36 changes: 2 additions & 34 deletions views/routing.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,8 @@
<div class="grid ">
<div class="grid__col col-12@m">
{%for rule in question.routing.rules %}
{%for expression in rule.expressionGroup.expressions %}
<div class="grid__col col-12@m">
{% if loop.first %}
<span class="u-fs-r--b">If </span>
{% else %}
<span class="u-fs-r--b">or if </span>
{% endif %}
{% if expression.left.answerId %}
<span class="u-fs-r"><a href="#{{ expression.left.answerId }}">Answer</a></span>
{% endif %}
<span class="u-fs-r--b"> {{ expression.condition }}</span>
{% if expression.right.customValue.number %}
<span class="u-fs-r"> {{ expression.right.customValue.number }}</span>
{% endif %}
</div>
{% if expression.right.optionIds %}
{%for option in expression.right.optionIds %}
<div class="grid__col col-12@m">
<ul>
{% if optionLabels[option] %}
<li class="list__item">
<span class="u-fs-r">{{ optionLabels[option] }}</span>
</li>
{% else %}
<li class="list__item">
<span class="u-fs-r">Not found</span>
</li>
{% endif %}
</ul>
</div>
{% endfor %}
{% endif %}

{% endfor %}
{% set expressionGroup = rule.expressionGroup %}
{% include "expressionGroup.html" %}
<div class="grid__col col-12@m">
<span class="u-fs-r--b">Goto </span>
{% if rule.destination.logical %}
Expand Down
46 changes: 22 additions & 24 deletions views/section.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
{%for section in sections %}
<div id={{ section.id }} class="panel panel--success">
<div class="panel__header panel">
<em class="u-fs-r--b">Section - {{ section.title | parseQuestionText | safe }}</em>
</div>
<div class="panel__body">
<div class="summary">
<div class="u-fs-r-b">
<em>Introduction Title: </em>
{{ section.introductionTitle | parseQuestionText | safe }}
</div>
<div id={{ section.id }} class="panel panel--success">
<div class="panel__header panel">
<em class="u-fs-r--b">Section - {{ section.title | parseQuestionText | safe }}</em>
</div>
<div class="panel__body">
<div class="summary">
<div class="u-fs-r-b">
<em>Introduction Title: </em>
{{ section.introductionTitle | parseQuestionText | safe }}
</div>
<div class="summary">
<div class="u-fs-r-b">
<em>Introduction content: </em>
{{ section.introductionContent | parseQuestionText | safe }}
</div>
</div>
<div class="summary">
<div class="u-fs-r-b">
<em>Introduction content: </em>
{{ section.introductionContent | parseQuestionText | safe }}
</div>
</div>
</div>
<br>
{%for folder in section.folders %}
{%for question in folder.pages %}
{% include "question.html" %}
{% endfor %}
</div>
</div>
</div>
<br>
{%for folder in section.folders %}
{%for question in folder.pages %}
{% include "question.html" %}
{% endfor %}
{% endfor %}
{% endfor %}
Loading

0 comments on commit 111fdc7

Please sign in to comment.