From d38371015435dca9b5c6084f9b48ba543fd2c865 Mon Sep 17 00:00:00 2001 From: mls-361 Date: Sun, 22 Aug 2021 22:49:12 +0200 Subject: [PATCH] =?UTF-8?q?En=20cours=20de=20d=C3=A9veloppement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/gui.go | 16 +++++++++-- internal/gui/jobs.go | 40 +++++++++++++++++++++++++++ internal/gui/layout.go | 6 ++-- internal/gui/static/css/jobs.css | 16 +++++++++++ internal/gui/static/css/workflows.css | 16 +++++++++++ internal/gui/static/js/dashboard.js | 36 ++++++++++++++---------- internal/gui/static/js/jobs.js | 9 ++++++ internal/gui/static/js/workflows.js | 9 ++++++ internal/gui/workflows.go | 40 +++++++++++++++++++++++++++ 9 files changed, 168 insertions(+), 20 deletions(-) create mode 100644 internal/gui/jobs.go create mode 100644 internal/gui/static/css/jobs.css create mode 100644 internal/gui/static/css/workflows.css create mode 100644 internal/gui/static/js/jobs.js create mode 100644 internal/gui/static/js/workflows.js create mode 100644 internal/gui/workflows.go diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 7479f8f..c4b1de3 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -28,18 +28,30 @@ func Build(ccs *components.Components) error { Render(w) })) - router.Get("/dashboard", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + router.Get("/gui/dashboard", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _ = newDashboard(ccs). build(). Render(w) })) - router.Get("/dashboard/update", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + router.Get("/gui/dashboard/update", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _ = newDashboard(ccs). update(). Render(w) })) + router.Get("/gui/job/list", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + _ = newJobList(ccs). + build(). + Render(w) + })) + + router.Get("/gui/workflow/list", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + _ = newWorkflowList(ccs). + build(). + Render(w) + })) + return nil } diff --git a/internal/gui/jobs.go b/internal/gui/jobs.go new file mode 100644 index 0000000..39990d6 --- /dev/null +++ b/internal/gui/jobs.go @@ -0,0 +1,40 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### gui ####### Copyright (c) 2021 mls-361 ##################################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ + +package gui + +import ( + g "github.com/maragudk/gomponents" + . "github.com/maragudk/gomponents/html" + + "forge.chapril.org/armen/armen/internal/components" +) + +type jobList struct { + app components.Application + storage components.Storage +} + +func newJobList(ccs *components.Components) *jobList { + return &jobList{ + app: ccs.Application, + storage: ccs.Storage, + } +} + +func (jl *jobList) content() g.Node { + return Div( + Class("jobs"), + ) +} + +func (jl *jobList) build() g.Node { + return buildPage(jl.app, "jobs", jl.content()) +} + +/* +######################################################################################################## @(°_°)@ ####### +*/ diff --git a/internal/gui/layout.go b/internal/gui/layout.go index de20368..777767c 100644 --- a/internal/gui/layout.go +++ b/internal/gui/layout.go @@ -58,9 +58,9 @@ func buildPage(app components.Application, name string, content g.Node) g.Node { Div( Class("navbar"), navbarLink(app.Name(), "/", "home", name), - navbarLink("dashboard", "/dashboard", "number of jobs and workflows per status", name), - navbarLink("jobs", "/search/jobs", "search for jobs", name), - navbarLink("workflows", "/search/workflows", "search for workflows", name), + navbarLink("dashboard", "/gui/dashboard", "number of jobs and workflows per status", name), + navbarLink("jobs", "/gui/search/jobs", "search for jobs", name), + navbarLink("workflows", "/gui/search/workflows", "search for workflows", name), ), ), ), diff --git a/internal/gui/static/css/jobs.css b/internal/gui/static/css/jobs.css new file mode 100644 index 0000000..9263629 --- /dev/null +++ b/internal/gui/static/css/jobs.css @@ -0,0 +1,16 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### jobs ####### Copyright (c) 2021 mls-361 #################################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ + +@charset "utf-8"; + +@import url("normalize.css"); +@import url("colors.css"); +@import url("common.css"); + +/* +######################################################################################################## @(°_°)@ ####### +*/ + diff --git a/internal/gui/static/css/workflows.css b/internal/gui/static/css/workflows.css new file mode 100644 index 0000000..f02df50 --- /dev/null +++ b/internal/gui/static/css/workflows.css @@ -0,0 +1,16 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### workflows ####### Copyright (c) 2021 mls-361 ############################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ + +@charset "utf-8"; + +@import url("normalize.css"); +@import url("colors.css"); +@import url("common.css"); + +/* +######################################################################################################## @(°_°)@ ####### +*/ + diff --git a/internal/gui/static/js/dashboard.js b/internal/gui/static/js/dashboard.js index 50de1ee..670e41d 100644 --- a/internal/gui/static/js/dashboard.js +++ b/internal/gui/static/js/dashboard.js @@ -7,25 +7,31 @@ (function() { const dashboard = document.getElementById("dashboard"); - window.addEventListener("load", function(event) { - window.setInterval( + var interval; + + window.onload = function(event) { + interval = window.setInterval( function() { - fetch("/dashboard/update").then(function(response) { - if (response.ok) { - response.text().then(function(html) { - dashboard.innerHTML = html; - }); - } else { - $.showError("Fetch error: invalid network response"); ////////////////////////////////////////// - } - }) - .catch(function(error) { - $.showError("Fetch error: " + error.message); ////////////////////////////////////////////////////// - }); + if (window.closed) { + window.clearInterval(interval); + } else { + fetch("/gui/dashboard/update").then(function(response) { + if (response.ok) { + response.text().then(function(html) { + dashboard.innerHTML = html; + }); + } else { + $.showError("Fetch error: invalid network response"); ////////////////////////////////////// + } + }) + .catch(function(error) { + $.showError("Fetch error: " + error.message); ////////////////////////////////////////////////// + }); + } }, 3000 ); - }); + }; })(); /* diff --git a/internal/gui/static/js/jobs.js b/internal/gui/static/js/jobs.js new file mode 100644 index 0000000..8e5196a --- /dev/null +++ b/internal/gui/static/js/jobs.js @@ -0,0 +1,9 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### jobs ####### Copyright (c) 2021 mls-361 #################################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ +/* +######################################################################################################## @(°_°)@ ####### +*/ + diff --git a/internal/gui/static/js/workflows.js b/internal/gui/static/js/workflows.js new file mode 100644 index 0000000..93f68ed --- /dev/null +++ b/internal/gui/static/js/workflows.js @@ -0,0 +1,9 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### workflows ####### Copyright (c) 2021 mls-361 ############################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ +/* +######################################################################################################## @(°_°)@ ####### +*/ + diff --git a/internal/gui/workflows.go b/internal/gui/workflows.go new file mode 100644 index 0000000..219c38c --- /dev/null +++ b/internal/gui/workflows.go @@ -0,0 +1,40 @@ +/* +------------------------------------------------------------------------------------------------------------------------ +####### gui ####### Copyright (c) 2021 mls-361 ##################################################### MIT License ####### +------------------------------------------------------------------------------------------------------------------------ +*/ + +package gui + +import ( + g "github.com/maragudk/gomponents" + . "github.com/maragudk/gomponents/html" + + "forge.chapril.org/armen/armen/internal/components" +) + +type workflowList struct { + app components.Application + storage components.Storage +} + +func newWorkflowList(ccs *components.Components) *workflowList { + return &workflowList{ + app: ccs.Application, + storage: ccs.Storage, + } +} + +func (wl *workflowList) content() g.Node { + return Div( + Class("jobs"), + ) +} + +func (wl *workflowList) build() g.Node { + return buildPage(wl.app, "workflows", wl.content()) +} + +/* +######################################################################################################## @(°_°)@ ####### +*/