From 99a4cc7b7a63dd9c7218dcff3573d6507641afae Mon Sep 17 00:00:00 2001 From: albert Date: Mon, 7 Oct 2024 19:54:53 +0200 Subject: [PATCH] wip --- TODO | 105 ++++++++++++++++++++++-------------------- handlers/bundle.go | 35 ++++++++++++-- routes/routes.go | 1 + templates/bundle.html | 55 +++++++++++++++++++++- 4 files changed, 141 insertions(+), 55 deletions(-) diff --git a/TODO b/TODO index 161eded..6b5822e 100644 --- a/TODO +++ b/TODO @@ -1,49 +1,56 @@ -Defining template: -{{ define “template_name” }} {{ end }} - -Using template: -{{ template “template_name” . }} - -Block: -{{ block “content” . }} {{ end }} - -Is equivalent to => {{ template “content” . }} {{ define “content” }} {{ end }} - -If: -{{ if var }} //… {{ else if var }} //… {{ else }} //… {{ end }} - -Assignment: -{{ $first_name := “arash” }} {{ $first_name = .Name }} - -With: -{{ with . Firstname }} // . refers to Firstname {{ end }} - -{{ with $ firstname := .Firstname }} // . and $firstname both refer to Firstname {{ end }} - -Range: -{{ range .Users }} {{ .Firstname }} {{ end }} - -{{ range $user := .Users }} {{ .Firstname }} {{ $user.Firstname }} {{ else }} No users found {{ end }} - -{{ range $index, $user := .Users }} {{ end }} - -Functions: -{{ if and cond1 cond2 … }} - -{{ if or cond1 cond2 … }} - -{{ if not cond }} - -{{ len var }} - -tmpl, _ := template.New(“template_name”).Parse(“...”) - -tmpl.Name() => name of current template - -tmpl.Execute(...) => execute current template - -tmpl.ExecuteTemplate(...) => execute template by name - -tmpl = tmpl.Lookup(“template_name”) => change current template - -tmpl.Templates() => Get defined templates \ No newline at end of file + Grupo6 string `json:"grupo6"` + Po int `json:"po" gorm:"index"` + Co int `json:"co"` + Colada string `json:"colada"` + Calidad string `json:"calidad"` + Matnr string `json:"matnr"` + Dibujo int `json:"dibujo"` + Operador string `json:"operador"` + Serie int `json:"serie"` + Nromatricula string `gorm:"primaryKey" json:"nromatricula"` + NroBulto string `json:"nro_bulto"` + EtiquetaDoble string `json:"etiqueta_doble"` + Fecha int `json:"fecha"` + Turno string `json:"turno"` + Observacion1 string `json:"observacion1"` + Observacion2 string `json:"observacion2"` + Observacion3 string `json:"observacion3"` + PaqueteLongitud float64 `json:"paquete_longitud"` + PaqueteAncho int `json:"paquete_ancho"` + PaqueteAlto float64 `json:"paquete_alto"` + PaquetePeso int `json:"paquete_peso"` + PaqueteNroSecciones int `json:"paquete_nro_secciones"` + PaqueteNroMantos int `json:"paquete_nro_mantos"` + PaqueteNroSeccManto int `json:"paquete_nro_secc_manto"` + SeccionTipo string `gorm:"index" json:"seccion_tipo"` + SeccionLongitud int `json:"seccion_longitud"` + SeccionAncho float64 `json:"seccion_ancho"` + SeccionAlto float64 `json:"seccion_alto"` + Idioma string `json:"idioma"` + Destino int `json:"destino"` + Hora int `json:"hora"` + Horario int `json:"horario"` + Inst string `json:"inst"` + Tren int `json:"tren"` + Normed string `json:"normed"` + Norpro string `json:"norpro"` + Nortol string `json:"nortol"` + Spras string `json:"spras"` + Statu int `json:"statu"` + Crlf string `json:"crlf"` + Maquina int `json:"maquina"` + Padre string `json:"padre"` + Paqpadre string `json:"paqpadre"` + RelevantTime string `json:"relevant_time"` + Desvio float64 `json:"desvio"` + Pesoteorico float64 `json:"pesoteorico"` + PesoteoricoReal float64 `json:"pesoteorico_real"` + DesvioTeoricoReal float64 `json:"desvio_teorico_real"` + FechaImpresion string `json:"fecha_impresion"` + PesoNivel1 float64 `json:"peso_nivel1"` + L3Sended bool `json:"l3_sended,omitempty"` + Confirmed bool `json:"confirmed,omitempty"` + SAP bool `json:"sap,omitempty"` + CreatedAt time.Time `gorm:"->;<-:create" json:"createdat,omitempty"` + UpdatedAt time.Time `json:"updatedat,omitempty"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedat,omitempty"` \ No newline at end of file diff --git a/handlers/bundle.go b/handlers/bundle.go index dd3f365..650af83 100644 --- a/handlers/bundle.go +++ b/handlers/bundle.go @@ -4,17 +4,42 @@ import ( "net/http" "text/template" + "git.espin.casa/albert/cml04-falcon-ui/helper" "git.espin.casa/albert/cml04-falcon-ui/storage" + "git.espin.casa/albert/cml04-falcon-ui/types" "github.com/julienschmidt/httprouter" ) func BundleHandler(storage storage.Storager) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - t, _ := template.ParseFiles("templates/base.html", "templates/bundle.html") - err := t.Execute(w, nil) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return + + if r.Method == http.MethodGet { + t, _ := template.ParseFiles("templates/base.html", "templates/bundle.html") + err := t.Execute(w, nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } } + + if r.Method == http.MethodPost { + // barcodes holder + Bundles := []types.BundleData{} + // parse form data from formulary + if err := r.ParseForm(); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + // barcode + codigo := r.FormValue("codigo") + // date range + fechas := r.FormValue("fechas") + // get range dates + inicio, final, err := helper.Dates(fechas) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + } } diff --git a/routes/routes.go b/routes/routes.go index 56e4c24..a30ca16 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -18,4 +18,5 @@ func CreateRoutes(r *httprouter.Router, storage storage.Storager) { r.GET("/labels", handlers.LabelsHandler()) r.GET("/standards", handlers.StandardsHandler(storage)) r.GET("/bundle", handlers.BundleHandler(storage)) + r.POST("/bundle", handlers.BundleHandler(storage)) } diff --git a/templates/bundle.html b/templates/bundle.html index 64b60a4..718a758 100644 --- a/templates/bundle.html +++ b/templates/bundle.html @@ -41,14 +41,67 @@ {{ if .}}