Catalog central pur app/errors.py ca sursa unica cod->{problema,fix},
consumat de API+UI+worker. Aditiv (field/message pastrate la octet) +
rar_error stocat superset. Scope: fluxul de declarare; login/signup/CSRF
neatinse. labels.parse_erori degradeaza gratios; UI progresiv AA light+dark.
631 teste.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
183 lines
9.8 KiB
HTML
183 lines
9.8 KiB
HTML
{#
|
|
_preview_rand.html — un singur rand de preview import (US-002, 3.6).
|
|
Doua moduri:
|
|
- display (editing falsy): <tr> normal + buton "Editeaza" pe coloana de actiuni.
|
|
- edit (editing truthy): <tr> cu un singur <td colspan> ce contine un FORM PROPRIU
|
|
(NU #confirm-form) cu grila responsiva refolosita din _trimitere_detaliu.html.
|
|
Swap pe RAND (hx-target pe #preview-row-N, outerHTML), NU pe #import-section (D-3.1).
|
|
La save, optional OOB pe rezumat + contor "gata de trimis" (include_oob).
|
|
#}
|
|
{%- set res = row.resolved -%}
|
|
{%- set status = row.resolved_status -%}
|
|
{%- set prestatii = res.get('prestatii') or [] -%}
|
|
{%- set op = (prestatii[0].get('cod_prestatie') or prestatii[0].get('cod_op_service', '')) if prestatii else '' -%}
|
|
{% if editing %}
|
|
{%- set err_map = {} -%}
|
|
{%- set fix_map = {} -%}
|
|
{%- for e in row.errors -%}{%- if e is mapping and e.get('field') -%}{%- set _ = err_map.update({e.field: (e.get('message') or e.get('msg'))}) -%}{%- if e.get('fix') -%}{%- set _ = fix_map.update({e.field: e.get('fix')}) -%}{%- endif -%}{%- endif -%}{%- endfor -%}
|
|
<tr id="preview-row-{{ row.row_index }}" data-status="{{ status }}" data-editing="1">
|
|
<td colspan="10" style="background:rgba(91,141,239,.06);">
|
|
<form class="rand-editare"
|
|
hx-post="/_import/{{ import_id }}/rand/{{ row.row_index }}/editeaza"
|
|
hx-target="#preview-row-{{ row.row_index }}"
|
|
hx-swap="outerHTML"
|
|
hx-indicator="#rand-spinner-{{ row.row_index }}"
|
|
hx-disabled-elt="find button"
|
|
hx-on::response-error="this.querySelector('.rand-eroare-banner').style.display='block';">
|
|
<input type="hidden" name="csrf_token" value="{{ csrf_token or '' }}">
|
|
|
|
<div style="display:flex; align-items:center; gap:8px; margin-bottom:8px;">
|
|
<strong style="font-size:13px;">Editare rand {{ row.row_index + 1 }}</strong>
|
|
<span class="pill s-{{ status }}" style="font-size:11px;">{{ status }}</span>
|
|
</div>
|
|
|
|
{% if message %}
|
|
<div class="flash" style="border-color:var(--err); background:color-mix(in srgb, var(--err) 12%, var(--card)); margin-bottom:10px;"
|
|
role="alert">{{ message }}</div>
|
|
{% endif %}
|
|
<div class="rand-eroare-banner" role="alert"
|
|
style="display:none; margin-bottom:10px; padding:8px 12px; border:1px solid var(--err);
|
|
background:color-mix(in srgb, var(--err) 12%, var(--card)); border-radius:6px; font-size:13px;">
|
|
Salvarea nu a reusit (retea / sesiune). Valorile introduse sunt pastrate — reincearca.
|
|
</div>
|
|
|
|
{% macro camp(nume, eticheta, valoare, tip='text') %}
|
|
<div>
|
|
<label for="e-{{ row.row_index }}-{{ nume }}" class="muted" style="font-size:12px; display:block;">{{ eticheta }}</label>
|
|
<input id="e-{{ row.row_index }}-{{ nume }}" type="{{ tip }}" name="{{ nume }}" value="{{ valoare or '' }}"
|
|
style="width:100%; {% if err_map.get(nume) %}border-color:var(--err);{% endif %}"
|
|
aria-label="{{ eticheta }} — randul {{ row.row_index + 1 }} (VIN: {{ res.get('vin') or '' }})"
|
|
{% if err_map.get(nume) %}aria-invalid="true"{% endif %}>
|
|
{% if err_map.get(nume) %}
|
|
<div class="s-error" style="font-size:12px; margin-top:2px;">{{ err_map.get(nume) }}</div>
|
|
{% endif %}
|
|
{% if fix_map.get(nume) %}
|
|
<span class="camp-fix">{{ fix_map.get(nume) }}</span>
|
|
{% endif %}
|
|
</div>
|
|
{% endmacro %}
|
|
|
|
<div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:10px 16px;">
|
|
{{ camp('nr_inmatriculare', 'Numar inmatriculare', res.get('nr_inmatriculare')) }}
|
|
{{ camp('vin', 'VIN (serie sasiu)', res.get('vin')) }}
|
|
{{ camp('data_prestatie', 'Data prestatie (YYYY-MM-DD)', res.get('data_prestatie')) }}
|
|
{{ camp('odometru_final', 'Odometru final', res.get('odometru_final')) }}
|
|
{{ camp('odometru_initial', 'Odometru initial (daca e cerut)', res.get('odometru_initial')) }}
|
|
</div>
|
|
|
|
<div style="margin-top:10px; display:flex; gap:8px; align-items:center; flex-wrap:wrap;">
|
|
<button type="submit" style="min-height:44px; padding:8px 18px;">Salveaza</button>
|
|
<button type="button" style="min-height:44px; padding:8px 18px;
|
|
background:var(--card); color:var(--muted); border-color:var(--line);"
|
|
hx-get="/_import/{{ import_id }}/rand/{{ row.row_index }}"
|
|
hx-target="#preview-row-{{ row.row_index }}" hx-swap="outerHTML">Anuleaza</button>
|
|
<span id="rand-spinner-{{ row.row_index }}" class="htmx-indicator muted" style="font-size:13px;">
|
|
se salveaza…
|
|
</span>
|
|
</div>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<script>
|
|
(function() {
|
|
/* Mutual-exclusion (D-3.2/3.6): cat un rand e in editare, dezactiveaza confirm + alte Editeaza. */
|
|
var btn = document.getElementById('confirm-btn');
|
|
if (btn) { btn.disabled = true; btn.title = 'Termina editarea randului inainte de a trimite.'; }
|
|
document.querySelectorAll('.btn-editeaza').forEach(function(b) { b.disabled = true; });
|
|
})();
|
|
</script>
|
|
{% else %}
|
|
{%- set disp_fix_map = {} -%}
|
|
{%- for e in row.errors -%}{%- if e is mapping and e.get('field') and e.get('fix') -%}{%- set _ = disp_fix_map.update({e.field: e.get('fix')}) -%}{%- endif -%}{%- endfor -%}
|
|
<tr id="preview-row-{{ row.row_index }}" data-status="{{ status }}"
|
|
style="{% if status == 'needs_review' %}background:rgba(230,179,74,.04);{% elif status in ('already_sent', 'duplicate_in_file') %}opacity:.65;{% endif %}">
|
|
<td class="muted">{{ row.row_index + 1 }}</td>
|
|
<td>{{ res.get('vin') or '<span class="muted">—</span>' | safe }}
|
|
{% if disp_fix_map.get('vin') %}<span class="camp-fix">{{ disp_fix_map.get('vin') }}</span>{% endif %}
|
|
</td>
|
|
<td>{{ res.get('nr_inmatriculare') or '' }}
|
|
{% if disp_fix_map.get('nr_inmatriculare') %}<span class="camp-fix">{{ disp_fix_map.get('nr_inmatriculare') }}</span>{% endif %}
|
|
</td>
|
|
<td>{{ res.get('data_prestatie') or '' }}
|
|
{% if disp_fix_map.get('data_prestatie') %}<span class="camp-fix">{{ disp_fix_map.get('data_prestatie') }}</span>{% endif %}
|
|
</td>
|
|
<td>{{ res.get('odometru_final') or '' }}
|
|
{% if disp_fix_map.get('odometru_final') %}<span class="camp-fix">{{ disp_fix_map.get('odometru_final') }}</span>{% endif %}
|
|
</td>
|
|
<td>{{ op or '<span class="muted">—</span>' | safe }}</td>
|
|
<td><span class="pill s-{{ status }}">{{ status }}</span></td>
|
|
<td class="muted" style="font-size:12px; white-space:normal; max-width:220px;">
|
|
{% if status == 'already_sent' and row.get('already_sent_info') %}
|
|
{% set ai = row.already_sent_info %}
|
|
deja trimis {{ (ai.get('created_at') or '')[:10] }}
|
|
{% if ai.get('id_prezentare') %}(#{{ ai.id_prezentare }}){% endif %}
|
|
{% elif status == 'duplicate_in_file' and row.get('duplicate_with') %}
|
|
dubla cu randul
|
|
{% for idx in row.duplicate_with %}{{ idx + 1 }}{% if not loop.last %}, {% endif %}{% endfor %}
|
|
{% elif row.flags %}
|
|
{{ row.flags[0] }}
|
|
{% elif row.errors %}
|
|
{%- for e in row.errors -%}
|
|
{%- if e is mapping -%}
|
|
{{ e.get('message') or e.get('msg') or (e.values() | list | first) }}
|
|
{%- else -%}
|
|
{{ e }}
|
|
{%- endif -%}
|
|
{%- if not loop.last %}; {% endif -%}
|
|
{%- endfor -%}
|
|
{% endif %}
|
|
</td>
|
|
<td style="text-align:center;">
|
|
{% if status == 'needs_review' %}
|
|
<label class="chk" style="min-height:44px; justify-content:center; cursor:pointer;"
|
|
title="Bifat inseamna ca ai verificat valorile si le incluzi in trimitere">
|
|
<input type="checkbox" form="confirm-form" name="reviewed_rows" value="{{ row.row_index }}"
|
|
onchange="window.updateN && window.updateN()"
|
|
aria-label="Verificat — randul {{ row.row_index + 1 }} (VIN: {{ res.get('vin', '') }})">
|
|
verif.
|
|
</label>
|
|
{% endif %}
|
|
</td>
|
|
<td style="text-align:center;">
|
|
{% if status not in ('already_sent', 'duplicate_in_file') %}
|
|
<button type="button" class="btn-editeaza"
|
|
style="min-height:44px; padding:6px 14px; font-size:13px;
|
|
background:transparent; border-color:var(--line); color:var(--ink);"
|
|
hx-get="/_import/{{ import_id }}/rand/{{ row.row_index }}/editare"
|
|
hx-target="#preview-row-{{ row.row_index }}" hx-swap="outerHTML"
|
|
aria-label="Editeaza randul {{ row.row_index + 1 }} (VIN: {{ res.get('vin', '') }})">
|
|
Editeaza
|
|
</button>
|
|
{% endif %}
|
|
</td>
|
|
</tr>
|
|
{% if include_oob %}
|
|
{# OOB: actualizeaza rezumatul si contorul "gata de trimis" dupa save, fara a re-randa sectiunea (D-3.1). #}
|
|
{% set status_labels = [
|
|
('ok','gata de trimis'), ('needs_review','verifica valori'), ('needs_mapping','fara cod RAR'),
|
|
('needs_data','date lipsa'), ('already_sent','deja trimis'), ('duplicate_in_file','dublicat in fisier')] %}
|
|
<div id="preview-rezumat" hx-swap-oob="true"
|
|
style="display:flex; gap:8px; flex-wrap:wrap; margin-bottom:12px;">
|
|
{% for status_key, label in status_labels %}
|
|
{%- set cnt = summary.get(status_key, 0) -%}
|
|
{% if cnt > 0 %}<span class="pill s-{{ status_key }}">{{ cnt }} {{ label }}</span>{% endif %}
|
|
{% endfor %}
|
|
</div>
|
|
<span id="preview-ok-count" hx-swap-oob="true" data-ok="{{ summary.get('ok', 0) }}" hidden></span>
|
|
<script>
|
|
(function() {
|
|
/* Editare incheiata: re-activeaza confirm + butoanele Editeaza, recalculeaza N.
|
|
Defer pe tick-ul urmator: la momentul rularii scriptului, swap-ul randului poate
|
|
sa nu se fi asezat inca, deci tr[data-editing] ar fi inca prezent si updateN ar
|
|
lasa confirm dezactivat (editing=true). Dupa setTimeout(0) randul e in mod display. */
|
|
setTimeout(function() {
|
|
document.querySelectorAll('.btn-editeaza').forEach(function(b) { b.disabled = false; });
|
|
var btn = document.getElementById('confirm-btn');
|
|
if (btn) btn.title = '';
|
|
if (window.updateN) window.updateN();
|
|
}, 0);
|
|
})();
|
|
</script>
|
|
{% endif %}
|
|
{% endif %}
|