Implementeaza PRD 3.6 (US-001..007), pe canalul de import + stratul web;
worker / masina stari / idempotenta / mapare raman neatinse.
- US-003/004: tab-ul "Trimiteri" eliminat; Trimiterile devin sectiune
permanenta sub upload pe Acasa ("Trimiterile tale"); upload comprimat la
bara slim (hero pastrat la first-run); ?tab=coada si /_fragments/coada
servesc Acasa (fara fragment orfan); poll gated pe visibilityState.
- US-001: coloana noua import_rows.override_json (nullable, Fernet, Approach B)
+ _migrate defensiv; ruta v1 + alias web .../rand/{i}/editeaza aplica patch
canonic ULTIMUL in _resolve_row_for_preview si commit_import (mutatie pura,
status rederivat, fara drift). Scoping JOIN -> 404, guard committed -> 409,
semantica empty=clear, decrypt fail -> no-op.
- US-002: buton "Editeaza" pe rand; swap pe <tr> + OOB contoare (nu pe sectiune);
form propriu (confirm dezactivat la editare); refoloseste grila responsiva +
error-map din _trimitere_detaliu.html; mutual-exclusion intre randuri.
- US-005/006: "De rezolvat", "Operatii salvate" si "Formate de coloane" ca
tabele (.tablewrap); H4: comutatorul reflecta auto_send STOCAT.
- US-007: bifa "auto-send" devine comutator etichetat pe COADA ("Pune automat
in coada" / "Tine pentru verificare"), scoped pe operatie; name="auto_send"
pastrat (semantica de prezenta -> bool corect cu ambele parsere, zero backend).
Fix-uri gasite la verificarea E2E in browser (htmx 1.9.12, JS — invizibile la
TestClient): useTemplateFragments=true (raspuns <tr>+OOB era parsat in context
de tabel -> swapError + contoare pierdute); re-activarea confirm-btn dupa salvare
deferita pe tick (evita editing=true tranzitoriu); n-hint actualizat de updateN.
Teste: 523 passed. E2E browser: Acasa unificata, upload slim, editare rand
(needs_data -> ok, swap pe rand, contoare OOB), Mapari tabelar + comutator.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
169 lines
8.8 KiB
HTML
169 lines
8.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 = {} -%}
|
|
{%- 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'))}) -%}{%- 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:#241a1a; 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:#241a1a; 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 %}
|
|
</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 %}
|
|
<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 }}</td>
|
|
<td>{{ res.get('nr_inmatriculare') or '' }}</td>
|
|
<td>{{ res.get('data_prestatie') or '' }}</td>
|
|
<td>{{ res.get('odometru_final') or '' }}</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 %}
|