This commit is contained in:
aespin 2024-10-23 10:06:35 +02:00
parent 55f9db7b01
commit 5ace78762e
7 changed files with 82 additions and 28 deletions

6
assets/js/index.js Normal file
View File

@ -0,0 +1,6 @@
$(document).ready(function () {
setTimeout(function() {
console.log("refresh");
location.reload();
}, 2000);
});

View File

@ -13,10 +13,11 @@ import (
func IndexHandler(storage storage.Storager) httprouter.Handle {
type PageView struct {
Stats *types.Stats
BundlesATA12 []types.BundleData
BundlesATA345 []types.BundleData
Barcodes []types.Barcode
Stats *types.Stats
BundlesATA12 []types.BundleData
BundlesATA345 []types.BundleData
BarcodesATA12 []types.Barcode
BarcodesATA345 []types.Barcode
}
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
// get current shift dates
@ -25,23 +26,37 @@ func IndexHandler(storage storage.Storager) httprouter.Handle {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//
// get ata12 shift bundles
bundles12, err := storage.ShiftListBundle(r.Context(), dates[0], dates[1], types.ATA12)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// get ata345 shift bundles
bundles345, err := storage.ShiftListBundle(r.Context(), dates[0], dates[1], types.ATA345)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// get ata12 shift barcodes
barcodesATA12, err := storage.ShiftListBarcode(r.Context(), dates[0], dates[1], types.ATA12)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// get ata345 shift barcodes
barcodesATA345, err := storage.ShiftListBarcode(r.Context(), dates[0], dates[1], types.ATA345)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// create view
view := &PageView{
Stats: &types.Stats{},
BundlesATA12: bundles12,
BundlesATA345: bundles345,
Barcodes: []types.Barcode{},
Stats: &types.Stats{},
BundlesATA12: bundles12,
BundlesATA345: bundles345,
BarcodesATA12: barcodesATA12,
BarcodesATA345: barcodesATA345,
}
t, _ := template.ParseFiles("templates/base.html", "templates/index.html")

File diff suppressed because one or more lines are too long

View File

@ -26,6 +26,7 @@ type DBConfig struct {
type Storager interface {
Barcode(ctx context.Context, reading string) (barcode *types.Barcode, err error)
ListBarcode(ctx context.Context, lb types.LoadingBed, inicio, final time.Time) (barcodes []types.Barcode, err error)
ShiftListBarcode(ctx context.Context, inicio, final time.Time, lb types.LoadingBed) (bundles []types.Barcode, err error)
Bundle(ctx context.Context, ua string) (bundle *types.BundleData, err error)
ListBundle(ctx context.Context, lb types.LoadingBed, inicio, final time.Time, confirmed bool) (bundles []types.BundleData, err error)
ShiftListBundle(ctx context.Context, inicio, final time.Time, lb types.LoadingBed) (bundles []types.BundleData, err error)
@ -36,6 +37,14 @@ type storage struct {
mux sync.RWMutex
}
// ShiftListBarcode implements Storager.
func (s *storage) ShiftListBarcode(ctx context.Context, inicio time.Time, final time.Time, lb types.LoadingBed) (barcodes []types.Barcode, err error) {
if err := s.db.Where("substr(barcode,1,3)=? and created_at >= ? and created_at < ?", types.MapQueryBed[lb], inicio, final).Order("created_at desc").Limit(limit).Find(&barcodes).WithContext(ctx).Error; err != nil {
return nil, err
}
return
}
// ShiftListBundle implements Storager.
func (s *storage) ShiftListBundle(ctx context.Context, inicio, final time.Time, lb types.LoadingBed) (bundles []types.BundleData, err error) {
if err := s.db.Where("substr(nromatricula,1,3)=? and created_at >= ? and created_at < ?", types.MapQueryBed[lb], inicio, final).Order("created_at desc").Limit(limit).Find(&bundles).WithContext(ctx).Error; err != nil {

View File

@ -49,17 +49,20 @@
</tr>
</tfoot>
<tbody>
{{if .BarcodesATA12}}
{{ range .BarcodesATA12}}
<tr>
<td>9401234567</td>
<td>1</td>
<td>05/10/2024 08:19</td>
<td>{{ .Barcode}}</td>
<td>{{ .LoadingBed}}</td>
<td>{{ .FormatCreatedAt}}</td>
</tr>
{{ end }}
{{ end }}
</tbody>
</table>
</div>
</nav>
</div>
{{ if .BundlesATA12 }}
<div class="column is-10">
<nav class="panel is-link">
<p class="panel-heading"><i class="fas fa-box"></i> Paquetes ATA12</p>
@ -98,7 +101,8 @@
</tr>
</tfoot>
<tbody>
{{ range .BundlesATA12 }}
{{ if .BundlesATA12 }}
{{ range .BundlesATA12 }}
<tr>
<td><a href="">{{ .Nromatricula }}</a></td>
<td><a href="">{{ .Po }}</a></td>
@ -125,6 +129,7 @@
{{ end }}
<td>{{ .FormatCreatedAt }}</td>
</tr>
{{ end }}
{{ end }}
</tbody>
</table>
@ -151,18 +156,21 @@
</tr>
</tfoot>
<tbody>
<tr>
<td>9401234567</td>
<td>1</td>
<td>05/10/2024 08:19</td>
</tr>
{{if .BarcodesATA345}}
{{ range .BarcodesATA345}}
<tr>
<td>{{ .Barcode}}</td>
<td>{{ .LoadingBed}}</td>
<td>{{ .FormatCreatedAt}}</td>
</tr>
{{ end }}
{{ end }}
</tbody>
</table>
</div>
</nav>
</div>
{{ end }}
{{ if .BundlesATA345 }}
<div class="column is-10">
<nav class="panel is-link">
<p class="panel-heading"><i class="fas fa-box"></i> Paquetes ATA345</p>
@ -201,7 +209,8 @@
</tr>
</tfoot>
<tbody>
{{ range .BundlesATA345 }}
{{ if .BundlesATA345 }}
{{ range .BundlesATA345 }}
<tr>
<td><a href="">{{ .Nromatricula }}</a></td>
<td><a href="">{{ .Po }}</a></td>
@ -228,13 +237,14 @@
{{ end }}
<td>{{ .FormatCreatedAt }}</td>
</tr>
{{ end }}
{{ end }}
</tbody>
</table>
</div>
</nav>
</div>
{{ end }}
</div>
</div>
<script src="/assets/js/index.js"></script>
{{ end }}

View File

@ -9,12 +9,16 @@
<div class="column is-three-fifths">
<nav class="panel is-link">
<p class="panel-heading"><i class="fas fa-barcode" aria-hidden="true"></i> Evacuaciones 12</p>
<div class="panel-block">
<div class="panel-block image is-3by2">
<img src="{{ .Label12 }}" />
</div>
</nav>
<nav class="panel is-link">
<p class="panel-heading"><i class="fas fa-barcode" aria-hidden="true"></i> Evacuaciones 345</p>
<div class="panel-block">
<figure class="image is-5by4">
<!-- <img src="{{ .Label345 }}" /> -->
</figure>
</div>
</nav>
</div>

View File

@ -46,9 +46,9 @@ func (b *Barcode) FormatLoadingBed() string {
}
func (b *Barcode) FormatCreatedAt() string {
return b.CreatedAt.Format("02/01/2006 15:04:03")
return b.CreatedAt.Format("02/01/2006 15:04:05")
}
func (b *Barcode) FormatUpdateAt() string {
return b.UpdatedAt.Format("02/01/2006 15:04:03")
return b.UpdatedAt.Format("02/01/2006 15:04:05")
}