Commit 81f84faa authored by Pierre Dittgen's avatar Pierre Dittgen

Template refactoring

parent 938ccb79
{% macro preview(source_data) %}
<p class="text">
Affichage de {{ source_data.preview_rows_nb }} lignes sur {{ source_data.rows_nb }} au total
</p>
<div class="table-responsive">
<table class="table table-striped table-bordered table-sm table-hover">
<thead class="thead-light">
<tr>
{% for col in source_data.header %}
<th scope="col">{{ col }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in source_data.preview_rows %}
<tr>
{% for val in row %}
<td>{{ val }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
{% macro body_errors(report, source_data) %}
<h3>Problèmes de contenu</h3>
<div class="table-responsive-sm">
<table class="table-sm table-bordered table-striped table-hover">
<thead class="thead-light">
<th scope="col">1</th>
{% for h in report.table.headers %}
<th scope="col" data-toggle="tooltip" title="{{ report.table.headers_title[loop.index - 1]}}">{{ h }}</th>
{% endfor %}
</thead>
<tbody>
{% for row in report.table.errors.by_rows %}
<tr>
{% if 'row' in row.errors %}
<th class="table-danger" data-toggle="tooltip" title="{{ row.errors.row.message }}">{{
row.row_id
}}</th>
{% if row.errors.row.code == 'blank-row' and not source_data.data_rows[row.row_id -2] %}
{% for _ in report.table.headers %}
<td class="table-danger" data-toggle="tooltip" title="{{ row.errors.row.message }}"></td>
{% endfor %}
{% endif %}
{% else %}
<th>{{ row.row_id }}</th>
{% endif %}
{% for d in source_data.data_rows[row.row_id - 2] %}
{% if loop.index in row.errors %}
<td class="table-danger" data-toggle="tooltip" title="{{ row.errors[loop.index].message }}">
{% elif 'row' in row.errors %}
<td class="table-danger" data-toggle="tooltip" title="{{ row.errors.row.message }}">
{% else %}
<td>
{% endif %}
{{ d }}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endmacro %}
\ No newline at end of file
<p class="text">
Affichage de {{ source_data.preview_rows_nb }} lignes sur {{ source_data.rows_nb }} au total
</p>
<div class="table-responsive">
<table class="table table-striped table-bordered table-sm table-hover">
<thead class="thead-light">
<tr>
{% for col in source_data.header %}
<th scope="col">{{ col }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in source_data.preview_rows %}
<tr>
{% for val in row %}
<td>{{ val }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
\ No newline at end of file
......@@ -26,12 +26,13 @@
</div>
</div>
{% import 'table_macros.html' as tables %}
{% if report.error_count == 0 %}
<h2>La table est valide</h2>
<p>Aucune erreur détectée</p>
{% include 'table_preview.html' %}
{{ tables.preview(source_data) }}
{% else %}
......@@ -58,53 +59,21 @@
{% if report.table.errors.body %}
{% if not report.table.display_body_errors %}
Merci de corriger ce(s) erreur(s) pour visualiser les erreurs de contenu.
<p class="text">
Veuillez corriger ce(s) erreur(s) pour visualiser les problèmes de contenu.<br />
<a href="#" id="show_body_errors" title="Attention, en cas de problème sur les colonnes, certains messages d'errur ne seront pas pertinents">Affichez
tout de même les erreurs de valeur</a>
</p>
<div id="body_errors" style="display: none">
{{ tables.body_errors(report, source_data) }}
</div>
{% else %}
<div>
<h3>Problèmes de contenu</h3>
<div class="table-responsive-sm">
<table class="table-sm table-bordered table-striped table-hover">
<thead class="thead-light">
<th scope="col">1</th>
{% for h in report.table.headers %}
<th scope="col" data-toggle="tooltip" title="{{ report.table.headers_title[loop.index - 1]}}">{{ h }}</th>
{% endfor %}
</thead>
<tbody>
{% for row in report.table.errors.by_rows %}
<tr>
{% if 'row' in row.errors %}
<th class="table-danger" data-toggle="tooltip" title="{{ row.errors.row.message }}">{{
row.row_id
}}</th>
{% if row.errors.row.code == 'blank-row' and not source_data.data_rows[row.row_id -2] %}
{% for _ in report.table.headers %}
<td class="table-danger" data-toggle="tooltip" title="{{ row.errors.row.message }}"></td>
{% endfor %}
{% endif %}
{% else %}
<th>{{ row.row_id }}</th>
{% endif %}
{% for d in source_data.data_rows[row.row_id - 2] %}
{% if loop.index in row.errors %}
<td class="table-danger" data-toggle="tooltip" title="{{ row.errors[loop.index].message }}">
{% elif 'row' in row.errors %}
<td class="table-danger" data-toggle="tooltip" title="{{ row.errors.row.message }}">
{% else %}
<td>
{% endif %}
{{ d }}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endif %}
{{ tables.body_errors(report, source_data) }}
</div>
{% endif %}
{% endif %}
{% endif %}
{% endblock %}
......@@ -112,12 +81,12 @@ Merci de corriger ce(s) erreur(s) pour visualiser les erreurs de contenu.
<script>
$(function () {
// Errors tooltip activate
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="tooltip"]').tooltip();
// Reload to re-validate
$('#btn-reload').on('click', function () {
$(this).prop('disabled', true)
window.location.reload(true);
// Show body errors
$('#show_body_errors').on('click', function () {
$('#body_errors').show();
$(this).remove();
})
})
</script>
......@@ -127,4 +96,4 @@ Merci de corriger ce(s) erreur(s) pour visualiser les erreurs de contenu.
{{ report.table.errors.body|length }} erreur(s) détectée(s)
#}
{% endblock %}
\ No newline at end of file
{% endblock %}
......@@ -156,32 +156,30 @@ def create_validata_report(goodtables_report, schema):
else:
report['table']['errors']['body'].append(err)
# If there are structure errors different to invalid-column-delimiter
# => don't display body errors
# Checks if there are structure errors different to invalid-column-delimiter
report['table']['display_body_errors'] = all(err['code'] == 'invalid-column-delimiter'
for err in report['table']['errors']['structure'])
if report['table']['display_body_errors']:
# and group body errors by row id
rows = []
current_row_id = 0
for err in report['table']['errors']['body']:
if not 'row-number' in err:
print('ERR', err)
row_id = err['row-number']
del err['row-number']
del err['context']
if row_id != current_row_id:
current_row_id = row_id
rows.append({'row_id': current_row_id, 'errors': {}})
column_id = err.get('column-number')
if column_id is not None:
del err['column-number']
rows[-1]['errors'][column_id] = err
else:
rows[-1]['errors']['row'] = err
report['table']['errors']['by_rows'] = rows
# Group body errors by row id
rows = []
current_row_id = 0
for err in report['table']['errors']['body']:
if not 'row-number' in err:
print('ERR', err)
row_id = err['row-number']
del err['row-number']
del err['context']
if row_id != current_row_id:
current_row_id = row_id
rows.append({'row_id': current_row_id, 'errors': {}})
column_id = err.get('column-number')
if column_id is not None:
del err['column-number']
rows[-1]['errors'][column_id] = err
else:
rows[-1]['errors']['row'] = err
report['table']['errors']['by_rows'] = rows
return report
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment