mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	Display owner of a runner as a tooltip instead of static text (#24377)
Before:  After:   --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		@@ -11,6 +11,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"code.gitea.io/gitea/models/db"
 | 
						"code.gitea.io/gitea/models/db"
 | 
				
			||||||
	repo_model "code.gitea.io/gitea/models/repo"
 | 
						repo_model "code.gitea.io/gitea/models/repo"
 | 
				
			||||||
 | 
						"code.gitea.io/gitea/models/shared/types"
 | 
				
			||||||
	user_model "code.gitea.io/gitea/models/user"
 | 
						user_model "code.gitea.io/gitea/models/user"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/timeutil"
 | 
						"code.gitea.io/gitea/modules/timeutil"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/translation"
 | 
						"code.gitea.io/gitea/modules/translation"
 | 
				
			||||||
@@ -28,7 +29,7 @@ type ActionRunner struct {
 | 
				
			|||||||
	Version     string                 `xorm:"VARCHAR(64)"`
 | 
						Version     string                 `xorm:"VARCHAR(64)"`
 | 
				
			||||||
	OwnerID     int64                  `xorm:"index"` // org level runner, 0 means system
 | 
						OwnerID     int64                  `xorm:"index"` // org level runner, 0 means system
 | 
				
			||||||
	Owner       *user_model.User       `xorm:"-"`
 | 
						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:"-"`
 | 
						Repo        *repo_model.Repository `xorm:"-"`
 | 
				
			||||||
	Description string                 `xorm:"TEXT"`
 | 
						Description string                 `xorm:"TEXT"`
 | 
				
			||||||
	Base        int                    // 0 native 1 docker 2 virtual machine
 | 
						Base        int                    // 0 native 1 docker 2 virtual machine
 | 
				
			||||||
@@ -52,14 +53,25 @@ type ActionRunner struct {
 | 
				
			|||||||
	Deleted timeutil.TimeStamp `xorm:"deleted"`
 | 
						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 {
 | 
						if r.RepoID != 0 {
 | 
				
			||||||
		return fmt.Sprintf("Repo(%s)", r.Repo.FullName())
 | 
							return r.Repo.FullName()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if r.OwnerID != 0 {
 | 
						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 {
 | 
					func (r *ActionRunner) Status() runnerv1.RunnerStatus {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										29
									
								
								models/shared/types/ownertype.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								models/shared/types/ownertype.go
									
									
									
									
									
										Normal file
									
								
							@@ -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")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -114,6 +114,11 @@ unknown = Unknown
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
rss_feed = RSS Feed
 | 
					rss_feed = RSS Feed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					concept_system_global = Global
 | 
				
			||||||
 | 
					concept_user_individual = Individual
 | 
				
			||||||
 | 
					concept_code_repository = Repository
 | 
				
			||||||
 | 
					concept_user_organization = Organization
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[aria]
 | 
					[aria]
 | 
				
			||||||
navbar = Navigation Bar
 | 
					navbar = Navigation Bar
 | 
				
			||||||
footer = Footer
 | 
					footer = Footer
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,15 +7,15 @@
 | 
				
			|||||||
			{{template "base/disable_form_autofill"}}
 | 
								{{template "base/disable_form_autofill"}}
 | 
				
			||||||
			{{.CsrfTokenHtml}}
 | 
								{{.CsrfTokenHtml}}
 | 
				
			||||||
			<div class="runner-basic-info">
 | 
								<div class="runner-basic-info">
 | 
				
			||||||
				<div class="field gt-dib gt-mr-4 disabled">
 | 
									<div class="field gt-dib gt-mr-4">
 | 
				
			||||||
					<label>{{.locale.Tr "actions.runners.status"}}</label>
 | 
										<label>{{.locale.Tr "actions.runners.status"}}</label>
 | 
				
			||||||
					<span class="runner-status-{{if .Runner.IsOnline}}online{{else}}offline{{end}}">{{.Runner.StatusLocaleName $.locale}}</span>
 | 
										<span class="runner-status-{{if .Runner.IsOnline}}online{{else}}offline{{end}}">{{.Runner.StatusLocaleName $.locale}}</span>
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
				<div class="field gt-dib gt-mr-4 disabled">
 | 
									<div class="field gt-dib gt-mr-4">
 | 
				
			||||||
					<label>{{.locale.Tr "actions.runners.last_online"}}</label>
 | 
										<label>{{.locale.Tr "actions.runners.last_online"}}</label>
 | 
				
			||||||
					<span>{{if .LastOnline}}{{TimeSinceUnix .LastOnline $.locale}}{{else}}{{$.locale.Tr "never"}}{{end}}</span>
 | 
										<span>{{if .LastOnline}}{{TimeSinceUnix .LastOnline $.locale}}{{else}}{{$.locale.Tr "never"}}{{end}}</span>
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
				<div class="field gt-dib gt-mr-4 disabled">
 | 
									<div class="field gt-dib gt-mr-4">
 | 
				
			||||||
					<label>{{.locale.Tr "actions.runners.agent_labels"}}</label>
 | 
										<label>{{.locale.Tr "actions.runners.agent_labels"}}</label>
 | 
				
			||||||
					<span>
 | 
										<span>
 | 
				
			||||||
						{{range .Runner.AgentLabels}}
 | 
											{{range .Runner.AgentLabels}}
 | 
				
			||||||
@@ -23,9 +23,9 @@
 | 
				
			|||||||
						{{end}}
 | 
											{{end}}
 | 
				
			||||||
					</span>
 | 
										</span>
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
				<div class="field gt-dib gt-mr-4 disabled">
 | 
									<div class="field gt-dib gt-mr-4">
 | 
				
			||||||
					<label>{{.locale.Tr "actions.runners.owner_type"}}</label>
 | 
										<label>{{.locale.Tr "actions.runners.owner_type"}}</label>
 | 
				
			||||||
					<span>{{.Runner.OwnType}}</span>
 | 
										<span data-tooltip-content="{{.Runner.BelongsToOwnerName}}">{{.Runner.BelongsToOwnerType.LocaleString $.locale}}</span>
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
			</div>
 | 
								</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,7 +65,7 @@
 | 
				
			|||||||
						<td>{{.ID}}</td>
 | 
											<td>{{.ID}}</td>
 | 
				
			||||||
						<td><p data-tooltip-content="{{.Description}}">{{.Name}}</p></td>
 | 
											<td><p data-tooltip-content="{{.Description}}">{{.Name}}</p></td>
 | 
				
			||||||
						<td>{{if .Version}}{{.Version}}{{else}}{{$.locale.Tr "unknown"}}{{end}}</td>
 | 
											<td>{{if .Version}}{{.Version}}{{else}}{{$.locale.Tr "unknown"}}{{end}}</td>
 | 
				
			||||||
						<td>{{.OwnType}}</td>
 | 
											<td><span data-tooltip-content="{{.BelongsToOwnerName}}">{{.BelongsToOwnerType.LocaleString $.locale}}<span></td>
 | 
				
			||||||
						<td class="runner-tags">
 | 
											<td class="runner-tags">
 | 
				
			||||||
							{{range .AllLabels}}<span class="ui label">{{.}}</span>{{end}}
 | 
												{{range .AllLabels}}<span class="ui label">{{.}}</span>{{end}}
 | 
				
			||||||
						</td>
 | 
											</td>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user