From 6e552e4de8db62e703fb8519dd65d9a8e944c6ea Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Mon, 24 Mar 2025 12:32:05 +0100 Subject: [PATCH] Add total RAM capacity calculation and update index view --- data.go | 6 ++++++ templates/index.gohtml | 10 ++++++---- views.go | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/data.go b/data.go index 1f8ba11..41578ab 100644 --- a/data.go +++ b/data.go @@ -53,3 +53,9 @@ func (a *App) GetBrandCount() (int, error) { err := a.db.Query("SELECT COUNT(DISTINCT brand) FROM assets").ScanSingle(&count) return count, err } + +func (a *App) GetTotalRamCapacity() (int, error) { + var capacity int + err := a.db.Query("SELECT SUM(capacity) FROM info_ram").ScanSingle(&capacity) + return capacity, err +} diff --git a/templates/index.gohtml b/templates/index.gohtml index 6aa2b34..c6782a3 100644 --- a/templates/index.gohtml +++ b/templates/index.gohtml @@ -1,10 +1,12 @@ -{{- /*gotype: main.IndexVM */}} +{{- /*gotype: main.IndexVM*/}} {{define "index"}} {{template "header"}} -

Some statistics

+

Statistics

+ The inventory contains:

Filter Devices

diff --git a/views.go b/views.go index a514f67..8c6a726 100644 --- a/views.go +++ b/views.go @@ -15,10 +15,11 @@ type App struct { } type IndexVM struct { - AssetCount int - BrandCount int - Brands []string - Types []string + AssetCount int + BrandCount int + TotalRamCapacity int + Brands []string + Types []string } func (a *App) getIndex(c *gin.Context) { @@ -36,6 +37,12 @@ func (a *App) getIndex(c *gin.Context) { return } + vm.TotalRamCapacity, err = a.GetTotalRamCapacity() + if err != nil { + c.AbortWithError(http.StatusInternalServerError, err) + return + } + vm.Brands, err = a.GetAllBrands() if err != nil { c.AbortWithError(http.StatusInternalServerError, err) @@ -236,6 +243,7 @@ func (a *App) getBrowse(c *gin.Context) { if len(types) > 0 { query += " AND assets.type IN (" + placeholders(len(types)) + ")" } + query += "ORDER BY assets.type, assets.brand, assets.name, assets.qr" vm := &BrowseVM{}