From 0cb8dbbaa7b8a9fb5d468980f90a1659a56f358e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 13 Jan 2023 13:19:56 +0800 Subject: [PATCH 1/8] Improve milestone filter on issues page --- models/issues/issue.go | 8 +++++++- options/locale/locale_en-US.ini | 5 ++++- routers/web/repo/issue.go | 31 ++++++++++++++++++++++++------- templates/repo/issue/list.tmpl | 14 ++++++++++---- 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/models/issues/issue.go b/models/issues/issue.go index 4a8ab06824aaa..6b05c272a5a4f 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -1238,7 +1238,11 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) { } if len(opts.MilestoneIDs) > 0 { - sess.In("issue.milestone_id", opts.MilestoneIDs) + if len(opts.MilestoneIDs) == 1 && opts.MilestoneIDs[0] == -1 { + sess.And("issue.milestone_id = 0") + } else { + sess.In("issue.milestone_id", opts.MilestoneIDs) + } } if opts.UpdatedAfterUnix != 0 { @@ -1648,6 +1652,8 @@ func getIssueStatsChunk(opts *IssueStatsOptions, issueIDs []int64) (*IssueStats, if opts.MilestoneID > 0 { sess.And("issue.milestone_id = ?", opts.MilestoneID) + } else if opts.MilestoneID == -1 { + sess.And("issue.milestone_id = 0") } if opts.AssigneeID > 0 { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a7ed7706407e4..0ec7c54686afe 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1293,7 +1293,10 @@ issues.filter_label = Label issues.filter_label_exclude = `Use alt + click/enter to exclude labels` issues.filter_label_no_select = All labels issues.filter_milestone = Milestone -issues.filter_milestone_no_select = All milestones +issues.filter_milestone_all = All milestones +issues.filter_milestone_no_selected = No milestones +issues.filter_milestone_open = Open milestones +issues.filter_milestone_closed = Closed milestones issues.filter_assignee = Assignee issues.filter_assginee_no_select = All assignees issues.filter_poster = Author diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index f037c771d475b..d22e0128e5c87 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -236,7 +236,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5) var mileIDs []int64 - if milestoneID > 0 { + if milestoneID > 0 || milestoneID == -1 { mileIDs = []int64{milestoneID} } @@ -427,20 +427,37 @@ func Issues(ctx *context.Context) { return } - var err error + renderMileStones(ctx) + if ctx.Written() { + return + } + + ctx.Data["CanWriteIssuesOrPulls"] = ctx.Repo.CanWriteIssuesOrPulls(isPullList) + + ctx.HTML(http.StatusOK, tplIssues) +} + +func renderMileStones(ctx *context.Context) { // Get milestones - ctx.Data["Milestones"], _, err = issues_model.GetMilestones(issues_model.GetMilestonesOption{ + milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ RepoID: ctx.Repo.Repository.ID, - State: api.StateType(ctx.FormString("state")), + State: api.StateAll, }) if err != nil { ctx.ServerError("GetAllRepoMilestones", err) return } - ctx.Data["CanWriteIssuesOrPulls"] = ctx.Repo.CanWriteIssuesOrPulls(isPullList) - - ctx.HTML(http.StatusOK, tplIssues) + openMilestones, closedMilestones := issues_model.MilestoneList{}, issues_model.MilestoneList{} + for _, milestone := range milestones { + if milestone.IsClosed { + closedMilestones = append(closedMilestones, milestone) + } else { + openMilestones = append(openMilestones, milestone) + } + } + ctx.Data["OpenMilestones"] = openMilestones + ctx.Data["ClosedMilestones"] = closedMilestones } // RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index ad0ce50ec15fb..bacbb8d652f0a 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -58,7 +58,7 @@ - From 4da0d94c39673749e2a2186a5d799e15e11a547e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 13 Jan 2023 13:24:07 +0800 Subject: [PATCH 2/8] selected --- templates/repo/issue/list.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index bacbb8d652f0a..ff4c468d9631c 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -68,15 +68,15 @@ {{svg "octicon-search" 16}} - {{.locale.Tr "repo.issues.filter_milestone_all"}} - {{.locale.Tr "repo.issues.filter_milestone_no_selected"}} + {{.locale.Tr "repo.issues.filter_milestone_all"}} + {{.locale.Tr "repo.issues.filter_milestone_no_selected"}}

{{.locale.Tr "repo.issues.filter_milestone_open"}}

{{range .OpenMilestones}} -     {{.Name}} +     {{.Name}} {{end}}

{{.locale.Tr "repo.issues.filter_milestone_closed"}}

{{range .ClosedMilestones}} -     {{.Name}} +     {{.Name}} {{end}} From ae769b2e9f13bd3a971332352218cbb814afe3b1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 29 Jan 2023 11:37:50 +0800 Subject: [PATCH 3/8] follow @delvh suggestion --- models/db/search.go | 6 +++ models/issues/issue.go | 2 +- options/locale/locale_en-US.ini | 2 +- routers/web/repo/issue.go | 6 +-- templates/repo/issue/list.tmpl | 24 ++++++++---- .../repo/issue/milestone/select_menu.tmpl | 38 ++++++++++++++++++ templates/repo/issue/new_form.tmpl | 39 +------------------ .../repo/issue/view_content/sidebar.tmpl | 39 +------------------ 8 files changed, 68 insertions(+), 88 deletions(-) create mode 100644 templates/repo/issue/milestone/select_menu.tmpl diff --git a/models/db/search.go b/models/db/search.go index f5273cb6f6bfa..26e082756a51b 100644 --- a/models/db/search.go +++ b/models/db/search.go @@ -27,3 +27,9 @@ const ( SearchOrderByForks SearchOrderBy = "num_forks ASC" SearchOrderByForksReverse SearchOrderBy = "num_forks DESC" ) + +const ( + // Which means a condition to filter the records which don't match any id. + // It's different from zero which means the condition could be ignored. + NoneID = -1 +) diff --git a/models/issues/issue.go b/models/issues/issue.go index 6b05c272a5a4f..a61b5a0d1f1dc 100644 --- a/models/issues/issue.go +++ b/models/issues/issue.go @@ -1238,7 +1238,7 @@ func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) { } if len(opts.MilestoneIDs) > 0 { - if len(opts.MilestoneIDs) == 1 && opts.MilestoneIDs[0] == -1 { + if len(opts.MilestoneIDs) == 1 && opts.MilestoneIDs[0] == db.NoneID { sess.And("issue.milestone_id = 0") } else { sess.In("issue.milestone_id", opts.MilestoneIDs) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 0ec7c54686afe..bd73b92d421f5 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1294,7 +1294,7 @@ issues.filter_label_exclude = `Use alt + click/enter t issues.filter_label_no_select = All labels issues.filter_milestone = Milestone issues.filter_milestone_all = All milestones -issues.filter_milestone_no_selected = No milestones +issues.filter_milestone_none = No milestones issues.filter_milestone_open = Open milestones issues.filter_milestone_closed = Closed milestones issues.filter_assignee = Assignee diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index d22e0128e5c87..c7e0db718c3a2 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -236,7 +236,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5) var mileIDs []int64 - if milestoneID > 0 || milestoneID == -1 { + if milestoneID > 0 || milestoneID == db.NoneID { // -1 to get those issues which have no any milestone assigned mileIDs = []int64{milestoneID} } @@ -427,7 +427,7 @@ func Issues(ctx *context.Context) { return } - renderMileStones(ctx) + renderMilestones(ctx) if ctx.Written() { return } @@ -437,7 +437,7 @@ func Issues(ctx *context.Context) { ctx.HTML(http.StatusOK, tplIssues) } -func renderMileStones(ctx *context.Context) { +func renderMilestones(ctx *context.Context) { // Get milestones milestones, _, err := issues_model.GetMilestones(issues_model.GetMilestonesOption{ RepoID: ctx.Repo.Repository.ID, diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index ff4c468d9631c..29566bc3fbef8 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -69,14 +69,24 @@ {{.locale.Tr "repo.issues.filter_milestone_all"}} - {{.locale.Tr "repo.issues.filter_milestone_no_selected"}} -

{{.locale.Tr "repo.issues.filter_milestone_open"}}

- {{range .OpenMilestones}} -     {{.Name}} + {{.locale.Tr "repo.issues.filter_milestone_none"}} + {{if .OpenMilestones}} +

{{.locale.Tr "repo.issues.filter_milestone_open"}}

+ {{range .OpenMilestones}} + + {{svg "octicon-milestone" 16 "mr-2"}} + {{.Name}} + + {{end}} {{end}} -

{{.locale.Tr "repo.issues.filter_milestone_closed"}}

- {{range .ClosedMilestones}} -     {{.Name}} + {{if .ClosedMilestones}} +

{{.locale.Tr "repo.issues.filter_milestone_closed"}}

+ {{range .ClosedMilestones}} + + {{svg "octicon-milestone" 16 "mr-2"}} + {{.Name}} + + {{end}} {{end}} diff --git a/templates/repo/issue/milestone/select_menu.tmpl b/templates/repo/issue/milestone/select_menu.tmpl new file mode 100644 index 0000000000000..807aa397526ab --- /dev/null +++ b/templates/repo/issue/milestone/select_menu.tmpl @@ -0,0 +1,38 @@ +
{{.locale.Tr "repo.issues.new.add_milestone_title"}}
+{{if or .OpenMilestones .ClosedMilestones}} + +{{end}} +
{{.locale.Tr "repo.issues.new.clear_milestone"}}
+{{if and (not .OpenMilestones) (not .ClosedMilestones)}} +
+ {{.locale.Tr "repo.issues.new.no_items"}} +
+{{else}} + {{if .OpenMilestones}} +
+
+ {{.locale.Tr "repo.issues.new.open_milestone"}} +
+ {{range .OpenMilestones}} + + {{svg "octicon-milestone" 16 "mr-2"}} + {{.Name}} + + {{end}} + {{end}} + {{if .ClosedMilestones}} +
+
+ {{.locale.Tr "repo.issues.new.closed_milestone"}} +
+ {{range .ClosedMilestones}} + + {{svg "octicon-milestone" 16 "mr-2"}} + {{.Name}} + + {{end}} + {{end}} +{{end}} diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index ed1fd4778f7d2..d278b187a39e4 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -81,44 +81,7 @@ {{end}}
diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 6cb00fdd1d24b..42911071cf19d 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -149,44 +149,7 @@ {{end}}
From b663d4d367c880bf57aaf704c4e8d99eef4f0adc Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 29 Jan 2023 11:46:06 +0800 Subject: [PATCH 4/8] follow @delvh suggestion --- templates/repo/issue/list.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 29566bc3fbef8..38d69d45a1a42 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -58,7 +58,7 @@
-