-
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
Conversation
joelanman
commented
Feb 18, 2016
- automatically store all POST data in session
- automatically send all session data to all views
- add example pages
@@ -18,5 +18,10 @@ main.area { | |||
} | |||
.header-proposition { | |||
clear: none; | |||
min-height: 6em; | |||
// min-height: 6em; |
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 we should delete code rather than commenting it out.
This is awesome. Two things spring to mind:
|
I really like the idea of this - it sounds really easy to use. Are there any security concerns of storing data in sessions by default? Would the outputs collide with other stuff - eg if users try to apply their own variables in routes? Would it be better if the data it exposes to the view were namespaced in some way? For example:
Using the data:
Then only save / restore the data if namespaced under Presumably this also means that you can apply nunjucks filters to all form data by default really easily, etc. That's cool. |
Namespacing is a good idea - Alex suggested Clearing session is why I've shied away from this approach for so long. It needs to be super clear how to do it. We can provide a page but how do we make sure people understand and use it - most importantly researchers in research sessions. |
@edwardhorsford you think we need to namespace the input name too? Why's that? |
I don't think we need to, but there's two good reasons we might want to:
|
I hope it's OK to comment here - what I've done, as someone very new to this is:
Not sure I'd need to namespace the inputs though. |
@glancyea more than welcome to comment - this is a big addition and we need to get it right. Is your prototype code available anywhere? Why do you need the licence namespace? Do you have another namespace in the prototype? |
in terms of opt-in, on a prototype, is there a reason you wouldn't want to store the form data in session? @edwardhorsford |
@joelanman I don't have another namespace, so |
@joelanman Just checking what else is in session - just the cookie details, so hardly any confusion I guess:
|
Looking again at what this does - and based on my experience with only one use - we have two functions this would not cover:
|
@glancyea not sure I follow point 1. In this approach, the session data is captured from all POSTs and sent to the page in all GETs. POSTS are redirected to GETs. One possible issue is it doesn't capture any GET request data - though we could add that if needed. On point 2, you could do this:
|
Some options for clearing session:
any other ideas? |
@joelanman I have a |
Anyone using data persistence and display in templates can probably follow some basic instructions, so I'd suggest not automating everything and the function (or set clear=clear) approach gives flexibility |
@joelanman Point one was that requests were arriving at routes.js in two ways: Point two is roughly what my function does - I pass an object with the calculated parameters and it merges i with the existing data before storing back to session. |
db76f60
to
0c82bef
Compare
d1209e8
to
a951713
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The markup for this section should be <pre><code>...</code></pre>
we should also use the styles from .code
for pre
and code
elements
I've tested this on my machine and on heroku, using Things it would be good to see:
|
{% 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably only display if data storage is turned on.
b3bf359
to
17f83f5
Compare
17f83f5
to
ee80ecb
Compare
Working through this PR with @joelanman we found a bug. If a user checks a checkbox, then returns to that checkbox later and unchecks all checkboxes, this doesn't get saved to the server (blank checkboxes don't get sent in POSTs). |
Not sure if this is an appropriate solution to this bug but what I've ended up doing is saving all the inputs from a single page into the session data object with the key being the page name (or URL). So when the page at
I think this would then mean that if the page was submitted again with empty checkboxes the entire It suits me to then refer to the data using the |
@tsmorgan where does |
Sorry @joelanman, just checking back now. I pass I guess if were a lot of subfolders (i.e. /application/form/aboutyou/) you'd maybe have to remove those slashes etc but generally I've found for testing I have a series of pages in a single folder with a different word for each page name so even if I only took the 'aboutyou' from that example I'd still get the data in a format that I could use. |
Just came across an issue where my form input name was Ideas? At the least we could print an error to the console if the input name is not a valid variable. |
I came across this and ended up writing a loop to replace the dashes with underscores before I added them to the session. Doesn't feel very intuitive to change people's input names for them, but at least this would keep things working. Either way you need there to be some well placed explanation/error message to make sure people aren't confused. Personally whilst working with this stuff I leaned heavily on a route like this: router.get('/session/view',function(req, res)
{
res.send("<pre>"+util.inspect(req.session,{depth:10})+"</pre>");
}); to let me get a view of what was in the session and how it was nested etc. Maybe adding something like this (along with whatever solution you decide) would help to alleviate confusion. |
Glad I'm not the only one! I suspect changing the input isn't a great idea - we're then encouraging two different naming patterns. At least erroring when a hyphen is encountered educates the users. |
@tsmorgan @edwardhorsford I wrote a simple filter to log data out to the browser console if you're interested? Could do a quick PR? Then it's simply a case of:
From within the template you're working on. @tsmorgan Add PR with this (as well as addressing another issue) #171 |
@paulmsmith can you see |
@joelanman I was just doing that as an example. It would be whatever the session data was passed into the template as I guess. ;) |
taking another bash at this in #205 |
# 4.2.1 - Track download links using events not pageviews # 4.2.0 - Add two analytics plugins for download and external link tracking - Update typography mixins to be mobile first (PR alphagov#157) # 4.1.1 - Update Accessible Media Player to remove dependency on $.browser (PR alphagov#206) # 4.1.0 - Add support for sending the `page` option to `GOVUK.analytics.trackEvent` (PR alphagov#203)