wip
This commit is contained in:
parent
eb99161ada
commit
06f9de21d1
@ -22,6 +22,7 @@ func Run() error {
|
||||
dbHost := flag.String("db-host", "db", "database host address")
|
||||
dbPort := flag.Int("db-port", 5432, "database tcp port")
|
||||
dbName := flag.String("db-name", "falcon", "database user password")
|
||||
flag.Parse()
|
||||
// setup logger
|
||||
log := logger.New(os.Stdout, *logLevel)
|
||||
// log fields
|
||||
|
@ -27,7 +27,7 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
|
||||
// post method
|
||||
if r.Method == http.MethodPost {
|
||||
// barcodes holder
|
||||
barcodes := []types.Barcode{}
|
||||
Barcodes := []types.Barcode{}
|
||||
// parse form data from formulary
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -47,7 +47,7 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
|
||||
return
|
||||
}
|
||||
// append barcode to holder
|
||||
barcodes = append(barcodes, *data)
|
||||
Barcodes = append(Barcodes, *data)
|
||||
} else {
|
||||
inicio := strings.Split(fechas, "-")[0]
|
||||
inicio = strings.TrimSpace(inicio)
|
||||
@ -67,12 +67,12 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
|
||||
return
|
||||
}
|
||||
//set barcodes
|
||||
barcodes = data
|
||||
Barcodes = data
|
||||
}
|
||||
// parse template files
|
||||
t, _ := template.ParseFiles("templates/base.html", "templates/barcodes.html")
|
||||
// execute templates
|
||||
err := t.Execute(w, barcodes)
|
||||
err := t.Execute(w, Barcodes)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -71,21 +71,23 @@ func (s *storage) ListBarcode(ctx context.Context, lb types.LoadingBed, inicio s
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if lb == types.ALL {
|
||||
if err := s.db.Where("created_at >= ? and created_at < ?", ti, tf).Find(barcodes).WithContext(ctx).Error; err != nil {
|
||||
if err := s.db.Where("created_at >= ? and created_at < ?", ti, tf).Find(&barcodes).WithContext(ctx).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := s.db.Where("loading_bed = ? and created_at >= ? and created_at < ?", lb, ti, tf).Find(barcodes).WithContext(ctx).Error; err != nil {
|
||||
if err := s.db.Where("loading_bed = ? and created_at >= ? and created_at < ?", lb, ti, tf).Find(&barcodes).WithContext(ctx).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
fmt.Printf("result: +%v\n", barcodes)
|
||||
return
|
||||
}
|
||||
|
||||
// Barcode implements Storager.
|
||||
func (s *storage) Barcode(ctx context.Context, reading string) (barcode *types.Barcode, err error) {
|
||||
if err := s.db.First(barcode, reading).WithContext(ctx).Error; err != nil {
|
||||
if err := s.db.First(&barcode, reading).WithContext(ctx).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
|
@ -38,7 +38,7 @@
|
||||
</div>
|
||||
<div class="column">
|
||||
<nav class="panel is-link">
|
||||
<p class="panel-heading"><i class="far fa-file"></i> Listar códigos leídos</p>
|
||||
<p class="panel-heading"><i class="far fa-file"></i> Busqueda de códigos</p>
|
||||
<form action="/barcodes" method="post">
|
||||
<div class="panel-block">
|
||||
<div class="field">
|
||||
@ -91,6 +91,40 @@
|
||||
</form>
|
||||
</nav>
|
||||
</div>
|
||||
{{ if .}}
|
||||
<div class="column">
|
||||
<nav class="panel is-link">
|
||||
<p class="panel-heading"><i class="far fa-file"></i> Listado códigos leídos</p>
|
||||
<div class="panel-block">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><abbr title="Unidad de almacén">UA</abbr></th>
|
||||
<th>Origen</th>
|
||||
<th>Fecha</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th><abbr title="Unidad de almacén">UA</abbr></th>
|
||||
<th>Origen</th>
|
||||
<th>Fecha</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
{{ range . }}
|
||||
<tr>
|
||||
<td>{{ .Barcode }}</td>
|
||||
<td>{{ .LoadingBed }}</td>
|
||||
<td>{{ .CreatedAt }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/js/barcode.js">
|
||||
|
Loading…
Reference in New Issue
Block a user