Skip to content

Commit ae860d3

Browse files
committed
Merge branch 'value-formats'
2 parents 148ca5b + d60cde8 commit ae860d3

17 files changed

Lines changed: 710 additions & 162 deletions

File tree

lib/importer/govuk-prototype-kit.config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
"path": "/templates/mapping.html",
3636
"type": "nunjucks"
3737
},
38+
{
39+
"name": "Choose field formats",
40+
"path": "/templates/format.html",
41+
"type": "nunjucks"
42+
},
3843
{
3944
"name": "Review your data",
4045
"path": "/templates/review.html",

lib/importer/nunjucks/importer/macros/field_mapper.njk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
</div>
4747
{% endif %}
4848

49+
<input type="hidden" name="mappings-present" value="yes">
4950
<table class="govuk-table">
5051
{% if params.caption %}
5152
<caption class="govuk-table__caption govuk-table__caption--m">{{params.caption}}</caption>
@@ -67,7 +68,7 @@
6768
<th scope="row" class="govuk-table__header">{{ h.name }}</th>
6869
<td class="govuk-table__cell">{{ h.examples }}</td>
6970
<td class="govuk-table__cell govuk-table__cell--numeric">
70-
<select class="govuk-select" style="float: right;" name="{{h.index}}">
71+
<select class="govuk-select" style="float: right;" name="field-{{h.index}}">
7172
<option name=""></option>
7273
{% for field in fields %}
7374
<option value="{{field.name}}" {% if field.name == currentValue or (mappingsLen == 0 and field.name == h.name) %}selected{% endif %}>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{#
2+
dudkFormatPicker shows each column heading mapped to a field whose type has
3+
format options from the current spreadsheet, alongside a drop-down containing
4+
available formats. This allows the user to choose a format for
5+
each column that needs one, to select how the value mapping should be applied.
6+
7+
The resulting data to be submitted to the 'importerMapDataPath'
8+
will be a map of column indices to format names.
9+
10+
It accepts a data object which is taken from the prototype kit's
11+
session data which is made available on every page, and contains the
12+
data submitted from forms to the backend, and also the current
13+
data import session.
14+
#}
15+
16+
{% macro dudkFormatPicker(params) %}
17+
{% set fields = params.data['importer.session']['fields'] %}
18+
{% set mapping = params.data['importer.session']['mapping'] %}
19+
{% set headings = importerGetHeaders(params.data) %}
20+
{% set headingError = headings.error %}
21+
{% set error = importerError(params.data) %}
22+
23+
{% if headingError %}
24+
<p id="mapping-error" class="govuk-error-message">
25+
<span class="govuk-visually-hidden">Error:</span> {{ headingError.text }}
26+
</p>
27+
{% endif %}
28+
29+
{% if error %}
30+
<div class="govuk-error-summary" data-module="govuk-error-summary">
31+
<div role="alert">
32+
<h2 class="govuk-error-summary__title">
33+
{{ error.text }}
34+
</h2>
35+
<div class="govuk-error-summary__body">
36+
<ul class="govuk-list govuk-error-summary__list">
37+
{% for e in error.extra %}
38+
<li>
39+
<a href="#field-{{ e | slugify }}">{{ e }}</a>
40+
</li>
41+
{% endfor %}
42+
</ul>
43+
</div>
44+
</div>
45+
</div>
46+
{% endif %}
47+
48+
<input type="hidden" name="formats-present" value="yes">
49+
<table class="govuk-table">
50+
{% if params.caption %}
51+
<caption class="govuk-table__caption govuk-table__caption--m">{{params.caption}}</caption>
52+
{% endif %}
53+
<thead class="govuk-table__head">
54+
<tr class="govuk-table__row">
55+
<th scope="col" class="govuk-table__header">{{params.columnTitle}}</th>
56+
<th scope="col" class="govuk-table__header">{{params.examplesTitle}}</th>
57+
<th scope="col" class="govuk-table__header">{{params.fieldAndTypeTitle}}</th>
58+
<th scope="col" class="govuk-table__header" style="padding-left: 1.5em">{{params.fieldsTitle}}</th>
59+
</tr>
60+
</thead>
61+
<tbody class="govuk-table__body">
62+
{% set mappingsLen = mapping | length %}
63+
{% set possibleFormatsByColumn = importerPossibleColumnFormats(params.data) %}
64+
{% set mappedColumnDetails = importerMappedColumnDetails(params.data) %}
65+
{% for h in headings.data %}
66+
{% set hIndex = loop.index0 %}
67+
{% set currentValue = importerErrorMappingData(error, hIndex) %}
68+
{% set possibleFormats = possibleFormatsByColumn[hIndex] %}
69+
{% set mapping = mappedColumnDetails[hIndex] %}
70+
71+
<tr class="govuk-table__row" id="field-{{ h.name | slugify }}">
72+
<th scope="row" class="govuk-table__header">{{ h.name }}</th>
73+
<td class="govuk-table__cell">{{ h.examples }}</td>
74+
<td class="govuk-table__cell">
75+
{% if mapping %}
76+
{{ mapping.fieldName }} ({{ mapping.typeName }})
77+
{% endif %}
78+
</td>
79+
<td class="govuk-table__cell govuk-table__cell--numeric">
80+
{% if possibleFormats %}
81+
<select class="govuk-select" style="float: right;" name="format-{{h.index}}">
82+
<optgroup label="Matches every row">
83+
{% for format in possibleFormats[0] %}
84+
<option value="{{format.name}}"
85+
{% if format.name == currentValue %}selected{% endif %}>
86+
{{format.displayName}}
87+
</option>
88+
{% endfor %}
89+
</optgroup>
90+
<optgroup label="Matches some rows">
91+
{% for format in possibleFormats[1] %}
92+
<option value="{{format.name}}"
93+
{% if format.name == currentValue %}selected{% endif %}>
94+
{{format.displayName}}
95+
</option>
96+
{% endfor %}
97+
</optgroup>
98+
</select>
99+
{% endif %}
100+
</td>
101+
</tr>
102+
{% endfor %}
103+
</tbody>
104+
</table>
105+
{% endmacro %}
106+

0 commit comments

Comments
 (0)