-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,7 @@ body { | |
width: 340px; | ||
transform: translateX(-350px); | ||
} | ||
|
||
.table-center { | ||
margin: 0 auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |