From bdce399592f95d8f71cd380eb9a7466f60d99170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Markovi=C4=87?= Date: Tue, 23 Jun 2026 01:08:14 +0200 Subject: [PATCH] =?UTF-8?q?Servis:=20auto-snimanje=20forme=20izmene=20+=20?= =?UTF-8?q?hx-boost=20navigacija=20(bez=20bljeska)=20-=20Forma=20Izmeni=20?= =?UTF-8?q?nalog=20snima=20se=20automatski=20(change=20na=20celoj=20formi,?= =?UTF-8?q?=20X-Autosave=E2=86=92204),=20bez=20dugmeta=20Sa=C4=8Duvaj=20-?= =?UTF-8?q?=20Ispravka:=20trazene=5Fnadogradnje=20je=20NOT=20NULL=20?= =?UTF-8?q?=E2=80=94=20slati=20prazan=20string=20umesto=20NULL=20-=20Iz=20?= =?UTF-8?q?kartice=20detalja=20uklonjeni=20dropdown=20statusa=20i=20datum?= =?UTF-8?q?=20zavr=C5=A1etka=20-=20Forma=20izmene=20vi=C5=A1e=20ne=20ubacu?= =?UTF-8?q?je=20te=C5=BEak=20JSON=20svih=20klijenata=20(nepotreban=20u=20i?= =?UTF-8?q?zmeni)=20-=20Navigacioni=20linkovi=20(Kategorije,=20Izmeni,=20N?= =?UTF-8?q?azad)=20dobili=20hx-boost=20=E2=80=94=20swap=20#glavni-sadrzaj?= =?UTF-8?q?=20bez=20punog=20reloda,=20pozadina=20ne=20trep=C4=87e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/sqlite/servis.go | 4 +- internal/handler/servis.go | 20 ++++++ web/templates/stranice/kategorije.html | 2 +- web/templates/stranice/magacin.html | 2 +- web/templates/stranice/servis_detalji.html | 26 +------ web/templates/stranice/servis_forma.html | 79 +++++++++++++++++++--- 6 files changed, 96 insertions(+), 37 deletions(-) diff --git a/internal/db/sqlite/servis.go b/internal/db/sqlite/servis.go index 6254fee..7c265b8 100644 --- a/internal/db/sqlite/servis.go +++ b/internal/db/sqlite/servis.go @@ -131,7 +131,7 @@ func (r *ServisRepo) Kreiraj(ctx context.Context, n *model.ServisniNalog) (int64 ostecenja, pin_uredjaja, pribor, datum_prijema, javni_token) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, nullInt64(n.KlijentID), nullInt64(n.TehnicarID), n.BrojNaloga, n.Uredjaj, - nullString(n.SerijskiBroj), n.OpisKvara, nullString(n.TrazeneNadogradnje), n.Status, + nullString(n.SerijskiBroj), n.OpisKvara, n.TrazeneNadogradnje, n.Status, nullFloat64(n.CenaOd), nullFloat64(n.CenaDo), nullFloat64(n.CenaKonacna), nullFloat64(n.Avans), nullString(n.Napomena), nullTime(n.GarancijaDo), nullTime(n.DatumZavrsetka), @@ -176,7 +176,7 @@ func (r *ServisRepo) Izmeni(ctx context.Context, n *model.ServisniNalog) error { avans = ?, napomena = ?, garancija_do = ?, datum_zavrsetka = ?, ostecenja = ?, pin_uredjaja = ?, pribor = ? WHERE id = ?`, - nullInt64(n.KlijentID), nullInt64(n.TehnicarID), n.Uredjaj, nullString(n.SerijskiBroj), n.OpisKvara, nullString(n.TrazeneNadogradnje), + nullInt64(n.KlijentID), nullInt64(n.TehnicarID), n.Uredjaj, nullString(n.SerijskiBroj), n.OpisKvara, n.TrazeneNadogradnje, n.Status, nullFloat64(n.CenaOd), nullFloat64(n.CenaDo), nullFloat64(n.CenaKonacna), nullFloat64(n.Avans), nullString(n.Napomena), nullTime(n.GarancijaDo), nullTime(n.DatumZavrsetka), nullString(n.Ostecenja), nullString(n.PinUredjaja), nullString(n.Pribor), diff --git a/internal/handler/servis.go b/internal/handler/servis.go index f1bc06b..a21acbb 100644 --- a/internal/handler/servis.go +++ b/internal/handler/servis.go @@ -304,8 +304,16 @@ func (h *Handler) SacuvajIzmenaNaloga(w http.ResponseWriter, r *http.Request) { return } + // auto-snimanje (forma se snima u realnom vremenu): umesto redirecta vraćamo 204, + // a greške kao kratak tekst sa statusom — JS na stranici to prikaže korisniku + autosave := r.Header.Get("X-Autosave") == "1" + nalog, greska := parseFormuNaloga(r) if greska != "" { + if autosave { + http.Error(w, greska, http.StatusBadRequest) + return + } podesavanja, _ := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB) klijenti, _ := h.KlijentiRepo.Lista(r.Context(), "") tehnicari, _ := h.KorisniciRepo.Lista(r.Context()) @@ -342,6 +350,10 @@ func (h *Handler) SacuvajIzmenaNaloga(w http.ResponseWriter, r *http.Request) { // ako nije izabran postojeći klijent, eventualno kreiraj novog iz polja forme if greska := h.mozdaKreirajKlijenta(r.Context(), r, &nalog); greska != "" { + if autosave { + http.Error(w, greska, http.StatusBadRequest) + return + } podesavanja, _ := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB) klijenti, _ := h.KlijentiRepo.Lista(r.Context(), "") tehnicari, _ := h.KorisniciRepo.Lista(r.Context()) @@ -362,6 +374,10 @@ func (h *Handler) SacuvajIzmenaNaloga(w http.ResponseWriter, r *http.Request) { if err := h.ServisRepo.Izmeni(r.Context(), &nalog); err != nil { slog.Error("greška pri čuvanju izmene naloga", "error", err) + if autosave { + http.Error(w, "Došlo je do greške pri čuvanju.", http.StatusInternalServerError) + return + } podesavanja, _ := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB) klijenti, _ := h.KlijentiRepo.Lista(r.Context(), "") tehnicari, _ := h.KorisniciRepo.Lista(r.Context()) @@ -380,6 +396,10 @@ func (h *Handler) SacuvajIzmenaNaloga(w http.ResponseWriter, r *http.Request) { return } + if autosave { + w.WriteHeader(http.StatusNoContent) + return + } http.Redirect(w, r, "/servis/"+strconv.FormatInt(id, 10)+"?sacuvano=1", http.StatusSeeOther) } diff --git a/web/templates/stranice/kategorije.html b/web/templates/stranice/kategorije.html index 437d2c6..3da31dc 100644 --- a/web/templates/stranice/kategorije.html +++ b/web/templates/stranice/kategorije.html @@ -27,7 +27,7 @@ {{end}} - + Nazad na magacin diff --git a/web/templates/stranice/magacin.html b/web/templates/stranice/magacin.html index 8312ab0..70e2bd4 100644 --- a/web/templates/stranice/magacin.html +++ b/web/templates/stranice/magacin.html @@ -30,7 +30,7 @@ + {{if eq .Tip "usluga"}}Nova usluga{{else if eq .Tip "trosak"}}Novi trošak{{else}}Novi artikal{{end}} {{end}} {{if and (eq .Tip "proizvod") (index .Dozvole "kategorija.pregled")}} - Kategorije + Kategorije {{end}} diff --git a/web/templates/stranice/servis_detalji.html b/web/templates/stranice/servis_detalji.html index 4374222..9a91d96 100644 --- a/web/templates/stranice/servis_detalji.html +++ b/web/templates/stranice/servis_detalji.html @@ -30,7 +30,7 @@ {{end}} - + Nazad na servis @@ -44,22 +44,6 @@
{{template "status-badge-detalji" .Nalog.Status}} -
- - - {{if .ZakljucanStatus}} - 🔒 Status zaključan — obrišite delove koji nedostaju - {{else}} - - {{end}} -
@@ -76,7 +60,7 @@ Otpremnica {{end}} - + Izmeni nalog
@@ -92,12 +76,6 @@
{{.Nalog.PredvidjenDatum.Format "02.01.2006."}}
{{end}} - {{if .Nalog.DatumZavrsetka}} -
-
Datum završetka
-
{{.Nalog.DatumZavrsetka.Format "02.01.2006."}}
-
- {{end}}
Garancija do
diff --git a/web/templates/stranice/servis_forma.html b/web/templates/stranice/servis_forma.html index 143687b..3577cbc 100644 --- a/web/templates/stranice/servis_forma.html +++ b/web/templates/stranice/servis_forma.html @@ -5,14 +5,18 @@ {{define "sadrzaj"}}
- + {{if not .Izmena}} + + {{end}} - + {{if .Izmena}}Nazad na nalog{{else}}Nazad na servis{{end}} @@ -21,7 +25,7 @@
{{.Greska}}
{{end}} -
+ @@ -304,18 +308,75 @@ style="width:100%;resize:vertical;">{{.Nalog.Napomena}}
- -
- Odustani - + {{if .Izmena}} + +
+
+ {{else}} + +
+ Odustani + +
+ {{end}}
+ +