From e33f112e01d2453f8674c05556944277bf38567b Mon Sep 17 00:00:00 2001
From: jladbrook <jhladbrook@gmail.com>
Date: Tue, 12 Sep 2023 13:26:51 +0100
Subject: [PATCH] resolve issue with sort icons on admin/users and
 admin/runners (#24360)

Fixes #24327 to avoid the sort icon changing the table header over
multiple lines and adds missing sort icons on the runners page.
---
 models/actions/runner.go                  |  6 ++++++
 routers/web/shared/actions/runners.go     |  1 +
 templates/shared/actions/runner_list.tmpl | 15 ++++++++++++---
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/models/actions/runner.go b/models/actions/runner.go
index c79a6827fc..ec6b49cf16 100644
--- a/models/actions/runner.go
+++ b/models/actions/runner.go
@@ -189,6 +189,12 @@ func (opts FindRunnerOptions) toOrder() string {
 		return "last_online ASC"
 	case "alphabetically":
 		return "name ASC"
+	case "reversealphabetically":
+		return "name DESC"
+	case "newest":
+		return "id DESC"
+	case "oldest":
+		return "id ASC"
 	}
 	return "last_online DESC"
 }
diff --git a/routers/web/shared/actions/runners.go b/routers/web/shared/actions/runners.go
index cab3d78cac..7ff1f3e33f 100644
--- a/routers/web/shared/actions/runners.go
+++ b/routers/web/shared/actions/runners.go
@@ -53,6 +53,7 @@ func RunnersList(ctx *context.Context, opts actions_model.FindRunnerOptions) {
 	ctx.Data["RegistrationToken"] = token.Token
 	ctx.Data["RunnerOwnerID"] = opts.OwnerID
 	ctx.Data["RunnerRepoID"] = opts.RepoID
+	ctx.Data["SortType"] = opts.Sort
 
 	pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
 
diff --git a/templates/shared/actions/runner_list.tmpl b/templates/shared/actions/runner_list.tmpl
index c4b70282ae..ead260f128 100644
--- a/templates/shared/actions/runner_list.tmpl
+++ b/templates/shared/actions/runner_list.tmpl
@@ -45,9 +45,18 @@
 		<table class="ui very basic striped table unstackable">
 			<thead>
 				<tr>
-					<th data-sortt-asc="online" data-sortt-desc="offline">{{.locale.Tr "actions.runners.status"}}</th>
-					<th data-sortt-asc="alphabetically">{{.locale.Tr "actions.runners.id"}}</th>
-					<th>{{.locale.Tr "actions.runners.name"}}</th>
+					<th data-sortt-asc="online" data-sortt-desc="offline">
+						{{.locale.Tr "actions.runners.status"}}
+						{{SortArrow "online" "offline" .SortType false}}
+					</th>
+					<th data-sortt-asc="newest" data-sortt-desc="oldest">
+						{{.locale.Tr "actions.runners.id"}}
+						{{SortArrow "oldest" "newest" .SortType false}}
+					</th>
+					<th data-sortt-asc="alphabetically" data-sortt-desc="reversealphabetically">
+						{{.locale.Tr "actions.runners.name"}}
+						{{SortArrow "alphabetically" "reversealphabetically" .SortType false}}
+					</th>
 					<th>{{.locale.Tr "actions.runners.version"}}</th>
 					<th>{{.locale.Tr "actions.runners.owner_type"}}</th>
 					<th>{{.locale.Tr "actions.runners.labels"}}</th>