-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show preview of imported sheet when selecting a sheet (#34)
On the sheet selection page, shows a preview of each sheet as the radio button is pressed, allowing users to check that it is the sheet that they want, which will be useful given the prevalence of both empty sheets and metadata sheets. One issue we will need to work around is sheets with too many columns, currently we are using overflow-x to show a scrollbar but we might want to find a better way (such as limiting the number of columns etc). It also removes the skips the review page until we are ready to re-instate it.
- Loading branch information
Showing
9 changed files
with
125 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 74 additions & 33 deletions
107
lib/importer/nunjucks/importer/macros/sheet_selector.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,94 @@ | ||
|
||
{# | ||
importerSheetSelector generates a radio button list which allows the | ||
user to choose which sheet is to be used to upload data. If there is | ||
importerSheetSelector generates a radio button list which allows the | ||
user to choose which sheet is to be used to upload data. If there is | ||
only a single sheet then it is selected by default. | ||
The list of sheet names is retrieved from the current spreadsheet | ||
The list of sheet names is retrieved from the current spreadsheet | ||
being uploaded, and will always contain at least one sheet. | ||
It accepts a data object which is taken from the prototype kit's | ||
session data which is made available on every page, and contains the | ||
data submitted from forms to the backend, and also the current | ||
It accepts a data object which is taken from the prototype kit's | ||
session data which is made available on every page, and contains the | ||
data submitted from forms to the backend, and also the current | ||
data import session. | ||
legend is the text that should be used for the legend part of the | ||
legend is the text that should be used for the legend part of the | ||
radio buttons, if none is supplied, then a legend is not added. | ||
#} | ||
{% from "importer/macros/table_view.njk" import importerTableView %} | ||
|
||
{% macro importerSheetSelector(data, legend) %} | ||
{% set selectedSheet = data['importer.session'].sheet %} | ||
{% set sheets = data['importer.session'].sheets %} | ||
{% set sheets = importSheetPreview(data) %} | ||
{% set tableRowIndex = sheets.length + 2 %} | ||
{% set error = importerError(data) %} | ||
|
||
<div class="govuk-form-group {% if error %}govuk-form-group--error{% endif %}"> | ||
<fieldset class="govuk-fieldset" aria-describedby="upload-error"> | ||
|
||
{% if legend %} | ||
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l"> | ||
<h1 class="govuk-fieldset__heading"> | ||
{{ legend }} | ||
</h1> | ||
</legend> | ||
{% endif %} | ||
|
||
{% if error %} | ||
<p id="upload-error" class="govuk-error-message"> | ||
<span class="govuk-visually-hidden">Error:</span> {{ error.text }} | ||
</p> | ||
{% endif %} | ||
|
||
<div class="govuk-radios" data-module="govuk-radios"> | ||
<style> | ||
div.selectable { display: none; overflow-x: auto} | ||
</style> | ||
|
||
<div class="govuk-form {% if error %}govuk-form-group--error{% endif %}"> | ||
<div class="govuk-form-group "> | ||
{% if legend %} | ||
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l"> | ||
<h1 class="govuk-fieldset__heading"> | ||
{{ legend }} | ||
</h1> | ||
</legend> | ||
{% endif %} | ||
|
||
{% if error %} | ||
<p id="upload-error" class="govuk-error-message"> | ||
<span class="govuk-visually-hidden">Error:</span> {{ error.text }} | ||
</p> | ||
{% endif %} | ||
|
||
<div class="govuk-radios rd-sheet-preview" data-module="govuk-radios"> | ||
{% for sheet in sheets %} | ||
<div class="govuk-radios__item"> | ||
<input class="govuk-radios__input" id="{{sheet}}" name="sheet" type="radio" value="{{ sheet }}" {% if | ||
selectedSheet==sheet %}checked{% endif %}> | ||
<label class="govuk-label govuk-radios__label" for="{{sheet}}"> | ||
{{sheet}} | ||
</label> | ||
</div> | ||
<input class="govuk-radios__input" id="{{sheet.name}}" name="sheet" type="radio" value="{{sheet.name}}" {% if selectedSheet==sheet.name %}checked="checked"{% endif %} data-preview-index="{{loop.index0}}" onclick="javascript:preview(this);"> | ||
<label class="govuk-label govuk-radios__label" for="{{sheet.name}}"> | ||
{{sheet.name}} | ||
</label> | ||
</div> <!-- .govuk-radios__item --> | ||
{% endfor %} | ||
</div> <!-- .govuk-radios --> | ||
</div> | ||
</div> | ||
|
||
<div id="previews" class="govuk-!-margin-top-6"> | ||
{% for sheet in sheets %} | ||
<div class="selectable"> | ||
{% if sheet.data.rows == null %} | ||
<div class="govuk-body"> | ||
Sheet '{{ sheet.name }}' is empty | ||
</div> | ||
{% else %} | ||
<div class="govuk-hint"> | ||
First {{sheet.data.rows | length}} rows of '{{sheet.name}}' | ||
</div> | ||
{{ importerTableView(sheet.data, hideHeader=true) }} | ||
{% endif %} | ||
</div> | ||
</fieldset> | ||
{% endfor %} | ||
</div> | ||
|
||
<script> | ||
const previews = Array.from(document.getElementById("previews").children); | ||
const preview = (elem) => { | ||
let index = parseInt(elem.dataset.previewIndex ?? -1); | ||
if (index < 0) { | ||
return; | ||
} | ||
previews.forEach((p) => {p.style.display = "none"}); | ||
previews[index].style.display = "block"; | ||
} | ||
{# Show the preview any default selected options when the page loads #} | ||
const currentlySelected = document.querySelector('input[type="radio"]:checked'); | ||
preview(currentlySelected); | ||
</script> | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters