Commit Graph

40 Commits

Author SHA1 Message Date
Tom Byers
a8a29698cb Replace gulp-base64 with gulp-base64-inline
The gulp-base64 package has 11 dependencies with
vulnerabilities listed against them as of this
time. It also doesn't seem to be maintained any
more. The last commit was in 2015 and there are
issues and pull requests up to bump the
dependencies.

This replaces it with gulp-base64-inline.

gulp-base64-inline takes a single path, which it
prepends to any image paths it finds. Our image
paths are actually URLs, not filesystem paths so
we need to send it a relative path to repoint the
URL.

This commit includes changes that remove a few
`@import`s from one of our sass partials.

They aren't needed as those files are imported
further up the stack and `_typography.scss` has an
import in it that overwrites the new
`_url-helpers.scss` we added here.
2019-04-12 15:36:57 +01:00
Tom Byers
fa851dcfec Bump remaining NPM packages used on client-side
Means that only the following packages will now be
out of date:

1. govuk_template_jinja
2. jquery

Reasons:

GOVUK Template Jinja

This bumps it to 0.24.1, after which the only
changes are to add analytics tracking to the
GOV.UK logo and cookie banner.

We don't need to track either of these and they
were added for GOVUK analytics work.

jQuery

jQuery stops supporting IE<9 after version
1.12. This is pretty much our support now but if
we move to IE>8 we shouldn't do it by bumping the
version. This would just increase the amount of
broken JS we ship to IE8.

Also: both are deprecated and we will move off
them in the near future.
2019-04-12 15:36:57 +01:00
Tom Byers
01b97986f6 Update diff-dom package to 3.1.0
Since it moved to ES Modules in version 2.3.1,
diff-dom stopped including the `diffDOM.js` file
in its NPM package.

We don't do any kind of bundling in our build yet,
just concatenation of our scripts and some
minification of the results so we can't take
advantage of this yet.

The `diffDOM.js` file is still available in the
Github release so this moves to referencing that
in the `package.json` instead, until we start
using a bundler.

I opened an issue to check this is what the author
intended:

https://github.com/fiduswriter/diffDOM/issues/84

The latest version also adds Rollup as a peer
dependency.
2019-04-12 15:36:57 +01:00
Tom Byers
05f3cb6797 Bump JSHint 2019-04-12 15:36:57 +01:00
Tom Byers
fed3381209 Bump Babel to 7.4.0
Requires replacing `babel-preset-es2015` for
`babel-preset-env` as Babel switched to this as of
version 6:

https://babeljs.io/docs/en/babel-preset-es2015

Note: this also moves all Babel packages to using
the scoped packages syntax, descended from the
`@babel` namespace.

https://docs.npmjs.com/about-scopes
2019-04-12 15:36:57 +01:00
Tom Byers
c3a1e6ed59 Bump Gulp to 4.0.0
Brings in a new API which is a breaking change:

https://github.com/gulpjs/gulp/blob/master/CHANGELOG.md#400

Requires gulpfile.babel.js to be a CommonJS module
and for all tasks to be exported.

Replaces using ES6 modules for the CommonJS to
include other packages to match the type of module
the gulpfile now is.

Updates to 4.0.0 include `series` and `parallel`
methods which remove the need for the
`run-sequence` package.

Also bumps gulp-specific libraries.
2019-04-12 15:36:57 +01:00
Tom Byers
c7f3b688cd Bump version of NodeJS to 10.15.3
Updates the README to reference this.

If running this locally, it's recommended to use
the 'n' NPM package to manage your version of
NodeJS, as described in the README:

https://github.com/alphagov/notifications-admin#first-time-setup
2019-04-12 15:36:57 +01:00
Tom Byers
d1c028e7d4 Add library for tracking carets in textareas 2019-03-25 15:58:23 +00:00
Chris Hill-Scott
0d3642148c Always pin to exact versions 2019-02-06 16:16:28 +00:00
Chris Hill-Scott
06a9e56589 Ensure Gulp tasks run sequentially
So that images are always copied into place before trying to build the
SASS.
2019-02-06 16:09:39 +00:00
Katie Smith
fb95e08f97 Pin patch version of govuk-elements-sass
Version 3.1.3 changed heading classes to display block - https://github.com/alphagov/govuk_elements/pull/552
This is a breaking change for us since we are using the heading classes
to make font bold - 3.1.3 adds line breaks in places where we don't want
them and causes some functional tests to fail.

Since we will be replacing govuk-elements with the new design system,
this commit pins the version of govuk-elements instead of updating all
the code to work with the lastest version.
2018-08-08 11:21:39 +01:00
Chris Hill-Scott
0b331f3e23 Upgrade GOV.UK template to newest version
Changes: https://github.com/alphagov/govuk_template/compare/v0.23.0...v0.24.0

Includes a new way of serving the font files which will:
- save us ~300kb on non-cachd requests
- speed up the parsing of the CSS file
2018-04-27 14:12:02 +01:00
snyk-bot
34bd1883c3 fix: package.json to reduce vulnerabilities
The following vulnerabilities are fixed with an upgrade:
- https://snyk.io/vuln/npm:minimatch:20160620

Latest report for alphagov/notifications-admin:
https://snyk.io/test/github/alphagov/notifications-admin
2018-03-29 02:10:58 +00:00
Chris Hill-Scott
35e7260d6f Fix bug with disappearing AJAX content in IE 9/10
We had a user report that the ‘inbound messages’ part of their dashboard
was appearing for a split second then disappearing.

This was caused by the Javascript on the page throwing an exception as
it was trying to re-render this part of the page. This meant it gave up
and rendered nothing.

The exception was caused by passing `undefined` as the second argument
to `.insertBefore`. This is acceptable in most browsers, but not older
versions of IE. This is fixed in the latest version of diffDOM (the 3rd
party library we use to do the AJAX stuff) by defaulting the second
argument to `.insertBefore` to `null`, which is acceptable in old IE
versions.

See the fix here: 8833d87e9d
2018-02-12 11:39:38 +00:00
Chris Hill-Scott
ef7a93bfde Restrict gulp-sass-lint to version 1.2.0
Version 1.3.0 introduced some breaking changes to do with file output.
Don’t have time to fix them now…
2018-01-18 10:34:29 +00:00
Chris Hill-Scott
4559fc9d29 Update NPM packages to the latest version 2018-01-17 16:50:39 +00:00
Chris Hill-Scott
48b49ebdd3 Update versions of GOV.UK packages
GOV.UK elements:
- Changelog: https://github.com/alphagov/govuk_elements/blob/master/packages/govuk-elements-sass/CHANGELOG.md#311
- Full changes: https://github.com/alphagov/govuk_elements/compare/v3.0.3...v3.1.1

GOV.UK template:
- Changelog: https://github.com/alphagov/govuk_template/blob/master/CHANGELOG.md
- Full changes: https://github.com/alphagov/govuk_template/compare/v0.19.2...v0.22.3

GOV.UK frontend toolkit:
- Changelog: https://github.com/alphagov/govuk_frontend_toolkit/blob/master/CHANGELOG.md#701
- Full changes: https://github.com/alphagov/govuk_frontend_toolkit/compare/v5.2.0...v7.0.1
2017-09-25 15:20:35 +01:00
Chris Hill-Scott
bb9fe35ab5 Upgrade GOV.UK toolkit, template and elements
We should make sure that the parts of the UI that we inherit from these
packages are kept up to date.

This commit:
- updates each dependency to the latest version
- makes patch (bug fixing) version bumps automatic because
  - it makes less work for us
  - we don’t get so far behind
  - we should be able to trust dependencies that are coming from other
    teams in this building

Full changes that this brings in:

GOV.UK Template
---

- Increase skiplink colour contrast ([GOV.UK Template PR #263](https://github.com/alphagov/govuk_template/pull/263))

GOV.UK Elements
---
- Too many to show – see
  https://github.com/alphagov/govuk_elements/compare/v1.1.1...v3.0.2#diff-4ac32a78649ca5bdd8e0ba38b7006a1e

GOV.UK Frontend Toolkit
---
- Too many to show – see
  https://github.com/alphagov/govuk_frontend_toolkit/compare/v4.6.0...v5.2.0#diff-4ac32a78649ca5bdd8e0ba38b7006a1e
2017-04-10 14:02:41 +01:00
Chris Hill-Scott
06e66cdee0 Upgrade Gulp SASS
Gulp was spitting out a lot of noise about stuff being out of date. The
cause seemed to be our outdated version of Gulp SASS. This commit
upgrades Gulp SASS to the latest version.

Changes:
---
https://github.com/dlmanning/gulp-sass/compare/v2.3.1...v3.1.0

This is a breaking change because one of the underlying libraries
includes a breaking change. But looking at their release notes, it
doesn’t seem to affect any SASS features that we’re using:

https://github.com/sass/libsass/releases/tag/3.4.0
2017-03-13 13:40:46 +00:00
Chris Hill-Scott
67e28cac7e Don’t halt Gulp watch on JS/SASS errors
Problem
---
You make a minor typo, save the file and your Gulp process dies without
you realising. You then spend 5 minutes trying to work out why your
changes aren’t appearing, no matter what edits you make.

Solution
---

Catch errors raised in processing the JS/SASS files and log them,
without killing the process.

How
---

Use a handy plugin called
[Gulp PrettyError](https://www.npmjs.com/package/gulp-prettyerror).
2017-03-13 13:17:20 +00:00
Chris Hill-Scott
c4bdd9c4a4 Upgrade GOV.UK template
GOV.UK crown logo image has been tweaked slightly, so our app didn’t
match newer prototypes.

Changes from here: https://github.com/alphagov/govuk_template/pull/237
2016-11-18 12:00:02 +00:00
Chris Hill-Scott
6c96b90922 Make relative timestamps update automatically
It’s weird to be on a page that says ‘2 seconds ago’ and stays stuck
there.

We don’t want to AJAX the whole page because it would get in the way of
interacting with the list of notifications.

This commit adds the venerable jQuery Timeago[1] plugin to keep the
relative times accurate and fresh.

1. http://timeago.yarp.com/
2016-09-29 09:28:13 +01:00
Chris Hill-Scott
3e42042156 Add a page to manage a service’s whitelist
Services who are in alpha or building prototypes need a way of sending
to any email address or phone number without having to sign the MOU.

This commit adds a page where they can whitelist up to 5 email addresses
and 5 phone numbers.

It uses the ‘list entry’ UI pattern from the Digital Marketplace
frontend toolkit [1] [2] [3].

I had to do some modification:
- of the Javascript, to make it work with the GOV.UK Module pattern
- of the template to make it work with WTForms
- of the content security policy, because the list entry pattern uses
  Hogan[1], which needs to use `eval()` (this should be fine if we’re
  only allowing it for scripts that we serve)
- of our SASS lint config, to allow browser-targeting mixins to come
  after normal rules (so that they can override them)

This commit also adds a new form class to validate and populate the two
whitelists. The validation is fairly rudimentary at the moment, and
doesn’t highlight which item in the list has the error, but it’s
probably good enough.

The list can only be updated all-at-once, this is how it’s possible to
remove items from the list without having to make multiple `POST`
requests.

1. 434ad30791/toolkit/templates/forms/list-entry.html
2. 434ad30791/toolkit/scss/forms/_list-entry.scss
3. 434ad30791/toolkit/javascripts/list-entry.js
4. http://twitter.github.io/hogan.js/
2016-09-29 09:27:38 +01:00
Chris Hill-Scott
b98b328d9b Upgrade diffDOM dependency
Features:

- Expose Diff object

Fixes:

- Reverse actions for modifyComment/Text
- Simplify diff on some text only diffs
- Simplify diff on single element removal
2016-09-01 11:22:52 +01:00
Chris Hill-Scott
52cdf389b0 Upgrade GOV.UK template
Full changes:
https://github.com/alphagov/govuk_template/compare/v0.17.1...v0.18.0
2016-08-01 07:41:16 +01:00
Chris Hill-Scott
33b4138e79 Patch update sections of the page on AJAX
Currently, when we update a section of the page with AJAX we replace the
entire HTML of the section with the new HTML. This causes problems:
- if you’re trying to interact with that section of the page, eg by
  inpecting it, clicking or hovering an element
- (probably) for screenreaders trying to navigate a page which is
  changing more than is necessary

This commit replaces the call to `.html()` with a pretty clever library
called diffDOM[1]. DiffDOM works by taking a diff of the old element and
the new element, then doing a patch update, ie only modifying the parts
that have changed.

This is similar in concept to React’s virtual DOM, while still allowing
us to render all markup from one set of templates on the server-side.

1. https://github.com/fiduswriter/diffDOM
2016-04-27 10:08:57 +01:00
Chris Hill-Scott
83b456095e Upgrade GOV.UK template to 0.17.1
Makes the size of the HTML file slightly smaller

Full changelog:

> # 0.17.1
>
> - Reduce file size of template: removes HTML comments, `type` attributes
>   on scripts, and uses HTML5 charset declaration. #208
> - Switch external link media query to be mobile first #205
> - Sass file cleanups
> - Replace old grid mixins with newer grid from frontend toolkit #134
> - Remove duplicate grey variables #201
>
> # 0.17.0
>
> - Add CSS hook (`.js-hidden`) for hiding content when JS is  enabled.
>   Some apps have an equivalent hook, which can be removed once
>   upgraded to this version
2016-04-25 09:58:35 +01:00
Chris Hill-Scott
1cbd37a920 Bring back SASS lint
The problem with SASS lint that we found in
https://github.com/alphagov/notifications-admin/pull/202
has been fixed (see https://github.com/sasstools/sass-lint/pull/550).

This commit reverts #202, re-enabling linting of SASS files.
2016-02-26 13:23:33 +00:00
Chris Hill-Scott
d53dfec3fd Temporarily remove SASS linting
Trying to install gulp-sass-lint fails because some of its dependencies are not
met:
> npm install gulp-sass-lint
> npm ERR! Darwin 15.3.0
> npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "gulp-sass-lint"
> npm ERR! node v5.7.0
> npm ERR! npm  v3.7.5
>
> npm ERR! No compatible version found: lodash.upperfirst@^3.0.0
> npm ERR! Valid install targets:
> npm ERR! 4.1.2, 4.1.1, 4.1.0, 4.0.2, 4.0.1, 4.0.0
> npm ERR!

This commit removes it until we can work out what the problem is.
2016-02-26 11:46:52 +00:00
Chris Hill-Scott
2202994fdc Fix GOV.UK template images 2016-02-23 10:56:48 +00:00
Chris Hill-Scott
fd54eeaeb7 Inline images in CSS
Because this commit’s parent added a few new images, we are now serving at
least a handful of images, therefore a few additional HTTP requests. It’s better
to combine multiple HTTP requests into one for performance reasons (up to a
point).

This commit adds an extra step to the preprocessing of SASS files which takes
any images it finds, base64 encodes them and inlines them into the distributed
CSS files.

It also modifies the content security policy to allow inline images.
2016-02-22 13:39:02 +00:00
Chris Hill-Scott
7ecc3a4821 Install GOV.UK Template with NPM
Since https://github.com/alphagov/govuk_template/pull/193 the Jinja version of
the GOV.UK Template is published with a `package.json`. This means
- we can consume it via NPM
- so we can get rid of Bower

Which is what this commit does.
2016-02-17 14:27:05 +00:00
Chris Hill-Scott
0201825c45 Add linting for SASS and Javascript
Similar to how PEP8 enforces Python style, there are tools for front end code:
- jshint[1] for Javascript
- sass-lint[2] for SASS

This commit adds the Gulp plugins for both, and sets up some sensible rules
(which can be iterated on).

It also adds a command to `./scripts/run_tests.sh`, so that any errors in the
front end code will fail the build before it has a chance to be deployed.

1. http://jshint.com/
2. https://www.npmjs.com/package/sass-lint
2016-02-08 12:02:22 +00:00
Chris Hill-Scott
a055c59050 Use NPM-published version of GOV.UK Elements
The version we want is available now:
https://www.npmjs.com/package/govuk-elements-sass
2016-01-18 11:56:59 +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
6bcbeaef70 Install GOV.UK Elements + Frontend Toolkit w/ NPM
Because:
- GOV.UK elements is now published with a package.json that only install the
  SASS files (https://github.com/alphagov/govuk_elements/pull/156)
- We can drop Git submodules, so one less dependency management tool

This commit also changes the `gulpfile.js` and `main.scss` files to use the
assets from `node_modules` rather than the Git submodules.
2016-01-14 16:45:26 +00:00
Chris Hill-Scott
1b7658e09a Fix flakiness with Gulp + Travis
Gulp was failing silently on Travis. I tracked this down to the task that
builds a custom, slimmed-down version of jQuery from source.

To fix this I’ve removed the task and replaced it with just `src`ing the
minified version of jQuery from `node_modules`.

Cons:
- A few more kb of JS

Pros:
- Less random, afternoon-chewing complexity
2016-01-12 15:16:16 +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