Add total RAM capacity calculation and update index view
This commit is contained in:
6
data.go
6
data.go
@@ -53,3 +53,9 @@ func (a *App) GetBrandCount() (int, error) {
|
|||||||
err := a.db.Query("SELECT COUNT(DISTINCT brand) FROM assets").ScanSingle(&count)
|
err := a.db.Query("SELECT COUNT(DISTINCT brand) FROM assets").ScanSingle(&count)
|
||||||
return count, err
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
{{- /*gotype: main.IndexVM */}}
|
{{- /*gotype: main.IndexVM*/}}
|
||||||
{{define "index"}}
|
{{define "index"}}
|
||||||
{{template "header"}}
|
{{template "header"}}
|
||||||
<h2>Some statistics</h2>
|
<h2>Statistics</h2>
|
||||||
|
The inventory contains:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Database contains {{.AssetCount}} assets.</li>
|
<li><b>{{.AssetCount}}</b> assets in total.</li>
|
||||||
<li>Database contains {{.BrandCount}} brands.</li>
|
<li><b>{{.BrandCount}}</b> unique brands.</li>
|
||||||
|
<li>a combined <b>{{.TotalRamCapacity | formatMemorySize}}</b> of RAM.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h2>Filter Devices</h2>
|
<h2>Filter Devices</h2>
|
||||||
|
|||||||
8
views.go
8
views.go
@@ -17,6 +17,7 @@ type App struct {
|
|||||||
type IndexVM struct {
|
type IndexVM struct {
|
||||||
AssetCount int
|
AssetCount int
|
||||||
BrandCount int
|
BrandCount int
|
||||||
|
TotalRamCapacity int
|
||||||
Brands []string
|
Brands []string
|
||||||
Types []string
|
Types []string
|
||||||
}
|
}
|
||||||
@@ -36,6 +37,12 @@ func (a *App) getIndex(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vm.TotalRamCapacity, err = a.GetTotalRamCapacity()
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
vm.Brands, err = a.GetAllBrands()
|
vm.Brands, err = a.GetAllBrands()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, err)
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
@@ -236,6 +243,7 @@ func (a *App) getBrowse(c *gin.Context) {
|
|||||||
if len(types) > 0 {
|
if len(types) > 0 {
|
||||||
query += " AND assets.type IN (" + placeholders(len(types)) + ")"
|
query += " AND assets.type IN (" + placeholders(len(types)) + ")"
|
||||||
}
|
}
|
||||||
|
query += "ORDER BY assets.type, assets.brand, assets.name, assets.qr"
|
||||||
|
|
||||||
vm := &BrowseVM{}
|
vm := &BrowseVM{}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user