1
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-04-18 00:47:48 -04:00

feat(runner): update edit.html

This commit is contained in:
fuxiaohei 2022-10-10 21:53:53 +08:00 committed by Jason Song
parent 206b2a104e
commit dff0d4b907
6 changed files with 91 additions and 218 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -1,197 +1,61 @@
{{template "base/head" .}}
<div class="page-content admin edit user">
<div class="page-content admin runners">
{{template "admin/navbar" .}}
<div class="ui container">
{{template "base/alert" .}}
<h4 class="ui top attached header">
{{.locale.Tr "admin.users.edit_account"}}
{{.locale.Tr "admin.runners.runner_title"}} #{{.Runner.ID}} {{.Runner.Name}}
</h4>
<div class="ui attached segment">
<form class="ui form" action="{{.Link}}" method="post">
{{template "base/disable_form_autofill"}}
{{.CsrfTokenHtml}}
<div class="field {{if .Err_UserName}}error{{end}}">
<label for="user_name">{{.locale.Tr "username"}}</label>
<input id="user_name" name="user_name" value="{{.User.Name}}" autofocus {{if not .User.IsLocal }}disabled{{end}}>
</div>
<!-- Types and name -->
<div class="inline required field {{if .Err_LoginType}}error{{end}}">
<label>{{.locale.Tr "admin.users.auth_source"}}</label>
<div class="ui selection type dropdown">
<input type="hidden" id="login_type" name="login_type" value="{{.LoginSource.Type.Int}}-{{.LoginSource.ID}}" required>
<div class="text">{{.locale.Tr "admin.users.local"}}</div>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<div class="item" data-value="0-0">{{.locale.Tr "admin.users.local"}}</div>
{{range .Sources}}
<div class="item" data-value="{{.Type.Int}}-{{.ID}}">{{.Name}}</div>
<div class="runner-basic-info">
<div class="field dib">
<label>{{.locale.Tr "admin.runners.last_online"}}</label>
<span>{{TimeSinceUnix .Runner.LastOnline $.locale}}</span>
</div>
<div class="field dib">
<label>{{.locale.Tr "admin.runners.agent_labels"}}</label>
<span>
{{range .Runner.AgentLabels}}
<span>{{.}}</span>
{{end}}
</div>
</span>
</div>
<div class="field dib">
<label>{{.locale.Tr "admin.runners.owner_type"}}</label>
<span>{{.Runner.OwnType}}</span>
</div>
</div>
<div class="inline field {{if .Err_Visibility}}error{{end}}">
<span class="inline required field"><label for="visibility">{{.locale.Tr "settings.visibility"}}</label></span>
<div class="ui selection type dropdown">
{{if .User.Visibility.IsPublic}}<input type="hidden" id="visibility" name="visibility" value="0">{{end}}
{{if .User.Visibility.IsLimited}}<input type="hidden" id="visibility" name="visibility" value="1">{{end}}
{{if .User.Visibility.IsPrivate}}<input type="hidden" id="visibility" name="visibility" value="2">{{end}}
<div class="text">
{{if .User.Visibility.IsPublic}}{{.locale.Tr "settings.visibility.public"}}{{end}}
{{if .User.Visibility.IsLimited}}{{.locale.Tr "settings.visibility.limited"}}{{end}}
{{if .User.Visibility.IsPrivate}}{{.locale.Tr "settings.visibility.private"}}{{end}}
</div>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
{{range $mode := .AllowedUserVisibilityModes}}
{{if $mode.IsPublic}}
<div class="item tooltip" data-content="{{$.locale.Tr "settings.visibility.public_tooltip"}}" data-value="0">{{$.locale.Tr "settings.visibility.public"}}</div>
{{else if $mode.IsLimited}}
<div class="item tooltip" data-content="{{$.locale.Tr "settings.visibility.limited_tooltip"}}" data-value="1">{{$.locale.Tr "settings.visibility.limited"}}</div>
{{else if $mode.IsPrivate}}
<div class="item tooltip" data-content="{{$.locale.Tr "settings.visibility.private_tooltip"}}" data-value="2">{{$.locale.Tr "settings.visibility.private"}}</div>
{{end}}
{{end}}
</div>
</div>
</div>
<div class="required non-local field {{if .Err_LoginName}}error{{end}} {{if eq .User.LoginSource 0}}hide{{end}}">
<label for="login_name">{{.locale.Tr "admin.users.auth_login_name"}}</label>
<input id="login_name" name="login_name" value="{{.User.LoginName}}" autofocus>
</div>
<div class="field {{if .Err_FullName}}error{{end}}">
<label for="full_name">{{.locale.Tr "settings.full_name"}}</label>
<input id="full_name" name="full_name" value="{{.User.FullName}}">
</div>
<div class="required field {{if .Err_Email}}error{{end}}">
<label for="email">{{.locale.Tr "email"}}</label>
<input id="email" name="email" type="email" value="{{.User.Email}}" autofocus required>
</div>
<div class="local field {{if .Err_Password}}error{{end}} {{if not (or (.User.IsLocal) (.User.IsOAuth2))}}hide{{end}}">
<label for="password">{{.locale.Tr "password"}}</label>
<input id="password" name="password" type="password" autocomplete="new-password">
<p class="help">{{.locale.Tr "admin.users.password_helper"}}</p>
</div>
<div class="field {{if .Err_Website}}error{{end}}">
<label for="website">{{.locale.Tr "settings.website"}}</label>
<input id="website" name="website" type="url" value="{{.User.Website}}" placeholder="e.g. http://mydomain.com or https://mydomain.com">
</div>
<div class="field {{if .Err_Location}}error{{end}}">
<label for="location">{{.locale.Tr "settings.location"}}</label>
<input id="location" name="location" value="{{.User.Location}}">
</div>
<div class="ui divider"></div>
<div class="inline field {{if .Err_MaxRepoCreation}}error{{end}}">
<label for="max_repo_creation">{{.locale.Tr "admin.users.max_repo_creation"}}</label>
<input id="max_repo_creation" name="max_repo_creation" type="number" value="{{.User.MaxRepoCreation}}">
<p class="help">{{.locale.Tr "admin.users.max_repo_creation_desc"}}</p>
</div>
<div class="ui divider"></div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.locale.Tr "admin.users.is_activated"}}</strong></label>
<input name="active" type="checkbox" {{if .User.IsActive}}checked{{end}}>
</div>
</div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.locale.Tr "admin.users.prohibit_login"}}</strong></label>
<input name="prohibit_login" type="checkbox" {{if .User.ProhibitLogin}}checked{{end}} {{if (eq .User.ID .SignedUserID)}}disabled{{end}}>
</div>
</div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.locale.Tr "admin.users.is_admin"}}</strong></label>
<input name="admin" type="checkbox" {{if .User.IsAdmin}}checked{{end}}>
</div>
</div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.locale.Tr "admin.users.is_restricted"}}</strong></label>
<input name="restricted" type="checkbox" {{if .User.IsRestricted}}checked{{end}}>
</div>
</div>
<div class="inline field"{{if DisableGitHooks}} hidden{{end}}>
<div class="ui checkbox tooltip" data-content="{{.locale.Tr "admin.users.allow_git_hook_tooltip"}}" data-variation="very wide">
<label><strong>{{.locale.Tr "admin.users.allow_git_hook"}}</strong></label>
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if DisableGitHooks}}disabled{{end}}>
</div>
</div>
<div class="inline field" {{if or (DisableImportLocal) (.DisableMigrations)}}hidden{{end}}>
<div class="ui checkbox">
<label><strong>{{.locale.Tr "admin.users.allow_import_local"}}</strong></label>
<input name="allow_import_local" type="checkbox" {{if .User.CanImportLocal}}checked{{end}} {{if DisableImportLocal}}disabled{{end}}>
</div>
</div>
{{if not .DisableRegularOrgCreation}}
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.locale.Tr "admin.users.allow_create_organization"}}</strong></label>
<input name="allow_create_organization" type="checkbox" {{if .User.CanCreateOrganization}}checked{{end}}>
</div>
</div>
{{end}}
{{if .TwoFactorEnabled}}
<div class="ui divider"></div>
<div class="inline field">
<div class="ui checkbox">
<label><strong>{{.locale.Tr "admin.users.reset_2fa"}}</strong></label>
<input name="reset_2fa" type="checkbox">
</div>
</div>
{{end}}
<div class="ui divider"></div>
<div class="field">
<button class="ui green button">{{.locale.Tr "admin.users.update_profile"}}</button>
<div class="ui red button delete-button" data-url="{{$.Link}}/delete" data-id="{{.User.ID}}">{{.locale.Tr "admin.users.delete_account"}}</div>
<label for="description">{{.locale.Tr "admin.runners.description"}}</label>
<input id="description" name="description" value="{{.Runner.Description}}">
</div>
<div class="field">
<label for="custom_labels">{{.locale.Tr "admin.runners.custom_labels"}}</label>
<input id="custom_labels" name="custom_labels" value="{{Join .Runner.CustomLabels `,`}}">
<p class="help">{{.locale.Tr "admin.runners.custom_labels_helper"}}</p>
</div>
<div class="ui divider"></div>
<div class="field">
<button class="ui green button">{{.locale.Tr "admin.runners.update_runner"}}</button>
<div class="ui red button delete-button" data-url="{{$.Link}}/delete" data-id="{{.Runner.ID}}">
{{.locale.Tr "admin.runners.delete_runner"}}</div>
</div>
</form>
</div>
<h4 class="ui top attached header">
{{.locale.Tr "settings.avatar"}}
{{.locale.Tr "admin.runner.task_list"}}
</h4>
<div class="ui attached segment">
<form class="ui form" action="{{.Link}}/avatar" method="post" enctype="multipart/form-data">
{{.CsrfTokenHtml}}
{{if not DisableGravatar}}
<div class="inline field">
<div class="ui radio checkbox">
<input name="source" value="lookup" type="radio" {{if not .User.UseCustomAvatar}}checked{{end}}>
<label>{{.locale.Tr "settings.lookup_avatar_by_mail"}}</label>
</div>
</div>
<div class="field {{if .Err_Gravatar}}error{{end}}">
<label for="gravatar">Avatar {{.locale.Tr "email"}}</label>
<input id="gravatar" name="gravatar" value="{{.User.AvatarEmail}}" />
</div>
{{end}}
<div class="inline field">
<div class="ui radio checkbox">
<input name="source" value="local" type="radio" {{if .User.UseCustomAvatar}}checked{{end}}>
<label>{{.locale.Tr "settings.enable_custom_avatar"}}</label>
</div>
</div>
<div class="inline field">
<label for="avatar">{{.locale.Tr "settings.choose_new_avatar"}}</label>
<input name="avatar" type="file" >
</div>
<div class="field">
<button class="ui green button">{{$.locale.Tr "settings.update_avatar"}}</button>
<a class="ui red button delete-post" data-request-url="{{.Link}}/avatar/delete" data-done-url="{{.Link}}">{{$.locale.Tr "settings.delete_current_avatar"}}</a>
</div>
</form>
Comming soon
</div>
</div>
</div>

View File

@ -1,5 +1,5 @@
{{template "base/head" .}}
<div class="page-content admin runner">
<div class="page-content admin runners">
{{template "admin/navbar" .}}
<div class="ui container">
{{template "base/alert" .}}
@ -33,51 +33,25 @@
</tr>
</thead>
<tbody>
<tr>
<td>online</td>
<td><a href="?">
<span class="runner-id">#1</span>
<span class="runner-name">focused_mcclintock</span>
</a></td>
<td>shared</td>
<td class="runner-tags">
<span>linux</span>
<span>amd64</span>
</td>
<td>3 days ago</td>
<td class="runner-ops">
<a href="#">{{svg "octicon-pencil"}}</a>
</td>
</tr>
<tr>
<td>offline</td>
<td><a href="?">
<span class="runner-id">#2</span>
<span class="runner-name">lucid_khorana</span>
</a></td>
<td>shared</td>
<td class="runner-tags">
<span>linux</span>
<span>aarch64</span>
<span>self-host</span>
<span>custom</span>
</td>
<td>3 minutes ago</td>
<td class="runner-ops">
<a href="#">{{svg "octicon-pencil"}}</a>
<a href="#">{{svg "octicon-x-circle"}}</a>
</td>
</tr>
{{range .Runners}}
<tr>
<td>{{.ID}}</td>
<td>{{.Name}}</td>
<td>status</td>
<td>
<a href="{{$.Link}}/{{.ID}}" class="tooltip" data-content="{{.Description}}">
<span class="runner-id">#{{.ID}}</span>
<span class="runner-name">{{.Name}}</span>
</a>
</td>
<td>{{.OwnType}}</td>
<td>{{.UUID}}</td>
<td>{{.Created}}</td>
<td class="runner-tags">
{{range .AllLabels}}
<span>{{.}}</span>
{{end}}
</td>
<td>{{TimeSinceUnix .LastOnline $.locale}}</td>
<td class="runner-ops">
<a href="#">{{svg "octicon-pencil"}}</a>
<a href="#">{{svg "octicon-x-circle"}}</a>
<a href="{{$.Link}}/{{.ID}}">{{svg "octicon-pencil"}}</a>
<a class="runner-ops-delete" href="{{$.Link}}/{{.ID}}/delete">{{svg "octicon-x-circle"}}</a>
</td>
</tr>
{{end}}

View File

@ -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;
}
}

View File

@ -36,5 +36,6 @@
@import "_explore";
@import "_review";
@import "_package";
@import "_runner";
@import "./helpers.less";