validation_macros.html 4.89 KB
Newer Older
Pierre Dittgen's avatar
Pierre Dittgen committed
1
{% macro preview(source_data) %}
Christophe Benz's avatar
Christophe Benz committed
2 3
<p>
    Prévisualisation de {{ source_data.preview_rows_nb }} ligne{% if source_data.preview_rows_nb > 1 %}s{% endif %} sur {{ source_data.rows_nb }} au total :
Pierre Dittgen's avatar
Pierre Dittgen committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
</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 %}

Pierre Dittgen's avatar
Pierre Dittgen committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
{% macro body_errors(report, source_data, print_mode) %}
    {% if print_mode %}
        {{ body_errors_pdf(report, source_data) }}
    {% else %}
        {{ body_errors_screen(report, source_data) }}
    {% endif %}
{% endmacro %}


{% macro body_errors_pdf(report, source_data) %}
<table id="table-errors" class="table table-striped table-bordered table-sm">
<thead class="thead-light">
    <th>Ligne</th>
    <th>Colonne</th>
    <th>Valeur</th>
    <th>Erreur</th>
</thead>
<tbody>
{% for row in report.table.errors.body_by_rows %}
    {% if 'row' in row.errors %}
        <tr>
            <td>{{ row.row_id }}</td>
            <td colspan="3">{{ row.errors.row.title }}</td>
        </tr>
    {% else %}
        {% for d in source_data.data_rows[row.row_id - 2] %}
            {% if loop.index in row.errors %}
            <tr>
                <td>{{ row.row_id }}</td>
                <td>{{ source_data.header[loop.index - 1] }}</td>
                <td>{{ d }}</td>
                <td>
                    <h5>{{row.errors[loop.index].title}}</h5>
                    {{ row.errors[loop.index].content | safe }}
                </td>
            </tr>
            {% endif %}
        {% endfor %}
    {% endif %}
{% endfor %}
{% endmacro %}


{% macro body_errors_screen(report, source_data) %}
Pierre Dittgen's avatar
Pierre Dittgen committed
71 72 73 74
<div class="table-responsive-sm">
    <table class="table-sm table-bordered table-striped table-hover">
        <thead class="thead-light">
            <th scope="col">1</th>
75
            {% for h in source_data.header %}
Pierre Dittgen's avatar
Pierre Dittgen committed
76
            <th scope="col" data-toggle="popover" title="{{ report.table.headers_title[loop.index - 1]}}" data-content="{{ report.table.headers_description[loop.index - 1] | commonmark2html | escape}}">{{
Pierre Dittgen's avatar
Pierre Dittgen committed
77
                h }}</th>
Pierre Dittgen's avatar
Pierre Dittgen committed
78 79 80
            {% endfor %}
        </thead>
        <tbody>
81
            {% for row in report.table.errors.body_by_rows %}
Pierre Dittgen's avatar
Pierre Dittgen committed
82 83
            <tr>
                {% if 'row' in row.errors %}
Pierre Dittgen's avatar
Pierre Dittgen committed
84 85 86
                <th class="table-danger" data-toggle="popover" title="{{ row.errors.row.title }}" data-content="{{ row.errors.row.content }}">
                    {{ row.row_id }}
                </th>
Pierre Dittgen's avatar
Pierre Dittgen committed
87 88
                {% if row.errors.row.code == 'blank-row' and not source_data.data_rows[row.row_id -2] %}
                {% for _ in report.table.headers %}
Pierre Dittgen's avatar
Pierre Dittgen committed
89
                <td class="table-danger" data-toggle="popover" title="{{ row.errors.row.title }}" data-content="{{ row.errors.row.content }}"></td>
Pierre Dittgen's avatar
Pierre Dittgen committed
90 91 92 93 94 95 96
                {% 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 %}
Pierre Dittgen's avatar
Pierre Dittgen committed
97
                <td class="table-danger" data-toggle="popover" title="{{row.errors[loop.index].title}}" data-content="{{ row.errors[loop.index].content }}">
Pierre Dittgen's avatar
Pierre Dittgen committed
98
                    {% elif 'row' in row.errors %}
Pierre Dittgen's avatar
Pierre Dittgen committed
99
                <td class="table-danger" data-toggle="popover" title="{{ row.errors.row.title }}" data-content="{{ row.errors.row.content }}">
Pierre Dittgen's avatar
Pierre Dittgen committed
100 101 102 103 104 105 106 107 108 109 110
                    {% else %}
                <td>
                    {% endif %}
                    {{ d }}
                </td>
                {% endfor %}
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
Pierre Dittgen's avatar
Pierre Dittgen committed
111 112 113 114 115
{% endmacro %}

{% macro error_statistics(report) %}

{% set structure_errors = report.table['error-stats']['structure-errors'] %}
116
{% if structure_errors['count'] != 0 %}
Christophe Benz's avatar
Christophe Benz committed
117
<p>Erreur de structure ({{ structure_errors['count'] }}) :</p>
Pierre Dittgen's avatar
Pierre Dittgen committed
118
<ul>
Christophe Benz's avatar
Christophe Benz committed
119 120
    {% for item in structure_errors['count-by-code'] %}
    <li>{{ item[0] }} ({{ item[1] }})</li>
Pierre Dittgen's avatar
Pierre Dittgen committed
121 122
    {% endfor %}
</ul>
Pierre Dittgen's avatar
Pierre Dittgen committed
123
{% else %}
Christophe Benz's avatar
Christophe Benz committed
124
<p>Aucune erreur de structure.</p>
Pierre Dittgen's avatar
Pierre Dittgen committed
125 126 127 128
{% endif %}

{% if report.table.do_display_body_errors %}
{% set value_errors = report.table['error-stats']['value-errors'] %}
Christophe Benz's avatar
Christophe Benz committed
129 130
{% if value_errors['count'] > 0 %}
<p>Erreur de contenu ({{ value_errors['count'] }} sur {{ value_errors['rows-count'] }} ligne{% if value_errors['rows-count'] > 1 %}s{% endif %}) :</p>
Pierre Dittgen's avatar
Pierre Dittgen committed
131
<ul>
Christophe Benz's avatar
Christophe Benz committed
132 133
    {% for item in value_errors['count-by-code'] %}
    <li>{{ item[0] }} ({{ item[1] }})</li>
Pierre Dittgen's avatar
Pierre Dittgen committed
134 135
    {% endfor %}
</ul>
136

Pierre Dittgen's avatar
Pierre Dittgen committed
137 138 139
{% endif %}
{% endif %}

Pierre Dittgen's avatar
Pierre Dittgen committed
140
{% endmacro %}