Skip to content

Commit 27a5e32

Browse files
committed
use name in dropdown
1 parent 524aa9e commit 27a5e32

File tree

7 files changed

+39
-26
lines changed

7 files changed

+39
-26
lines changed

routers/web/repo/issue_list.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -505,18 +505,15 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
505505
viewType = "all"
506506
}
507507

508-
var (
509-
assigneeID = ctx.FormInt64("assignee")
510-
posterID = ctx.FormInt64("poster")
511-
mentionedID int64
512-
reviewRequestedID int64
513-
reviewedID int64
514-
)
508+
assigneeID := ctx.FormInt64("assignee")
509+
posterUsername := ctx.FormString("poster")
510+
posterUserID := shared_user.GetFilterUserIDByName(ctx, posterUsername)
511+
var mentionedID, reviewRequestedID, reviewedID int64
515512

516513
if ctx.IsSigned {
517514
switch viewType {
518515
case "created_by":
519-
posterID = ctx.Doer.ID
516+
posterUserID = ctx.Doer.ID
520517
case "mentioned":
521518
mentionedID = ctx.Doer.ID
522519
case "assigned":
@@ -564,7 +561,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
564561
ProjectID: projectID,
565562
AssigneeID: assigneeID,
566563
MentionedID: mentionedID,
567-
PosterID: posterID,
564+
PosterID: posterUserID,
568565
ReviewRequestedID: reviewRequestedID,
569566
ReviewedID: reviewedID,
570567
IsPull: isPullOption,
@@ -646,7 +643,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
646643
},
647644
RepoIDs: []int64{repo.ID},
648645
AssigneeID: assigneeID,
649-
PosterID: posterID,
646+
PosterID: posterUserID,
650647
MentionedID: mentionedID,
651648
ReviewRequestedID: reviewRequestedID,
652649
ReviewedID: reviewedID,
@@ -800,24 +797,24 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
800797
ctx.Data["IssueStats"] = issueStats
801798
ctx.Data["OpenCount"] = issueStats.OpenCount
802799
ctx.Data["ClosedCount"] = issueStats.ClosedCount
803-
linkStr := "%s?q=%s&type=%s&sort=%s&state=%s&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%d&archived=%t"
800+
linkStr := "%s?q=%s&type=%s&sort=%s&state=%s&labels=%s&milestone=%d&project=%d&assignee=%d&poster=%v&archived=%t"
804801
ctx.Data["AllStatesLink"] = fmt.Sprintf(linkStr, ctx.Link,
805802
url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "all", url.QueryEscape(selectLabels),
806-
milestoneID, projectID, assigneeID, posterID, archived)
803+
milestoneID, projectID, assigneeID, url.QueryEscape(posterUsername), archived)
807804
ctx.Data["OpenLink"] = fmt.Sprintf(linkStr, ctx.Link,
808805
url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "open", url.QueryEscape(selectLabels),
809-
milestoneID, projectID, assigneeID, posterID, archived)
806+
milestoneID, projectID, assigneeID, url.QueryEscape(posterUsername), archived)
810807
ctx.Data["ClosedLink"] = fmt.Sprintf(linkStr, ctx.Link,
811808
url.QueryEscape(keyword), url.QueryEscape(viewType), url.QueryEscape(sortType), "closed", url.QueryEscape(selectLabels),
812-
milestoneID, projectID, assigneeID, posterID, archived)
809+
milestoneID, projectID, assigneeID, url.QueryEscape(posterUsername), archived)
813810
ctx.Data["SelLabelIDs"] = labelIDs
814811
ctx.Data["SelectLabels"] = selectLabels
815812
ctx.Data["ViewType"] = viewType
816813
ctx.Data["SortType"] = sortType
817814
ctx.Data["MilestoneID"] = milestoneID
818815
ctx.Data["ProjectID"] = projectID
819816
ctx.Data["AssigneeID"] = assigneeID
820-
ctx.Data["PosterID"] = posterID
817+
ctx.Data["PosterUsername"] = posterUsername
821818
ctx.Data["Keyword"] = keyword
822819
ctx.Data["IsShowClosed"] = isShowClosed
823820
switch {
@@ -838,7 +835,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
838835
pager.AddParamString("milestone", fmt.Sprint(milestoneID))
839836
pager.AddParamString("project", fmt.Sprint(projectID))
840837
pager.AddParamString("assignee", fmt.Sprint(assigneeID))
841-
pager.AddParamString("poster", fmt.Sprint(posterID))
838+
pager.AddParamString("poster", posterUsername)
842839
pager.AddParamString("archived", fmt.Sprint(archived))
843840

844841
ctx.Data["Page"] = pager

routers/web/shared/user/helper.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package user
55

66
import (
7+
"context"
78
"slices"
9+
"strconv"
810

911
"code.gitea.io/gitea/models/user"
1012
)
@@ -24,3 +26,17 @@ func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
2426
}
2527
return users
2628
}
29+
30+
func GetFilterUserIDByName(ctx context.Context, name string) int64 {
31+
if name == "" {
32+
return 0
33+
}
34+
u, err := user.GetUserByName(ctx, name)
35+
if err != nil {
36+
if id, err := strconv.ParseInt(name, 10, 64); err == nil {
37+
return id
38+
}
39+
return 0
40+
}
41+
return u.ID
42+
}

routers/web/user/home.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"code.gitea.io/gitea/modules/setting"
3434
"code.gitea.io/gitea/modules/util"
3535
"code.gitea.io/gitea/routers/web/feed"
36+
"code.gitea.io/gitea/routers/web/shared/user"
3637
"code.gitea.io/gitea/services/context"
3738
feed_service "code.gitea.io/gitea/services/feed"
3839
issue_service "code.gitea.io/gitea/services/issue"
@@ -441,7 +442,8 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
441442
// FIXME: this feature doesn't work at the moment, because frontend can't use a "user-remote-search" dropdown directly
442443
// the existing "/posters" handlers doesn't work for this case, it is unable to list the related users correctly.
443444
// In the future, we need something like github: "author:user1" to accept usernames directly.
444-
opts.PosterID, _ = strconv.ParseInt(ctx.FormString("poster"), 10, 64)
445+
posterUsername := ctx.FormString("poster")
446+
opts.PosterID = user.GetFilterUserIDByName(ctx, posterUsername)
445447
opts.AssigneeID, _ = strconv.ParseInt(ctx.FormString("assignee"), 10, 64)
446448

447449
isFuzzy := ctx.FormBool("fuzzy")
@@ -659,9 +661,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
659661
pager.AddParamString("state", fmt.Sprint(ctx.Data["State"]))
660662
pager.AddParamString("labels", selectedLabels)
661663
pager.AddParamString("fuzzy", fmt.Sprint(isFuzzy))
662-
if opts.PosterID != 0 {
663-
pager.AddParamString("poster", fmt.Sprint(opts.PosterID))
664-
}
664+
pager.AddParamString("poster", posterUsername)
665665
if opts.AssigneeID != 0 {
666666
pager.AddParamString("assignee", fmt.Sprint(opts.AssigneeID))
667667
}

templates/repo/issue/filter_list.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{$queryLink := QueryBuild "?" "q" $.Keyword "type" $.ViewType "sort" $.SortType "state" $.State "labels" $.SelectLabels "milestone" $.MilestoneID "project" $.ProjectID "assignee" $.AssigneeID "poster" $.PosterID "archived" (Iif $.ShowArchivedLabels NIL)}}
1+
{{$queryLink := QueryBuild "?" "q" $.Keyword "type" $.ViewType "sort" $.SortType "state" $.State "labels" $.SelectLabels "milestone" $.MilestoneID "project" $.ProjectID "assignee" $.AssigneeID "poster" $.PosterUsername "archived" (Iif $.ShowArchivedLabels NIL)}}
22
<!-- Label -->
33
<div class="ui {{if not .Labels}}disabled{{end}} dropdown jump item label-filter">
44
<span class="text">
@@ -131,7 +131,7 @@
131131
<div class="ui dropdown jump item user-remote-search" data-tooltip-content="{{ctx.Locale.Tr "repo.author_search_tooltip"}}"
132132
data-search-url="{{if .Milestone}}{{$.RepoLink}}/issues/posters{{else}}{{$.Link}}/posters{{end}}"
133133
data-selected-user-id="{{$.PosterID}}"
134-
data-action-jump-url="{{QueryBuild $queryLink "poster" NIL}}&poster={user_id}"
134+
data-action-jump-url="{{QueryBuild $queryLink "poster" NIL}}&poster={username}"
135135
>
136136
<span class="text">
137137
{{ctx.Locale.Tr "repo.issues.filter_poster"}}

templates/repo/issue/search.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<input type="hidden" name="milestone" value="{{$.MilestoneID}}">
88
<input type="hidden" name="project" value="{{$.ProjectID}}">
99
<input type="hidden" name="assignee" value="{{$.AssigneeID}}">
10-
<input type="hidden" name="poster" value="{{$.PosterID}}">
10+
<input type="hidden" name="poster" value="{{$.PosterUsername}}">
1111
{{end}}
1212
{{template "shared/search/input" dict "Value" .Keyword}}
1313
{{if .PageIsIssueList}}

templates/user/dashboard/issues.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</div>
3737
</div>
3838

39-
{{$queryLinkWithFilter := QueryBuild $queryLink "poster" $.SearchFilterPosterID "assignee" $.SearchFilterAssigneeID}}
39+
{{$queryLinkWithFilter := QueryBuild $queryLink "poster" $.SearchFilterPosterUsername "assignee" $.SearchFilterAssigneeID}}
4040
<div class="flex-container-main content">
4141
<div class="list-header">
4242
<div class="small-menu-items ui compact tiny menu list-header-toggle flex-items-block">

web_src/js/features/repo-issue-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ function initDropdownUserRemoteSearch(el: Element) {
110110
for (const item of resp.results) {
111111
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>`;
112112
if (item.full_name) html += `<span class="search-fullname tw-ml-2">${htmlEscape(item.full_name)}</span>`;
113-
processedResults.push({value: item.user_id, name: html});
113+
processedResults.push({value: item.username, name: html});
114114
}
115115
resp.results = processedResults;
116116
return resp;
117117
},
118118
},
119119
action: (_text, value) => {
120-
window.location.href = actionJumpUrl.replace('{user_id}', encodeURIComponent(value));
120+
window.location.href = actionJumpUrl.replace('{username}', encodeURIComponent(value));
121121
},
122122
onShow: () => {
123123
$searchDropdown.dropdown('filter', ' '); // trigger a search on first show

0 commit comments

Comments
 (0)