@@ -62,6 +62,7 @@ func Projects(ctx *context.Context) {
6262 keyword := ctx .FormTrim ("q" )
6363 repo := ctx .Repo .Repository
6464 page := max (ctx .FormInt ("page" ), 1 )
65+ ownerID := repo .OwnerID
6566
6667 ctx .Data ["OpenCount" ] = repo .NumOpenProjects
6768 ctx .Data ["ClosedCount" ] = repo .NumClosedProjects
@@ -73,22 +74,71 @@ func Projects(ctx *context.Context) {
7374 total = repo .NumClosedProjects
7475 }
7576
76- projects , count , err := db .FindAndCount [project_model.Project ](ctx , project_model.SearchOptions {
77+ projects := make ([]* project_model.Project , 0 , total )
78+
79+ repoProjects , count , err := db .FindAndCount [project_model.Project ](ctx , project_model.SearchOptions {
7780 ListOptions : db.ListOptions {
7881 PageSize : setting .UI .IssuePagingNum ,
7982 Page : page ,
8083 },
81- RepoID : repo .ID ,
8284 IsClosed : optional .Some (isShowClosed ),
8385 OrderBy : project_model .GetSearchOrderByBySortType (sortType ),
8486 Type : project_model .TypeRepository ,
8587 Title : keyword ,
8688 })
8789 if err != nil {
88- ctx .ServerError ("GetProjects" , err )
90+ ctx .ServerError ("GetRepoProjects" , err )
91+ return
92+ }
93+ projects = append (projects , repoProjects ... )
94+
95+ openOrgProjects , openCountForOrgProjects , err := db .FindAndCount [project_model.Project ](ctx , project_model.SearchOptions {
96+ ListOptions : db.ListOptions {
97+ PageSize : setting .UI .IssuePagingNum ,
98+ Page : page ,
99+ },
100+ OwnerID : ownerID ,
101+ IsClosed : optional .Some (false ),
102+ OrderBy : project_model .GetSearchOrderByBySortType (sortType ),
103+ Type : project_model .TypeOrganization ,
104+ Title : keyword ,
105+ })
106+ if err != nil {
107+ ctx .ServerError ("GetOrgProjects" , err )
108+ return
109+ }
110+
111+ closeOrgProjects , closeCountForOrgProjects , err := db .FindAndCount [project_model.Project ](ctx , project_model.SearchOptions {
112+ ListOptions : db.ListOptions {
113+ PageSize : setting .UI .IssuePagingNum ,
114+ Page : page ,
115+ },
116+ OwnerID : ownerID ,
117+ IsClosed : optional .Some (true ),
118+ OrderBy : project_model .GetSearchOrderByBySortType (sortType ),
119+ Type : project_model .TypeOrganization ,
120+ Title : keyword ,
121+ })
122+ if err != nil {
123+ ctx .ServerError ("GetOrgProjects" , err )
89124 return
90125 }
91126
127+ if isShowClosed {
128+ count += closeCountForOrgProjects
129+ total += int (closeCountForOrgProjects )
130+ projects = append (projects , closeOrgProjects ... )
131+ } else {
132+ count += openCountForOrgProjects
133+ total += int (openCountForOrgProjects )
134+ projects = append (projects , openOrgProjects ... )
135+ }
136+
137+ totalOpenCount := repo .NumOpenProjects + int (openCountForOrgProjects )
138+ totalCloseCount := repo .NumClosedProjects + int (closeCountForOrgProjects )
139+ ctx .Data ["OpenCount" ] = totalOpenCount
140+ ctx .Data ["ClosedCount" ] = totalCloseCount
141+
92142 if err := project_service .LoadIssueNumbersForProjects (ctx , projects , ctx .Doer ); err != nil {
93143 ctx .ServerError ("LoadIssueNumbersForProjects" , err )
94144 return
0 commit comments