From 49808136c5af5946851c5486d4630482d79eff8b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 12 May 2023 17:43:27 +0900 Subject: [PATCH] Display owner of a runner as a tooltip instead of static text (#24377) Before: ![image](https://user-images.githubusercontent.com/18380374/234779250-8bbd325c-190e-4a30-ac3e-766498d17df5.png) After: ![image](https://user-images.githubusercontent.com/18380374/234779094-e232ecba-d9f4-4d62-a702-6d5e4a522782.png) ![image](https://user-images.githubusercontent.com/18380374/234779120-0293af17-a566-4b69-b454-af4e95844e3b.png) --------- Co-authored-by: silverwind Co-authored-by: Giteabot Co-authored-by: wxiaoguang Co-authored-by: Lunny Xiao --- models/actions/runner.go | 22 +++++++++++++---- models/shared/types/ownertype.go | 29 +++++++++++++++++++++++ options/locale/locale_en-US.ini | 5 ++++ templates/shared/actions/runner_edit.tmpl | 10 ++++---- templates/shared/actions/runner_list.tmpl | 2 +- 5 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 models/shared/types/ownertype.go diff --git a/models/actions/runner.go b/models/actions/runner.go index cce8b4f443..f1638eb0ba 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/shared/types" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/translation" @@ -28,7 +29,7 @@ type ActionRunner struct { Version string `xorm:"VARCHAR(64)"` OwnerID int64 `xorm:"index"` // org level runner, 0 means system Owner *user_model.User `xorm:"-"` - RepoID int64 `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global + RepoID int64 `xorm:"index"` // repo level runner, if OwnerID also is zero, then it's a global Repo *repo_model.Repository `xorm:"-"` Description string `xorm:"TEXT"` Base int // 0 native 1 docker 2 virtual machine @@ -52,14 +53,25 @@ type ActionRunner struct { Deleted timeutil.TimeStamp `xorm:"deleted"` } -func (r *ActionRunner) OwnType() string { +// BelongsToOwnerName before calling, should guarantee that all attributes are loaded +func (r *ActionRunner) BelongsToOwnerName() string { if r.RepoID != 0 { - return fmt.Sprintf("Repo(%s)", r.Repo.FullName()) + return r.Repo.FullName() } if r.OwnerID != 0 { - return fmt.Sprintf("Org(%s)", r.Owner.Name) + return r.Owner.Name } - return "Global" + return "" +} + +func (r *ActionRunner) BelongsToOwnerType() types.OwnerType { + if r.RepoID != 0 { + return types.OwnerTypeRepository + } + if r.OwnerID != 0 { + return types.OwnerTypeOrganization + } + return types.OwnerTypeSystemGlobal } func (r *ActionRunner) Status() runnerv1.RunnerStatus { diff --git a/models/shared/types/ownertype.go b/models/shared/types/ownertype.go new file mode 100644 index 0000000000..e6fe4e4cfd --- /dev/null +++ b/models/shared/types/ownertype.go @@ -0,0 +1,29 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package types + +import "code.gitea.io/gitea/modules/translation" + +type OwnerType string + +const ( + OwnerTypeSystemGlobal = "system-global" + OwnerTypeIndividual = "individual" + OwnerTypeRepository = "repository" + OwnerTypeOrganization = "organization" +) + +func (o OwnerType) LocaleString(locale translation.Locale) string { + switch o { + case OwnerTypeSystemGlobal: + return locale.Tr("concept_system_global") + case OwnerTypeIndividual: + return locale.Tr("concept_user_individual") + case OwnerTypeRepository: + return locale.Tr("concept_code_repository") + case OwnerTypeOrganization: + return locale.Tr("concept_user_organization") + } + return locale.Tr("unknown") +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index ccac8faf99..d7c392a624 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -114,6 +114,11 @@ unknown = Unknown rss_feed = RSS Feed +concept_system_global = Global +concept_user_individual = Individual +concept_code_repository = Repository +concept_user_organization = Organization + [aria] navbar = Navigation Bar footer = Footer diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl index 94da2269b7..657d565d64 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -7,15 +7,15 @@ {{template "base/disable_form_autofill"}} {{.CsrfTokenHtml}}
-
+
{{.Runner.StatusLocaleName $.locale}}
-
+
{{if .LastOnline}}{{TimeSinceUnix .LastOnline $.locale}}{{else}}{{$.locale.Tr "never"}}{{end}}
-
+
{{range .Runner.AgentLabels}} @@ -23,9 +23,9 @@ {{end}}
-
+
- {{.Runner.OwnType}} + {{.Runner.BelongsToOwnerType.LocaleString $.locale}}
diff --git a/templates/shared/actions/runner_list.tmpl b/templates/shared/actions/runner_list.tmpl index f8b056ae7a..7c786d8807 100644 --- a/templates/shared/actions/runner_list.tmpl +++ b/templates/shared/actions/runner_list.tmpl @@ -65,7 +65,7 @@ {{.ID}}

{{.Name}}

{{if .Version}}{{.Version}}{{else}}{{$.locale.Tr "unknown"}}{{end}} - {{.OwnType}} + {{.BelongsToOwnerType.LocaleString $.locale}} {{range .AllLabels}}{{.}}{{end}}