mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	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)
This commit is contained in:
		| @@ -42,7 +42,7 @@ func NewFuncMap() template.FuncMap { | |||||||
| 		"HTMLFormat":   htmlutil.HTMLFormat, | 		"HTMLFormat":   htmlutil.HTMLFormat, | ||||||
| 		"HTMLEscape":   htmlEscape, | 		"HTMLEscape":   htmlEscape, | ||||||
| 		"QueryEscape":  queryEscape, | 		"QueryEscape":  queryEscape, | ||||||
| 		"QueryBuild":   queryBuild, | 		"QueryBuild":   QueryBuild, | ||||||
| 		"JSEscape":     jsEscapeSafe, | 		"JSEscape":     jsEscapeSafe, | ||||||
| 		"SanitizeHTML": SanitizeHTML, | 		"SanitizeHTML": SanitizeHTML, | ||||||
| 		"URLJoin":      util.URLJoin, | 		"URLJoin":      util.URLJoin, | ||||||
| @@ -294,24 +294,27 @@ func timeEstimateString(timeSec any) string { | |||||||
| 	return util.TimeEstimateString(v) | 	return util.TimeEstimateString(v) | ||||||
| } | } | ||||||
|  |  | ||||||
| func queryBuild(a ...any) template.URL { | // QueryBuild builds a query string from a list of key-value pairs. | ||||||
|  | // It omits the nil and empty strings, but it doesn't omit other zero values, | ||||||
|  | // because the zero value of number types may have a meaning. | ||||||
|  | func QueryBuild(a ...any) template.URL { | ||||||
| 	var s string | 	var s string | ||||||
| 	if len(a)%2 == 1 { | 	if len(a)%2 == 1 { | ||||||
| 		if v, ok := a[0].(string); ok { | 		if v, ok := a[0].(string); ok { | ||||||
| 			if v == "" || (v[0] != '?' && v[0] != '&') { | 			if v == "" || (v[0] != '?' && v[0] != '&') { | ||||||
| 				panic("queryBuild: invalid argument") | 				panic("QueryBuild: invalid argument") | ||||||
| 			} | 			} | ||||||
| 			s = v | 			s = v | ||||||
| 		} else if v, ok := a[0].(template.URL); ok { | 		} else if v, ok := a[0].(template.URL); ok { | ||||||
| 			s = string(v) | 			s = string(v) | ||||||
| 		} else { | 		} else { | ||||||
| 			panic("queryBuild: invalid argument") | 			panic("QueryBuild: invalid argument") | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	for i := len(a) % 2; i < len(a); i += 2 { | 	for i := len(a) % 2; i < len(a); i += 2 { | ||||||
| 		k, ok := a[i].(string) | 		k, ok := a[i].(string) | ||||||
| 		if !ok { | 		if !ok { | ||||||
| 			panic("queryBuild: invalid argument") | 			panic("QueryBuild: invalid argument") | ||||||
| 		} | 		} | ||||||
| 		var v string | 		var v string | ||||||
| 		if va, ok := a[i+1].(string); ok { | 		if va, ok := a[i+1].(string); ok { | ||||||
|   | |||||||
| @@ -1109,7 +1109,7 @@ delete_preexisting_success = Deleted unadopted files in %s | |||||||
| blame_prior = View blame prior to this change | blame_prior = View blame prior to this change | ||||||
| blame.ignore_revs = Ignoring revisions in <a href="%s">.git-blame-ignore-revs</a>. Click <a href="%s">here to bypass</a> and see the normal blame view. | blame.ignore_revs = Ignoring revisions in <a href="%s">.git-blame-ignore-revs</a>. Click <a href="%s">here to bypass</a> and see the normal blame view. | ||||||
| blame.ignore_revs.failed = Failed to ignore revisions in <a href="%s">.git-blame-ignore-revs</a>. | blame.ignore_revs.failed = Failed to ignore revisions in <a href="%s">.git-blame-ignore-revs</a>. | ||||||
| author_search_tooltip = Shows a maximum of 30 users | user_search_tooltip = Shows a maximum of 30 users | ||||||
|  |  | ||||||
| tree_path_not_found_commit = Path %[1]s doesn't exist in commit %[2]s | tree_path_not_found_commit = Path %[1]s doesn't exist in commit %[2]s | ||||||
| tree_path_not_found_branch = Path %[1]s doesn't exist in branch %[2]s | tree_path_not_found_branch = Path %[1]s doesn't exist in branch %[2]s | ||||||
| @@ -1529,7 +1529,8 @@ issues.filter_assignee = Assignee | |||||||
| issues.filter_assginee_no_select = All assignees | issues.filter_assginee_no_select = All assignees | ||||||
| issues.filter_assginee_no_assignee = No assignee | issues.filter_assginee_no_assignee = No assignee | ||||||
| issues.filter_poster = Author | issues.filter_poster = Author | ||||||
| issues.filter_poster_no_select = All authors | issues.filter_user_placeholder = Search users | ||||||
|  | issues.filter_user_no_select = All users | ||||||
| issues.filter_type = Type | issues.filter_type = Type | ||||||
| issues.filter_type.all_issues = All issues | issues.filter_type.all_issues = All issues | ||||||
| issues.filter_type.assigned_to_you = Assigned to you | issues.filter_type.assigned_to_you = Assigned to you | ||||||
|   | |||||||
| @@ -339,12 +339,7 @@ func ViewProject(ctx *context.Context) { | |||||||
| 	// 0 means issues with no label | 	// 0 means issues with no label | ||||||
| 	// blank means labels will not be filtered for issues | 	// blank means labels will not be filtered for issues | ||||||
| 	selectLabels := ctx.FormString("labels") | 	selectLabels := ctx.FormString("labels") | ||||||
| 	if selectLabels == "" { | 	if selectLabels != "" { | ||||||
| 		ctx.Data["AllLabels"] = true |  | ||||||
| 	} else if selectLabels == "0" { |  | ||||||
| 		ctx.Data["NoLabel"] = true |  | ||||||
| 	} |  | ||||||
| 	if len(selectLabels) > 0 { |  | ||||||
| 		labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ",")) | 		labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ",")) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true) | 			ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true) | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ import ( | |||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/url" |  | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
|  |  | ||||||
| @@ -531,12 +530,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt | |||||||
| 	// 0 means issues with no label | 	// 0 means issues with no label | ||||||
| 	// blank means labels will not be filtered for issues | 	// blank means labels will not be filtered for issues | ||||||
| 	selectLabels := ctx.FormString("labels") | 	selectLabels := ctx.FormString("labels") | ||||||
| 	if selectLabels == "" { | 	if selectLabels != "" { | ||||||
| 		ctx.Data["AllLabels"] = true |  | ||||||
| 	} else if selectLabels == "0" { |  | ||||||
| 		ctx.Data["NoLabel"] = true |  | ||||||
| 	} |  | ||||||
| 	if len(selectLabels) > 0 { |  | ||||||
| 		labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ",")) | 		labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ",")) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true) | 			ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true) | ||||||
| @@ -616,8 +610,6 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt | |||||||
| 		ctx.Data["TotalTrackedTime"] = totalTrackedTime | 		ctx.Data["TotalTrackedTime"] = totalTrackedTime | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	archived := ctx.FormBool("archived") |  | ||||||
|  |  | ||||||
| 	page := ctx.FormInt("page") | 	page := ctx.FormInt("page") | ||||||
| 	if page <= 1 { | 	if page <= 1 { | ||||||
| 		page = 1 | 		page = 1 | ||||||
| @@ -792,21 +784,13 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	showArchivedLabels := ctx.FormBool("archived_labels") | ||||||
|  | 	ctx.Data["ShowArchivedLabels"] = showArchivedLabels | ||||||
| 	ctx.Data["PinnedIssues"] = pinned | 	ctx.Data["PinnedIssues"] = pinned | ||||||
| 	ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.Doer.IsAdmin) | 	ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.Doer.IsAdmin) | ||||||
| 	ctx.Data["IssueStats"] = issueStats | 	ctx.Data["IssueStats"] = issueStats | ||||||
| 	ctx.Data["OpenCount"] = issueStats.OpenCount | 	ctx.Data["OpenCount"] = issueStats.OpenCount | ||||||
| 	ctx.Data["ClosedCount"] = issueStats.ClosedCount | 	ctx.Data["ClosedCount"] = issueStats.ClosedCount | ||||||
| 	linkStr := "%s?q=%s&type=%s&sort=%s&state=%s&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%v&archived=%t" |  | ||||||
| 	ctx.Data["AllStatesLink"] = fmt.Sprintf(linkStr, ctx.Link, |  | ||||||
| 		url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "all", url.QueryEscape(selectLabels), |  | ||||||
| 		milestoneID, projectID, assigneeID, url.QueryEscape(posterUsername), archived) |  | ||||||
| 	ctx.Data["OpenLink"] = fmt.Sprintf(linkStr, ctx.Link, |  | ||||||
| 		url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "open", url.QueryEscape(selectLabels), |  | ||||||
| 		milestoneID, projectID, assigneeID, url.QueryEscape(posterUsername), archived) |  | ||||||
| 	ctx.Data["ClosedLink"] = fmt.Sprintf(linkStr, ctx.Link, |  | ||||||
| 		url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "closed", url.QueryEscape(selectLabels), |  | ||||||
| 		milestoneID, projectID, assigneeID, url.QueryEscape(posterUsername), archived) |  | ||||||
| 	ctx.Data["SelLabelIDs"] = labelIDs | 	ctx.Data["SelLabelIDs"] = labelIDs | ||||||
| 	ctx.Data["SelectLabels"] = selectLabels | 	ctx.Data["SelectLabels"] = selectLabels | ||||||
| 	ctx.Data["ViewType"] = viewType | 	ctx.Data["ViewType"] = viewType | ||||||
| @@ -814,6 +798,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt | |||||||
| 	ctx.Data["MilestoneID"] = milestoneID | 	ctx.Data["MilestoneID"] = milestoneID | ||||||
| 	ctx.Data["ProjectID"] = projectID | 	ctx.Data["ProjectID"] = projectID | ||||||
| 	ctx.Data["AssigneeID"] = assigneeID | 	ctx.Data["AssigneeID"] = assigneeID | ||||||
|  | 	ctx.Data["PosterUserID"] = posterUserID | ||||||
| 	ctx.Data["PosterUsername"] = posterUsername | 	ctx.Data["PosterUsername"] = posterUsername | ||||||
| 	ctx.Data["Keyword"] = keyword | 	ctx.Data["Keyword"] = keyword | ||||||
| 	ctx.Data["IsShowClosed"] = isShowClosed | 	ctx.Data["IsShowClosed"] = isShowClosed | ||||||
| @@ -825,7 +810,6 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt | |||||||
| 	default: | 	default: | ||||||
| 		ctx.Data["State"] = "open" | 		ctx.Data["State"] = "open" | ||||||
| 	} | 	} | ||||||
| 	ctx.Data["ShowArchivedLabels"] = archived |  | ||||||
|  |  | ||||||
| 	pager.AddParamString("q", keyword) | 	pager.AddParamString("q", keyword) | ||||||
| 	pager.AddParamString("type", viewType) | 	pager.AddParamString("type", viewType) | ||||||
| @@ -836,8 +820,9 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt | |||||||
| 	pager.AddParamString("project", fmt.Sprint(projectID)) | 	pager.AddParamString("project", fmt.Sprint(projectID)) | ||||||
| 	pager.AddParamString("assignee", fmt.Sprint(assigneeID)) | 	pager.AddParamString("assignee", fmt.Sprint(assigneeID)) | ||||||
| 	pager.AddParamString("poster", posterUsername) | 	pager.AddParamString("poster", posterUsername) | ||||||
| 	pager.AddParamString("archived", fmt.Sprint(archived)) | 	if showArchivedLabels { | ||||||
|  | 		pager.AddParamString("archived_labels", "true") | ||||||
|  | 	} | ||||||
| 	ctx.Data["Page"] = pager | 	ctx.Data["Page"] = pager | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -66,12 +66,6 @@ func Milestones(ctx *context.Context) { | |||||||
| 	} | 	} | ||||||
| 	ctx.Data["OpenCount"] = stats.OpenCount | 	ctx.Data["OpenCount"] = stats.OpenCount | ||||||
| 	ctx.Data["ClosedCount"] = stats.ClosedCount | 	ctx.Data["ClosedCount"] = stats.ClosedCount | ||||||
| 	linkStr := "%s/milestones?state=%s&q=%s&sort=%s" |  | ||||||
| 	ctx.Data["OpenLink"] = fmt.Sprintf(linkStr, ctx.Repo.RepoLink, "open", |  | ||||||
| 		url.QueryEscape(keyword), url.QueryEscape(sortType)) |  | ||||||
| 	ctx.Data["ClosedLink"] = fmt.Sprintf(linkStr, ctx.Repo.RepoLink, "closed", |  | ||||||
| 		url.QueryEscape(keyword), url.QueryEscape(sortType)) |  | ||||||
|  |  | ||||||
| 	if ctx.Repo.Repository.IsTimetrackerEnabled(ctx) { | 	if ctx.Repo.Repository.IsTimetrackerEnabled(ctx) { | ||||||
| 		if err := issues_model.MilestoneList(miles).LoadTotalTrackedTimes(ctx); err != nil { | 		if err := issues_model.MilestoneList(miles).LoadTotalTrackedTimes(ctx); err != nil { | ||||||
| 			ctx.ServerError("LoadTotalTrackedTimes", err) | 			ctx.ServerError("LoadTotalTrackedTimes", err) | ||||||
|   | |||||||
| @@ -312,12 +312,7 @@ func ViewProject(ctx *context.Context) { | |||||||
| 	// 0 means issues with no label | 	// 0 means issues with no label | ||||||
| 	// blank means labels will not be filtered for issues | 	// blank means labels will not be filtered for issues | ||||||
| 	selectLabels := ctx.FormString("labels") | 	selectLabels := ctx.FormString("labels") | ||||||
| 	if selectLabels == "" { | 	if selectLabels != "" { | ||||||
| 		ctx.Data["AllLabels"] = true |  | ||||||
| 	} else if selectLabels == "0" { |  | ||||||
| 		ctx.Data["NoLabel"] = true |  | ||||||
| 	} |  | ||||||
| 	if len(selectLabels) > 0 { |  | ||||||
| 		labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ",")) | 		labelIDs, err = base.StringsToInt64s(strings.Split(selectLabels, ",")) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true) | 			ctx.Flash.Error(ctx.Tr("invalid_data", selectLabels), true) | ||||||
|   | |||||||
| @@ -5,79 +5,19 @@ | |||||||
| 		<h2 class="tw-mb-0 tw-flex-1 tw-break-anywhere">{{.Project.Title}}</h2> | 		<h2 class="tw-mb-0 tw-flex-1 tw-break-anywhere">{{.Project.Title}}</h2> | ||||||
| 			<div class="project-toolbar-right"> | 			<div class="project-toolbar-right"> | ||||||
| 				<div class="ui secondary filter menu labels"> | 				<div class="ui secondary filter menu labels"> | ||||||
| 					<!-- Label --> | 					{{$queryLink := QueryBuild "?" "labels" .SelectLabels "assignee" $.AssigneeID "archived_labels" (Iif $.ShowArchivedLabels "true")}} | ||||||
| 					<div class="ui {{if not .Labels}}disabled{{end}} dropdown jump item label-filter"> |  | ||||||
| 						<span class="text"> |  | ||||||
| 							{{ctx.Locale.Tr "repo.issues.filter_label"}} |  | ||||||
| 						</span> |  | ||||||
| 						{{svg "octicon-triangle-down" 14 "dropdown icon"}} |  | ||||||
| 						<div class="menu"> |  | ||||||
| 							<div class="ui icon search input"> |  | ||||||
| 								<i class="icon">{{svg "octicon-search" 16}}</i> |  | ||||||
| 								<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_label"}}"> |  | ||||||
| 							</div> |  | ||||||
| 							<div class="ui checkbox compact archived-label-filter"> |  | ||||||
| 								<input name="archived" type="checkbox" |  | ||||||
| 									id="archived-filter-checkbox" |  | ||||||
| 									{{if .ShowArchivedLabels}}checked{{end}} |  | ||||||
| 								> |  | ||||||
| 								<label for="archived-filter-checkbox"> |  | ||||||
| 									{{ctx.Locale.Tr "repo.issues.label_archived_filter"}} |  | ||||||
| 									<i class="tw-ml-1" data-tooltip-content={{ctx.Locale.Tr "repo.issues.label_archive_tooltip"}}> |  | ||||||
| 										{{svg "octicon-info"}} |  | ||||||
| 									</i> |  | ||||||
| 								</label> |  | ||||||
| 							</div> |  | ||||||
| 							<span class="info">{{ctx.Locale.Tr "repo.issues.filter_label_exclude"}}</span> |  | ||||||
| 							<div class="divider"></div> |  | ||||||
| 							<a class="{{if .AllLabels}}active selected {{end}}item" href="?assignee={{$.AssigneeID}}{{if $.ShowArchivedLabels}}&archived=true{{end}}">{{ctx.Locale.Tr "repo.issues.filter_label_no_select"}}</a> |  | ||||||
| 							<a class="{{if .NoLabel}}active selected {{end}}item" href="?assignee={{$.AssigneeID}}{{if $.ShowArchivedLabels}}&archived=true{{end}}">{{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}}</a> |  | ||||||
| 							{{$previousExclusiveScope := "_no_scope"}} |  | ||||||
| 							{{range .Labels}} |  | ||||||
| 								{{$exclusiveScope := .ExclusiveScope}} |  | ||||||
| 								{{if and (ne $previousExclusiveScope $exclusiveScope)}} |  | ||||||
| 									<div class="divider" data-scope="{{.ExclusiveScope}}"></div> |  | ||||||
| 								{{end}} |  | ||||||
| 								{{$previousExclusiveScope = $exclusiveScope}} |  | ||||||
| 								<a class="item label-filter-item tw-flex tw-items-center" data-label-id="{{.ID}}" data-scope="{{.ExclusiveScope}}" {{if .IsArchived}}data-is-archived{{end}} |  | ||||||
| 									href="?labels={{.QueryString}}&assignee={{$.AssigneeID}}{{if $.ShowArchivedLabels}}&archived=true{{end}}"> |  | ||||||
| 									{{if .IsExcluded}} |  | ||||||
| 										{{svg "octicon-circle-slash"}} |  | ||||||
| 									{{else if .IsSelected}} |  | ||||||
| 										{{if $exclusiveScope}} |  | ||||||
| 											{{svg "octicon-dot-fill"}} |  | ||||||
| 										{{else}} |  | ||||||
| 											{{svg "octicon-check"}} |  | ||||||
| 										{{end}} |  | ||||||
| 									{{end}} |  | ||||||
| 									{{ctx.RenderUtils.RenderLabel .}} |  | ||||||
| 									<p class="tw-ml-auto">{{template "repo/issue/labels/label_archived" .}}</p> |  | ||||||
| 								</a> |  | ||||||
| 							{{end}} |  | ||||||
| 						</div> |  | ||||||
| 					</div> |  | ||||||
|  |  | ||||||
| 					<!-- Assignee --> | 					{{template "repo/issue/filter_item_label" dict "Labels" .Labels "QueryLink" $queryLink "SupportArchivedLabel" true}} | ||||||
| 					<div class="ui {{if not .Assignees}}disabled{{end}} dropdown jump item"> |  | ||||||
| 						<span class="text"> | 					{{template "repo/issue/filter_item_user_assign" dict | ||||||
| 							{{ctx.Locale.Tr "repo.issues.filter_assignee"}} | 						"QueryParamKey" "assignee" | ||||||
| 						</span> | 						"QueryLink" $queryLink | ||||||
| 						{{svg "octicon-triangle-down" 14 "dropdown icon"}} | 						"UserSearchList" $.Assignees | ||||||
| 						<div class="menu"> | 						"SelectedUserId" $.AssigneeID | ||||||
| 							<div class="ui icon search input"> | 						"TextFilterTitle" (ctx.Locale.Tr "repo.issues.filter_assignee") | ||||||
| 								<i class="icon">{{svg "octicon-search" 16}}</i> | 						"TextZeroValue" (ctx.Locale.Tr "repo.issues.filter_assginee_no_select") | ||||||
| 								<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_assignee"}}"> | 						"TextNegativeOne" (ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee") | ||||||
| 							</div> | 					}} | ||||||
| 							<a class="{{if not .AssigneeID}}active selected {{end}}item" href="?labels={{.SelectLabels}}{{if $.ShowArchivedLabels}}&archived=true{{end}}">{{ctx.Locale.Tr "repo.issues.filter_assginee_no_select"}}</a> |  | ||||||
| 							<a class="{{if eq .AssigneeID -1}}active selected {{end}}item" href="?labels={{.SelectLabels}}&assignee=-1{{if $.ShowArchivedLabels}}&archived=true{{end}}">{{ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee"}}</a> |  | ||||||
| 							<div class="divider"></div> |  | ||||||
| 							{{range .Assignees}} |  | ||||||
| 								<a class="{{if eq $.AssigneeID .ID}}active selected{{end}} item tw-flex" href="?labels={{$.SelectLabels}}&assignee={{.ID}}{{if $.ShowArchivedLabels}}&archived=true{{end}}"> |  | ||||||
| 									{{ctx.AvatarUtils.Avatar . 20}}{{template "repo/search_name" .}} |  | ||||||
| 								</a> |  | ||||||
| 							{{end}} |  | ||||||
| 						</div> |  | ||||||
| 					</div> |  | ||||||
| 				</div> | 				</div> | ||||||
| 			</div> | 			</div> | ||||||
| 		{{if $canWriteProject}} | 		{{if $canWriteProject}} | ||||||
|   | |||||||
							
								
								
									
										45
									
								
								templates/repo/issue/filter_item_label.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								templates/repo/issue/filter_item_label.tmpl
									
									
									
									
									
										Normal file
									
								
							| @@ -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}} | ||||||
|  | <div class="item ui dropdown jump {{if not .Labels}}disabled{{end}} label-filter"> | ||||||
|  | 	<span class="text">{{ctx.Locale.Tr "repo.issues.filter_label"}}</span> | ||||||
|  | 	{{svg "octicon-triangle-down" 14 "dropdown icon"}} | ||||||
|  | 	<div class="menu flex-items-menu"> | ||||||
|  | 		<div class="ui icon search input"> | ||||||
|  | 			<i class="icon">{{svg "octicon-search" 16}}</i> | ||||||
|  | 			<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_label"}}"> | ||||||
|  | 		</div> | ||||||
|  | 		{{if .SupportArchivedLabel}}{{/* this checkbox has a hard dependency with the "labels" and "archived_label" query parameter */}} | ||||||
|  | 		<label class="label-filter-archived-toggle flex-text-block"> | ||||||
|  | 			<input type="checkbox"> {{ctx.Locale.Tr "repo.issues.label_archived_filter"}} | ||||||
|  | 			<span data-tooltip-content={{ctx.Locale.Tr "repo.issues.label_archive_tooltip"}}>{{svg "octicon-info"}}</span> | ||||||
|  | 		</label> | ||||||
|  | 		{{end}} | ||||||
|  | 		<span class="info">{{ctx.Locale.Tr "repo.issues.filter_label_exclude"}}</span> | ||||||
|  | 		<div class="divider"></div> | ||||||
|  | 		<a class="item label-filter-query-default" href="{{QueryBuild $queryLink "labels" NIL}}">{{ctx.Locale.Tr "repo.issues.filter_label_no_select"}}</a> | ||||||
|  | 		<a class="item label-filter-query-not-set" href="{{QueryBuild $queryLink "labels" 0}}">{{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}}</a> | ||||||
|  | 		{{$previousExclusiveScope := "_no_scope"}} | ||||||
|  | 		{{range .Labels}} | ||||||
|  | 			{{$exclusiveScope := .ExclusiveScope}} | ||||||
|  | 			{{if and (ne $previousExclusiveScope $exclusiveScope)}} | ||||||
|  | 				<div class="divider" data-scope="{{.ExclusiveScope}}"></div> | ||||||
|  | 			{{end}} | ||||||
|  | 			{{$previousExclusiveScope = $exclusiveScope}} | ||||||
|  | 			<a class="item label-filter-query-item" data-label-id="{{.ID}}" data-scope="{{.ExclusiveScope}}" {{if .IsArchived}}data-is-archived{{end}} | ||||||
|  | 				href="{{QueryBuild $queryLink "labels" .QueryString}}"> | ||||||
|  | 				{{if .IsExcluded}} | ||||||
|  | 					{{svg "octicon-circle-slash"}} | ||||||
|  | 				{{else if .IsSelected}} | ||||||
|  | 					{{Iif $exclusiveScope (svg "octicon-dot-fill") (svg "octicon-check")}} | ||||||
|  | 				{{end}} | ||||||
|  | 				{{ctx.RenderUtils.RenderLabel .}} | ||||||
|  | 				<p class="tw-ml-auto">{{template "repo/issue/labels/label_archived" .}}</p> | ||||||
|  | 			</a> | ||||||
|  | 		{{end}} | ||||||
|  | 	</div> | ||||||
|  | </div> | ||||||
							
								
								
									
										31
									
								
								templates/repo/issue/filter_item_user_assign.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								templates/repo/issue/filter_item_user_assign.tmpl
									
									
									
									
									
										Normal file
									
								
							| @@ -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}} | ||||||
|  | <div class="item ui dropdown jump {{if not .UserSearchList}}disabled{{end}}"> | ||||||
|  | 	{{$.TextFilterTitle}} {{svg "octicon-triangle-down" 14 "dropdown icon"}} | ||||||
|  | 	<div class="menu"> | ||||||
|  | 		<div class="ui icon search input"> | ||||||
|  | 			<i class="icon">{{svg "octicon-search" 16}}</i> | ||||||
|  | 			<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_user_placeholder"}}"> | ||||||
|  | 		</div> | ||||||
|  | 		{{if $.TextZeroValue}} | ||||||
|  | 			<a class="item {{if not .SelectedUserId}}selected{{end}}" href="{{QueryBuild $queryLink $.QueryParamKey NIL}}">{{$.TextZeroValue}}</a> | ||||||
|  | 		{{end}} | ||||||
|  | 		{{if $.TextNegativeOne}} | ||||||
|  | 			<a class="item {{if eq .SelectedUserId -1}}selected{{end}}" href="{{QueryBuild $queryLink $.QueryParamKey -1}}">{{$.TextNegativeOne}}</a> | ||||||
|  | 		{{end}} | ||||||
|  | 		<div class="divider"></div> | ||||||
|  | 		{{range .UserSearchList}} | ||||||
|  | 			<a class="item {{if eq $.SelectedUserId .ID}}selected{{end}}" href="{{QueryBuild $queryLink $.QueryParamKey .ID}}"> | ||||||
|  | 				{{ctx.AvatarUtils.Avatar . 20}}{{template "repo/search_name" .}} | ||||||
|  | 			</a> | ||||||
|  | 		{{end}} | ||||||
|  | 	</div> | ||||||
|  | </div> | ||||||
							
								
								
									
										23
									
								
								templates/repo/issue/filter_item_user_fetch.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								templates/repo/issue/filter_item_user_fetch.tmpl
									
									
									
									
									
										Normal file
									
								
							| @@ -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}} | ||||||
|  | <div class="item ui dropdown custom user-remote-search" data-tooltip-content="{{ctx.Locale.Tr "repo.user_search_tooltip"}}" | ||||||
|  | 		data-search-url="{{$.UserSearchUrl}}" | ||||||
|  | 		data-selected-user-id="{{$.SelectedUserId}}" | ||||||
|  | 		data-action-jump-url="{{QueryBuild $queryLink $.QueryParamKey NIL}}&{{$.QueryParamKey}}={username}" | ||||||
|  | > | ||||||
|  | 	{{$.TextFilterTitle}} {{svg "octicon-triangle-down" 14 "dropdown icon"}} | ||||||
|  | 	<div class="menu"> | ||||||
|  | 		<div class="ui icon search input"> | ||||||
|  | 			<i class="icon">{{svg "octicon-search" 16}}</i> | ||||||
|  | 			<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_user_placeholder"}}"> | ||||||
|  | 		</div> | ||||||
|  | 		<a class="item" data-value="">{{ctx.Locale.Tr "repo.issues.filter_user_no_select"}}</a> | ||||||
|  | 		<a class="item item-from-input tw-hidden"></a> | ||||||
|  | 	</div> | ||||||
|  | </div> | ||||||
| @@ -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")}} | ||||||
| <!-- Label --> |  | ||||||
| <div class="ui {{if not .Labels}}disabled{{end}} dropdown jump item label-filter"> | {{template "repo/issue/filter_item_label" dict "Labels" .Labels "QueryLink" $queryLink "SupportArchivedLabel" true}} | ||||||
| 	<span class="text"> |  | ||||||
| 		{{ctx.Locale.Tr "repo.issues.filter_label"}} |  | ||||||
| 	</span> |  | ||||||
| 	{{svg "octicon-triangle-down" 14 "dropdown icon"}} |  | ||||||
| 	<div class="menu"> |  | ||||||
| 		<div class="ui icon search input"> |  | ||||||
| 			<i class="icon">{{svg "octicon-search" 16}}</i> |  | ||||||
| 			<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_label"}}"> |  | ||||||
| 		</div> |  | ||||||
| 		<div class="ui checkbox compact archived-label-filter"> |  | ||||||
| 			<input name="archived" type="checkbox" |  | ||||||
| 				id="archived-filter-checkbox" |  | ||||||
| 				{{if .ShowArchivedLabels}}checked{{end}} |  | ||||||
| 			> |  | ||||||
| 			<label for="archived-filter-checkbox"> |  | ||||||
| 				{{ctx.Locale.Tr "repo.issues.label_archived_filter"}} |  | ||||||
| 				<i class="tw-ml-1" data-tooltip-content={{ctx.Locale.Tr "repo.issues.label_archive_tooltip"}}> |  | ||||||
| 					{{svg "octicon-info"}} |  | ||||||
| 				</i> |  | ||||||
| 			</label> |  | ||||||
| 		</div> |  | ||||||
| 		<span class="info">{{ctx.Locale.Tr "repo.issues.filter_label_exclude"}}</span> |  | ||||||
| 		<div class="divider"></div> |  | ||||||
| 		<a class="{{if .AllLabels}}active selected {{end}}item" href="{{QueryBuild $queryLink "labels" NIL}}">{{ctx.Locale.Tr "repo.issues.filter_label_no_select"}}</a> |  | ||||||
| 		<a class="{{if .NoLabel}}active selected {{end}}item" href="{{QueryBuild $queryLink "labels" 0}}">{{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}}</a> |  | ||||||
| 		{{$previousExclusiveScope := "_no_scope"}} |  | ||||||
| 		{{range .Labels}} |  | ||||||
| 			{{$exclusiveScope := .ExclusiveScope}} |  | ||||||
| 			{{if and (ne $previousExclusiveScope $exclusiveScope)}} |  | ||||||
| 				<div class="divider" data-scope="{{.ExclusiveScope}}"></div> |  | ||||||
| 			{{end}} |  | ||||||
| 			{{$previousExclusiveScope = $exclusiveScope}} |  | ||||||
| 			<a class="item label-filter-item tw-flex tw-items-center" data-label-id="{{.ID}}" data-scope="{{.ExclusiveScope}}" {{if .IsArchived}}data-is-archived{{end}} |  | ||||||
| 				href="{{QueryBuild $queryLink "labels" .QueryString}}"> |  | ||||||
| 				{{if .IsExcluded}} |  | ||||||
| 					{{svg "octicon-circle-slash"}} |  | ||||||
| 				{{else if .IsSelected}} |  | ||||||
| 					{{if $exclusiveScope}} |  | ||||||
| 						{{svg "octicon-dot-fill"}} |  | ||||||
| 					{{else}} |  | ||||||
| 						{{svg "octicon-check"}} |  | ||||||
| 					{{end}} |  | ||||||
| 				{{end}} |  | ||||||
| 				{{ctx.RenderUtils.RenderLabel .}} |  | ||||||
| 				<p class="tw-ml-auto">{{template "repo/issue/labels/label_archived" .}}</p> |  | ||||||
| 			</a> |  | ||||||
| 		{{end}} |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
|  |  | ||||||
| {{if not .Milestone}} | {{if not .Milestone}} | ||||||
| <!-- Milestone --> | <!-- Milestone --> | ||||||
| @@ -128,46 +79,24 @@ | |||||||
| 	</div> | 	</div> | ||||||
| </div> | </div> | ||||||
|  |  | ||||||
| <!-- Author --> | {{/* TODO: the UserSearchUrl is old logic but not right, milestone could also have "pull request" posters */}} | ||||||
| <div class="ui dropdown jump item user-remote-search" data-tooltip-content="{{ctx.Locale.Tr "repo.author_search_tooltip"}}" | {{template "repo/issue/filter_item_user_fetch" dict | ||||||
| 	data-search-url="{{if .Milestone}}{{$.RepoLink}}/issues/posters{{else}}{{$.Link}}/posters{{end}}" | 	"QueryParamKey" "poster" | ||||||
| 	data-selected-user-id="{{$.PosterID}}" | 	"QueryLink" $queryLink | ||||||
| 	data-action-jump-url="{{QueryBuild $queryLink "poster" NIL}}&poster={username}" | 	"UserSearchUrl" (Iif .Milestone (print $.RepoLink "/issues/posters") (print $.Link "/posters")) | ||||||
| > | 	"SelectedUserId" $.PosterUserID | ||||||
| 	<span class="text"> | 	"TextFilterTitle" (ctx.Locale.Tr "repo.issues.filter_poster") | ||||||
| 		{{ctx.Locale.Tr "repo.issues.filter_poster"}} | }} | ||||||
| 	</span> |  | ||||||
| 	{{svg "octicon-triangle-down" 14 "dropdown icon"}} |  | ||||||
| 	<div class="menu"> |  | ||||||
| 		<div class="ui icon search input"> |  | ||||||
| 			<i class="icon">{{svg "octicon-search" 16}}</i> |  | ||||||
| 			<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_poster"}}"> |  | ||||||
| 		</div> |  | ||||||
| 		<a class="item" data-value="0">{{ctx.Locale.Tr "repo.issues.filter_poster_no_select"}}</a> |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
|  |  | ||||||
| <!-- Assignee --> | {{template "repo/issue/filter_item_user_assign" dict | ||||||
| <div class="ui {{if not .Assignees}}disabled{{end}} dropdown jump item"> | 	"QueryParamKey" "assignee" | ||||||
| 	<span class="text"> | 	"QueryLink" $queryLink | ||||||
| 		{{ctx.Locale.Tr "repo.issues.filter_assignee"}} | 	"UserSearchList" $.Assignees | ||||||
| 	</span> | 	"SelectedUserId" $.AssigneeID | ||||||
| 	{{svg "octicon-triangle-down" 14 "dropdown icon"}} | 	"TextFilterTitle" (ctx.Locale.Tr "repo.issues.filter_assignee") | ||||||
| 	<div class="menu"> | 	"TextZeroValue" (ctx.Locale.Tr "repo.issues.filter_assginee_no_select") | ||||||
| 		<div class="ui icon search input"> | 	"TextNegativeOne" (ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee") | ||||||
| 			<i class="icon">{{svg "octicon-search" 16}}</i> | }} | ||||||
| 			<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_assignee"}}"> |  | ||||||
| 		</div> |  | ||||||
| 		<a class="{{if not .AssigneeID}}active selected {{end}}item" href="{{QueryBuild $queryLink "assignee" NIL}}">{{ctx.Locale.Tr "repo.issues.filter_assginee_no_select"}}</a> |  | ||||||
| 		<a class="{{if eq .AssigneeID -1}}active selected {{end}}item" href="{{QueryBuild $queryLink "assignee" -1}}">{{ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee"}}</a> |  | ||||||
| 		<div class="divider"></div> |  | ||||||
| 		{{range .Assignees}} |  | ||||||
| 			<a class="{{if eq $.AssigneeID .ID}}active selected{{end}} item tw-flex" href="{{QueryBuild $queryLink "assignee" .ID}}"> |  | ||||||
| 				{{ctx.AvatarUtils.Avatar . 20}}{{template "repo/search_name" .}} |  | ||||||
| 			</a> |  | ||||||
| 		{{end}} |  | ||||||
| 	</div> |  | ||||||
| </div> |  | ||||||
|  |  | ||||||
| {{if .IsSigned}} | {{if .IsSigned}} | ||||||
| 	<!-- Type --> | 	<!-- Type --> | ||||||
|   | |||||||
| @@ -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"}} | ||||||
| <div class="small-menu-items ui compact tiny menu"> | <div class="small-menu-items ui compact tiny menu"> | ||||||
| 	<a class="{{if eq .State "open"}}active {{end}}item" href="{{if eq .State "open"}}{{.AllStatesLink}}{{else}}{{.OpenLink}}{{end}}"> | 	<a class="{{if eq .State "open"}}active {{end}}item flex-text-inline" href="{{if eq .State "open"}}{{$allStatesLink}}{{else}}{{$openLink}}{{end}}"> | ||||||
| 		{{if .PageIsMilestones}} | 		{{if .PageIsMilestones}} | ||||||
| 			{{svg "octicon-milestone" 16 "tw-mr-2"}} | 			{{svg "octicon-milestone"}} | ||||||
| 		{{else if .PageIsPullList}} |  | ||||||
| 			{{svg "octicon-git-pull-request" 16 "tw-mr-2"}} |  | ||||||
| 		{{else}} | 		{{else}} | ||||||
| 			{{svg "octicon-issue-opened" 16 "tw-mr-2"}} | 			{{Iif .PageIsPullList (svg "octicon-git-pull-request") (svg "octicon-issue-opened")}} | ||||||
| 		{{end}} | 		{{end}} | ||||||
| 		{{ctx.Locale.PrettyNumber .OpenCount}} {{ctx.Locale.Tr "repo.issues.open_title"}} | 		{{ctx.Locale.PrettyNumber .OpenCount}} {{ctx.Locale.Tr "repo.issues.open_title"}} | ||||||
| 	</a> | 	</a> | ||||||
| 	<a class="{{if eq .State "closed"}}active {{end}}item" href="{{if eq .State "closed"}}{{.AllStatesLink}}{{else}}{{.ClosedLink}}{{end}}"> | 	<a class="{{if eq .State "closed"}}active {{end}}item flex-text-inline" href="{{if eq .State "closed"}}{{$allStatesLink}}{{else}}{{$closedLink}}{{end}}"> | ||||||
| 		{{svg "octicon-check" 16 "tw-mr-2"}} | 		{{svg "octicon-check"}} | ||||||
| 		{{ctx.Locale.PrettyNumber .ClosedCount}} {{ctx.Locale.Tr "repo.issues.closed_title"}} | 		{{ctx.Locale.PrettyNumber .ClosedCount}} {{ctx.Locale.Tr "repo.issues.closed_title"}} | ||||||
| 	</a> | 	</a> | ||||||
| </div> | </div> | ||||||
|   | |||||||
| @@ -1390,8 +1390,9 @@ table th[data-sortt-desc] .svg { | |||||||
|   min-width: 0; |   min-width: 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| /* to override Fomantic's default display: block for ".menu .item", and use a slightly larger gap for menu item content */ | /* to override Fomantic's default display: block for ".menu .item", and use a slightly larger gap for menu item content | ||||||
| .ui.dropdown .menu.flex-items-menu > .item { | the "!important" is necessary to override Fomantic UI menu item styles, meanwhile we should keep the "hidden" items still hidden */ | ||||||
|  | .ui.dropdown .menu.flex-items-menu > .item:not(.hidden, .filtered, .tw-hidden) { | ||||||
|   display: flex !important; |   display: flex !important; | ||||||
|   align-items: center; |   align-items: center; | ||||||
|   gap: .5rem; |   gap: .5rem; | ||||||
|   | |||||||
| @@ -74,24 +74,6 @@ | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| .repository .filter.menu.labels .label-filter .menu .info { |  | ||||||
|   display: inline-block; |  | ||||||
|   padding: 0.5rem 0; |  | ||||||
|   font-size: 12px; |  | ||||||
|   width: 100%; |  | ||||||
|   white-space: nowrap; |  | ||||||
|   margin-left: 10px; |  | ||||||
|   margin-right: 8px; |  | ||||||
|   text-align: left; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| .repository .filter.menu.labels .label-filter .menu .info code { |  | ||||||
|   border: 1px solid var(--color-secondary); |  | ||||||
|   border-radius: var(--border-radius); |  | ||||||
|   padding: 1px 2px; |  | ||||||
|   font-size: 11px; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /* make all issue filter dropdown menus popup leftward, to avoid go out the viewport (right side) */ | /* make all issue filter dropdown menus popup leftward, to avoid go out the viewport (right side) */ | ||||||
| .repository .filter.menu .ui.dropdown .menu { | .repository .filter.menu .ui.dropdown .menu { | ||||||
|   max-height: 500px; |   max-height: 500px; | ||||||
| @@ -108,6 +90,24 @@ | |||||||
|   left: 0; |   left: 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | .repository .filter.menu .ui.dropdown.label-filter .menu .info { | ||||||
|  |   display: inline-block; | ||||||
|  |   padding: 0.5rem 0; | ||||||
|  |   font-size: 12px; | ||||||
|  |   width: 100%; | ||||||
|  |   white-space: nowrap; | ||||||
|  |   margin-left: 10px; | ||||||
|  |   margin-right: 8px; | ||||||
|  |   text-align: left; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | .repository .filter.menu .ui.dropdown.label-filter .menu .info code { | ||||||
|  |   border: 1px solid var(--color-secondary); | ||||||
|  |   border-radius: var(--border-radius); | ||||||
|  |   padding: 1px 2px; | ||||||
|  |   font-size: 11px; | ||||||
|  | } | ||||||
|  |  | ||||||
| /* For the secondary pointing menu, respect its own border-bottom */ | /* For the secondary pointing menu, respect its own border-bottom */ | ||||||
| /* style reference: https://semantic-ui.com/collections/menu.html#pointing */ | /* style reference: https://semantic-ui.com/collections/menu.html#pointing */ | ||||||
| .repository .ui.tabs.container .ui.menu:not(.secondary.pointing) { | .repository .ui.tabs.container .ui.menu:not(.secondary.pointing) { | ||||||
|   | |||||||
| @@ -68,10 +68,8 @@ | |||||||
|   background-color: var(--color-secondary-dark-4); |   background-color: var(--color-secondary-dark-4); | ||||||
| } | } | ||||||
|  |  | ||||||
| .archived-label-filter { | .label-filter-archived-toggle { | ||||||
|   margin-left: 10px; |   margin: 8px 10px; | ||||||
|   font-size: 12px; |   font-size: 12px; | ||||||
|   display: flex !important; |  | ||||||
|   margin-bottom: 8px; |  | ||||||
|   min-width: fit-content; |   min-width: fit-content; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| import {updateIssuesMeta} from './repo-common.ts'; | import {updateIssuesMeta} from './repo-common.ts'; | ||||||
| import {toggleElem, hideElem, isElemHidden, queryElems} from '../utils/dom.ts'; | import {toggleElem, isElemHidden, queryElems} from '../utils/dom.ts'; | ||||||
| import {htmlEscape} from 'escape-goat'; | import {htmlEscape} from 'escape-goat'; | ||||||
| import {confirmModal} from './comp/ConfirmModal.ts'; | import {confirmModal} from './comp/ConfirmModal.ts'; | ||||||
| import {showErrorToast} from '../modules/toast.ts'; | import {showErrorToast} from '../modules/toast.ts'; | ||||||
| @@ -95,34 +95,51 @@ function initRepoIssueListCheckboxes() { | |||||||
| function initDropdownUserRemoteSearch(el: Element) { | function initDropdownUserRemoteSearch(el: Element) { | ||||||
|   let searchUrl = el.getAttribute('data-search-url'); |   let searchUrl = el.getAttribute('data-search-url'); | ||||||
|   const actionJumpUrl = el.getAttribute('data-action-jump-url'); |   const actionJumpUrl = el.getAttribute('data-action-jump-url'); | ||||||
|   const selectedUserId = el.getAttribute('data-selected-user-id'); |   const selectedUserId = parseInt(el.getAttribute('data-selected-user-id')); | ||||||
|  |   let selectedUsername = ''; | ||||||
|   if (!searchUrl.includes('?')) searchUrl += '?'; |   if (!searchUrl.includes('?')) searchUrl += '?'; | ||||||
|   const $searchDropdown = fomanticQuery(el); |   const $searchDropdown = fomanticQuery(el); | ||||||
|  |   const elSearchInput = el.querySelector<HTMLInputElement>('.ui.search input'); | ||||||
|  |   const elItemFromInput = el.querySelector('.menu > .item-from-input'); | ||||||
|  |  | ||||||
|   $searchDropdown.dropdown('setting', { |   $searchDropdown.dropdown('setting', { | ||||||
|     fullTextSearch: true, |     fullTextSearch: true, | ||||||
|     selectOnKeydown: false, |     selectOnKeydown: false, | ||||||
|     apiSettings: { |     action: (_text, value) => { | ||||||
|  |       window.location.href = actionJumpUrl.replace('{username}', encodeURIComponent(value)); | ||||||
|  |     }, | ||||||
|  |   }); | ||||||
|  |  | ||||||
|  |   type ProcessedResult = {value: string, name: string}; | ||||||
|  |   const processedResults: ProcessedResult[] = []; // to be used by dropdown to generate menu items | ||||||
|  |   const syncItemFromInput = () => { | ||||||
|  |     elItemFromInput.setAttribute('data-value', elSearchInput.value); | ||||||
|  |     elItemFromInput.textContent = elSearchInput.value; | ||||||
|  |     toggleElem(elItemFromInput, !processedResults.length); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   if (!searchUrl) { | ||||||
|  |     elSearchInput.addEventListener('input', syncItemFromInput); | ||||||
|  |   } else { | ||||||
|  |     $searchDropdown.dropdown('setting', 'apiSettings', { | ||||||
|       cache: false, |       cache: false, | ||||||
|       url: `${searchUrl}&q={query}`, |       url: `${searchUrl}&q={query}`, | ||||||
|       onResponse(resp) { |       onResponse(resp) { | ||||||
|         // the content is provided by backend IssuePosters handler |         // the content is provided by backend IssuePosters handler | ||||||
|         const processedResults = []; // to be used by dropdown to generate menu items |         processedResults.length = 0; | ||||||
|         for (const item of resp.results) { |         for (const item of resp.results) { | ||||||
|           let html = `<img class="ui avatar tw-align-middle" src="${htmlEscape(item.avatar_link)}" aria-hidden="true" alt="" width="20" height="20"><span class="gt-ellipsis">${htmlEscape(item.username)}</span>`; |           let html = `<img class="ui avatar tw-align-middle" src="${htmlEscape(item.avatar_link)}" aria-hidden="true" alt="" width="20" height="20"><span class="gt-ellipsis">${htmlEscape(item.username)}</span>`; | ||||||
|           if (item.full_name) html += `<span class="search-fullname tw-ml-2">${htmlEscape(item.full_name)}</span>`; |           if (item.full_name) html += `<span class="search-fullname tw-ml-2">${htmlEscape(item.full_name)}</span>`; | ||||||
|  |           if (selectedUserId === item.user_id) selectedUsername = item.username; | ||||||
|           processedResults.push({value: item.username, name: html}); |           processedResults.push({value: item.username, name: html}); | ||||||
|         } |         } | ||||||
|         resp.results = processedResults; |         resp.results = processedResults; | ||||||
|  |         syncItemFromInput(); | ||||||
|         return resp; |         return resp; | ||||||
|       }, |       }, | ||||||
|     }, |     }); | ||||||
|     action: (_text, value) => { |     $searchDropdown.dropdown('setting', 'onShow', () => $searchDropdown.dropdown('filter', ' ')); // trigger a search on first show | ||||||
|       window.location.href = actionJumpUrl.replace('{username}', encodeURIComponent(value)); |   } | ||||||
|     }, |  | ||||||
|     onShow: () => { |  | ||||||
|       $searchDropdown.dropdown('filter', ' '); // trigger a search on first show |  | ||||||
|     }, |  | ||||||
|   }); |  | ||||||
|  |  | ||||||
|   // we want to generate the dropdown menu items by ourselves, replace its internal setup functions |   // we want to generate the dropdown menu items by ourselves, replace its internal setup functions | ||||||
|   const dropdownSetup = {...$searchDropdown.dropdown('internal', 'setup')}; |   const dropdownSetup = {...$searchDropdown.dropdown('internal', 'setup')}; | ||||||
| @@ -151,7 +168,7 @@ function initDropdownUserRemoteSearch(el: Element) { | |||||||
|       for (const el of menu.querySelectorAll('.item.active, .item.selected')) { |       for (const el of menu.querySelectorAll('.item.active, .item.selected')) { | ||||||
|         el.classList.remove('active', 'selected'); |         el.classList.remove('active', 'selected'); | ||||||
|       } |       } | ||||||
|       menu.querySelector(`.item[data-value="${selectedUserId}"]`)?.classList.add('selected'); |       menu.querySelector(`.item[data-value="${CSS.escape(selectedUsername)}"]`)?.classList.add('selected'); | ||||||
|     }, 0); |     }, 0); | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
| @@ -203,44 +220,9 @@ async function initIssuePinSort() { | |||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  |  | ||||||
| function initArchivedLabelFilter() { |  | ||||||
|   const archivedLabelEl = document.querySelector<HTMLInputElement>('#archived-filter-checkbox'); |  | ||||||
|   if (!archivedLabelEl) return; |  | ||||||
|  |  | ||||||
|   const url = new URL(window.location.href); |  | ||||||
|   const archivedLabels = document.querySelectorAll('[data-is-archived]'); |  | ||||||
|  |  | ||||||
|   if (!archivedLabels.length) { |  | ||||||
|     hideElem('.archived-label-filter'); |  | ||||||
|     return; |  | ||||||
|   } |  | ||||||
|   const selectedLabels = (url.searchParams.get('labels') || '') |  | ||||||
|     .split(',') |  | ||||||
|     .map((id) => parseInt(id) < 0 ? `${~id + 1}` : id); // selectedLabels contains -ve ids, which are excluded so convert any -ve value id to +ve |  | ||||||
|  |  | ||||||
|   const archivedElToggle = () => { |  | ||||||
|     for (const label of archivedLabels) { |  | ||||||
|       const id = label.getAttribute('data-label-id'); |  | ||||||
|       toggleElem(label, archivedLabelEl.checked || selectedLabels.includes(id)); |  | ||||||
|     } |  | ||||||
|   }; |  | ||||||
|  |  | ||||||
|   archivedElToggle(); |  | ||||||
|   archivedLabelEl.addEventListener('change', () => { |  | ||||||
|     archivedElToggle(); |  | ||||||
|     if (archivedLabelEl.checked) { |  | ||||||
|       url.searchParams.set('archived', 'true'); |  | ||||||
|     } else { |  | ||||||
|       url.searchParams.delete('archived'); |  | ||||||
|     } |  | ||||||
|     window.location.href = url.href; |  | ||||||
|   }); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| export function initRepoIssueList() { | export function initRepoIssueList() { | ||||||
|   if (!document.querySelector('.page-content.repository.issue-list, .page-content.repository.milestone-issue-list')) return; |   if (!document.querySelector('.page-content.repository.issue-list, .page-content.repository.milestone-issue-list')) return; | ||||||
|   initRepoIssueListCheckboxes(); |   initRepoIssueListCheckboxes(); | ||||||
|   queryElems(document, '.ui.dropdown.user-remote-search', (el) => initDropdownUserRemoteSearch(el)); |   queryElems(document, '.ui.dropdown.user-remote-search', (el) => initDropdownUserRemoteSearch(el)); | ||||||
|   initIssuePinSort(); |   initIssuePinSort(); | ||||||
|   initArchivedLabelFilter(); |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,7 +1,14 @@ | |||||||
| import $ from 'jquery'; | import $ from 'jquery'; | ||||||
| import {htmlEscape} from 'escape-goat'; | import {htmlEscape} from 'escape-goat'; | ||||||
| import {createTippy, showTemporaryTooltip} from '../modules/tippy.ts'; | import {createTippy, showTemporaryTooltip} from '../modules/tippy.ts'; | ||||||
| import {addDelegatedEventListener, createElementFromHTML, hideElem, showElem, toggleElem} from '../utils/dom.ts'; | import { | ||||||
|  |   addDelegatedEventListener, | ||||||
|  |   createElementFromHTML, | ||||||
|  |   hideElem, | ||||||
|  |   queryElems, | ||||||
|  |   showElem, | ||||||
|  |   toggleElem, | ||||||
|  | } from '../utils/dom.ts'; | ||||||
| import {setFileFolding} from './file-fold.ts'; | import {setFileFolding} from './file-fold.ts'; | ||||||
| import {ComboMarkdownEditor, getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.ts'; | import {ComboMarkdownEditor, getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.ts'; | ||||||
| import {parseIssuePageInfo, toAbsoluteUrl} from '../utils.ts'; | import {parseIssuePageInfo, toAbsoluteUrl} from '../utils.ts'; | ||||||
| @@ -12,19 +19,6 @@ import {fomanticQuery} from '../modules/fomantic/base.ts'; | |||||||
|  |  | ||||||
| const {appSubUrl} = window.config; | const {appSubUrl} = window.config; | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @param {HTMLElement} item |  | ||||||
|  */ |  | ||||||
| function excludeLabel(item) { |  | ||||||
|   const href = item.getAttribute('href'); |  | ||||||
|   const id = item.getAttribute('data-label-id'); |  | ||||||
|  |  | ||||||
|   const regStr = `labels=((?:-?[0-9]+%2c)*)(${id})((?:%2c-?[0-9]+)*)&`; |  | ||||||
|   const newStr = 'labels=$1-$2$3&'; |  | ||||||
|  |  | ||||||
|   window.location.assign(href.replace(new RegExp(regStr), newStr)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| export function initRepoIssueSidebarList() { | export function initRepoIssueSidebarList() { | ||||||
|   const issuePageInfo = parseIssuePageInfo(); |   const issuePageInfo = parseIssuePageInfo(); | ||||||
|   const crossRepoSearch = $('#crossRepoSearch').val(); |   const crossRepoSearch = $('#crossRepoSearch').val(); | ||||||
| @@ -58,24 +52,74 @@ export function initRepoIssueSidebarList() { | |||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  |  | ||||||
| export function initRepoIssueLabelFilter() { | function initRepoIssueLabelFilter(elDropdown: Element) { | ||||||
|   // the "label-filter" is used in 2 templates: projects/view, issue/filter_list (issue list page including the milestone page) |   const url = new URL(window.location.href); | ||||||
|   $('.ui.dropdown.label-filter a.label-filter-item').each(function () { |   const showArchivedLabels = url.searchParams.get('archived_labels') === 'true'; | ||||||
|     $(this).on('click', function (e) { |   const queryLabels = url.searchParams.get('labels') || ''; | ||||||
|       if (e.altKey) { |   const selectedLabelIds = new Set<string>(); | ||||||
|         e.preventDefault(); |   for (const id of queryLabels ? queryLabels.split(',') : []) { | ||||||
|         excludeLabel(this); |     selectedLabelIds.add(`${Math.abs(parseInt(id))}`); // "labels" contains negative ids, which are excluded | ||||||
|       } |   } | ||||||
|  |  | ||||||
|  |   const excludeLabel = (e: MouseEvent|KeyboardEvent, item: Element) => { | ||||||
|  |     e.preventDefault(); | ||||||
|  |     e.stopPropagation(); | ||||||
|  |     const labelId = item.getAttribute('data-label-id'); | ||||||
|  |     let labelIds: string[] = queryLabels ? queryLabels.split(',') : []; | ||||||
|  |     labelIds = labelIds.filter((id) => Math.abs(parseInt(id)) !== Math.abs(parseInt(labelId))); | ||||||
|  |     labelIds.push(`-${labelId}`); | ||||||
|  |     url.searchParams.set('labels', labelIds.join(',')); | ||||||
|  |     window.location.assign(url); | ||||||
|  |   }; | ||||||
|  |  | ||||||
|  |   // alt(or option) + click to exclude label | ||||||
|  |   queryElems(elDropdown, '.label-filter-query-item', (el) => { | ||||||
|  |     el.addEventListener('click', (e: MouseEvent) => { | ||||||
|  |       if (e.altKey) excludeLabel(e, el); | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
|   $('.ui.dropdown.label-filter').on('keydown', (e) => { |   // alt(or option) + enter to exclude selected label | ||||||
|  |   elDropdown.addEventListener('keydown', (e: KeyboardEvent) => { | ||||||
|     if (e.altKey && e.key === 'Enter') { |     if (e.altKey && e.key === 'Enter') { | ||||||
|       const selectedItem = document.querySelector('.ui.dropdown.label-filter .menu .item.selected'); |       const selectedItem = elDropdown.querySelector('.label-filter-query-item.selected'); | ||||||
|       if (selectedItem) { |       if (selectedItem) excludeLabel(e, selectedItem); | ||||||
|         excludeLabel(selectedItem); |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|   }); |   }); | ||||||
|  |   // no "labels" query parameter means "all issues" | ||||||
|  |   elDropdown.querySelector('.label-filter-query-default').classList.toggle('selected', queryLabels === ''); | ||||||
|  |   // "labels=0" query parameter means "issues without label" | ||||||
|  |   elDropdown.querySelector('.label-filter-query-not-set').classList.toggle('selected', queryLabels === '0'); | ||||||
|  |  | ||||||
|  |   // prepare to process "archived" labels | ||||||
|  |   const elShowArchivedLabel = elDropdown.querySelector('.label-filter-archived-toggle'); | ||||||
|  |   if (!elShowArchivedLabel) return; | ||||||
|  |   const elShowArchivedInput = elShowArchivedLabel.querySelector<HTMLInputElement>('input'); | ||||||
|  |   elShowArchivedInput.checked = showArchivedLabels; | ||||||
|  |   const archivedLabels = elDropdown.querySelectorAll('.item[data-is-archived]'); | ||||||
|  |   // if no archived labels, hide the toggle and return | ||||||
|  |   if (!archivedLabels.length) { | ||||||
|  |     hideElem(elShowArchivedLabel); | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   // show the archived labels if the toggle is checked or the label is selected | ||||||
|  |   for (const label of archivedLabels) { | ||||||
|  |     toggleElem(label, showArchivedLabels || selectedLabelIds.has(label.getAttribute('data-label-id'))); | ||||||
|  |   } | ||||||
|  |   // update the url when the toggle is changed and reload | ||||||
|  |   elShowArchivedInput.addEventListener('input', () => { | ||||||
|  |     if (elShowArchivedInput.checked) { | ||||||
|  |       url.searchParams.set('archived_labels', 'true'); | ||||||
|  |     } else { | ||||||
|  |       url.searchParams.delete('archived_labels'); | ||||||
|  |     } | ||||||
|  |     window.location.assign(url); | ||||||
|  |   }); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export function initRepoIssueFilterItemLabel() { | ||||||
|  |   // the "label-filter" is used in 2 templates: projects/view, issue/filter_list (issue list page including the milestone page) | ||||||
|  |   queryElems(document, '.ui.dropdown.label-filter', initRepoIssueLabelFilter); | ||||||
| } | } | ||||||
|  |  | ||||||
| export function initRepoIssueCommentDelete() { | export function initRepoIssueCommentDelete() { | ||||||
|   | |||||||
| @@ -29,7 +29,7 @@ import { | |||||||
|   initRepoIssueWipTitle, |   initRepoIssueWipTitle, | ||||||
|   initRepoPullRequestMergeInstruction, |   initRepoPullRequestMergeInstruction, | ||||||
|   initRepoPullRequestAllowMaintainerEdit, |   initRepoPullRequestAllowMaintainerEdit, | ||||||
|   initRepoPullRequestReview, initRepoIssueSidebarList, initRepoIssueLabelFilter, |   initRepoPullRequestReview, initRepoIssueSidebarList, initRepoIssueFilterItemLabel, | ||||||
| } from './features/repo-issue.ts'; | } from './features/repo-issue.ts'; | ||||||
| import {initRepoEllipsisButton, initCommitStatuses} from './features/repo-commit.ts'; | import {initRepoEllipsisButton, initCommitStatuses} from './features/repo-commit.ts'; | ||||||
| import {initRepoTopicBar} from './features/repo-home.ts'; | import {initRepoTopicBar} from './features/repo-home.ts'; | ||||||
| @@ -181,7 +181,7 @@ onDomReady(() => { | |||||||
|     initRepoGraphGit, |     initRepoGraphGit, | ||||||
|     initRepoIssueContentHistory, |     initRepoIssueContentHistory, | ||||||
|     initRepoIssueList, |     initRepoIssueList, | ||||||
|     initRepoIssueLabelFilter, |     initRepoIssueFilterItemLabel, | ||||||
|     initRepoIssueSidebarList, |     initRepoIssueSidebarList, | ||||||
|     initRepoIssueReferenceRepositorySearch, |     initRepoIssueReferenceRepositorySearch, | ||||||
|     initRepoIssueWipTitle, |     initRepoIssueWipTitle, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user