|
| 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