diff --git a/models/bots/runner.go b/models/bots/runner.go index 78eb62d405..90dcea7294 100644 --- a/models/bots/runner.go +++ b/models/bots/runner.go @@ -19,6 +19,7 @@ import ( // ErrRunnerNotExist represents an error for bot runner not exist type ErrRunnerNotExist struct { + ID int64 UUID string Token string } @@ -79,6 +80,7 @@ type FindRunnerOptions struct { db.ListOptions RepoID int64 OwnerID int64 + Sort string } func (opts FindRunnerOptions) toCond() builder.Cond { @@ -140,6 +142,20 @@ func GetRunnerByUUID(uuid string) (*Runner, error) { return &runner, nil } +// GetRunnerByID returns a bot runner via id +func GetRunnerByID(id int64) (*Runner, error) { + var runner Runner + has, err := db.GetEngine(db.DefaultContext).Where("id=?", id).Get(&runner) + if err != nil { + return nil, err + } else if !has { + return nil, ErrRunnerNotExist{ + ID: id, + } + } + return &runner, nil +} + // GetRunnerByToken returns a bot runner via token func GetRunnerByToken(token string) (*Runner, error) { var runner Runner diff --git a/routers/web/admin/runners.go b/routers/web/admin/runners.go index 952c71466b..ccc7afe963 100644 --- a/routers/web/admin/runners.go +++ b/routers/web/admin/runners.go @@ -65,43 +65,22 @@ func Runners(ctx *context.Context) { ctx.HTML(http.StatusOK, tplRunners) } -// NewRunner render adding a new runner page -func NewRunner(ctx *context.Context) { - ctx.Data["Title"] = ctx.Tr("admin.runners.new") - ctx.Data["PageIsAdmin"] = true - ctx.Data["PageIsAdminRunners"] = true - - ctx.HTML(http.StatusOK, tplRunnerNew) -} - -// NewRunnerPost response for adding a new runner -func NewRunnerPost(ctx *context.Context) { - // form := web.GetForm(ctx).(*forms.AdminCreateRunnerForm) - ctx.Data["Title"] = ctx.Tr("admin.runners.new") - ctx.Data["PageIsAdmin"] = true - ctx.Data["PageIsAdminRunners"] = true - - if ctx.HasError() { - ctx.HTML(http.StatusOK, tplRunnerNew) - return - } - - // ctx.Flash.Success(ctx.Tr("admin.runners.new_success", u.Name)) - // ctx.Redirect(setting.AppSubURL + "/admin/users/" + strconv.FormatInt(u.ID, 10)) -} - // EditRunner show editing runner page func EditRunner(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("admin.runners.edit") ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdminRunners"] = true - prepareUserInfo(ctx) - if ctx.Written() { + runner, err := bots_model.GetBuildByID(ctx.ParamsInt64(":runnerid")) + if err != nil { + ctx.ServerError("GetRunnerByID", err) return } + ctx.Data["Runner"] = runner - ctx.HTML(http.StatusOK, tplUserEdit) + // TODO: get task list for this runner + + ctx.HTML(http.StatusOK, tplRunnerEdit) } // EditRunnerPost response for editing runner @@ -127,3 +106,30 @@ func DeleteRunner(ctx *context.Context) { "redirect": setting.AppSubURL + "/admin/runners", }) } + +/** +// NewRunner render adding a new runner page +func NewRunner(ctx *context.Context) { + ctx.Data["Title"] = ctx.Tr("admin.runners.new") + ctx.Data["PageIsAdmin"] = true + ctx.Data["PageIsAdminRunners"] = true + + ctx.HTML(http.StatusOK, tplRunnerNew) +} + +// NewRunnerPost response for adding a new runner +func NewRunnerPost(ctx *context.Context) { + // form := web.GetForm(ctx).(*forms.AdminCreateRunnerForm) + ctx.Data["Title"] = ctx.Tr("admin.runners.new") + ctx.Data["PageIsAdmin"] = true + ctx.Data["PageIsAdminRunners"] = true + + if ctx.HasError() { + ctx.HTML(http.StatusOK, tplRunnerNew) + return + } + + // ctx.Flash.Success(ctx.Tr("admin.runners.new_success", u.Name)) + // ctx.Redirect(setting.AppSubURL + "/admin/users/" + strconv.FormatInt(u.ID, 10)) +} +**/ diff --git a/routers/web/web.go b/routers/web/web.go index 86b2fa2b43..ecd8e856f6 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -628,7 +628,6 @@ func RegisterRoutes(m *web.Route) { m.Group("/runners", func() { m.Get("", admin.Runners) - m.Combo("/new").Get(admin.NewRunner).Post(bindIgnErr(forms.AdminCreateRunnerForm{}), admin.NewRunnerPost) m.Combo("/{runnerid}").Get(admin.EditRunner).Post(bindIgnErr(forms.AdminEditRunnerForm{}), admin.EditRunnerPost) m.Post("/{runnerid}/delete", admin.DeleteRunner) }) diff --git a/templates/admin/runner/list.tmpl b/templates/admin/runner/list.tmpl index 9500613aba..61adc43161 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" .}} @@ -10,7 +10,7 @@
-
+
@@ -22,26 +22,64 @@ - + - - - + + + + + + + + + + + + + + + + + + + {{range .Runners}} - - - - - - - - + + + + + + + + {{end}}
ID{{.locale.Tr "admin.runners.status"}} - {{.locale.Tr "admin.runners.name"}} + {{.locale.Tr "admin.runners.id"}} {{.locale.Tr "admin.runners.own_type"}}{{.locale.Tr "admin.runners.uuid"}}{{.locale.Tr "admin.runners.created"}}{{.locale.Tr "admin.runners.edit"}}{{.locale.Tr "admin.runners.tags"}}{{.locale.Tr "admin.runners.latest_contact"}}
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"}} +
{{.ID}}{{.Name}}{{.OwnType}}{{.UUID}}{{.Created}}{{svg "octicon-pencil"}}
{{.ID}}{{.Name}}{{.OwnType}}{{.UUID}}{{.Created}} + {{svg "octicon-pencil"}} + {{svg "octicon-x-circle"}} +
diff --git a/web_src/less/_runner.less b/web_src/less/_runner.less new file mode 100644 index 0000000000..0a47ba8d93 --- /dev/null +++ b/web_src/less/_runner.less @@ -0,0 +1,5 @@ +@import "variables.less"; + +.admin.runner{ + +}