diff --git a/models/bots/runner.go b/models/bots/runner.go index 7112d45784..f2824b1dc9 100644 --- a/models/bots/runner.go +++ b/models/bots/runner.go @@ -74,6 +74,18 @@ func (r *Runner) OwnType() string { return r.Repo.FullName() } +func (r *Runner) StatusType() string { + switch r.Status { + case runnerv1.RunnerStatus_RUNNER_STATUS_OFFLINE: + return "offline" + case runnerv1.RunnerStatus_RUNNER_STATUS_IDLE: + return "online" + case runnerv1.RunnerStatus_RUNNER_STATUS_ACTIVE: + return "online" + } + return "unknown" +} + // AllLabels returns agent and custom labels func (r *Runner) AllLabels() []string { return append(r.AgentLabels, r.CustomLabels...) diff --git a/routers/web/admin/runners.go b/routers/web/admin/runners.go index a37cce8661..c44a425973 100644 --- a/routers/web/admin/runners.go +++ b/routers/web/admin/runners.go @@ -8,12 +8,16 @@ package admin import ( "net/http" "net/url" + "strings" bots_model "code.gitea.io/gitea/models/bots" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/web" + "code.gitea.io/gitea/services/forms" ) const ( @@ -88,18 +92,33 @@ func EditRunner(ctx *context.Context) { // EditRunnerPost response for editing runner func EditRunnerPost(ctx *context.Context) { - // form := web.GetForm(ctx).(*forms.AdminEditRunnerForm) + runner, err := bots_model.GetRunnerByID(ctx.ParamsInt64(":runnerid")) + if err != nil { + log.Warn("EditRunnerPost.GetRunnerByID failed: %v, url: %s", err, ctx.Req.URL) + ctx.ServerError("EditRunnerPost.GetRunnerByID", err) + return + } + + form := web.GetForm(ctx).(*forms.AdminEditRunnerForm) + runner.Description = form.Description + runner.CustomLabels = strings.Split(form.CustomLabels, ",") + + err = bots_model.UpdateRunner(ctx, runner, "description", "custom_labels") + if err != nil { + log.Warn("EditRunnerPost.UpdateRunner failed: %v, url: %s", err, ctx.Req.URL) + ctx.Flash.Warning(ctx.Tr("admin.runners.edit_failed")) + ctx.Redirect(setting.AppSubURL + "/admin/runners/" + url.PathEscape(ctx.Params(":runnerid"))) + return + } + ctx.Data["Title"] = ctx.Tr("admin.runners.edit") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminRunners"] = true - if ctx.HasError() { - ctx.HTML(http.StatusOK, tplUserEdit) - return - } + log.Debug("EditRunnerPost success: %s", ctx.Req.URL) - ctx.Flash.Success(ctx.Tr("admin.users.update_profile_success")) - ctx.Redirect(setting.AppSubURL + "/admin/users/" + url.PathEscape(ctx.Params(":userid"))) + ctx.Flash.Success(ctx.Tr("admin.runners.edit_success")) + ctx.Redirect(setting.AppSubURL + "/admin/runners/" + url.PathEscape(ctx.Params(":runnerid"))) } // DeleteRunner response for deleting a runner diff --git a/services/forms/admin.go b/services/forms/admin.go index 8c1ba0589e..8a1e679f68 100644 --- a/services/forms/admin.go +++ b/services/forms/admin.go @@ -86,8 +86,8 @@ func (f *AdminCreateRunnerForm) Validate(req *http.Request, errs binding.Errors) // AdminEditRunnerForm form for admin to create runner type AdminEditRunnerForm struct { - Name string `binding:"Required"` - Type string + Description string + CustomLabels string } // Validate validates form fields diff --git a/templates/admin/runner/edit.tmpl b/templates/admin/runner/edit.tmpl index 5a7f7f8c20..b12b53101c 100644 --- a/templates/admin/runner/edit.tmpl +++ b/templates/admin/runner/edit.tmpl @@ -11,6 +11,10 @@ {{template "base/disable_form_autofill"}} {{.CsrfTokenHtml}}
+
+ + {{.Runner.StatusType}} +
{{TimeSinceUnix .Runner.LastOnline $.locale}} @@ -55,7 +59,7 @@ {{.locale.Tr "admin.runner.task_list"}}
- Comming soon + Comming soon
diff --git a/templates/admin/runner/list.tmpl b/templates/admin/runner/list.tmpl index dc85a82d3d..d0167fb910 100644 --- a/templates/admin/runner/list.tmpl +++ b/templates/admin/runner/list.tmpl @@ -35,7 +35,7 @@ {{range .Runners}} - status + {{.StatusType}} #{{.ID}} diff --git a/web_src/less/_runner.less b/web_src/less/_runner.less index f5e1953d4a..dacbe94f9e 100644 --- a/web_src/less/_runner.less +++ b/web_src/less/_runner.less @@ -10,4 +10,9 @@ .runner-basic-info .dib { margin-right: 1em; } + .runner-status-online{ + .ui.label; + background-color: var(--color-green); + color: var(--color-white); + } }