@ -183,34 +183,39 @@ func Issues(ctx *context.Context) {
viewType string
viewType string
sortType = ctx . Query ( "sort" )
sortType = ctx . Query ( "sort" )
filterMode = models . FilterModeAll
filterMode = models . FilterModeAll
assigneeID int64
posterID int64
)
)
if ctxUser . IsOrganization ( ) {
if ctxUser . IsOrganization ( ) {
viewType = "all"
viewType = "all"
} else {
} else {
viewType = ctx . Query ( "type" )
viewType = ctx . Query ( "type" )
types := [ ] string { "assigned" , "created_by" }
types := [ ] string { "all" , "a ssigned" , "created_by" }
if ! com . IsSliceContainsStr ( types , viewType ) {
if ! com . IsSliceContainsStr ( types , viewType ) {
viewType = "all"
viewType = "all"
}
}
switch viewType {
switch viewType {
case "all" :
filterMode = models . FilterModeAll
case "assigned" :
case "assigned" :
filterMode = models . FilterModeAssign
filterMode = models . FilterModeAssign
assigneeID = ctxUser . ID
case "created_by" :
case "created_by" :
filterMode = models . FilterModeCreate
filterMode = models . FilterModeCreate
posterID = ctxUser . ID
}
}
}
}
page := ctx . QueryInt ( "page" )
if page <= 1 {
page = 1
}
repoID := ctx . QueryInt64 ( "repo" )
repoID := ctx . QueryInt64 ( "repo" )
isShowClosed := ctx . Query ( "state" ) == "closed"
isShowClosed := ctx . Query ( "state" ) == "closed"
// Get repositories.
// Get repositories.
var err error
var err error
var repos [ ] * models . Repository
var repos [ ] * models . Repository
userRepoIDs := make ( [ ] int64 , 0 , len ( repos ) )
if ctxUser . IsOrganization ( ) {
if ctxUser . IsOrganization ( ) {
env , err := ctxUser . AccessibleReposEnv ( ctx . User . ID )
env , err := ctxUser . AccessibleReposEnv ( ctx . User . ID )
if err != nil {
if err != nil {
@ -230,9 +235,6 @@ func Issues(ctx *context.Context) {
repos = ctxUser . Repos
repos = ctxUser . Repos
}
}
allCount := 0
repoIDs := make ( [ ] int64 , 0 , len ( repos ) )
showRepos := make ( [ ] * models . Repository , 0 , len ( repos ) )
for _ , repo := range repos {
for _ , repo := range repos {
if ( isPullList && repo . NumPulls == 0 ) ||
if ( isPullList && repo . NumPulls == 0 ) ||
( ! isPullList &&
( ! isPullList &&
@ -240,85 +242,129 @@ func Issues(ctx *context.Context) {
continue
continue
}
}
repoIDs = append ( repoIDs , repo . ID )
userRepoIDs = append ( userRepoIDs , repo . ID )
if isPullList {
allCount += repo . NumOpenPulls
repo . NumOpenIssues = repo . NumOpenPulls
repo . NumClosedIssues = repo . NumClosedPulls
} else {
allCount += repo . NumOpenIssues
}
}
if filterMode != models . FilterModeAll {
var issues [ ] * models . Issue
// Calculate repository issue count with filter mode.
switch filterMode {
numOpen , numClosed := repo . IssueStats ( ctxUser . ID , filterMode , isPullList )
case models . FilterModeAll :
repo . NumOpenIssues , repo . NumClosedIssues = int ( numOpen ) , int ( numClosed )
// Get all issues from repositories from this user.
}
issues , err = models . Issues ( & models . IssuesOptions {
RepoIDs : userRepoIDs ,
if repo . ID == repoID ||
RepoID : repoID ,
( isShowClosed && repo . NumClosedIssues > 0 ) ||
Page : page ,
( ! isShowClosed && repo . NumOpenIssues > 0 ) {
IsClosed : util . OptionalBoolOf ( isShowClosed ) ,
showRepos = append ( showRepos , repo )
IsPull : util . OptionalBoolOf ( isPullList ) ,
}
SortType : sortType ,
}
} )
ctx . Data [ "Repos" ] = showRepos
if len ( repoIDs ) == 0 {
repoIDs = [ ] int64 { - 1 }
}
issueStats := models . GetUserIssueStats ( repoID , ctxUser . ID , repoIDs , filterMode , isPullList )
issueStats . AllCount = int64 ( allCount )
page := ctx . QueryInt ( "page" )
if page <= 1 {
page = 1
}
var total int
case models . FilterModeAssign :
if ! isShowClosed {
// Get all issues assigned to this user.
total = int ( issueStats . OpenCount )
issues , err = models . Issues ( & models . IssuesOptions {
} else {
RepoID : repoID ,
total = int ( issueStats . ClosedCount )
AssigneeID : ctxUser . ID ,
}
Page : page ,
ctx . Data [ "Page" ] = paginater . New ( total , setting . UI . IssuePagingNum , page , 5 )
IsClosed : util . OptionalBoolOf ( isShowClosed ) ,
IsPull : util . OptionalBoolOf ( isPullList ) ,
SortType : sortType ,
} )
// Get issues.
case models . FilterModeCreate :
issues , err := models . Issues ( & models . IssuesOptions {
// Get all issues created by this user.
AssigneeID : assigneeID ,
issues , err = models . Issues ( & models . IssuesOptions {
RepoID : repoID ,
PosterID : ctxUser . ID ,
Page : page ,
IsClosed : util . OptionalBoolOf ( isShowClosed ) ,
IsPull : util . OptionalBoolOf ( isPullList ) ,
SortType : sortType ,
} )
case models . FilterModeMention :
// Get all issues created by this user.
issues , err = models . Issues ( & models . IssuesOptions {
RepoID : repoID ,
RepoID : repoID ,
PosterID : posterID ,
MentionedID : ctxUser . ID ,
RepoIDs : repoIDs ,
Page : page ,
Page : page ,
IsClosed : util . OptionalBoolOf ( isShowClosed ) ,
IsClosed : util . OptionalBoolOf ( isShowClosed ) ,
IsPull : util . OptionalBoolOf ( isPullList ) ,
IsPull : util . OptionalBoolOf ( isPullList ) ,
SortType : sortType ,
SortType : sortType ,
} )
} )
}
if err != nil {
if err != nil {
ctx . Handle ( 500 , "Issues" , err )
ctx . Handle ( 500 , "Issues" , err )
return
return
}
}
// Get posters and repository.
showRepos := make ( [ ] * models . Repository , 0 , len ( issues ) )
for i := range issues {
showReposSet := make ( map [ int64 ] bool )
issues [ i ] . Repo , err = models . GetRepositoryByID ( issues [ i ] . RepoID )
if repoID > 0 {
repo , err := models . GetRepositoryByID ( repoID )
if err != nil {
if err != nil {
ctx . Handle ( 500 , "GetRepositoryByID" , fmt . Errorf ( "[#%d]%v" , issues [ i ] . ID , err ) )
ctx . Handle ( 500 , "GetRepositoryByID" , fmt . Errorf ( "[#%d]%v" , repo ID, err ) )
return
return
}
}
if err = issues [ i ] . R epo. GetOwner ( ) ; err != nil {
if err = r epo. GetOwner ( ) ; err != nil {
ctx . Handle ( 500 , "GetOwner" , fmt . Errorf ( "[#%d]%v" , issues [ i ] . ID , err ) )
ctx . Handle ( 500 , "GetOwner" , fmt . Errorf ( "[#%d]%v" , repo ID, err ) )
return
return
}
}
// Check if user has access to given repository.
if ! repo . IsOwnedBy ( ctxUser . ID ) && ! repo . HasAccess ( ctxUser ) {
ctx . Handle ( 404 , "Issues" , fmt . Errorf ( "#%d" , repoID ) )
return
}
showReposSet [ repoID ] = true
showRepos = append ( showRepos , repo )
}
for _ , issue := range issues {
// Get Repository data.
issue . Repo , err = models . GetRepositoryByID ( issue . RepoID )
if err != nil {
ctx . Handle ( 500 , "GetRepositoryByID" , fmt . Errorf ( "[#%d]%v" , issue . RepoID , err ) )
return
}
}
ctx . Data [ "Issues" ] = issues
// Get Owner data.
if err = issue . Repo . GetOwner ( ) ; err != nil {
ctx . Handle ( 500 , "GetOwner" , fmt . Errorf ( "[#%d]%v" , issue . RepoID , err ) )
return
}
// Append repo to list of shown repos
if filterMode == models . FilterModeAll {
// Use a map to make sure we don't add the same Repository twice.
_ , ok := showReposSet [ issue . RepoID ]
if ! ok {
showReposSet [ issue . RepoID ] = true
// Append to list of shown Repositories.
showRepos = append ( showRepos , issue . Repo )
}
}
}
issueStats := models . GetUserIssueStats ( repoID , ctxUser . ID , userRepoIDs , filterMode , isPullList )
var total int
if ! isShowClosed {
total = int ( issueStats . OpenCount )
} else {
total = int ( issueStats . ClosedCount )
}
ctx . Data [ "Issues" ] = issues
ctx . Data [ "Repos" ] = showRepos
ctx . Data [ "Page" ] = paginater . New ( total , setting . UI . IssuePagingNum , page , 5 )
ctx . Data [ "IssueStats" ] = issueStats
ctx . Data [ "IssueStats" ] = issueStats
ctx . Data [ "ViewType" ] = viewType
ctx . Data [ "ViewType" ] = viewType
ctx . Data [ "SortType" ] = sortType
ctx . Data [ "SortType" ] = sortType
ctx . Data [ "RepoID" ] = repoID
ctx . Data [ "RepoID" ] = repoID
ctx . Data [ "IsShowClosed" ] = isShowClosed
ctx . Data [ "IsShowClosed" ] = isShowClosed
if isShowClosed {
if isShowClosed {
ctx . Data [ "State" ] = "closed"
ctx . Data [ "State" ] = "closed"
} else {
} else {