-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DO NOT MERGE Auto data storage #157
Changes from 19 commits
ed8905b
9ba0c15
08b21a7
83fe52b
51001ec
751b528
278b944
2aea8c4
c4a6a8e
a951713
1e8724f
e602fc3
974d835
f90c847
35baeb3
4ee4889
ec2accc
f4adfd7
2dbfed0
ee80ecb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ main.area { | |
.header-proposition { | ||
clear: none; | ||
min-height: 6em; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Example - Passing data | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<main id="content" role="main"> | ||
|
||
{% include "includes/breadcrumb_examples.html" %} | ||
|
||
<div class="grid-row"> | ||
<div class="column-two-thirds"> | ||
|
||
<h1 class="heading-xlarge"> | ||
Passing data | ||
</h1> | ||
|
||
<p> | ||
You may want to use or display data a user has entered over a few screens. The kit automatically stores all data entered, so you can show it later. | ||
</p> | ||
|
||
<p> | ||
To clear the data (for example at the end of a user research session) click the "Clear data" link in the footer. | ||
</p> | ||
|
||
<p> | ||
You can see the code for this example here: | ||
</p> | ||
|
||
<pre> | ||
<div class="code"> | ||
/app/views/examples/pass-data.html | ||
/app/views/examples/vehicle-type.html | ||
/app/views/examples/vehicle-features.html | ||
/app/views/examples/vehicle-check-answers.html | ||
|
||
</div> | ||
</pre> | ||
|
||
<form action="/examples/vehicle-type" method="post" class="form"> | ||
|
||
<div class="form-group"> | ||
<fieldset> | ||
|
||
<legend class="visuallyhidden"> | ||
What is your vehicle registration number? | ||
</legend> | ||
|
||
<label for="vehicleRegistration" class="form-label"> | ||
What is your vehicle registration number? | ||
</label> | ||
|
||
<input class="form-control" type="text" name="vehicleRegistration"> | ||
|
||
</fieldset> | ||
</div> | ||
|
||
<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,105 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Check your answers | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<main id="content" role="main"> | ||
|
||
<div class="grid-row"> | ||
<div class="column-two-thirds"> | ||
<h1 class="heading-large"> | ||
Check your answers before sending your application | ||
</h1> | ||
|
||
<p> | ||
When a user has entered data on pages, show it by using code like this: | ||
</p> | ||
|
||
<pre> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The markup for this section should be |
||
<div class="code">{% raw %} | ||
<tr> | ||
<td> | ||
Vehicle type: | ||
</td> | ||
<td> | ||
{{vehicleType}} | ||
</td> | ||
</tr> | ||
{% endraw %}</div></pre> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
|
||
<table class="check-your-answers"> | ||
|
||
<thead> | ||
<tr> | ||
<th colspan="2"> | ||
<h2 class="heading-medium"> | ||
Vehicle details | ||
</h2> | ||
</th> | ||
<th> | ||
</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<tr> | ||
<td> | ||
Registration number | ||
</td> | ||
<td> | ||
{{vehicleRegistration}} | ||
</td> | ||
<td class="change-answer"> | ||
<a href="/examples/pass-data"> | ||
Change <span class="visuallyhidden">registration number</span> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
Vehicle type | ||
</td> | ||
<td> | ||
{{vehicleType}} | ||
</td> | ||
<td class="change-answer"> | ||
<a href="/examples/vehicle-type"> | ||
Change <span class="visuallyhidden">vehicle type</span> | ||
</a> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
Vehicle features | ||
</td> | ||
<td> | ||
{{vehicleFeature}} | ||
</td> | ||
<td class="change-answer"> | ||
<a href="/examples/vehicle-type"> | ||
Change <span class="visuallyhidden">vehicle features</span> | ||
</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<p> | ||
<a href="/examples"> | ||
Return to prototype kit examples | ||
</a> | ||
</p> | ||
</div> | ||
|
||
</main> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels like this page could have some kind of 'summary' paragraph describing how you then use the data - eg an example of the markup to use in the page. Would also be good to have a link back to the main examples - so users have a return path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeh good idea - adding |
||
|
||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Example - Passing data | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<main id="content" role="main"> | ||
|
||
{% include "includes/breadcrumb_examples.html" %} | ||
|
||
<div class="grid-row"> | ||
<div class="column-two-thirds"> | ||
|
||
<form action="/examples/vehicle-check-answers" method="post" class="form"> | ||
|
||
<div class="form-group"> | ||
<fieldset> | ||
|
||
<legend class="visuallyhidden"> | ||
Which of these applies to your vehicle? (Select all that apply) | ||
</legend> | ||
|
||
<p class="heading-medium"> | ||
Which of these applies to your vehicle? (Select all that apply) | ||
</p> | ||
|
||
<label class="block-label"> | ||
<input type="checkbox" name="vehicleFeature" value="Heated seats"> | ||
Heated seats | ||
</label> | ||
|
||
<label class="block-label"> | ||
<input type="checkbox" name="vehicleFeature" value="Radio"> | ||
Radio | ||
</label> | ||
|
||
<label class="block-label"> | ||
<input type="checkbox" name="vehicleFeature" value="Suspension"> | ||
Suspension | ||
</label> | ||
|
||
</fieldset> | ||
</div> | ||
|
||
<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,55 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Example - Passing data | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<main id="content" role="main"> | ||
|
||
{% include "includes/breadcrumb_examples.html" %} | ||
|
||
<div class="grid-row"> | ||
<div class="column-two-thirds"> | ||
|
||
<form action="/examples/vehicle-features" method="post" class="form"> | ||
|
||
<div class="form-group"> | ||
<fieldset> | ||
|
||
<legend class="visuallyhidden"> | ||
What type of vehicle do you have? | ||
</legend> | ||
|
||
<p class="heading-medium"> | ||
What type of vehicle do you have? | ||
</p> | ||
|
||
<label for="vehicleTypeCar" class="block-label"> | ||
<input type="radio" id="vehicleTypeCar" name="vehicleType" value="Car"> | ||
Car | ||
</label> | ||
|
||
<label for="vehicleTypeLorry" class="block-label"> | ||
<input type="radio" id="vehicleTypeLorry" name="vehicleType" value="Lorry"> | ||
Lorry | ||
</label> | ||
|
||
<label for="vehicleTypeIceCream" class="block-label"> | ||
<input type="radio" id="vehicleTypeIceCream" name="vehicleType" value="Ice-cream van"> | ||
Ice-cream van | ||
</label> | ||
|
||
</fieldset> | ||
</div> | ||
|
||
<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 |
---|---|---|
|
@@ -20,3 +20,11 @@ | |
{% include "includes/scripts.html" %} | ||
<!-- GOV.UK Prototype kit {{releaseVersion}} --> | ||
{% endblock %} | ||
|
||
{% block footer_support_links %} | ||
<ul> | ||
<li> | ||
<a href="/prototype-admin/clear-data">Clear data</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably only display if data storage is turned on. |
||
</li> | ||
</ul> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends "layout.html" %} | ||
|
||
{% block page_title %} | ||
Clear data | ||
{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<main id="content" role="main"> | ||
|
||
<h1 class="heading-medium"> | ||
Data cleared | ||
</h1> | ||
|
||
<p> | ||
The session data has been cleared. | ||
</p> | ||
|
||
<p> | ||
<a href="/"> | ||
Prototype home page | ||
</a> | ||
</p> | ||
|
||
</main> | ||
|
||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,3 +95,29 @@ exports.findAvailablePort = function(app){ | |
}); | ||
|
||
} | ||
|
||
// Middleware - store any data sent in session, and pass it to all views | ||
|
||
exports.autoStoreData = function (req, res, next) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a description for what this function does? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the next line is:
is that ok, or you want to add to that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should come before the function, and be a bit more descriptive - my preference would be that a user could get a full idea of the function and how to use it from the comment - not having to read the code. |
||
|
||
|
||
if (!req.session.data){ | ||
req.session.data = {}; | ||
} | ||
|
||
for (var i in req.body){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some kind of comment indicating what this is doing? Ie document that if you don't want data saved, add an underscore to the name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// any input where the name starts with _ is ignored | ||
if (i.indexOf("_") != 0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indexOf is built-in and can only return an integer, so you dont need to check for strict equals |
||
req.session.data[i] = req.body[i]; | ||
} | ||
} | ||
|
||
// send session data to all views | ||
|
||
for (var i in req.session.data){ | ||
res.locals[i] = req.session.data[i]; | ||
} | ||
|
||
next(); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could have more detail here, or in a later paragraph. 'The kit automatically stores all data entered in to form fields, using the name field' etc
You could then include a code snippet showing this with the named field.