Skip to content

Commit

Permalink
Add display jobs feature
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Aug 10, 2015
1 parent 2585ab7 commit e8ca0cd
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
16 changes: 16 additions & 0 deletions db/jobs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
package db

import (
"gopkg.in/mgo.v2"
)

// CronJob Model
type Job struct {
Name string
Schedule string
Script string
}

func GetJobs(db *mgo.Database, query interface{}, limit int) (result []Job, err error) {
jobs := db.C("jobs")
statement := jobs.Find(query)
if limit > 0 {
statement = statement.Limit(limit)
}

err = statement.All(&result)

return
}
26 changes: 26 additions & 0 deletions server/jobs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package server

import (
"github.com/elct9620/go-plurk-robot/db"
"github.com/labstack/echo"
)

// TODO(elct9620): Should improve this using global template variable
type JobPage struct {
Jobs []db.Job
HideNav bool
}

func jobs(c *echo.Context) error {

mdb, _ := getDatabase()
jobs, err := db.GetJobs(mdb, nil, 0)

defer mdb.Session.Close()

if err != nil {
return err
}

return c.Render(200, "jobs", JobPage{jobs, false})
}
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func setupRoute(s *echo.Echo) {
s.Get("/", index)
s.Get("/login", login)
s.Post("/login", verifyLogin)

s.Get("/jobs", jobs)
}

func index(c *echo.Context) error {
Expand Down
4 changes: 4 additions & 0 deletions server/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ body {
width: 340px;
transform: translateX(-350px);
}

.table-center {
margin: 0 auto;
}
28 changes: 28 additions & 0 deletions server/template/jobs.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{ define "jobs" }}

{{ template "_common/header" . }}

<div class="mdl-grid">
<div class="mdl-cell mdl-cell--2-col"></div>
<div class="mdl-cell mdl-cell--8-col">
<table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp table-center">
<thead>
<tr>
<th class="mdl-data-table__cell--non-numberic">Name</th>
<th class="mdl-data-table__cell--non-numberic">Schedule</th>
</tr>
</thead>
{{ range .Jobs }}
<tr>
<td class="mdl-data-table__cell--non-numberic">{{ .Name }}</td>
<td class="mdl-data-table__cell--non-numberic">{{ .Schedule }}</td>
</tr>
{{ end }}
</table>
</div>
<div class="mdl-cell mdl-cell--2-col"></div>
</div>

{{ template "_common/footer" . }}

{{ end }}

0 comments on commit e8ca0cd

Please sign in to comment.