diff --git a/cmd/nano-run/run_cmd.go b/cmd/nano-run/run_cmd.go index e0240a8..292f044 100644 --- a/cmd/nano-run/run_cmd.go +++ b/cmd/nano-run/run_cmd.go @@ -15,6 +15,7 @@ import ( type runCmd struct { Directory string `long:"directory" short:"d" env:"DIRECTORY" description:"Data directory" default:"run"` + UI string `long:"ui" env:"UI" description:"Path to UI directory" default:"templates"` Interval time.Duration `long:"interval" short:"i" env:"INTERVAL" description:"Requeue interval" default:"3s"` Attempts int `long:"attempts" short:"a" env:"ATTEMPTS" description:"Max number of attempts" default:"5"` Concurrency int `long:"concurrency" short:"c" env:"CONCURRENCY" description:"Number of parallel worker (0 - mean number of CPU)" default:"0"` @@ -35,6 +36,7 @@ func (cfg *runCmd) Execute([]string) error { srv := runner.DefaultConfig() srv.Bind = cfg.Bind srv.WorkingDirectory = cfg.Directory + srv.UIDirectory = cfg.UI srv.ConfigDirectory = tmpDir unit := server.DefaultUnit() diff --git a/server/runner/handler.go b/server/runner/handler.go index 09fabc0..af0002d 100644 --- a/server/runner/handler.go +++ b/server/runner/handler.go @@ -91,14 +91,13 @@ func (cfg Config) Create(global context.Context) (*Server, error) { ctx, cancel := context.WithCancel(global) router := gin.Default() + router.LoadHTMLGlob(filepath.Join(cfg.UIDirectory, "*.html")) + router.Static("/static", filepath.Join(cfg.UIDirectory, "static")) server.Attach(router.Group("/api/"), units, workers) - ui.Attach(router.Group("/ui/"), units, cfg.UIDirectory) - router.Group("/", func(gctx *gin.Context) { + ui.Attach(router.Group("/ui/"), units) + router.GET("/", func(gctx *gin.Context) { gctx.Redirect(http.StatusTemporaryRedirect, "ui") }) - //router.Path("/").Methods("GET").HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { - // http.Redirect(writer, request, "ui", http.StatusTemporaryRedirect) - //}) srv := &Server{ Handler: router, diff --git a/server/ui/router.go b/server/ui/router.go index 66acf3e..5c0417a 100644 --- a/server/ui/router.go +++ b/server/ui/router.go @@ -1,11 +1,9 @@ package ui import ( - "html/template" "net/http" "path/filepath" - "github.com/Masterminds/sprig" "github.com/gin-gonic/gin" "nano-run/server" @@ -13,21 +11,23 @@ import ( func Expose(units []server.Unit, uiDir string) http.Handler { router := gin.New() - Attach(router, units, uiDir) + router.LoadHTMLGlob(filepath.Join(uiDir, "*.html")) + Attach(router, units) return router } -func Attach(router gin.IRouter, units []server.Unit, uiDir string) { +func Attach(router gin.IRouter, units []server.Unit) { ui := &uiRouter{ - dir: uiDir, units: units, } + router.GET("", func(gctx *gin.Context) { + gctx.Redirect(http.StatusTemporaryRedirect, "units") + }) router.GET("/units", ui.listUnits) router.GET("/unit/:name", ui.unitInfo) } type uiRouter struct { - dir string units []server.Unit } @@ -58,15 +58,3 @@ func (ui *uiRouter) listUnits(gctx *gin.Context) { reply.Units = ui.units gctx.HTML(http.StatusOK, "units-list.html", reply) } - -func (ui *uiRouter) getTemplate(name string) *template.Template { - t, err := template.New("").Funcs(sprig.HtmlFuncMap()).ParseFiles(filepath.Join(ui.dir, name)) - if err == nil { - return t - } - t, err = template.New("").Parse("Ooops... Page not found") - if err != nil { - panic(err) - } - return t -} diff --git a/templates/unit-info.html b/templates/unit-info.html index 8696c4d..782002c 100644 --- a/templates/unit-info.html +++ b/templates/unit-info.html @@ -1,18 +1,106 @@ - + + + + + -
- -

{{.Unit.Name}}

- {{if .Unit.Secured}} - secured +
+
+
+

Units :: {{.Unit.Name}}

+

+ +

+
+ + + {{with .Unit.Authorization}} + {{end}} - -

- {{.Unit.Mode}}, - {{.Unit.Workers}}, - {{.Unit.Interval}}, - {{.Unit.Timeout}}, -

-
+ + \ No newline at end of file diff --git a/templates/units-list.html b/templates/units-list.html index cee058e..1b34212 100644 --- a/templates/units-list.html +++ b/templates/units-list.html @@ -1,17 +1,78 @@ + + + + -{{range .Units}} -
- -

{{.Name}}

-
-

- {{.Mode}}, - {{.Workers}}, - {{.Interval}}, - {{.Timeout}}, -

-
-{{end}} +
+ +

Units

+
+
+
+ + + + + + + + + + + + + + + {{range .Units}} + + + + + + + + + + + {{end}} + +
NameModeConcurrencyAttemptsIntervalTimeoutMax request sizeWorking directory
+ + {{.Name}}{{if .Secured}} (secured){{end}} + + + {{.Mode}} + + {{.Workers}} + + {{.Attempts}} + + {{.Interval}} + + {{with .Timeout}} + {{.}} + {{else}} + ∞ + {{end}} + + {{with .MaxRequest}} + {{.}} + {{else}} + ∞ + {{end}} + + {{with .WorkDir}} +
+ static +

{{.}}

+
+ {{else}} + dynamic + {{end}} +
+
+
\ No newline at end of file