diff --git a/models/bots/runner.go b/models/bots/runner.go index 90dcea7294..cecc2e7e9f 100644 --- a/models/bots/runner.go +++ b/models/bots/runner.go @@ -72,6 +72,11 @@ func (r *Runner) OwnType() string { return r.Repo.FullName() } +// AllLabels returns agent and custom labels +func (r *Runner) AllLabels() []string { + return append(r.AgentLabels, r.CustomLabels...) +} + func init() { db.RegisterModel(&Runner{}) } @@ -81,6 +86,7 @@ type FindRunnerOptions struct { RepoID int64 OwnerID int64 Sort string + Filter string } func (opts FindRunnerOptions) toCond() builder.Cond { @@ -92,19 +98,36 @@ func (opts FindRunnerOptions) toCond() builder.Cond { cond = cond.And(builder.Eq{"owner_id": opts.OwnerID}) } cond = cond.Or(builder.Eq{"repo_id": 0, "owner_id": 0}) + if opts.Filter != "" { + cond = cond.And(builder.Like{"name", opts.Filter}) + } return cond } +func (opts FindRunnerOptions) toOrder() string { + switch opts.Sort { + case "online": + return "last_online DESC" + case "offline": + return "last_online ASC" + case "alphabetically": + return "name ASC" + } + return "last_online DESC" +} + func CountRunners(opts FindRunnerOptions) (int64, error) { return db.GetEngine(db.DefaultContext). Table("bots_runner"). Where(opts.toCond()). + OrderBy(opts.toOrder()). Count() } func FindRunners(opts FindRunnerOptions) (runners RunnerList, err error) { sess := db.GetEngine(db.DefaultContext). - Where(opts.toCond()) + Where(opts.toCond()). + OrderBy(opts.toOrder()) if opts.Page > 0 { sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) } diff --git a/routers/web/admin/runners.go b/routers/web/admin/runners.go index ccc7afe963..a37cce8661 100644 --- a/routers/web/admin/runners.go +++ b/routers/web/admin/runners.go @@ -38,17 +38,19 @@ func Runners(ctx *context.Context) { Page: page, PageSize: 100, }, + Sort: ctx.Req.URL.Query().Get("sort"), + Filter: ctx.Req.URL.Query().Get("q"), } count, err := bots_model.CountRunners(opts) if err != nil { - ctx.ServerError("SearchUsers", err) + ctx.ServerError("AdminRunners", err) return } runners, err := bots_model.FindRunners(opts) if err != nil { - ctx.ServerError("SearchUsers", err) + ctx.ServerError("AdminRunners", err) return } if err := runners.LoadAttributes(ctx); err != nil { @@ -56,6 +58,7 @@ func Runners(ctx *context.Context) { return } + ctx.Data["Keyword"] = opts.Filter ctx.Data["Runners"] = runners ctx.Data["Total"] = count @@ -71,7 +74,7 @@ func EditRunner(ctx *context.Context) { ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminRunners"] = true - runner, err := bots_model.GetBuildByID(ctx.ParamsInt64(":runnerid")) + runner, err := bots_model.GetRunnerByID(ctx.ParamsInt64(":runnerid")) if err != nil { ctx.ServerError("GetRunnerByID", err) return diff --git a/templates/admin/runner/edit.tmpl b/templates/admin/runner/edit.tmpl index 29dcaa127a..5a7f7f8c20 100644 --- a/templates/admin/runner/edit.tmpl +++ b/templates/admin/runner/edit.tmpl @@ -1,197 +1,61 @@ {{template "base/head" .}} -