diff options
author | Bwko <bouwko@gmail.com> | 2016-12-24 15:41:09 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2016-12-24 22:41:09 +0800 |
commit | a345a03d99f6e3d46a20620869e29424a0c55499 (patch) | |
tree | 5f1b218a6b5d1a782101914bf2d8504f95c76918 /models/issue_label.go | |
parent | f27d87d93ba8578dfc36b636de5dc01e26e58d0d (diff) | |
download | gitea-a345a03d99f6e3d46a20620869e29424a0c55499.tar.gz gitea-a345a03d99f6e3d46a20620869e29424a0c55499.zip |
Added sorting to the labels & milestones page (#199)
Diffstat (limited to 'models/issue_label.go')
-rw-r--r-- | models/issue_label.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/models/issue_label.go b/models/issue_label.go index 39805ba80d..f06f0f97c3 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -171,12 +171,22 @@ func GetLabelsInRepoByIDs(repoID int64, labelIDs []int64) ([]*Label, error) { } // GetLabelsByRepoID returns all labels that belong to given repository by ID. -func GetLabelsByRepoID(repoID int64) ([]*Label, error) { +func GetLabelsByRepoID(repoID int64, sortType string) ([]*Label, error) { labels := make([]*Label, 0, 10) - return labels, x. - Where("repo_id = ?", repoID). - Asc("name"). - Find(&labels) + sess := x.Where("repo_id = ?", repoID) + + switch sortType { + case "reversealphabetically": + sess.Desc("name") + case "leastissues": + sess.Asc("num_issues") + case "mostissues": + sess.Desc("num_issues") + default: + sess.Asc("name") + } + + return labels, sess.Find(&labels) } func getLabelsByIssueID(e Engine, issueID int64) ([]*Label, error) { |