From dff0d4b907aa1c6bdabba85cccf4da25a82c09db Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Mon, 10 Oct 2022 21:53:53 +0800 Subject: [PATCH] feat(runner): update edit.html --- models/bots/runner.go | 25 +++- routers/web/admin/runners.go | 9 +- templates/admin/runner/edit.tmpl | 204 ++++++------------------------- templates/admin/runner/list.tmpl | 58 +++------ web_src/less/_runner.less | 12 +- web_src/less/index.less | 1 + 6 files changed, 91 insertions(+), 218 deletions(-) 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" .}} -
+
{{template "admin/navbar" .}}
{{template "base/alert" .}}

- {{.locale.Tr "admin.users.edit_account"}} + {{.locale.Tr "admin.runners.runner_title"}} #{{.Runner.ID}} {{.Runner.Name}}

{{template "base/disable_form_autofill"}} {{.CsrfTokenHtml}} -
- - -
- -
- -

- {{.locale.Tr "settings.avatar"}} + {{.locale.Tr "admin.runner.task_list"}}

-
- {{.CsrfTokenHtml}} - {{if not DisableGravatar}} -
-
- - -
-
-
- - -
- {{end}} - -
-
- - -
-
- -
- - -
- -
- - {{$.locale.Tr "settings.delete_current_avatar"}} -
-
+ Comming soon
diff --git a/templates/admin/runner/list.tmpl b/templates/admin/runner/list.tmpl index 61adc43161..dc85a82d3d 100644 --- a/templates/admin/runner/list.tmpl +++ b/templates/admin/runner/list.tmpl @@ -1,5 +1,5 @@ {{template "base/head" .}} -
+
{{template "admin/navbar" .}}
{{template "base/alert" .}} @@ -33,51 +33,25 @@ - - online - - #1 - focused_mcclintock - - shared - - linux - amd64 - - 3 days ago - - {{svg "octicon-pencil"}} - - - - offline - - #2 - lucid_khorana - - shared - - linux - aarch64 - self-host - custom - - 3 minutes ago - - {{svg "octicon-pencil"}} - {{svg "octicon-x-circle"}} - - {{range .Runners}} - {{.ID}} - {{.Name}} + status + + + #{{.ID}} + {{.Name}} + + {{.OwnType}} - {{.UUID}} - {{.Created}} + + {{range .AllLabels}} + {{.}} + {{end}} + + {{TimeSinceUnix .LastOnline $.locale}} - {{svg "octicon-pencil"}} - {{svg "octicon-x-circle"}} + {{svg "octicon-pencil"}} + {{svg "octicon-x-circle"}} {{end}} diff --git a/web_src/less/_runner.less b/web_src/less/_runner.less index 0a47ba8d93..f5e1953d4a 100644 --- a/web_src/less/_runner.less +++ b/web_src/less/_runner.less @@ -1,5 +1,13 @@ @import "variables.less"; -.admin.runner{ - +.admin.runners { + .runner-ops > a { + margin-left: 0.5em; + } + .runner-ops-delete { + color: var(--color-red-light); + } + .runner-basic-info .dib { + margin-right: 1em; + } } diff --git a/web_src/less/index.less b/web_src/less/index.less index 2d670ac2d5..dafed3eb27 100644 --- a/web_src/less/index.less +++ b/web_src/less/index.less @@ -36,5 +36,6 @@ @import "_explore"; @import "_review"; @import "_package"; +@import "_runner"; @import "./helpers.less";