Skip to content

Commit

Permalink
WIP dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Jun 14, 2015
1 parent ff8ac0c commit dd00de0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 161 deletions.
24 changes: 19 additions & 5 deletions dcron/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
}
47 changes: 3 additions & 44 deletions templates/dashboard.html.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Blank</title>
<title>Dcron</title>

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="/bootstrap/themes/flatly/bootstrap.min.css">
Expand All @@ -22,14 +22,14 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Blank</a>
<a class="navbar-brand" href="/">Dcron</a>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ .CurrentUser.Email }} <span class="caret"></span></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="caret"></span></a>

<ul class="dropdown-menu" role="menu">
<li><a href="javascript:void(0)" data-toggle="modal" data-target="#user-settings-modal">User Settings</a></li>
Expand All @@ -43,47 +43,6 @@
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

<!-- User Settings Modal -->
<div class="modal fade" id="user-settings-modal" tabindex="-1" role="dialog" aria-labelledby="user-settings-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="user-settings-label">User Settings</h4>
</div>

<form method="post" action="/users/{{ .CurrentUser.ID }}">

<div class="modal-body">
<input type="hidden" name="_method" value="put">

<div class="form-group">
<label class="control-label" for="email">Email:</label>
<input type="text" name="Email" id="email" class="form-control" value="{{ .CurrentUser.Email }}">
</div>

<div class="form-group">
<label class="control-label" for="password">New Password:</label>
<input type="password" name="Password" id="password" class="form-control">
</div>

<div class="form-group">
<label class="control-label" for="password-again">New Password Again:</label>
<input type="password" name="PasswordAgain" id="password-again" class="form-control">
</div>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" onclick="$(this).closest('form').submit()">Save changes</button>
</div>

</form>

</div>
</div>
</div>
{{template "content" .}}
</body>
</html>
18 changes: 14 additions & 4 deletions templates/home.html.tmpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{{define "content"}}
<div class="container">
<div class="row">
<div class="jumbotron">
<h1>Hello, World!</h1>
<p>Welcome to your new Go web project.</p>
</div>
</div>

<table class="table table-striped">
<tr>
<th>Job</th>
<th>Last</th>
</tr>
{{ range $job := .Jobs }}
<tr>
<td>{{ $job.Name }}</td>
<td>{{ $job.LastSuccess }}</td>
<td>{{ if isSuccess }}Success{{ end }}</td>
</tr>
{{ end }}
</table>
</div>
{{end}}
68 changes: 0 additions & 68 deletions templates/users/login-signup-parent.html.tmpl

This file was deleted.

19 changes: 0 additions & 19 deletions templates/users/login.html.tmpl

This file was deleted.

21 changes: 0 additions & 21 deletions templates/users/signup.html.tmpl

This file was deleted.

0 comments on commit dd00de0

Please sign in to comment.