From b257e0456b819e4ee460acd9d1f449bd09c71ad0 Mon Sep 17 00:00:00 2001
From: stevegt <stevegt@t7a.org>
Date: Tue, 5 Mar 2019 15:39:41 +0100
Subject: [PATCH] Add ability to sort issues by due date (#6206) (#6244)

Signed-off-by: Steve Traugott <stevegt@t7a.org>
---
 models/issue.go                      | 4 ++++
 options/locale/locale_en-US.ini      | 2 ++
 templates/repo/issue/list.tmpl       | 2 ++
 templates/user/dashboard/issues.tmpl | 2 ++
 4 files changed, 10 insertions(+)

diff --git a/models/issue.go b/models/issue.go
index 396c029d46..0429ac4c8c 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -1279,6 +1279,10 @@ func sortIssuesSession(sess *xorm.Session, sortType string) {
 		sess.Asc("issue.num_comments")
 	case "priority":
 		sess.Desc("issue.priority")
+	case "nearduedate":
+		sess.Asc("issue.deadline_unix")
+	case "farduedate":
+		sess.Desc("issue.deadline_unix")
 	default:
 		sess.Desc("issue.created_unix")
 	}
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index c5a62cb488..f188f1f2ae 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -722,6 +722,8 @@ issues.filter_sort.recentupdate = Recently updated
 issues.filter_sort.leastupdate = Least recently updated
 issues.filter_sort.mostcomment = Most commented
 issues.filter_sort.leastcomment = Least commented
+issues.filter_sort.nearduedate = Nearest due date
+issues.filter_sort.farduedate = Farthest due date
 issues.filter_sort.moststars = Most stars
 issues.filter_sort.feweststars = Fewest stars
 issues.filter_sort.mostforks = Most forks
diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl
index 023dfececd..758b64f27e 100644
--- a/templates/repo/issue/list.tmpl
+++ b/templates/repo/issue/list.tmpl
@@ -106,6 +106,8 @@
 							<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort=leastupdate&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
 							<a class="{{if eq .SortType "mostcomment"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort=mostcomment&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_sort.mostcomment"}}</a>
 							<a class="{{if eq .SortType "leastcomment"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort=leastcomment&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_sort.leastcomment"}}</a>
+							<a class="{{if eq .SortType "nearduedate"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort=nearduedate&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_sort.nearduedate"}}</a>
+							<a class="{{if eq .SortType "farduedate"}}active{{end}} item" href="{{$.Link}}?q={{$.Keyword}}&type={{$.ViewType}}&sort=farduedate&state={{$.State}}&labels={{.SelectLabels}}&milestone={{$.MilestoneID}}&assignee={{$.AssigneeID}}">{{.i18n.Tr "repo.issues.filter_sort.farduedate"}}</a>
 						</div>
 					</div>
 				</div>
diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl
index fe27a4439c..b5990e61e0 100644
--- a/templates/user/dashboard/issues.tmpl
+++ b/templates/user/dashboard/issues.tmpl
@@ -53,6 +53,8 @@
 							<a class="{{if eq .SortType "leastupdate"}}active{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&repo={{.RepoID}}&sort=leastupdate&state={{$.State}}">{{.i18n.Tr "repo.issues.filter_sort.leastupdate"}}</a>
 							<a class="{{if eq .SortType "mostcomment"}}active{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&repo={{.RepoID}}&sort=mostcomment&state={{$.State}}">{{.i18n.Tr "repo.issues.filter_sort.mostcomment"}}</a>
 							<a class="{{if eq .SortType "leastcomment"}}active{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&repo={{.RepoID}}&sort=leastcomment&state={{$.State}}">{{.i18n.Tr "repo.issues.filter_sort.leastcomment"}}</a>
+							<a class="{{if eq .SortType "nearduedate"}}active{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&repo={{.RepoID}}&sort=nearduedate&state={{$.State}}">{{.i18n.Tr "repo.issues.filter_sort.nearduedate"}}</a>
+							<a class="{{if eq .SortType "farduedate"}}active{{end}} item" href="{{$.Link}}?type={{$.ViewType}}&repo={{.RepoID}}&sort=farduedate&state={{$.State}}">{{.i18n.Tr "repo.issues.filter_sort.farduedate"}}</a>
 						</div>
 					</div>
 				</div>