Skip to content

Commit

Permalink
add 'check eligibility cost time' pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryTrimble committed Feb 20, 2017
1 parent 08368b7 commit 6129101
Show file tree
Hide file tree
Showing 15 changed files with 797 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app/routes.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
var express = require('express')
var router = express.Router()

router.use(function (req, res, next) {

// Store common vars in string

res.locals.formData = "";
res.locals.formQuery = "?";
res.locals.data = {};

for (var name in req.query){
var value = req.query[name];
res.locals.formData += '<input type="hidden" name="'+name+'" value="' + value + '">\n';
res.locals.formQuery += name + "=" + value + "&";
res.locals.data[name] = value;
}

next();

});

// Route index page
router.get('/', function (req, res) {
res.render('index')
})

// add your routes here

module.exports = router
128 changes: 128 additions & 0 deletions docs/documentation_routes.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,134 @@ router.get('/examples/over-18', function (req, res) {
}
})

// routes for 'check eligibility, cost and time' pattern

// question in /docs/examples/check-eligibility-cost-time/over-18
router.get('/examples/check-eligibility-cost-time/passengers', function (req, res) {

// get the answer from the query string (eg. ?over18="yes")
var over18 = req.query.over18;

console.log(over18);

if (over18 == "no" ){

// if users is NOT 18 or over
res.redirect("/docs/examples/check-eligibility-cost-time/result/not-eligible" + res.locals.formQuery);

} else {

// if users IS 18 or over
res.render('examples/check-eligibility-cost-time/passengers/index.html');

}

});

// question in /docs/examples/check-eligibility-cost-time/passengers
router.get('/examples/check-eligibility-cost-time/weight/empty', function (req, res) {

console.log("passengers");

// get the answer from the query string (eg. ?over18="yes")
var passengers = req.query.passengers;

if (passengers == "yes" ){

// if vehicles WILL be carrying passengers
res.redirect("/docs/examples/check-eligibility-cost-time/result/not-eligible" + res.locals.formQuery);

} else {

// if vehicles will NOT be carrying passengers
res.render('examples/check-eligibility-cost-time/weight/empty/index.html');

}

});

// question in /docs/examples/check-eligibility-cost-time/weight/empty/index.html
// question in /docs/examples/check-eligibility-cost-time/weight/loaded/index.html
router.get('/examples/check-eligibility-cost-time/how-many-vehicles', function (req, res) {

console.log("weight");

// get the answer from the query string (eg. ?over18="yes")
var weight_empty = req.query.weight_empty;
var weight_loaded = req.query.weight_loaded;

if (weight_empty == "less than 1,525 kg" && weight_loaded==undefined ){

// if vehicles are TOO LIGHT when empty for licence
res.redirect("/docs/examples/check-eligibility-cost-time/weight/loaded" + res.locals.formQuery);

} else if (weight_empty == "less than 1,525 kg" && weight_loaded== "less than 3,5000 kg" ){

// if vehicles are TOO LIGHT when empty and loaded for licence
res.redirect("/docs/examples/check-eligibility-cost-time/result/not-eligible" + res.locals.formQuery);

} else {

// if vehicles are HEAVY ENOUGH when empty or loaded for licence
res.render('examples/check-eligibility-cost-time/how-many-vehicles/index.html');

}

});

// question in /docs/examples/check-eligibility-cost-time/licence-type/just-your-goods/index.html
router.get('/examples/check-eligibility-cost-time/result/eligible', function (req, res) {

console.log("just_your_goods");

// get the answer from the query string (eg. ?over18="yes")
var just_your_goods = req.query.just_your_goods;
var outside_uk = req.query.outside_uk;

if (just_your_goods == "no" && outside_uk ==undefined ){

// user needs INTERNATIONAL licence
res.redirect("/docs/examples/check-eligibility-cost-time/licence-type/outside-uk" + res.locals.formQuery);

} else {

// user needs STANDARD licence
res.render('examples/check-eligibility-cost-time/result/eligible/index.html');

}

});

// calculate amounts in /docs/examples/check-eligibility-cost-time/result/cost
router.get('/examples/check-eligibility-cost-time/result/cost', function (req, res) {

console.log("application_cost");

// get the answer from the query string (eg. ?over18="yes")
var amount = req.query.amount;

if (amount == "value"){

// if user IS related to child
res.redirect("/docs/examples/check-eligibility-cost-time/result/not-eligible" + res.locals.formQuery);

} else {

var application_cost = 257 + 401 + 6650 + (req.query.how_many_vehicles - 1) * 3700

application_cost = application_cost.toString().replace(/,/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");

var maintenance_costs = 6650 + (req.query.how_many_vehicles - 1) * 3700

maintenance_costs = maintenance_costs.toString().replace(/,/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");

// if user is NOT related to child
res.render('examples/check-eligibility-cost-time/result/cost/index.html', {application_cost : application_cost, maintenance_costs : maintenance_costs});

}

});

module.exports = router

// Strip off markdown extensions if present and redirect
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "layout.html" %} {% block page_title %} Example - Forms {% endblock %} {% block content %}
<main id="content" role="main">

<div class="grid-row">
<div class="column-two-thirds">

<form method="get" action="/docs/examples/check-eligibility-cost-time/licence-type/just-your-goods" class="form">

{{formData | safe}}

<h1 class="heading-large">
How many vehicles will you operate?
</h1>

<fieldset>
<legend class="visuallyhidden">
How many vehicles will you operate?
</legend>

<label class="form-label" for="how_many_vehicles_1">Number of vehicles</label>
<input class="form-control form-control-1-8" id="how_many_vehicles_1" type="text" name="how_many_vehicles">

<br>
<br>

</fieldset>

<div class="form-group">
<input type="submit" class="button" value="Continue" />
</div>

</form>

</div>
</div>

</main>
{% endblock %}
61 changes: 61 additions & 0 deletions docs/views/examples/check-eligibility-cost-time/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends "layout.html" %} {% block page_title %} Check eligibility, cost and time {% endblock %} {% block content %}
<main id="content" role="main">

<div class="grid-row">
<div class="column-two-thirds">

<form method="get" action="/docs/examples/check-eligibility-cost-time/over-18" class="form">

{{formData | safe}}

<h1 class="heading-large">
Check eligibility, cost and time
</h1>

<p>
You may want to let users check first eligibility, cost and time for using your service.
</p>

<p>
You can see the code for this example here:
</p>

<div class="code">
/docs/documentation_routes.js
/docs/views/examples/check-eligibility-cost-time
</div>

<br>

<fieldset>
<legend class="visuallyhidden">
Check eligibility, cost and time
</legend>

<p class="">In this section you'll be asked between 4 and 6 questions.</p>

<p class="">The answers you give will show:</p>

<ul class="list list-bullet ">
<li>if you're eligible to transport goods</li>
<li>how much it will cost for you to apply</li>
<li>how long the application process will take</li>
</ul>

<p class="">This information will be different depending on your answers.</p>

</fieldset>

<br>

<div class="form-group">
<input type="submit" class="button" value="Continue to questions" />
</div>

</form>

</div>
</div>

</main>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends "layout.html" %} {% block page_title %} Driving lessons {% endblock %} {% block content %}
<main id="content" role="main">

<div class="grid-row">
<div class="column-two-thirds">

<form method="get" action="/docs/examples/check-eligibility-cost-time/result/eligible" class="form">

{{formData | safe}}

<h1 class="heading-large">
Will you be transporting just your own goods?
</h1>

<fieldset>
<legend class="visuallyhidden">
Will you be transporting just your own goods?
</legend>

<div class="form-group">
<label for="just_your_goods_1" class="block-label">
<input type="radio" id="just_your_goods_1" name="just_your_goods" value="yes">
Yes
</label>

<label for="just_your_goods_2" class="block-label">
<input type="radio" id="just_your_goods_2" name="just_your_goods" value="no">
No
</label>

<label for="just_your_goods_3" class="block-label">
<input type="radio" id="just_your_goods_3" name="just_your_goods" value="no">
Not sure
</label>

</div>

</fieldset>

<div class="form-group">
<input type="submit" class="button" value="Continue" />
</div>

</form>

</div>
</div>

</main>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends "layout.html" %} {% block page_title %} Driving lessons {% endblock %} {% block content %}
<main id="content" role="main">

<div class="grid-row">
<div class="column-two-thirds">

<form method="get" action="/docs/examples/check-eligibility-cost-time/result/eligible" class="form">

{{formData | safe}}

<h1 class="heading-large">
Will you be transporting outside the UK?
</h1>

<fieldset>
<legend class="visuallyhidden">
Will you be transporting outside the UK?
</legend>

<div class="form-group">
<label for="outside_uk_1" class="block-label">
<input type="radio" id="outside_uk_1" name="outside_uk" value="yes">
Yes
</label>

<label for="outside_uk_2" class="block-label">
<input type="radio" id="outside_uk_2" name="outside_uk" value="no">
No
</label>

<label for="outside_uk_3" class="block-label">
<input type="radio" id="outside_uk_3" name="outside_uk" value="no">
Not sure
</label>

</div>

</fieldset>

<div class="form-group">
<input type="submit" class="button" value="Continue" />
</div>

</form>

</div>
</div>

</main>
{% endblock %}
Loading

0 comments on commit 6129101

Please sign in to comment.