Skip to content

Commit 45e6c00

Browse files
committed
Added sorting to the labels & milestones page
1 parent cf045b0 commit 45e6c00

File tree

7 files changed

+83
-14
lines changed

7 files changed

+83
-14
lines changed

conf/locale/locale_en-US.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ issues.label_modify = Label Modification
551551
issues.label_deletion = Label Deletion
552552
issues.label_deletion_desc = Deleting this label will remove its information in all related issues. Do you want to continue?
553553
issues.label_deletion_success = Label has been deleted successfully!
554+
issues.label.filter_sort.alphabetically = Alphabetically
555+
issues.label.filter_sort.reverse_alphabetically = Reverse alphabetically
554556
issues.num_participants = %d Participants
555557
issues.attachment.open_tab = `Click to see "%s" in a new tab`
556558
issues.attachment.download = `Click to download "%s"`
@@ -604,6 +606,12 @@ milestones.edit_success = Changes of milestone '%s' has been saved successfully!
604606
milestones.deletion = Milestone Deletion
605607
milestones.deletion_desc = Deleting this milestone will remove its information in all related issues. Do you want to continue?
606608
milestones.deletion_success = Milestone has been deleted successfully!
609+
milestones.filter_sort.closest_due_date = Closest due date
610+
milestones.filter_sort.furthest_due_date = Furthest due date
611+
milestones.filter_sort.least_complete = Least complete
612+
milestones.filter_sort.most_complete = Most complete
613+
milestones.filter_sort.most_issues = Most issues
614+
milestones.filter_sort.least_issues = Least issues
607615

608616
wiki = Wiki
609617
wiki.welcome = Welcome to Wiki!

models/issue.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,12 +1456,28 @@ func GetMilestonesByRepoID(repoID int64) ([]*Milestone, error) {
14561456
}
14571457

14581458
// GetMilestones returns a list of milestones of given repository and status.
1459-
func GetMilestones(repoID int64, page int, isClosed bool) ([]*Milestone, error) {
1459+
func GetMilestones(repoID int64, page int, isClosed bool, sortType string) ([]*Milestone, error) {
14601460
miles := make([]*Milestone, 0, setting.UI.IssuePagingNum)
14611461
sess := x.Where("repo_id = ? AND is_closed = ?", repoID, isClosed)
14621462
if page > 0 {
14631463
sess = sess.Limit(setting.UI.IssuePagingNum, (page-1)*setting.UI.IssuePagingNum)
14641464
}
1465+
1466+
switch sortType {
1467+
case "furthestduedate":
1468+
sess.Desc("deadline_unix")
1469+
case "leastcomplete":
1470+
sess.Asc("completeness")
1471+
case "mostcomplete":
1472+
sess.Desc("completeness")
1473+
case "leastissues":
1474+
sess.Asc("num_issues")
1475+
case "mostissues":
1476+
sess.Desc("num_issues")
1477+
default:
1478+
sess.Asc("deadline_unix")
1479+
}
1480+
14651481
return miles, sess.Find(&miles)
14661482
}
14671483

models/issue_label.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,22 @@ func GetLabelsInRepoByIDs(repoID int64, labelIDs []int64) ([]*Label, error) {
144144
}
145145

146146
// GetLabelsByRepoID returns all labels that belong to given repository by ID.
147-
func GetLabelsByRepoID(repoID int64) ([]*Label, error) {
147+
func GetLabelsByRepoID(repoID int64, sortType string) ([]*Label, error) {
148148
labels := make([]*Label, 0, 10)
149-
return labels, x.
150-
Where("repo_id = ?", repoID).
151-
Asc("name").
152-
Find(&labels)
149+
sess := x.Where("repo_id = ?", repoID)
150+
151+
switch sortType {
152+
case "reversealphabetically":
153+
sess.Desc("name")
154+
case "leastissues":
155+
sess.Asc("num_issues")
156+
case "mostissues":
157+
sess.Desc("num_issues")
158+
default:
159+
sess.Asc("name")
160+
}
161+
162+
return labels, sess.Find(&labels)
153163
}
154164

155165
func getLabelsByIssueID(e Engine, issueID int64) ([]*Label, error) {

routers/api/v1/repo/label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func ListLabels(ctx *context.APIContext) {
15-
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
15+
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"))
1616
if err != nil {
1717
ctx.Error(500, "GetLabelsByRepoID", err)
1818
return

routers/repo/issue.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func MustAllowPulls(ctx *context.Context) {
7777
}
7878

7979
func RetrieveLabels(ctx *context.Context) {
80-
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
80+
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort"))
8181
if err != nil {
8282
ctx.Handle(500, "RetrieveLabels.GetLabels", err)
8383
return
@@ -87,6 +87,7 @@ func RetrieveLabels(ctx *context.Context) {
8787
}
8888
ctx.Data["Labels"] = labels
8989
ctx.Data["NumLabels"] = len(labels)
90+
ctx.Data["SortType"] = ctx.Query("sort")
9091
}
9192

9293
func Issues(ctx *context.Context) {
@@ -257,12 +258,12 @@ func renderAttachmentSettings(ctx *context.Context) {
257258

258259
func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) {
259260
var err error
260-
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false)
261+
ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "")
261262
if err != nil {
262263
ctx.Handle(500, "GetMilestones", err)
263264
return
264265
}
265-
ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true)
266+
ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "")
266267
if err != nil {
267268
ctx.Handle(500, "GetMilestones", err)
268269
return
@@ -280,7 +281,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models.
280281
return nil
281282
}
282283

283-
labels, err := models.GetLabelsByRepoID(repo.ID)
284+
labels, err := models.GetLabelsByRepoID(repo.ID, "")
284285
if err != nil {
285286
ctx.Handle(500, "GetLabelsByRepoID", err)
286287
return nil
@@ -557,7 +558,7 @@ func ViewIssue(ctx *context.Context) {
557558
for i := range issue.Labels {
558559
labelIDMark[issue.Labels[i].ID] = true
559560
}
560-
labels, err := models.GetLabelsByRepoID(repo.ID)
561+
labels, err := models.GetLabelsByRepoID(repo.ID, "")
561562
if err != nil {
562563
ctx.Handle(500, "GetLabelsByRepoID", err)
563564
return
@@ -1039,6 +1040,7 @@ func Milestones(ctx *context.Context) {
10391040
ctx.Data["OpenCount"] = openCount
10401041
ctx.Data["ClosedCount"] = closedCount
10411042

1043+
sortType := ctx.Query("sort")
10421044
page := ctx.QueryInt("page")
10431045
if page <= 1 {
10441046
page = 1
@@ -1052,7 +1054,7 @@ func Milestones(ctx *context.Context) {
10521054
}
10531055
ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5)
10541056

1055-
miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed)
1057+
miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType)
10561058
if err != nil {
10571059
ctx.Handle(500, "GetMilestones", err)
10581060
return
@@ -1068,8 +1070,9 @@ func Milestones(ctx *context.Context) {
10681070
ctx.Data["State"] = "open"
10691071
}
10701072

1073+
ctx.Data["SortType"] = sortType
10711074
ctx.Data["IsShowClosed"] = isShowClosed
1072-
ctx.HTML(200, MILESTONE)
1075+
ctx.HTML(200, tplMilestone)
10731076
}
10741077

10751078
func NewMilestone(ctx *context.Context) {

templates/repo/issue/labels.tmpl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@
3434
</div>
3535
<div class="ui divider"></div>
3636

37+
<div class="ui right floated secondary filter menu">
38+
<!-- Sort -->
39+
<div class="ui dropdown type jump item">
40+
<span class="text">
41+
{{.i18n.Tr "repo.issues.filter_sort"}}
42+
<i class="dropdown icon"></i>
43+
</span>
44+
<div class="menu">
45+
<a class="{{if or (eq .SortType "alphabetically") (not .SortType)}}active{{end}} item" href="{{$.Link}}?sort=alphabetically&state={{$.State}}">{{.i18n.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
46+
<a class="{{if eq .SortType "reversealphabetically"}}active{{end}} item" href="{{$.Link}}?sort=reversealphabetically&state={{$.State}}">{{.i18n.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
47+
<a class="{{if eq .SortType "leastissues"}}active{{end}} item" href="{{$.Link}}?sort=leastissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_issues"}}</a>
48+
<a class="{{if eq .SortType "mostissues"}}active{{end}} item" href="{{$.Link}}?sort=mostissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_issues"}}</a>
49+
</div>
50+
</div>
51+
</div>
3752
{{template "base/alert" .}}
3853
<div class="ui black label">{{.i18n.Tr "repo.issues.label_count" .NumLabels}}</div>
3954
<div class="label list">

templates/repo/issue/milestones.tmpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@
2323
</a>
2424
</div>
2525

26+
<div class="ui right floated secondary filter menu">
27+
<!-- Sort -->
28+
<div class="ui dropdown type jump item">
29+
<span class="text">
30+
{{.i18n.Tr "repo.issues.filter_sort"}}
31+
<i class="dropdown icon"></i>
32+
</span>
33+
<div class="menu">
34+
<a class="{{if or (eq .SortType "closestduedate") (not .SortType)}}active{{end}} item" href="{{$.Link}}?sort=closestduedate&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.closest_due_date"}}</a>
35+
<a class="{{if eq .SortType "furthestduedate"}}active{{end}} item" href="{{$.Link}}?sort=furthestduedate&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.furthest_due_date"}}</a>
36+
<a class="{{if eq .SortType "leastcomplete"}}active{{end}} item" href="{{$.Link}}?sort=leastcomplete&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_complete"}}</a>
37+
<a class="{{if eq .SortType "mostcomplete"}}active{{end}} item" href="{{$.Link}}?sort=mostcomplete&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_complete"}}</a>
38+
<a class="{{if eq .SortType "mostissues"}}active{{end}} item" href="{{$.Link}}?sort=mostissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_issues"}}</a>
39+
<a class="{{if eq .SortType "leastissues"}}active{{end}} item" href="{{$.Link}}?sort=leastissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_issues"}}</a>
40+
</div>
41+
</div>
42+
</div>
2643
<div class="milestone list">
2744
{{range .Milestones}}
2845
<li class="item">

0 commit comments

Comments
 (0)