From 90d20be5411a25e6e5e3ac25990265445ec71bc0 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 10 Dec 2024 11:38:22 +0800 Subject: Refactor issue filter (labels, poster, assignee) (#32771) Rewrite a lot of legacy strange code, remove duplicate code, remove jquery, and make these filters reusable. Let's forget the old code, new code affects: * issue list open/close switch * issue list filter (label, author, assignee) * milestone list open/close switch * milestone issue list filter (label, author, assignee) * project view (label, assignee) --- templates/projects/view.tmpl | 84 +++------------- templates/repo/issue/filter_item_label.tmpl | 45 +++++++++ templates/repo/issue/filter_item_user_assign.tmpl | 31 ++++++ templates/repo/issue/filter_item_user_fetch.tmpl | 23 +++++ templates/repo/issue/filter_list.tmpl | 111 ++++------------------ templates/repo/issue/openclose.tmpl | 25 +++-- 6 files changed, 147 insertions(+), 172 deletions(-) create mode 100644 templates/repo/issue/filter_item_label.tmpl create mode 100644 templates/repo/issue/filter_item_user_assign.tmpl create mode 100644 templates/repo/issue/filter_item_user_fetch.tmpl (limited to 'templates') diff --git a/templates/projects/view.tmpl b/templates/projects/view.tmpl index acaf45e8d2..966d3bf604 100644 --- a/templates/projects/view.tmpl +++ b/templates/projects/view.tmpl @@ -5,79 +5,19 @@

{{.Project.Title}}

{{if $canWriteProject}} diff --git a/templates/repo/issue/filter_item_label.tmpl b/templates/repo/issue/filter_item_label.tmpl new file mode 100644 index 0000000000..67bfab6fb0 --- /dev/null +++ b/templates/repo/issue/filter_item_label.tmpl @@ -0,0 +1,45 @@ +{{/* +* "labels" from query string (needed by JS) +* QueryLink +* Labels +* SupportArchivedLabel, if true, then it needs "archived_labels" from query string +*/}} +{{$queryLink := .QueryLink}} + diff --git a/templates/repo/issue/filter_item_user_assign.tmpl b/templates/repo/issue/filter_item_user_assign.tmpl new file mode 100644 index 0000000000..4f1db71d57 --- /dev/null +++ b/templates/repo/issue/filter_item_user_assign.tmpl @@ -0,0 +1,31 @@ +{{/* This is a user list for filter, the data is provided by a local variable assignment +* QueryParamKey: eg: "poster", "assignee" +* QueryLink +* UserSearchList +* SelectedUserId: 0 or empty means default, -1 means "no user is set" +* TextFilterTitle +* TextZeroValue: the text for "all issues" +* TextNegativeOne: the text for "issues with no assignee" +*/}} +{{$queryLink := .QueryLink}} + diff --git a/templates/repo/issue/filter_item_user_fetch.tmpl b/templates/repo/issue/filter_item_user_fetch.tmpl new file mode 100644 index 0000000000..cab128a787 --- /dev/null +++ b/templates/repo/issue/filter_item_user_fetch.tmpl @@ -0,0 +1,23 @@ +{{/* This is a user list for filter, the data is provided by a remote "fetch" request +* QueryParamKey: eg: "poster", "assignee" +* QueryLink +* UserSearchUrl +* SelectedUserId +* TextFilterTitle +*/}} +{{$queryLink := .QueryLink}} + diff --git a/templates/repo/issue/filter_list.tmpl b/templates/repo/issue/filter_list.tmpl index e686f1d60f..c78d23d51c 100644 --- a/templates/repo/issue/filter_list.tmpl +++ b/templates/repo/issue/filter_list.tmpl @@ -1,55 +1,6 @@ -{{$queryLink := QueryBuild "?" "q" $.Keyword "type" $.ViewType "sort" $.SortType "state" $.State "labels" $.SelectLabels "milestone" $.MilestoneID "project" $.ProjectID "assignee" $.AssigneeID "poster" $.PosterUsername "archived" (Iif $.ShowArchivedLabels NIL)}} - - +{{$queryLink := QueryBuild "?" "q" $.Keyword "type" $.ViewType "sort" $.SortType "state" $.State "labels" $.SelectLabels "milestone" $.MilestoneID "project" $.ProjectID "assignee" $.AssigneeID "poster" $.PosterUsername "archived_labels" (Iif $.ShowArchivedLabels "true")}} + +{{template "repo/issue/filter_item_label" dict "Labels" .Labels "QueryLink" $queryLink "SupportArchivedLabel" true}} {{if not .Milestone}} @@ -128,46 +79,24 @@ - - +{{/* TODO: the UserSearchUrl is old logic but not right, milestone could also have "pull request" posters */}} +{{template "repo/issue/filter_item_user_fetch" dict + "QueryParamKey" "poster" + "QueryLink" $queryLink + "UserSearchUrl" (Iif .Milestone (print $.RepoLink "/issues/posters") (print $.Link "/posters")) + "SelectedUserId" $.PosterUserID + "TextFilterTitle" (ctx.Locale.Tr "repo.issues.filter_poster") +}} - - +{{template "repo/issue/filter_item_user_assign" dict + "QueryParamKey" "assignee" + "QueryLink" $queryLink + "UserSearchList" $.Assignees + "SelectedUserId" $.AssigneeID + "TextFilterTitle" (ctx.Locale.Tr "repo.issues.filter_assignee") + "TextZeroValue" (ctx.Locale.Tr "repo.issues.filter_assginee_no_select") + "TextNegativeOne" (ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee") +}} {{if .IsSigned}} diff --git a/templates/repo/issue/openclose.tmpl b/templates/repo/issue/openclose.tmpl index eb2d6e09ee..b9dd04a7db 100644 --- a/templates/repo/issue/openclose.tmpl +++ b/templates/repo/issue/openclose.tmpl @@ -1,16 +1,23 @@ +{{/* this tmpl is quite dirty, it should not mix unrelated things together .... need to split it in the future*/}} +{{$allStatesLink := ""}}{{$openLink := ""}}{{$closedLink := ""}} +{{if .PageIsMilestones}} + {{$allStatesLink = QueryBuild "?" "q" $.Keyword "sort" $.SortType "state" "all"}} +{{else}} + {{$allStatesLink = QueryBuild "?" "q" $.Keyword "type" $.ViewType "sort" $.SortType "state" "all" "labels" $.SelectLabels "milestone" $.MilestoneID "project" $.ProjectID "assignee" $.AssigneeID "poster" $.PosterUsername "archived_labels" (Iif $.ShowArchivedLabels "true")}} +{{end}} +{{$openLink = QueryBuild $allStatesLink "state" "open"}} +{{$closedLink = QueryBuild $allStatesLink "state" "closed"}} -- cgit v1.2.3