Jobs & Workflows https://armen.surge.sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

124 lines
2.6 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### gui ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package gui
import (
"strconv"
"forge.chapril.org/armen/jw"
g "github.com/maragudk/gomponents"
. "github.com/maragudk/gomponents/html"
"forge.chapril.org/armen/armen/internal/components"
)
type dashboard struct {
app components.Application
storage components.Storage
stats *jw.Stats
}
func newDashboard(ccs *components.Components) *dashboard {
return &dashboard{
app: ccs.Application,
storage: ccs.Storage,
}
}
func (d *dashboard) title(title string) g.Node {
return H1(
Class("title"),
g.Text(title),
)
}
func (d *dashboard) empty() g.Node {
return Div(
Class("value"),
)
}
func (d *dashboard) value(name string, value int) g.Node {
return Div(
Class("value"),
A(
Class("label"),
g.Text(name),
Href("/"),
),
Span(
Class(name),
g.Raw(strconv.Itoa(value)),
),
)
}
func (d *dashboard) metrics() g.Node {
return Div(
Class("metrics"),
Div(
Class("panel"),
Div(
d.title("Jobs"),
d.value(string(jw.StatusTodo), d.stats.Jobs.Todo),
d.value(string(jw.StatusPending), d.stats.Jobs.Pending),
d.value(string(jw.StatusRunning), d.stats.Jobs.Running),
d.value(string(jw.StatusSucceeded), d.stats.Jobs.Succeeded),
d.value(string(jw.StatusFailed), d.stats.Jobs.Failed),
Hr(),
d.value("total", d.stats.Jobs.Total),
),
),
Div(
Class("panel"),
Div(
d.title("Workflows"),
d.empty(),
d.empty(),
d.value(string(jw.StatusRunning), d.stats.Workflows.Running),
d.value(string(jw.StatusSucceeded), d.stats.Workflows.Succeeded),
d.value(string(jw.StatusFailed), d.stats.Workflows.Failed),
Hr(),
d.value("total", d.stats.Workflows.Total),
),
),
)
}
func (d *dashboard) content() g.Node {
return Div(
ID("dashboard"),
Class("dashboard"),
d.metrics(),
)
}
func (d *dashboard) build() g.Node {
var err error
d.stats, err = d.storage.Stats()
if err != nil {
return buildPage(d.app, "dashboard", g.Text("ERROR")) //AFINIR
}
return buildPage(d.app, "dashboard", d.content())
}
func (d *dashboard) update() g.Node {
var err error
d.stats, err = d.storage.Stats()
if err != nil {
return g.Text("ERROR") //AFINIR
}
return d.metrics()
}
/*
######################################################################################################## @(°_°)@ #######
*/