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.
 
 
 

123 lines
3.0 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### gui ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package gui
import (
"fmt"
"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
}
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, url string) g.Node {
return Div(
Class("value"),
A(
Class("label"),
g.Text(name),
Href(url),
),
Span(
Class(name),
g.Raw(strconv.Itoa(value)),
),
)
}
func (d *dashboard) metrics(ms *jw.Metrics) g.Node {
const jobURL = "/gui/job/list?status=%s"
const wfURL = "/gui/workflow/list?status=%s"
return Div(
Class("metrics"),
Div(
Class("panel"),
Div(
d.title("Jobs"),
d.value(string(jw.StatusTodo), ms.Jobs.Todo, fmt.Sprintf(jobURL, jw.StatusTodo)),
d.value(string(jw.StatusPending), ms.Jobs.Pending, fmt.Sprintf(jobURL, jw.StatusPending)),
d.value(string(jw.StatusRunning), ms.Jobs.Running, fmt.Sprintf(jobURL, jw.StatusRunning)),
d.value(string(jw.StatusSucceeded), ms.Jobs.Succeeded, fmt.Sprintf(jobURL, jw.StatusSucceeded)),
d.value(string(jw.StatusFailed), ms.Jobs.Failed, fmt.Sprintf(jobURL, jw.StatusFailed)),
Hr(),
d.value("total", ms.Jobs.Total, "/gui/job/list"),
),
),
Div(
Class("panel"),
Div(
d.title("Workflows"),
d.empty(),
d.empty(),
d.value(string(jw.StatusRunning), ms.Workflows.Running, fmt.Sprintf(wfURL, jw.StatusRunning)),
d.value(string(jw.StatusSucceeded), ms.Workflows.Succeeded, fmt.Sprintf(wfURL, jw.StatusSucceeded)),
d.value(string(jw.StatusFailed), ms.Workflows.Failed, fmt.Sprintf(wfURL, jw.StatusFailed)),
Hr(),
d.value("total", ms.Workflows.Total, "/gui/workflow/list"),
),
),
)
}
func (d *dashboard) content(ms *jw.Metrics) g.Node {
return Div(
ID("dashboard"),
Class("dashboard"),
d.metrics(ms),
)
}
func (d *dashboard) build() g.Node {
ms, err := d.storage.Metrics()
if err != nil {
return buildPage(d.app, "dashboard", g.Text("ERROR")) //AFINIR
}
return buildPage(d.app, "dashboard", d.content(ms))
}
func (d *dashboard) update() g.Node {
ms, err := d.storage.Metrics()
if err != nil {
return g.Text("ERROR") //AFINIR
}
return d.metrics(ms)
}
/*
######################################################################################################## @(°_°)@ #######
*/