Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI] IssuePage multi repo select #8741

Merged
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
16222fe
Make repository list @ issues/PR page persist
Mar 19, 2019
14d711a
Enable multiple selections in repo list @ issues/PR page
Mar 19, 2019
95a0853
Remove redundant code
Mar 26, 2019
a555ce6
Merge branch 'master' into master
oscarlofwenhamn Mar 26, 2019
1da7a50
Merge branch 'master' into master
zeripath Mar 26, 2019
0fcd877
Merge branch 'master' into master
lunny Mar 27, 2019
fd7fa02
Merge branch 'master' into master
lunny Mar 27, 2019
6ab937d
Merge branch 'master' into master
techknowlogick Mar 27, 2019
662966b
Merge branch 'master' into master
Apr 1, 2019
070a7d1
Add 'All' button
Apr 1, 2019
827b3ff
Remove redundant variable
Apr 1, 2019
c1c2aab
Add RepoIDs to label link
Apr 5, 2019
f44626b
Merge branch 'master' into master
oscarlofwenhamn Apr 5, 2019
5351328
Merge branch 'master' into master
oscarlofwenhamn Apr 8, 2019
2a2efda
Merge branch 'master' into master
oscarlofwenhamn Apr 12, 2019
097e8d0
Merge branch 'origin/master' into master
May 9, 2019
72d602e
Revert part of code to previous version to troubleshoot build failure
May 9, 2019
ce103d7
Implement old and new pieces of code whilst adhering to multi select
May 9, 2019
1cc586f
Attempt to join the two versions
May 9, 2019
898a7bc
Update tests to desired state
May 9, 2019
11ce5ec
Merge branch 'master' into master
oscarlofwenhamn May 13, 2019
283ed33
Merge remote-tracking branch 'origin/master'
May 13, 2019
f476dc4
Fix pagination implementation and tests
May 13, 2019
5562f9b
Merge branch 'feature/multiselect-issue-repos'
May 13, 2019
6ef65ff
Correct behavior when passing zero to array
May 13, 2019
7038fdf
Merge remote-tracking branch 'origin/master'
May 15, 2019
8695d21
Merge remote-tracking branch 'origin/master'
May 20, 2019
a2179e6
Comment out test url returning 404
May 20, 2019
3fc7bb1
Comment out another test url returning 404
May 20, 2019
847510e
Merge branch 'master' into master
oscarlofwenhamn May 27, 2019
a4580a1
Reenable tests and test fix
May 27, 2019
0e0754b
Drop repo from repo map and total count if permission denied
May 27, 2019
e0f3579
Remove extra parenthesis
May 27, 2019
08fc6e5
Merge branch 'master' into issue-page_multi-repo-select
6543 Oct 30, 2019
157a6f8
Merge branch 'master' into issue-page_multi-repo-select
6543 Oct 30, 2019
a6a89ba
make template work again
6543 Oct 30, 2019
0c2def7
Merge branch 'master' into issue-page_multi-repo-select
6543 Oct 30, 2019
5c6108e
Merge branch 'master' into issue-page_multi-repo-select
6543 Oct 30, 2019
85f44e1
Merge branch 'master' into issue-page_multi-repo-select
6543 Oct 30, 2019
5b843a8
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 2, 2019
21448cb
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 4, 2019
5519862
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 6, 2019
4d6747a
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 14, 2019
d347252
find bug!
6543 Nov 15, 2019
e3df4ef
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 16, 2019
9ae260c
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 16, 2019
e2f0a2d
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 16, 2019
cd913d9
forgot the '#' at bugfixing
6543 Nov 16, 2019
50c70bb
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 17, 2019
855a1de
delete unused RepoID
6543 Nov 17, 2019
f1498c7
compile regex only one time
6543 Nov 17, 2019
2d916a4
make fmt
6543 Nov 17, 2019
5d19684
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 17, 2019
91e0502
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 17, 2019
bce9432
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 18, 2019
9b3838c
local variable = capital letter lower
6543 Nov 18, 2019
7ff4124
check if repos query pattern is correct
6543 Nov 18, 2019
39fbe89
pagination remove last , - make regex work again
6543 Nov 18, 2019
bdfd142
use Replace instead of ReplaceAll; del delete
6543 Nov 18, 2019
df7ef06
fix test
6543 Nov 18, 2019
9ffb6da
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 18, 2019
05a48ee
how did this test binary got in?!?
6543 Nov 18, 2019
96a2fcf
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 18, 2019
d7377fe
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 19, 2019
17cd0bd
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 20, 2019
3b72e44
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 20, 2019
d8aab33
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 20, 2019
1773335
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 20, 2019
fc74b1f
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 20, 2019
753e961
dont replace -> cut fisrt & last string
6543 Nov 21, 2019
93d2d13
jet another regex
6543 Nov 21, 2019
bee6c40
dont use nonexisting repo for test
6543 Nov 22, 2019
8ee3a5a
exclude /issues?type=created_by from test
6543 Nov 22, 2019
e9cb140
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 22, 2019
8736f3f
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 23, 2019
dc7cc12
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 24, 2019
5dcf6be
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 25, 2019
59a02b3
add table to querys
6543 Nov 25, 2019
c8a4333
add new issue for test
6543 Nov 25, 2019
86ccafe
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 25, 2019
745c223
dont make a workaround or something else
6543 Nov 25, 2019
066126c
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 25, 2019
fdf8a18
fix misspell
6543 Nov 25, 2019
e8f3f5c
CI.redo()
6543 Nov 25, 2019
0fb0542
englisch txt update
6543 Nov 26, 2019
a8c124c
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 26, 2019
b5370c8
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 27, 2019
a129421
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 27, 2019
a6a61ce
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 28, 2019
c4037ed
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 29, 2019
a490171
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 29, 2019
ccc6316
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 30, 2019
6f86f49
add sugestions
6543 Nov 30, 2019
6f3ae82
Tweak & Fix
6543 Nov 30, 2019
605821b
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 30, 2019
5decbde
Merge branch 'master' into issue-page_multi-repo-select
6543 Nov 30, 2019
04939b7
Merge branch 'master' into issue-page_multi-repo-select
6543 Dec 1, 2019
7312446
Merge branch 'master' into issue-page_multi-repo-select
6543 Dec 1, 2019
028a625
CI.restart()
6543 Dec 1, 2019
064c27b
Merge branch 'master' into issue-page_multi-repo-select
techknowlogick Dec 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions integrations/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,20 @@ func testLinksAsUser(userName string, t *testing.T) {
"/api/swagger",
"/api/v1/swagger",
"/issues",
"/issues?type=your_repositories&repo=0&sort=&state=open",
"/issues?type=assigned&repo=0&sort=&state=open",
"/issues?type=created_by&repo=0&sort=&state=open",
"/issues?type=your_repositories&repo=0&sort=&state=closed",
"/issues?type=assigned&repo=0&sort=&state=closed",
"/issues?type=created_by&repo=0&sort=&state=closed",
"/issues?type=your_repositories&repos=[0]&sort=&state=open",
"/issues?type=assigned&repos=[0]&sort=&state=open",
"/issues?type=your_repositories&repos=[0]&sort=&state=closed",
"/issues?type=assigned&repos=[]&sort=&state=closed",
"/issues?type=assigned&sort=&state=open",
"/issues?type=created_by&repos=[1,2]&sort=&state=closed",
"/issues?type=created_by&repos=[1,2]&sort=&state=open",
"/pulls",
"/pulls?type=your_repositories&repo=0&sort=&state=open",
"/pulls?type=assigned&repo=0&sort=&state=open",
"/pulls?type=created_by&repo=0&sort=&state=open",
"/pulls?type=your_repositories&repo=0&sort=&state=closed",
"/pulls?type=assigned&repo=0&sort=&state=closed",
"/pulls?type=created_by&repo=0&sort=&state=closed",
"/pulls?type=your_repositories&repos=[2]&sort=&state=open",
"/pulls?type=assigned&repos=[]&sort=&state=open",
"/pulls?type=created_by&repos=[0]&sort=&state=open",
"/pulls?type=your_repositories&repos=[0]&sort=&state=closed",
"/pulls?type=assigned&repos=[0]&sort=&state=closed",
"/pulls?type=created_by&repos=[0]&sort=&state=closed",
"/notifications",
"/repo/create",
"/repo/migrate",
Expand Down
2 changes: 1 addition & 1 deletion models/fixtures/issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@
is_closed: false
is_pull: true
created_unix: 946684820
updated_unix: 978307180
updated_unix: 978307180
4 changes: 4 additions & 0 deletions models/fixtures/issue_assignees.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
id: 2
assignee_id: 1
issue_id: 6
-
id: 3
assignee_id: 2
issue_id: 6
18 changes: 9 additions & 9 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) {
// UserIssueStatsOptions contains parameters accepted by GetUserIssueStats.
type UserIssueStatsOptions struct {
UserID int64
RepoID int64
RepoIDs []int64
UserRepoIDs []int64
FilterMode int
IsPull bool
Expand All @@ -1392,19 +1392,19 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {

cond := builder.NewCond()
cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull})
if opts.RepoID > 0 {
cond = cond.And(builder.Eq{"issue.repo_id": opts.RepoID})
if len(opts.RepoIDs) > 0 {
cond = cond.And(builder.In("issue.repo_id", opts.RepoIDs))
}

switch opts.FilterMode {
case FilterModeAll:
stats.OpenCount, err = x.Where(cond).And("is_closed = ?", false).
stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue))
if err != nil {
return nil, err
}
stats.ClosedCount, err = x.Where(cond).And("is_closed = ?", true).
stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
And(builder.In("issue.repo_id", opts.UserRepoIDs)).
Count(new(Issue))
if err != nil {
Expand All @@ -1426,14 +1426,14 @@ func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
return nil, err
}
case FilterModeCreate:
stats.OpenCount, err = x.Where(cond).And("is_closed = ?", false).
And("poster_id = ?", opts.UserID).
stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
And("issue.poster_id = ?", opts.UserID).
Count(new(Issue))
if err != nil {
return nil, err
}
stats.ClosedCount, err = x.Where(cond).And("is_closed = ?", true).
And("poster_id = ?", opts.UserID).
stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
And("issue.poster_id = ?", opts.UserID).
Count(new(Issue))
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion models/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestGetUserIssueStats(t *testing.T) {
{
UserIssueStatsOptions{
UserID: 1,
RepoID: 1,
RepoIDs: []int64{1},
FilterMode: FilterModeAll,
},
IssueStats{
Expand Down
135 changes: 78 additions & 57 deletions routers/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ package user

import (
"bytes"
"encoding/json"
"fmt"
"regexp"
"sort"
"strconv"
"strings"

"code.gitea.io/gitea/models"
Expand All @@ -20,7 +23,6 @@ import (

"github.com/keybase/go-crypto/openpgp"
"github.com/keybase/go-crypto/openpgp/armor"
"github.com/unknwon/com"
)

const (
Expand Down Expand Up @@ -149,6 +151,9 @@ func Dashboard(ctx *context.Context) {
ctx.HTML(200, tplDashboard)
}

// Regexp for repos query
var issueReposQueryPattern = regexp.MustCompile(`^\[\d+(,\d+)*,?\]$`)

// Issues render the user issues page
func Issues(ctx *context.Context) {
isPullList := ctx.Params(":type") == "pulls"
Expand Down Expand Up @@ -194,7 +199,25 @@ func Issues(ctx *context.Context) {
page = 1
}

repoID := ctx.QueryInt64("repo")
reposQuery := ctx.Query("repos")
var repoIDs []int64
if issueReposQueryPattern.MatchString(reposQuery) {
// remove "[" and "]" from string
reposQuery = reposQuery[1 : len(reposQuery)-1]
//for each ID (delimiter ",") add to int to repoIDs
for _, rID := range strings.Split(reposQuery, ",") {
// Ensure nonempty string entries
if rID != "" && rID != "0" {
rIDint64, err := strconv.ParseInt(rID, 10, 64)
if err == nil {
repoIDs = append(repoIDs, rIDint64)
6543 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
} else {
log.Error("issueReposQueryPattern not match with query")
}

isShowClosed := ctx.Query("state") == "closed"

// Get repositories.
Expand Down Expand Up @@ -232,20 +255,9 @@ func Issues(ctx *context.Context) {
SortType: sortType,
}

if repoID > 0 {
opts.RepoIDs = []int64{repoID}
}

switch filterMode {
case models.FilterModeAll:
if repoID > 0 {
if !com.IsSliceContainsInt64(userRepoIDs, repoID) {
// force an empty result
opts.RepoIDs = []int64{-1}
}
} else {
opts.RepoIDs = userRepoIDs
}
opts.RepoIDs = userRepoIDs
case models.FilterModeAssign:
opts.AssigneeID = ctxUser.ID
case models.FilterModeCreate:
Expand Down Expand Up @@ -273,6 +285,10 @@ func Issues(ctx *context.Context) {
}
opts.LabelIDs = labelIDs

if len(repoIDs) > 0 {
6543 marked this conversation as resolved.
Show resolved Hide resolved
opts.RepoIDs = repoIDs
}

issues, err := models.Issues(opts)
if err != nil {
ctx.ServerError("Issues", err)
Expand All @@ -281,46 +297,30 @@ func Issues(ctx *context.Context) {

showReposMap := make(map[int64]*models.Repository, len(counts))
for repoID := range counts {
6543 marked this conversation as resolved.
Show resolved Hide resolved
repo, err := models.GetRepositoryByID(repoID)
if err != nil {
ctx.ServerError("GetRepositoryByID", err)
return
}
showReposMap[repoID] = repo
}

if repoID > 0 {
if _, ok := showReposMap[repoID]; !ok {
repo, err := models.GetRepositoryByID(repoID)
if models.IsErrRepoNotExist(err) {
ctx.NotFound("GetRepositoryByID", err)
return
} else if err != nil {
ctx.ServerError("GetRepositoryByID", fmt.Errorf("[%d]%v", repoID, err))
return
if repoID > 0 {
6543 marked this conversation as resolved.
Show resolved Hide resolved
if _, ok := showReposMap[repoID]; !ok {
6543 marked this conversation as resolved.
Show resolved Hide resolved
repo, err := models.GetRepositoryByID(repoID)
6543 marked this conversation as resolved.
Show resolved Hide resolved
if models.IsErrRepoNotExist(err) {
ctx.NotFound("GetRepositoryByID", err)
return
} else if err != nil {
ctx.ServerError("GetRepositoryByID", fmt.Errorf("[%d]%v", repoID, err))
return
}
showReposMap[repoID] = repo
}
showReposMap[repoID] = repo
}

repo := showReposMap[repoID]
repo := showReposMap[repoID]

// Check if user has access to given repository.
perm, err := models.GetUserRepoPermission(repo, ctxUser)
if err != nil {
ctx.ServerError("GetUserRepoPermission", fmt.Errorf("[%d]%v", repoID, err))
return
}
if !perm.CanRead(models.UnitTypeIssues) {
if log.IsTrace() {
log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+
"User in repo has Permissions: %-+v",
ctxUser,
models.UnitTypeIssues,
repo,
perm)
// Check if user has access to given repository.
perm, err := models.GetUserRepoPermission(repo, ctxUser)
if err != nil {
ctx.ServerError("GetUserRepoPermission", fmt.Errorf("[%d]%v", repoID, err))
return
}
if !perm.CanRead(models.UnitTypeIssues) {
log.Error("User created Issues in Repository which they no longer have access to: [%d]", repoID)
}
zeripath marked this conversation as resolved.
Show resolved Hide resolved
ctx.Status(404)
return
}
}

Expand All @@ -342,7 +342,7 @@ func Issues(ctx *context.Context) {

issueStats, err := models.GetUserIssueStats(models.UserIssueStatsOptions{
UserID: ctxUser.ID,
RepoID: repoID,
RepoIDs: repoIDs,
UserRepoIDs: userRepoIDs,
FilterMode: filterMode,
IsPull: isPullList,
Expand All @@ -353,11 +353,26 @@ func Issues(ctx *context.Context) {
return
}

var total int
allIssueStats, err := models.GetUserIssueStats(models.UserIssueStatsOptions{
UserID: ctxUser.ID,
UserRepoIDs: userRepoIDs,
FilterMode: filterMode,
IsPull: isPullList,
IsClosed: isShowClosed,
})
if err != nil {
ctx.ServerError("GetUserIssueStats All", err)
return
}

var shownIssues int
var totalIssues int
if !isShowClosed {
total = int(issueStats.OpenCount)
shownIssues = int(issueStats.OpenCount)
totalIssues = int(allIssueStats.OpenCount)
} else {
total = int(issueStats.ClosedCount)
shownIssues = int(issueStats.ClosedCount)
totalIssues = int(allIssueStats.ClosedCount)
}

ctx.Data["Issues"] = issues
Expand All @@ -367,18 +382,24 @@ func Issues(ctx *context.Context) {
ctx.Data["IssueStats"] = issueStats
ctx.Data["ViewType"] = viewType
ctx.Data["SortType"] = sortType
ctx.Data["RepoID"] = repoID
ctx.Data["RepoIDs"] = repoIDs
ctx.Data["IsShowClosed"] = isShowClosed
ctx.Data["TotalIssueCount"] = totalIssues

if isShowClosed {
ctx.Data["State"] = "closed"
} else {
ctx.Data["State"] = "open"
}

pager := context.NewPagination(total, setting.UI.IssuePagingNum, page, 5)
// Convert []int64 to string
reposParam, _ := json.Marshal(repoIDs)

ctx.Data["ReposParam"] = string(reposParam)

pager := context.NewPagination(shownIssues, setting.UI.IssuePagingNum, page, 5)
pager.AddParam(ctx, "type", "ViewType")
pager.AddParam(ctx, "repo", "RepoID")
pager.AddParam(ctx, "repos", "ReposParam")
pager.AddParam(ctx, "sort", "SortType")
pager.AddParam(ctx, "state", "State")
pager.AddParam(ctx, "labels", "SelectLabels")
Expand Down
Loading