mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-08 17:05:45 +02:00
feat(bots): update runner data in html page
This commit is contained in:
parent
848a1ae309
commit
5b989e2a11
@ -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...)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -11,6 +11,10 @@
|
||||
{{template "base/disable_form_autofill"}}
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="runner-basic-info">
|
||||
<div class="field dib">
|
||||
<label>{{.locale.Tr "admin.runners.status"}}</label>
|
||||
<span class="runner-status-{{.Runner.StatusType}}">{{.Runner.StatusType}}</span>
|
||||
</div>
|
||||
<div class="field dib">
|
||||
<label>{{.locale.Tr "admin.runners.last_online"}}</label>
|
||||
<span>{{TimeSinceUnix .Runner.LastOnline $.locale}}</span>
|
||||
@ -55,7 +59,7 @@
|
||||
{{.locale.Tr "admin.runner.task_list"}}
|
||||
</h4>
|
||||
<div class="ui attached segment">
|
||||
Comming soon
|
||||
Comming soon
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -35,7 +35,7 @@
|
||||
<tbody>
|
||||
{{range .Runners}}
|
||||
<tr>
|
||||
<td>status</td>
|
||||
<td><span class="runner-status-{{.StatusType}}">{{.StatusType}}</span></td>
|
||||
<td>
|
||||
<a href="{{$.Link}}/{{.ID}}" class="tooltip" data-content="{{.Description}}">
|
||||
<span class="runner-id">#{{.ID}}</span>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user