From dd00de0a17ed387ef61b54a6ed9a5dacd4ec0597 Mon Sep 17 00:00:00 2001 From: Victor Castell Date: Mon, 15 Jun 2015 01:15:12 +0200 Subject: [PATCH] WIP dashboard --- dcron/api.go | 24 +++++-- templates/dashboard.html.tmpl | 47 +------------ templates/home.html.tmpl | 18 +++-- templates/users/login-signup-parent.html.tmpl | 68 ------------------- templates/users/login.html.tmpl | 19 ------ templates/users/signup.html.tmpl | 21 ------ 6 files changed, 36 insertions(+), 161 deletions(-) delete mode 100644 templates/users/login-signup-parent.html.tmpl delete mode 100644 templates/users/login.html.tmpl delete mode 100644 templates/users/signup.html.tmpl diff --git a/dcron/api.go b/dcron/api.go index d598c4da3..f1fa5e5d3 100644 --- a/dcron/api.go +++ b/dcron/api.go @@ -16,10 +16,12 @@ import ( func (a *AgentCommand) ServeHTTP() { r := mux.NewRouter().StrictSlash(true) r.HandleFunc("/", a.IndexHandler) - r.HandleFunc("/dashboard", GetHome) r.HandleFunc("/members", a.MembersHandler) r.HandleFunc("/leader", a.LeaderHandler) + subui := r.PathPrefix("/ui").Subrouter() + subui.HandleFunc("/dashboard", a.DashboardHandler) + sub := r.PathPrefix("/jobs").Subrouter() sub.HandleFunc("/", a.JobCreateOrUpdateHandler).Methods("POST", "PUT") sub.HandleFunc("/", a.JobsHandler).Methods("GET") @@ -175,19 +177,31 @@ func (a *AgentCommand) LeaderHandler(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) } -func GetHome(w http.ResponseWriter, r *http.Request) { +func (a *AgentCommand) DashboardHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") + jobs, _ := a.etcd.GetJobs() + tmpl, err := template.ParseFiles("templates/dashboard.html.tmpl", "templates/home.html.tmpl") if err != nil { return } + funcs := template.FuncMap{ + "isSuccess": func() bool { + return true //job.LastSuccess.After(job.LastError) + }, + } + tmpl.Funcs(funcs) + data := struct { - Pepe string + Jobs []*Job }{ - "foo", + Jobs: jobs, } - tmpl.Execute(w, data) + err = tmpl.Execute(w, data) + if err != nil { + log.Error(err) + } } diff --git a/templates/dashboard.html.tmpl b/templates/dashboard.html.tmpl index dccb0ec87..ba1c20a07 100644 --- a/templates/dashboard.html.tmpl +++ b/templates/dashboard.html.tmpl @@ -1,7 +1,7 @@ - Blank + Dcron @@ -22,14 +22,14 @@ - Blank + Dcron - - - {{template "content" .}} diff --git a/templates/home.html.tmpl b/templates/home.html.tmpl index 35c95cd04..2da3e6b60 100644 --- a/templates/home.html.tmpl +++ b/templates/home.html.tmpl @@ -1,10 +1,20 @@ {{define "content"}}
-
-

Hello, World!

-

Welcome to your new Go web project.

-
+ + + + + + + {{ range $job := .Jobs }} + + + + + + {{ end }} +
JobLast
{{ $job.Name }}{{ $job.LastSuccess }}{{ if isSuccess }}Success{{ end }}
{{end}} diff --git a/templates/users/login-signup-parent.html.tmpl b/templates/users/login-signup-parent.html.tmpl deleted file mode 100644 index 837444db1..000000000 --- a/templates/users/login-signup-parent.html.tmpl +++ /dev/null @@ -1,68 +0,0 @@ - - - - Blank - - - - - - - - {{template "content"}} - - diff --git a/templates/users/login.html.tmpl b/templates/users/login.html.tmpl deleted file mode 100644 index f493e0432..000000000 --- a/templates/users/login.html.tmpl +++ /dev/null @@ -1,19 +0,0 @@ -{{define "content"}} -
-
-
- -
-
-
-{{end}} \ No newline at end of file diff --git a/templates/users/signup.html.tmpl b/templates/users/signup.html.tmpl deleted file mode 100644 index 87b6de198..000000000 --- a/templates/users/signup.html.tmpl +++ /dev/null @@ -1,21 +0,0 @@ -{{define "content"}} -
-
-
- -
-
-
-{{end}} \ No newline at end of file