add categorization to account resources
This commit is contained in:
@@ -18,7 +18,7 @@ type Account struct {
|
|||||||
Min int
|
Min int
|
||||||
Max int
|
Max int
|
||||||
}
|
}
|
||||||
Resources map[string]any
|
Resources map[string]map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
type Constraint struct {
|
type Constraint struct {
|
||||||
@@ -46,6 +46,7 @@ type NumericResource struct {
|
|||||||
Global Constraint
|
Global Constraint
|
||||||
Nodes map[string]Constraint
|
Nodes map[string]Constraint
|
||||||
Total Constraint
|
Total Constraint
|
||||||
|
Category string
|
||||||
}
|
}
|
||||||
|
|
||||||
type StorageResource struct {
|
type StorageResource struct {
|
||||||
@@ -60,6 +61,7 @@ type StorageResource struct {
|
|||||||
Global Constraint
|
Global Constraint
|
||||||
Nodes map[string]Constraint
|
Nodes map[string]Constraint
|
||||||
Total Constraint
|
Total Constraint
|
||||||
|
Category string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListResource struct {
|
type ListResource struct {
|
||||||
@@ -69,6 +71,7 @@ type ListResource struct {
|
|||||||
Global []Match
|
Global []Match
|
||||||
Nodes map[string][]Match
|
Nodes map[string][]Match
|
||||||
Total []Match
|
Total []Match
|
||||||
|
Category string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceChart struct {
|
type ResourceChart struct {
|
||||||
@@ -104,58 +107,60 @@ func HandleGETAccount(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range account.Resources {
|
for category, resources := range account.Resources {
|
||||||
switch t := v.(type) {
|
for resource, v := range resources {
|
||||||
case NumericResource:
|
switch t := v.(type) {
|
||||||
avail, prefix := common.FormatNumber(t.Total.Avail*t.Multiplier, t.Base)
|
case NumericResource:
|
||||||
account.Resources[k] = ResourceChart{
|
avail, prefix := common.FormatNumber(t.Total.Avail*t.Multiplier, t.Base)
|
||||||
Type: t.Type,
|
account.Resources[category][resource] = ResourceChart{
|
||||||
Display: t.Display,
|
|
||||||
Name: t.Name,
|
|
||||||
Used: t.Total.Used,
|
|
||||||
Max: t.Total.Max,
|
|
||||||
Avail: avail,
|
|
||||||
Prefix: prefix,
|
|
||||||
Unit: t.Unit,
|
|
||||||
ColorHex: InterpolateColorHSV(Green, Red, float64(t.Total.Used)/float64(t.Total.Max)).ToHTML(),
|
|
||||||
}
|
|
||||||
case StorageResource:
|
|
||||||
avail, prefix := common.FormatNumber(t.Total.Avail*t.Multiplier, t.Base)
|
|
||||||
account.Resources[k] = ResourceChart{
|
|
||||||
Type: t.Type,
|
|
||||||
Display: t.Display,
|
|
||||||
Name: t.Name,
|
|
||||||
Used: t.Total.Used,
|
|
||||||
Max: t.Total.Max,
|
|
||||||
Avail: avail,
|
|
||||||
Prefix: prefix,
|
|
||||||
Unit: t.Unit,
|
|
||||||
ColorHex: InterpolateColorHSV(Green, Red, float64(t.Total.Used)/float64(t.Total.Max)).ToHTML(),
|
|
||||||
}
|
|
||||||
case ListResource:
|
|
||||||
l := struct {
|
|
||||||
Type string
|
|
||||||
Display bool
|
|
||||||
Resources []ResourceChart
|
|
||||||
}{
|
|
||||||
Type: t.Type,
|
|
||||||
Display: t.Display,
|
|
||||||
Resources: []ResourceChart{},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, r := range t.Total {
|
|
||||||
l.Resources = append(l.Resources, ResourceChart{
|
|
||||||
Type: t.Type,
|
Type: t.Type,
|
||||||
Display: t.Display,
|
Display: t.Display,
|
||||||
Name: r.Name,
|
Name: t.Name,
|
||||||
Used: r.Used,
|
Used: t.Total.Used,
|
||||||
Max: r.Max,
|
Max: t.Total.Max,
|
||||||
Avail: float64(r.Avail), // usually an int
|
Avail: avail,
|
||||||
Unit: "",
|
Prefix: prefix,
|
||||||
ColorHex: InterpolateColorHSV(Green, Red, float64(r.Used)/float64(r.Max)).ToHTML(),
|
Unit: t.Unit,
|
||||||
})
|
ColorHex: InterpolateColorHSV(Green, Red, float64(t.Total.Used)/float64(t.Total.Max)).ToHTML(),
|
||||||
|
}
|
||||||
|
case StorageResource:
|
||||||
|
avail, prefix := common.FormatNumber(t.Total.Avail*t.Multiplier, t.Base)
|
||||||
|
account.Resources[category][resource] = ResourceChart{
|
||||||
|
Type: t.Type,
|
||||||
|
Display: t.Display,
|
||||||
|
Name: t.Name,
|
||||||
|
Used: t.Total.Used,
|
||||||
|
Max: t.Total.Max,
|
||||||
|
Avail: avail,
|
||||||
|
Prefix: prefix,
|
||||||
|
Unit: t.Unit,
|
||||||
|
ColorHex: InterpolateColorHSV(Green, Red, float64(t.Total.Used)/float64(t.Total.Max)).ToHTML(),
|
||||||
|
}
|
||||||
|
case ListResource:
|
||||||
|
l := struct {
|
||||||
|
Type string
|
||||||
|
Display bool
|
||||||
|
Resources []ResourceChart
|
||||||
|
}{
|
||||||
|
Type: t.Type,
|
||||||
|
Display: t.Display,
|
||||||
|
Resources: []ResourceChart{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range t.Total {
|
||||||
|
l.Resources = append(l.Resources, ResourceChart{
|
||||||
|
Type: t.Type,
|
||||||
|
Display: t.Display,
|
||||||
|
Name: r.Name,
|
||||||
|
Used: r.Used,
|
||||||
|
Max: r.Max,
|
||||||
|
Avail: float64(r.Avail), // usually an int
|
||||||
|
Unit: "",
|
||||||
|
ColorHex: InterpolateColorHSV(Green, Red, float64(r.Used)/float64(r.Max)).ToHTML(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
account.Resources[category][resource] = l
|
||||||
}
|
}
|
||||||
account.Resources[k] = l
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +176,7 @@ func HandleGETAccount(c *gin.Context) {
|
|||||||
|
|
||||||
func GetUserAccount(auth common.Auth) (Account, error) {
|
func GetUserAccount(auth common.Auth) (Account, error) {
|
||||||
account := Account{
|
account := Account{
|
||||||
Resources: map[string]any{},
|
Resources: map[string]map[string]any{},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := common.RequestContext{
|
ctx := common.RequestContext{
|
||||||
@@ -225,6 +230,10 @@ func GetUserAccount(auth common.Auth) (Account, error) {
|
|||||||
m := v.(map[string]any)
|
m := v.(map[string]any)
|
||||||
t := m["type"].(string)
|
t := m["type"].(string)
|
||||||
r := resources[k].(map[string]any)
|
r := resources[k].(map[string]any)
|
||||||
|
category := m["category"].(string)
|
||||||
|
if _, ok := account.Resources[category]; !ok {
|
||||||
|
account.Resources[category] = map[string]any{}
|
||||||
|
}
|
||||||
if t == "numeric" {
|
if t == "numeric" {
|
||||||
n := NumericResource{}
|
n := NumericResource{}
|
||||||
n.Type = t
|
n.Type = t
|
||||||
@@ -233,7 +242,7 @@ func GetUserAccount(auth common.Auth) (Account, error) {
|
|||||||
if err_m != nil || err_r != nil {
|
if err_m != nil || err_r != nil {
|
||||||
return account, fmt.Errorf("%s\n%s", err_m.Error(), err_r.Error())
|
return account, fmt.Errorf("%s\n%s", err_m.Error(), err_r.Error())
|
||||||
}
|
}
|
||||||
account.Resources[k] = n
|
account.Resources[category][k] = n
|
||||||
} else if t == "storage" {
|
} else if t == "storage" {
|
||||||
n := StorageResource{}
|
n := StorageResource{}
|
||||||
n.Type = t
|
n.Type = t
|
||||||
@@ -242,7 +251,7 @@ func GetUserAccount(auth common.Auth) (Account, error) {
|
|||||||
if err_m != nil || err_r != nil {
|
if err_m != nil || err_r != nil {
|
||||||
return account, fmt.Errorf("%s\n%s", err_m.Error(), err_r.Error())
|
return account, fmt.Errorf("%s\n%s", err_m.Error(), err_r.Error())
|
||||||
}
|
}
|
||||||
account.Resources[k] = n
|
account.Resources[category][k] = n
|
||||||
} else if t == "list" {
|
} else if t == "list" {
|
||||||
n := ListResource{}
|
n := ListResource{}
|
||||||
n.Type = t
|
n.Type = t
|
||||||
@@ -251,7 +260,7 @@ func GetUserAccount(auth common.Auth) (Account, error) {
|
|||||||
if err_m != nil || err_r != nil {
|
if err_m != nil || err_r != nil {
|
||||||
return account, fmt.Errorf("%s\n%s", err_m.Error(), err_r.Error())
|
return account, fmt.Errorf("%s\n%s", err_m.Error(), err_r.Error())
|
||||||
}
|
}
|
||||||
account.Resources[k] = n
|
account.Resources[category][k] = n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<link rel="modulepreload" href="scripts/dialog.js">
|
<link rel="modulepreload" href="scripts/dialog.js">
|
||||||
<style>
|
<style>
|
||||||
@media screen and (width >= 1264px){
|
@media screen and (width >= 1264px){
|
||||||
#resource-container {
|
.resource-container {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fill, calc(100% / 6));
|
grid-template-columns: repeat(auto-fill, calc(100% / 6));
|
||||||
grid-gap: 0;
|
grid-gap: 0;
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@media screen and (width <= 1264px) and (width >= 680px) {
|
@media screen and (width <= 1264px) and (width >= 680px) {
|
||||||
#resource-container {
|
.resource-container {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fill, 200px);
|
grid-template-columns: repeat(auto-fill, 200px);
|
||||||
grid-gap: 0;
|
grid-gap: 0;
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@media screen and (width <= 680px) {
|
@media screen and (width <= 680px) {
|
||||||
#resource-container {
|
.resource-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0;
|
gap: 0;
|
||||||
@@ -54,49 +54,54 @@
|
|||||||
</section>
|
</section>
|
||||||
<section class="w3-card w3-padding">
|
<section class="w3-card w3-padding">
|
||||||
<h3>Cluster Resources</h3>
|
<h3>Cluster Resources</h3>
|
||||||
<div id="resource-container">
|
<div>
|
||||||
{{range .account.Resources}}
|
{{range $category, $v := .account.Resources}}
|
||||||
{{if .Display}}
|
{{if ne $category ""}}
|
||||||
{{if eq .Type "numeric"}}
|
<h4>{{$category}}</h4>
|
||||||
{{template "resource-chart" .}}
|
{{end}}
|
||||||
{{end}}
|
<div class="resource-container">
|
||||||
{{if eq .Type "storage"}}
|
{{range $v}}
|
||||||
{{template "resource-chart" .}}
|
{{if .Display}}
|
||||||
{{end}}
|
{{if eq .Type "numeric"}}
|
||||||
{{if eq .Type "list"}}
|
|
||||||
{{range .Resources}}
|
|
||||||
{{template "resource-chart" .}}
|
{{template "resource-chart" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{if eq .Type "storage"}}
|
||||||
|
{{template "resource-chart" .}}
|
||||||
|
{{end}}
|
||||||
|
{{if eq .Type "list"}}
|
||||||
|
{{range .Resources}}
|
||||||
|
{{template "resource-chart" .}}
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<modal-dialog id="change-password-dialog">
|
|
||||||
<template shadowrootmode="open">
|
|
||||||
<link rel="stylesheet" href="modules/w3.css">
|
|
||||||
<link rel="stylesheet" href="css/style.css">
|
|
||||||
<link rel="stylesheet" href="css/form.css">
|
|
||||||
<dialog class="w3-container w3-card w3-border-0">
|
|
||||||
<p class="w3-large" id="prompt" style="text-align: center;">
|
|
||||||
Change Password
|
|
||||||
</p>
|
|
||||||
<div id="body">
|
|
||||||
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
|
||||||
<label for="new-password">New Password</label>
|
|
||||||
<input class="w3-input w3-border" id="new-password" name="new-password" type="password" required>
|
|
||||||
<label for="confirm-password">Confirm Password</label>
|
|
||||||
<input class="w3-input w3-border" id="confirm-password" name="confirm-password" type="password" required>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<div id="controls" class="w3-center w3-container">
|
|
||||||
<button id="cancel" type="submit" value="cancel" form="form" class="w3-button w3-margin" style="background-color: var(--negative-color, #f00); color: var(--lightbg-text-color, black);" formnovalidate>CANCEL</button>
|
|
||||||
<button id="confirm" type="submit" value="confirm" form="form" class="w3-button w3-margin" style="background-color: var(--positive-color, #0f0); color: var(--lightbg-text-color, black);">CONFIRM</button>
|
|
||||||
</div>
|
|
||||||
</dialog>
|
|
||||||
</template>
|
|
||||||
</modal-dialog>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
<template id="change-password-dialog">
|
||||||
|
<link rel="stylesheet" href="modules/w3.css">
|
||||||
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
<link rel="stylesheet" href="css/form.css">
|
||||||
|
<dialog class="w3-container w3-card w3-border-0">
|
||||||
|
<p class="w3-large" id="prompt" style="text-align: center;">
|
||||||
|
Change Password
|
||||||
|
</p>
|
||||||
|
<div id="body">
|
||||||
|
<form method="dialog" class="input-grid" style="grid-template-columns: auto 1fr;" id="form">
|
||||||
|
<label for="new-password">New Password</label>
|
||||||
|
<input class="w3-input w3-border" id="new-password" name="new-password" type="password" required>
|
||||||
|
<label for="confirm-password">Confirm Password</label>
|
||||||
|
<input class="w3-input w3-border" id="confirm-password" name="confirm-password" type="password" required>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div id="controls" class="w3-center w3-container">
|
||||||
|
<button id="cancel" type="submit" value="cancel" form="form" class="w3-button w3-margin" style="background-color: var(--negative-color, #f00); color: var(--lightbg-text-color, black);" formnovalidate>CANCEL</button>
|
||||||
|
<button id="confirm" type="submit" value="confirm" form="form" class="w3-button w3-margin" style="background-color: var(--positive-color, #0f0); color: var(--lightbg-text-color, black);">CONFIRM</button>
|
||||||
|
</div>
|
||||||
|
</dialog>
|
||||||
|
</template>
|
||||||
</html>
|
</html>
|
Reference in New Issue
Block a user