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 | |
parent | f27d87d93ba8578dfc36b636de5dc01e26e58d0d (diff) | |
download | gitea-a345a03d99f6e3d46a20620869e29424a0c55499.tar.gz gitea-a345a03d99f6e3d46a20620869e29424a0c55499.zip |
Added sorting to the labels & milestones page (#199)
-rw-r--r-- | models/issue.go | 18 | ||||
-rw-r--r-- | models/issue_label.go | 20 | ||||
-rw-r--r-- | options/locale/locale_en-US.ini | 8 | ||||
-rw-r--r-- | routers/api/v1/repo/label.go | 2 | ||||
-rw-r--r-- | routers/repo/issue.go | 15 | ||||
-rw-r--r-- | templates/repo/issue/labels.tmpl | 15 | ||||
-rw-r--r-- | templates/repo/issue/milestones.tmpl | 17 |
7 files changed, 82 insertions, 13 deletions
diff --git a/models/issue.go b/models/issue.go index 57490bbc5b..86becdbbae 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1503,12 +1503,28 @@ func GetMilestonesByRepoID(repoID int64) ([]*Milestone, error) { } // GetMilestones returns a list of milestones of given repository and status. -func GetMilestones(repoID int64, page int, isClosed bool) ([]*Milestone, error) { +func GetMilestones(repoID int64, page int, isClosed bool, sortType string) ([]*Milestone, error) { miles := make([]*Milestone, 0, setting.UI.IssuePagingNum) sess := x.Where("repo_id = ? AND is_closed = ?", repoID, isClosed) if page > 0 { sess = sess.Limit(setting.UI.IssuePagingNum, (page-1)*setting.UI.IssuePagingNum) } + + switch sortType { + case "furthestduedate": + sess.Desc("deadline_unix") + case "leastcomplete": + sess.Asc("completeness") + case "mostcomplete": + sess.Desc("completeness") + case "leastissues": + sess.Asc("num_issues") + case "mostissues": + sess.Desc("num_issues") + default: + sess.Asc("deadline_unix") + } + return miles, sess.Find(&miles) } 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) { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 1be1528118..97725a950a 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -557,6 +557,8 @@ issues.label_modify = Label Modification issues.label_deletion = Label Deletion issues.label_deletion_desc = Deleting this label will remove its information in all related issues. Do you want to continue? issues.label_deletion_success = Label has been deleted successfully! +issues.label.filter_sort.alphabetically = Alphabetically +issues.label.filter_sort.reverse_alphabetically = Reverse alphabetically issues.num_participants = %d Participants issues.attachment.open_tab = `Click to see "%s" in a new tab` issues.attachment.download = `Click to download "%s"` @@ -610,6 +612,12 @@ milestones.edit_success = Changes of milestone '%s' has been saved successfully! milestones.deletion = Milestone Deletion milestones.deletion_desc = Deleting this milestone will remove its information in all related issues. Do you want to continue? milestones.deletion_success = Milestone has been deleted successfully! +milestones.filter_sort.closest_due_date = Closest due date +milestones.filter_sort.furthest_due_date = Furthest due date +milestones.filter_sort.least_complete = Least complete +milestones.filter_sort.most_complete = Most complete +milestones.filter_sort.most_issues = Most issues +milestones.filter_sort.least_issues = Least issues wiki = Wiki wiki.welcome = Welcome to Wiki! diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index a2bf3a9e40..c22db517c3 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -15,7 +15,7 @@ import ( // ListLabels list all the labels of a repository func ListLabels(ctx *context.APIContext) { - labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID) + labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort")) if err != nil { ctx.Error(500, "GetLabelsByRepoID", err) return diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 14c1ea1aa7..1cf5722ed1 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -82,7 +82,7 @@ func MustAllowPulls(ctx *context.Context) { // RetrieveLabels find all the labels of a repository func RetrieveLabels(ctx *context.Context) { - labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID) + labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Query("sort")) if err != nil { ctx.Handle(500, "RetrieveLabels.GetLabels", err) return @@ -92,6 +92,7 @@ func RetrieveLabels(ctx *context.Context) { } ctx.Data["Labels"] = labels ctx.Data["NumLabels"] = len(labels) + ctx.Data["SortType"] = ctx.Query("sort") } // Issues render issues page @@ -274,12 +275,12 @@ func renderAttachmentSettings(ctx *context.Context) { // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *models.Repository) { var err error - ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false) + ctx.Data["OpenMilestones"], err = models.GetMilestones(repo.ID, -1, false, "") if err != nil { ctx.Handle(500, "GetMilestones", err) return } - ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true) + ctx.Data["ClosedMilestones"], err = models.GetMilestones(repo.ID, -1, true, "") if err != nil { ctx.Handle(500, "GetMilestones", err) return @@ -298,7 +299,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *models.Repository) []*models. return nil } - labels, err := models.GetLabelsByRepoID(repo.ID) + labels, err := models.GetLabelsByRepoID(repo.ID, "") if err != nil { ctx.Handle(500, "GetLabelsByRepoID", err) return nil @@ -583,7 +584,7 @@ func ViewIssue(ctx *context.Context) { for i := range issue.Labels { labelIDMark[issue.Labels[i].ID] = true } - labels, err := models.GetLabelsByRepoID(repo.ID) + labels, err := models.GetLabelsByRepoID(repo.ID, "") if err != nil { ctx.Handle(500, "GetLabelsByRepoID", err) return @@ -1079,6 +1080,7 @@ func Milestones(ctx *context.Context) { ctx.Data["OpenCount"] = openCount ctx.Data["ClosedCount"] = closedCount + sortType := ctx.Query("sort") page := ctx.QueryInt("page") if page <= 1 { page = 1 @@ -1092,7 +1094,7 @@ func Milestones(ctx *context.Context) { } ctx.Data["Page"] = paginater.New(total, setting.UI.IssuePagingNum, page, 5) - miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed) + miles, err := models.GetMilestones(ctx.Repo.Repository.ID, page, isShowClosed, sortType) if err != nil { ctx.Handle(500, "GetMilestones", err) return @@ -1108,6 +1110,7 @@ func Milestones(ctx *context.Context) { ctx.Data["State"] = "open" } + ctx.Data["SortType"] = sortType ctx.Data["IsShowClosed"] = isShowClosed ctx.HTML(200, tplMilestone) } diff --git a/templates/repo/issue/labels.tmpl b/templates/repo/issue/labels.tmpl index eef82b80a8..ab3afe5976 100644 --- a/templates/repo/issue/labels.tmpl +++ b/templates/repo/issue/labels.tmpl @@ -34,6 +34,21 @@ </div> <div class="ui divider"></div> + <div class="ui right floated secondary filter menu"> + <!-- Sort --> + <div class="ui dropdown type jump item"> + <span class="text"> + {{.i18n.Tr "repo.issues.filter_sort"}} + <i class="dropdown icon"></i> + </span> + <div class="menu"> + <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> + <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> + <a class="{{if eq .SortType "leastissues"}}active{{end}} item" href="{{$.Link}}?sort=leastissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_issues"}}</a> + <a class="{{if eq .SortType "mostissues"}}active{{end}} item" href="{{$.Link}}?sort=mostissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_issues"}}</a> + </div> + </div> + </div> {{template "base/alert" .}} <div class="ui black label">{{.i18n.Tr "repo.issues.label_count" .NumLabels}}</div> <div class="label list"> diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl index 038eaabd8f..3703301e19 100644 --- a/templates/repo/issue/milestones.tmpl +++ b/templates/repo/issue/milestones.tmpl @@ -23,6 +23,23 @@ </a> </div> + <div class="ui right floated secondary filter menu"> + <!-- Sort --> + <div class="ui dropdown type jump item"> + <span class="text"> + {{.i18n.Tr "repo.issues.filter_sort"}} + <i class="dropdown icon"></i> + </span> + <div class="menu"> + <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> + <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> + <a class="{{if eq .SortType "leastcomplete"}}active{{end}} item" href="{{$.Link}}?sort=leastcomplete&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_complete"}}</a> + <a class="{{if eq .SortType "mostcomplete"}}active{{end}} item" href="{{$.Link}}?sort=mostcomplete&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_complete"}}</a> + <a class="{{if eq .SortType "mostissues"}}active{{end}} item" href="{{$.Link}}?sort=mostissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.most_issues"}}</a> + <a class="{{if eq .SortType "leastissues"}}active{{end}} item" href="{{$.Link}}?sort=leastissues&state={{$.State}}">{{.i18n.Tr "repo.milestones.filter_sort.least_issues"}}</a> + </div> + </div> + </div> <div class="milestone list"> {{range .Milestones}} <li class="item"> |