Commit Graph

25 Commits

Author SHA1 Message Date
Chris Hill-Scott
4411f8cb37 Allow custom interval on AJAX sections of page
Some pages with AJAX should update quickly, because the data is likely
to be changing quickly, and be finished changing sooner. Other pages we
want to have tick over a bit slower.

This commit adds an optional ‘interval’ parameter to the updateContent
modules, which sets how often the page should ping the server for an
update.

It then sets the interval for the dashboard page to be 10 seconds,
rather than the default 1.5 seconds.
2016-03-23 13:40:23 +00:00
Chris Hill-Scott
8f0dd98d13 Remove method that maintain’s scroll parity
Since we don’t anticipate placeholder textboxes ever scrolling in the future,
this can be removed.
2016-03-18 09:24:25 +00:00
Chris Hill-Scott
0f3b0b38bc Make textboxes expand to fit contents
This applies to any textbox which has placeholders.

There are two reasons to do this:

1. Scrolling in textboxes is fiddly, especially on touch devices
2. Keeping the placeholders aligned with the textbox is fiddly too

These can both be avoided by always having the textbox be larger than its
contents so it never needs to scroll.

By default—and unlike other block-level elements—textboxes dont expand to fit
their contents. The layer with the placeholders in _does_ however, because it’s
a normal block-level element.

Since the layer with the placeholders always has an exact copy of what in the
textbox, we can set the textbox’s height to match the height of the layer with
the placeholders, and do this every time the content changes.
2016-03-18 09:19:21 +00:00
Chris Hill-Scott
836fe77c37 Fix bug with ‘ghost’ links in template textbox
This is a bug with the code that highlights placeholders.

It was taking the value of the textbox and copying it straight into the HTML
of the layer that contains the blue lozenges. This meant that any HTML that the
user typed into the textbox was rendered by the browser.

This commit fixes the bug by:
1. taking the contents of the textbox
2. copying it to the _text_ (not inner HTML) of a temporary `<div>`
3. taking the inner HTML of that `<div>` (whose text has been encoded with HTML
   entities in step 2., eg `>` becomes `&gt;`)
4. using that for the HTML content of the layer with the blue lozenges
2016-03-09 16:58:51 +00:00
Chris Hill-Scott
b31c9fbc0d Make job page poll for updates
This is a first go at having the job page update without refreshing.

The approach I’ve taken is to do all the rendering of HTML on the server side,
rather than use a Javascipt templating engine like mustache. This ensures that
we don’t have to maintain two sets of templates.

So the approach is to split the job page into partials. These partials can then:
- be included in the job page to render the whole page
- be rendered indivudually and then returned as a blob of HTML inside a JSON
  response

Then I’ve added a Javascript module which looks for areas of the page that should
be reloaded. For each area of the page it will poll a URL and re-render that
section of the page when it gets new HTML. It implements some throttling so that
API calls will never happen more frequently than 0.67 times/second.
2016-03-03 14:28:36 +00:00
Chris Hill-Scott
f743759751 Reset file upload field when user navigates back
**Problem**

The file upload form submit automatically whenever the name of the selected file
changes.

If the user picks a file, and then navigates back the field is pre-filled
because the page is loaded from the browser’s back/forward cache.

This means that if they pick the same file again, the value of the upload field
hasn’t changed, and the form won’t be submitted.

**Solution**

The solution is to clear the form field[1] if the page is being loaded from the
back/forward cache. Then any time the user picks a file it represents and
actual change.

1. http://stackoverflow.com/questions/8861181/clear-all-fields-in-a-form-upon-going-back-with-browser-back-button
2016-03-03 09:05:43 +00:00
Chris Hill-Scott
0d12714401 Automatically focus the first form field error
Because we’re not showing a summary of error messages screen reader users might
take a while to discover that there’s an error on the page. Since the only
real action on a page with errors is to correct them this commit adds some
Javascript to send focus straight to the first error message on a page.
2016-02-23 07:29:51 +00:00
Chris Hill-Scott
16fbfe49a3 Fix missing CSRF token on send SMS page
As part of https://github.com/alphagov/notifications-admin/pull/187 the file
upload pattern was changed to auto-submit once a file had been picked. The
form that was submitted was, however, missing a CSRF token, as well as a submit
button for non-JS users.

This commit makes the file upload pattern self-contained, so that it will always
include a form with a CSRF token in a hidden input and a submit button, which is
then hidden when Javascript loads.
2016-02-23 07:29:50 +00:00
Chris Hill-Scott
97a3bf9225 Remove the ‘manage templates’ page
The ‘manage templates’ page was almost identical to the ‘send text messages’
page.

This commit consolidates them into one and makes them all hang together.

Part of this means tweaks to the javascript so that files upload as soon as
you’ve chosen them.
2016-02-22 13:39:02 +00:00
Chris Hill-Scott
d1a7c8ef39 Make ‘edit template’ textboxes the same width
This involves:
- removing the hard coded width on any textbox that does placeholder
  highlighting
- adding JS to make sure that the extra layers on top of the textbox inherit
  the width of the textbox that the user types in (so the layers don’t get
  misaligned)

Keeping the textboxes at 2/3 width for consistency with how wide the messages
are on the ‘manage templates’ page.
2016-02-08 10:03:30 +00:00
Chris Hill-Scott
4447af3fec Add custom file upload component
The default browser file upload control is difficult to style, but looks totally
out of place.

This commit replaces it with one that has a GOV.UK style button, as a first
step.

Based heavily on this example:
http://tympanus.net/codrops/2015/09/15/styling-customizing-file-inputs-smart-way/
2016-02-03 17:16:17 +00:00
Chris Hill-Scott
776539462e Make autofocus textbox module
This commit adds a very small Javascript module to autofocus a textbox on page
load. It should only be used once per page.

It also adds a parameter to the textbox macro which adds the attribute to
trigger autofocus.
2016-02-02 16:38:10 +00:00
Chris Hill-Scott
3617f2e936 Move service and user nav to proposition header
This commit moves user-related navigation into the proposition header (the black
bar) at the top of the site. It adds some custom SASS to override GOV.UK
template and align these navigation items to the right (because it looks
better).

It then removes the service chooser dropdown (and its associated SASS and JS) in
favour of a link alongside the user-related navigation items. ‘Switch service’
is the best language for this that we’ve come up with so far.

This means that the only way of adding a new service is from the `/services`
page. So this commit removes the redirect if you land on this page with only one
service (else it would prevent you from ever being able to add more).
2016-02-01 13:52:45 +00:00
Rebecca Law
8737edfad1 Merge branch 'master' of github.com:alphagov/notifications-admin into api-keys-flow
Conflicts:
	tests/app/main/views/test_api_keys.py
2016-01-21 12:31:28 +00:00
Chris Hill-Scott
9784a9936c Add pages for create/view/revoke API keys
Copying what they’ve done on GOV.UK Pay, we should let users:
- generate as many keys as they want
- only see the key at time of creation
- give keys a name
- revoke any key at any time (this should be a one way operation)

And based on discussions with @minglis and @servingUpAces, the keys should be
used in conjunction with some kind of service ID, which gets encrypted with the
key. In other words the secret itself never gets sent over the wire.

This commit adds the UI (but not the underlying API integration) for doing the
above.
2016-01-20 16:22:23 +00:00
Chris Hill-Scott
482abb97d5 Put message previews on ‘Send SMS’ page
A previous commit removed these to differentiate between this page and the
manage templates page. It turns out that we do want previews on this page
because:
- the users for the two pages might be different—they might only be allowed to
  do one or the other depending what permissions they have
- it’s useful to see what the placeholders in the message are before uploading
  a CSV, to make sure the CSV has the correct column headings

This commit re-adds the message preview with a simpler UI. Discussed with
@antimega and we both agreed that the speech bubble tails on the messages should
go.
2016-01-20 13:12:20 +00:00
Chris Hill-Scott
a08089a47d Use HTML5 details element for the service switcher
The previous service switcher was built purely in Javascript, which meant that,
for the purposes of progressive enhancement, it had to load in the open state.
Setting it to the closed state with Javascript happened a fraction of a second
after page load. This caused an unpleasant flicker as the whole page shifted up
and down as it loaded.

This commit changes the switcher to use the native HTML5 `details` and
`summary` elements[1].

This commit adds a polyfill from GOV.UK Elements for browsers which don’t
support `details`/`summary`.

1. http://html5doctor.com/the-details-and-summary-elements/
2016-01-19 11:45:18 +00:00
Chris Hill-Scott
c4544eb833 Add API key component
This commit adds a component for showing an API key. Usage:

```jinja
{{ from 'components/api-key.html' import api_key }}
{{ api_key('e1b0751388f3cd0fc9982c701acdb3c2') }}
```

Depending on the user’s browser, it works in three different ways.

No Javascript
---
The API key is shown on the page.

Older browsers with Javascript
---
The API key is hidden, and users can click a button to reveal it.

Newer browsers that support copying to clipboard without Flash
---
As above, but when the key is shown there is a button which copies it to the
clipboard. This is acheived by using
[this polyfill](https://www.npmjs.com/package/query-command-supported)
to reliably detect browser support for the ‘copy’ command.

The styling of the component is a bit different to the initial sketch. I think
a grey button works better than green. Green feels like it’s going to take you
somewhere else.
2016-01-17 09:39:09 +00:00
Chris Hill-Scott
2554fbe0e0 Simplify template picker to be just radio buttons
Includes making the selection buttons work properly
2016-01-14 10:59:51 +00:00
Chris Hill-Scott
4cb535a2e1 Add progressive enhancement to service switcher
- by default, the menu is open
- if Javascript is enabled/loaded, the links are hidden, and visual cues (▶) to
  show that it can be opened are added
- clicking it opens and closes it
2016-01-12 11:47:02 +00:00
Chris Hill-Scott
84cdd2f4f0 Add Javascript feature detection for oninput
This commit adds a feature detection for the `oninput` event, which isn’t
supported in older browsers[1].

This means that the code that highlights placeholders will only be run in
browsers that support the `oninput` event.

1. http://caniuse.com/#feat=input-event
2016-01-06 09:39:42 +00:00
Chris Hill-Scott
74da3b1adf Use EcmaScript 6, w/ transpiling for compatibility
ES6 has some nice new features. Specifically relevant to this piece of
work are:

Arrow functions[1], whose `this` context is bound the value of `this` in the
current scope and can’t be overidden. The code is cleaner as a result, and
doesn’t need the addition of a bind polyfill for older browsers.

Template strings[2], which are similar to triple-quoted multi line strings in
Python. This means less fiddly and error-prone string concatenation.

This commit adds Babel[3] to the Gulp pipeline. This transpiles Javascript
written to the ES6 specification into code which is compatible with older
browsers that don’t understand ES6 syntax.

It also rewrites the gulpfile itself using some ES6 syntax, for the same reasons.

1. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions
2. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings
3. https://babeljs.io
2016-01-06 09:39:42 +00:00
Chris Hill-Scott
3ed415fb75 Enhance message textbox by styling placeholders
Users can add placeholders to their messages, eg

> …your vehicle ((registration number))

when the message is sent, this gets replaced with the data the user uploads, eg

> …your vehicle LC12 BFL

We reckon that it will be useful to see that the placeholder has been
recognised, ie that its syntax is correct, before uploading any data.

We reckon that the best way to do this is by styling it differently to the rest
of the text that the user types.

This is not a trivial problem. There are two possible ways to do it:

1 Write a Google Docs-style text rendering engine, which completely replaces
  the native HTML `<textarea>` with a custom control, and programme what should
  happen when the user types something that looks like a placeholder, or
  presses an arrow key, or makes a selection, or…
2 Leave the `<textarea>` in place, unmodified, and duplicate layers in front
  of/behind it to visually replace a placeholder with the blue lozenge

Unsurprisingly, this commit implements 2.

There are four layers. Each layer contains live-updated copy of the text in the
textbox, and each is styled differently:
- one layer behind the textbox to make the blue background
- the textbox itself
- a layer with the white text, which overlays the black text of the textbox
- a layer with an inner shadow to knock back the brackets

This is because of some interesting limitations:
- The text in the foreground and background must occupy the same physical space,
  so no deleting characters from the duplicated layers
- Words can’t be split up into multiple elements,
  eg `<span>((</span>regist…`:—this results in slightly different kerning to
  `((regis…`, which messes up the alignment of the layers
- The textbox can’t be completely overlapped with a block of colour, because
  the cursor disappears behind it. Trying to edit text when you can’t see the
  cursor is hard.

Implementation

Technically this makes use of Paul Hayes work on Javascript modules in the
GOV.UK frontend toolkit[1].

It also makes use of the `oninput` event to detect changes to the textbox’s
contents. This is much more performant than `onkeydown`, `onpaste`, etc. Without
it the delay between user input and the layers all updating is too slow and you
see misalignment of the layers.

1. https://github.com/alphagov/govuk_frontend_toolkit/pull/227
2016-01-06 09:39:42 +00:00
Chris Hill-Scott
5ebeec08ae Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.

There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
  and meant depending on Ruby, and having the SASS Gem globally installed—so
  you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
  ironed out the initial rough patches

The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
  GOV.UK template as a proper dependency

…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.

Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2016-01-05 13:12:35 +00:00
Rebecca Law
11d79951f3 Moved the templates into the app directory.
Added Manager to the app.py
2015-11-23 16:07:19 +00:00