From 0995c14c7caecc3e4930b3a21f28d58e2eaea299 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sat, 25 Sep 2021 15:41:15 +0200 Subject: [PATCH 01/36] Add basic files and functions --- options/locale/locale_en-US.ini | 2 ++ routers/web/user/notification.go | 6 ++++++ routers/web/web.go | 1 + templates/user/notification/notification_div.tmpl | 6 ++++++ .../notification/notification_subscriptions.tmpl | 12 ++++++++++++ 5 files changed, 27 insertions(+) create mode 100644 templates/user/notification/notification_subscriptions.tmpl diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 2ee0f5b56664..f29ae4291710 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2786,6 +2786,8 @@ pin = Pin notification mark_as_read = Mark as read mark_as_unread = Mark as unread mark_all_as_read = Mark all as read +subscriptions = Subscriptions +watching = Watching [gpg] default_key=Signed with default key diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index ec3395cbc17a..23970b8dfc8c 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -19,6 +19,7 @@ import ( const ( tplNotification base.TplName = "user/notification/notification" tplNotificationDiv base.TplName = "user/notification/notification_div" + tplNotificationSubscriptions base.TplName = "user/notification/notification_subscriptions" ) // GetNotificationCount is the middleware that sets the notification count in the context @@ -191,3 +192,8 @@ func NotificationPurgePost(c *context.Context) { url := fmt.Sprintf("%s/notifications", setting.AppSubURL) c.Redirect(url, http.StatusSeeOther) } + +// NotificationSubscriptions returns the list of subscribed issues/repos +func NotificationSubscriptions(c *context.Context) { + c.HTML(http.StatusOK, tplNotificationSubscriptions) +} diff --git a/routers/web/web.go b/routers/web/web.go index 8d984abcf2ed..012ad377210b 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1042,6 +1042,7 @@ func RegisterRoutes(m *web.Route) { m.Group("/notifications", func() { m.Get("", user.Notifications) + m.Get("/subscriptions", user.NotificationSubscriptions) m.Post("/status", user.NotificationStatusPost) m.Post("/purge", user.NotificationPurgePost) }, reqSignIn) diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index 8976e1fda4a0..ed49efadde06 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -10,6 +10,12 @@ {{.i18n.Tr "notification.read"}} + + {{$.CsrfTokenHtml}} + + {{if and (eq .Status 1)}}
{{$.CsrfTokenHtml}} diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl new file mode 100644 index 000000000000..69849da61509 --- /dev/null +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -0,0 +1,12 @@ +{{template "base/head" .}} + +{{template "base/footer" .}} From 36150af01db72775847686646ca394aa67b90555 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sat, 25 Sep 2021 18:21:01 +0200 Subject: [PATCH 02/36] Fix and improve pages --- models/notification_subscriptions.go | 47 +++++++ options/locale/locale_en-US.ini | 1 + routers/web/user/notification.go | 116 +++++++++++++++++- routers/web/web.go | 1 + .../notification_subscriptions.tmpl | 35 ++++-- 5 files changed, 189 insertions(+), 11 deletions(-) create mode 100644 models/notification_subscriptions.go diff --git a/models/notification_subscriptions.go b/models/notification_subscriptions.go new file mode 100644 index 000000000000..cf548f6ddb0a --- /dev/null +++ b/models/notification_subscriptions.go @@ -0,0 +1,47 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package models + +import ( + //"fmt" + //"strconv" + + "code.gitea.io/gitea/models/db" + //"code.gitea.io/gitea/modules/log" + //"code.gitea.io/gitea/modules/setting" + //"code.gitea.io/gitea/modules/timeutil" + + //"xorm.io/builder" + //"xorm.io/xorm" +) + +// GetSubscribed returns subscribed issues and pull requests +func GetSubscriptions(pageSize int, user *User) ([]*Issue, error) { + sql := "SELECT * FROM issue WHERE (issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE is_watching = ? AND user_id = ?))"+ + "OR ((issue.id IN ((SELECT comment.issue_id FROM comment WHERE poster_id = ?))) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))"+ + "OR ((issue.id IN (SELECT issue.id FROM issue WHERE issue.poster_id = ?)) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))" + //issues := make([]*Issue, 0, pageSize) + var issues []*Issue + return issues, db.GetEngine(db.DefaultContext).SQL(sql, true, user.ID, user.ID, user.ID, false, user.ID, user.ID, false).Find(&issues) +} + +// GetSubscriptionsCount counts the subscribed issues/PRs +func GetSubscriptionsCount(user *User) (int64, error) { + return getSubscriptionsCount(db.GetEngine(db.DefaultContext), user) +} + +func getSubscriptionsCount(e db.Engine, user *User) (count int64, err error) { + sql := "SELECT * FROM issue WHERE (issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE is_watching = ? AND user_id = ?))"+ + "OR ((issue.id IN ((SELECT comment.issue_id FROM comment WHERE poster_id = ?))) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))"+ + "OR ((issue.id IN (SELECT issue.id FROM issue WHERE issue.poster_id = ?)) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))" + + count, err = e.SQL(sql, true, user.ID, user.ID, user.ID, false, user.ID, user.ID, false). + /*Where("(issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE is_watching = ? AND user_id = ?))"+ + "OR ((issue.id IN ((SELECT comment.issue_id FROM comment WHERE poster_id = ?))) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))"+ + "OR ((issue.id IN (SELECT issue.id FROM issue WHERE issue.poster_id = ?)) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))", + true, user.ID, user.ID, user.ID, false, user.ID, user.ID, false).*/ + Count(&Issue{}) + return +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index f29ae4291710..fe28757d4f9e 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2788,6 +2788,7 @@ mark_as_unread = Mark as unread mark_all_as_read = Mark all as read subscriptions = Subscriptions watching = Watching +no_subscriptions = No subscriptions [gpg] default_key=Signed with default key diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 23970b8dfc8c..77347fc9990d 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -13,7 +13,9 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" ) const ( @@ -193,7 +195,119 @@ func NotificationPurgePost(c *context.Context) { c.Redirect(url, http.StatusSeeOther) } -// NotificationSubscriptions returns the list of subscribed issues/repos +// NotificationSubscriptions returns the list of subscribed issues func NotificationSubscriptions(c *context.Context) { + var ( + page = c.FormInt("page") + perPage = c.FormInt("perPage") + ) + if page < 1 { + page = 1 + } + if perPage < 1 { + perPage = 20 + } +/* + total, err := models.GetSubscriptionsCount(c.User) + if err != nil { + c.ServerError("ErrGetSubscriptionsCount", err) + return + } + + // redirect to last page if request page is more than total pages + pager := context.NewPagination(int(total), perPage, page, 5) + if pager.Paginater.Current() < page { + c.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current())) + return + } +*/ + issues, err := models.GetSubscriptions(perPage, c.User) + if err != nil { + c.ServerError("ErrGetSubscriptions", err) + return + } + c.Data["Issues"] = issues + + c.Data["Status"] = 1 + + //pager.SetDefaultParams(c) + //c.Data["Page"] = pager + + c.HTML(http.StatusOK, tplNotificationSubscriptions) +} + +// NotificationSubscriptions returns the list of watching repos +func NotificationWatching(c *context.Context) { + page := c.FormInt("page") + if page < 1 { + page = 1 + } + + var orderBy models.SearchOrderBy + c.Data["SortType"] = c.FormString("sort") + switch c.FormString("sort") { + case "newest": + orderBy = models.SearchOrderByNewest + case "oldest": + orderBy = models.SearchOrderByOldest + case "recentupdate": + orderBy = models.SearchOrderByRecentUpdated + case "leastupdate": + orderBy = models.SearchOrderByLeastUpdated + case "reversealphabetically": + orderBy = models.SearchOrderByAlphabeticallyReverse + case "alphabetically": + orderBy = models.SearchOrderByAlphabetically + case "moststars": + orderBy = models.SearchOrderByStarsReverse + case "feweststars": + orderBy = models.SearchOrderByStars + case "mostforks": + orderBy = models.SearchOrderByForksReverse + case "fewestforks": + orderBy = models.SearchOrderByForks + default: + c.Data["SortType"] = "recentupdate" + orderBy = models.SearchOrderByRecentUpdated + } + +/* + total, err := models.GetWatchingReposCount(c.User) + if err != nil { + c.ServerError("ErrGetWatchingReposCount", err) + return + } +*/ + repos, count, err := models.SearchRepository(&models.SearchRepoOptions{ + ListOptions: db.ListOptions{ + PageSize: setting.UI.User.RepoPagingNum, + Page: page, + }, + Actor: c.User, + Keyword: c.FormTrim("q"), + OrderBy: orderBy, + Private: c.IsSigned, + WatchedByID: c.User.ID, + Collaborate: util.OptionalBoolFalse, + TopicOnly: c.FormBool("topic"), + IncludeDescription: setting.UI.SearchRepoDescription, + }) + + total := int(count) + c.Data["Total"] = total + + if err != nil { + c.ServerError("ErrSearchRepository", err) + return + } + c.Data["Repos"] = repos + + // redirect to last page if request page is more than total pages + pager := context.NewPagination(total, setting.UI.User.RepoPagingNum, page, 5) + pager.SetDefaultParams(c) + c.Data["Page"] = pager + + c.Data["Status"] = 2 + c.HTML(http.StatusOK, tplNotificationSubscriptions) } diff --git a/routers/web/web.go b/routers/web/web.go index 012ad377210b..0f62a40c179e 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1043,6 +1043,7 @@ func RegisterRoutes(m *web.Route) { m.Group("/notifications", func() { m.Get("", user.Notifications) m.Get("/subscriptions", user.NotificationSubscriptions) + m.Get("/watching", user.NotificationWatching) m.Post("/status", user.NotificationStatusPost) m.Post("/purge", user.NotificationPurgePost) }, reqSignIn) diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index 69849da61509..be183ded5866 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -1,12 +1,27 @@ {{template "base/head" .}} - +
+
+ +
+ {{if eq .Status 1}} + {{if eq (len .Issues) 0}} + {{.i18n.Tr "notification.no_subscriptions"}} + {{else}} + {{template "shared/issuelist" .}} + {{end}} + {{else}} + {{template "explore/repo_search" .}} + {{template "explore/repo_list" .}} + {{end}} +
+ {{template "base/paginate" .}} +
+
{{template "base/footer" .}} From c4fbc667a3ef89c01bf28725f9e1886b8beae7f3 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sat, 25 Sep 2021 19:12:07 +0200 Subject: [PATCH 03/36] Fix issues and improve --- models/issue.go | 12 +++++ models/notification_subscriptions.go | 47 ------------------- routers/web/user/notification.go | 36 ++++++++------ .../notification_subscriptions.tmpl | 4 +- 4 files changed, 35 insertions(+), 64 deletions(-) delete mode 100644 models/notification_subscriptions.go diff --git a/models/issue.go b/models/issue.go index b8c7053b2d2a..eeb7c057ddaa 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1128,6 +1128,7 @@ type IssuesOptions struct { PosterID int64 MentionedID int64 ReviewRequestedID int64 + SubscribedID int64 MilestoneIDs []int64 ProjectID int64 ProjectBoardID int64 @@ -1225,6 +1226,10 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) { applyReviewRequestedCondition(sess, opts.ReviewRequestedID) } + if opts.SubscribedID > 0 { + applySubscribedCondition(sess, opts.SubscribedID) + } + if len(opts.MilestoneIDs) > 0 { sess.In("issue.milestone_id", opts.MilestoneIDs) } @@ -1315,6 +1320,13 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) reviewRequestedID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, reviewRequestedID) } +func applySubscribedCondition(sess *xorm.Session, subscribedID int64) *xorm.Session { + return sess.And("(issue.id IN (SELECT issue_id FROM issue_watch WHERE (is_watching = ?) AND user_id = ?)) "+ + "OR ((issue.id IN ((SELECT issue_id FROM comment WHERE poster_id = ?))) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?)))) "+ + "OR ((issue.id IN (SELECT id FROM issue WHERE poster_id = ?)) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?))))", + true, subscribedID, subscribedID, subscribedID, false, subscribedID, subscribedID, false) +} + // CountIssuesByRepo map from repoID to number of issues matching the options func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) { sess := db.NewSession(db.DefaultContext) diff --git a/models/notification_subscriptions.go b/models/notification_subscriptions.go deleted file mode 100644 index cf548f6ddb0a..000000000000 --- a/models/notification_subscriptions.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package models - -import ( - //"fmt" - //"strconv" - - "code.gitea.io/gitea/models/db" - //"code.gitea.io/gitea/modules/log" - //"code.gitea.io/gitea/modules/setting" - //"code.gitea.io/gitea/modules/timeutil" - - //"xorm.io/builder" - //"xorm.io/xorm" -) - -// GetSubscribed returns subscribed issues and pull requests -func GetSubscriptions(pageSize int, user *User) ([]*Issue, error) { - sql := "SELECT * FROM issue WHERE (issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE is_watching = ? AND user_id = ?))"+ - "OR ((issue.id IN ((SELECT comment.issue_id FROM comment WHERE poster_id = ?))) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))"+ - "OR ((issue.id IN (SELECT issue.id FROM issue WHERE issue.poster_id = ?)) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))" - //issues := make([]*Issue, 0, pageSize) - var issues []*Issue - return issues, db.GetEngine(db.DefaultContext).SQL(sql, true, user.ID, user.ID, user.ID, false, user.ID, user.ID, false).Find(&issues) -} - -// GetSubscriptionsCount counts the subscribed issues/PRs -func GetSubscriptionsCount(user *User) (int64, error) { - return getSubscriptionsCount(db.GetEngine(db.DefaultContext), user) -} - -func getSubscriptionsCount(e db.Engine, user *User) (count int64, err error) { - sql := "SELECT * FROM issue WHERE (issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE is_watching = ? AND user_id = ?))"+ - "OR ((issue.id IN ((SELECT comment.issue_id FROM comment WHERE poster_id = ?))) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))"+ - "OR ((issue.id IN (SELECT issue.id FROM issue WHERE issue.poster_id = ?)) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))" - - count, err = e.SQL(sql, true, user.ID, user.ID, user.ID, false, user.ID, user.ID, false). - /*Where("(issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE is_watching = ? AND user_id = ?))"+ - "OR ((issue.id IN ((SELECT comment.issue_id FROM comment WHERE poster_id = ?))) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))"+ - "OR ((issue.id IN (SELECT issue.id FROM issue WHERE issue.poster_id = ?)) AND (NOT issue.id IN (SELECT issue_watch.issue_id FROM issue_watch WHERE user_id = ? AND is_watching = ?)))", - true, user.ID, user.ID, user.ID, false, user.ID, user.ID, false).*/ - Count(&Issue{}) - return -} diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 77347fc9990d..7d50cee62325 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -207,31 +207,37 @@ func NotificationSubscriptions(c *context.Context) { if perPage < 1 { perPage = 20 } -/* - total, err := models.GetSubscriptionsCount(c.User) - if err != nil { - c.ServerError("ErrGetSubscriptionsCount", err) - return - } - // redirect to last page if request page is more than total pages - pager := context.NewPagination(int(total), perPage, page, 5) - if pager.Paginater.Current() < page { - c.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current())) + count, err := models.CountIssues(&models.IssuesOptions{ + SubscribedID: c.User.ID, + }) + if err != nil { + c.ServerError("CountIssues", err) return } -*/ - issues, err := models.GetSubscriptions(perPage, c.User) + issues, err := models.Issues(&models.IssuesOptions{ + ListOptions: db.ListOptions{ + PageSize: setting.UI.IssuePagingNum, + Page: page, + }, + SubscribedID: c.User.ID, + }) if err != nil { - c.ServerError("ErrGetSubscriptions", err) + c.ServerError("Issues", err) return } c.Data["Issues"] = issues c.Data["Status"] = 1 - //pager.SetDefaultParams(c) - //c.Data["Page"] = pager + // redirect to last page if request page is more than total pages + pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5) + if pager.Paginater.Current() < page { + c.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current())) + return + } + pager.SetDefaultParams(c) + c.Data["Page"] = pager c.HTML(http.StatusOK, tplNotificationSubscriptions) } diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index be183ded5866..e317d5371c9b 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -14,14 +14,14 @@ {{if eq (len .Issues) 0}} {{.i18n.Tr "notification.no_subscriptions"}} {{else}} - {{template "shared/issuelist" .}} + {{template "shared/issuelist" mergeinto . "listType" "dashboard"}} {{end}} {{else}} {{template "explore/repo_search" .}} {{template "explore/repo_list" .}} + {{template "base/paginate" .}} {{end}} - {{template "base/paginate" .}} {{template "base/footer" .}} From fdc94e4ed511ef1e8a8060e401ba779de6cb3807 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sat, 25 Sep 2021 20:15:53 +0200 Subject: [PATCH 04/36] Improvemtents to the layout --- .../user/notification/notification_div.tmpl | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index ed49efadde06..ec02f4f7cd06 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -10,22 +10,24 @@ {{.i18n.Tr "notification.read"}} - - {{$.CsrfTokenHtml}} - - - {{if and (eq .Status 1)}} - +
+ {{$.CsrfTokenHtml}} -
- -
- - {{end}} + +
+ {{if and (eq .Status 1)}} +
+ {{$.CsrfTokenHtml}} +
+ +
+
+ {{end}} +
{{if eq (len .Notifications) 0}} From 46de94fe58267857da5489d188be7e8fe6d044c3 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sat, 25 Sep 2021 20:44:48 +0200 Subject: [PATCH 05/36] Fmt --- models/issue.go | 2 +- routers/web/user/notification.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/models/issue.go b/models/issue.go index eeb7c057ddaa..b515e63c3661 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1128,7 +1128,7 @@ type IssuesOptions struct { PosterID int64 MentionedID int64 ReviewRequestedID int64 - SubscribedID int64 + SubscribedID int64 MilestoneIDs []int64 ProjectID int64 ProjectBoardID int64 diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 7d50cee62325..11c37664491c 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -11,16 +11,16 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" ) const ( - tplNotification base.TplName = "user/notification/notification" - tplNotificationDiv base.TplName = "user/notification/notification_div" + tplNotification base.TplName = "user/notification/notification" + tplNotificationDiv base.TplName = "user/notification/notification_div" tplNotificationSubscriptions base.TplName = "user/notification/notification_subscriptions" ) @@ -209,7 +209,7 @@ func NotificationSubscriptions(c *context.Context) { } count, err := models.CountIssues(&models.IssuesOptions{ - SubscribedID: c.User.ID, + SubscribedID: c.User.ID, }) if err != nil { c.ServerError("CountIssues", err) @@ -220,7 +220,7 @@ func NotificationSubscriptions(c *context.Context) { PageSize: setting.UI.IssuePagingNum, Page: page, }, - SubscribedID: c.User.ID, + SubscribedID: c.User.ID, }) if err != nil { c.ServerError("Issues", err) @@ -277,13 +277,13 @@ func NotificationWatching(c *context.Context) { orderBy = models.SearchOrderByRecentUpdated } -/* - total, err := models.GetWatchingReposCount(c.User) - if err != nil { - c.ServerError("ErrGetWatchingReposCount", err) - return - } -*/ + /* + total, err := models.GetWatchingReposCount(c.User) + if err != nil { + c.ServerError("ErrGetWatchingReposCount", err) + return + } + */ repos, count, err := models.SearchRepository(&models.SearchRepoOptions{ ListOptions: db.ListOptions{ PageSize: setting.UI.User.RepoPagingNum, From 6995bc894cd63bd6155ec7c3d497002b8e36864f Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sat, 25 Sep 2021 21:02:46 +0200 Subject: [PATCH 06/36] Fix 500 with pulls --- routers/web/user/notification.go | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 11c37664491c..aa53db19fa93 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + pull_service "code.gitea.io/gitea/services/pull" ) const ( @@ -228,6 +229,38 @@ func NotificationSubscriptions(c *context.Context) { } c.Data["Issues"] = issues + commitStatus, err := pull_service.GetIssuesLastCommitStatus(issues) + if err != nil { + c.ServerError("GetIssuesLastCommitStatus", err) + return + } + c.Data["CommitStatus"] = commitStatus + + var issueList = models.IssueList(issues) + approvalCounts, err := issueList.GetApprovalCounts() + if err != nil { + c.ServerError("ApprovalCounts", err) + return + } + c.Data["ApprovalCounts"] = func(issueID int64, typ string) int64 { + counts, ok := approvalCounts[issueID] + if !ok || len(counts) == 0 { + return 0 + } + reviewTyp := models.ReviewTypeApprove + if typ == "reject" { + reviewTyp = models.ReviewTypeReject + } else if typ == "waiting" { + reviewTyp = models.ReviewTypeRequest + } + for _, count := range counts { + if count.Type == reviewTyp { + return count.Count + } + } + return 0 + } + c.Data["Status"] = 1 // redirect to last page if request page is more than total pages From e2f8a59071b7a04dfbcc38588604d98e9865fdd6 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 26 Sep 2021 08:54:58 +0200 Subject: [PATCH 07/36] Also view issues from watched repos --- models/issue.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/models/issue.go b/models/issue.go index b515e63c3661..13557cec8649 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1322,9 +1322,10 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) func applySubscribedCondition(sess *xorm.Session, subscribedID int64) *xorm.Session { return sess.And("(issue.id IN (SELECT issue_id FROM issue_watch WHERE (is_watching = ?) AND user_id = ?)) "+ - "OR ((issue.id IN ((SELECT issue_id FROM comment WHERE poster_id = ?))) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?)))) "+ - "OR ((issue.id IN (SELECT id FROM issue WHERE poster_id = ?)) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?))))", - true, subscribedID, subscribedID, subscribedID, false, subscribedID, subscribedID, false) + "OR ((issue.id IN (SELECT issue_id FROM comment WHERE poster_id = ?)) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?)))) "+ + "OR ((issue.id IN (SELECT id FROM issue WHERE poster_id = ?)) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?)))) "+ + "OR (issue.repo_id IN (SELECT id FROM watch WHERE user_id = ? AND mode = ?) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?))))", + true, subscribedID, subscribedID, subscribedID, false, subscribedID, subscribedID, false, subscribedID, true, subscribedID, false) } // CountIssuesByRepo map from repoID to number of issues matching the options From e33179042973046784a1d02f76ab59b3f8e9668e Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 26 Sep 2021 09:48:49 +0200 Subject: [PATCH 08/36] Add filter options --- routers/web/user/notification.go | 54 ++++++++++++++++++- .../notification_subscriptions.tmpl | 53 ++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index aa53db19fa93..f73731557535 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -209,8 +209,52 @@ func NotificationSubscriptions(c *context.Context) { perPage = 20 } + viewType := c.FormString("type") + sortType := c.FormString("sort") + types := []string{"all", "assigned", "created_by", "mentioned"} + if !util.IsStringInSlice(viewType, types, true) { + viewType = "all" + } + c.Data["SortType"] = sortType + c.Data["ViewType"] = viewType + + state := c.FormString("state") + states := []string{"all", "open", "closed"} + if !util.IsStringInSlice(state, states, true) { + state = "all" + } + c.Data["State"] = state + var showClosed util.OptionalBool + switch state { + case "all": + showClosed = util.OptionalBoolNone + case "closed": + showClosed = util.OptionalBoolTrue + case "open": + showClosed = util.OptionalBoolFalse + } + + var ( + assigneeID int64 + posterID int64 + mentionedID int64 + ) + + switch viewType { + case "created_by": + posterID = c.User.ID + case "mentioned": + mentionedID = c.User.ID + case "assigned": + assigneeID = c.User.ID + } + count, err := models.CountIssues(&models.IssuesOptions{ SubscribedID: c.User.ID, + AssigneeID: assigneeID, + MentionedID: mentionedID, + PosterID: posterID, + IsClosed: showClosed, }) if err != nil { c.ServerError("CountIssues", err) @@ -222,6 +266,11 @@ func NotificationSubscriptions(c *context.Context) { Page: page, }, SubscribedID: c.User.ID, + AssigneeID: assigneeID, + MentionedID: mentionedID, + PosterID: posterID, + SortType: sortType, + IsClosed: showClosed, }) if err != nil { c.ServerError("Issues", err) @@ -269,7 +318,10 @@ func NotificationSubscriptions(c *context.Context) { c.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current())) return } - pager.SetDefaultParams(c) + // pager.SetDefaultParams(c) + pager.AddParam(c, "type", "ViewType") + pager.AddParam(c, "sort", "SortType") + pager.AddParam(c, "state", "State") c.Data["Page"] = pager c.HTML(http.StatusOK, tplNotificationSubscriptions) diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index e317d5371c9b..f6f74cdd4fa7 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -11,7 +11,60 @@
{{if eq .Status 1}} + {{if eq (len .Issues) 0}} +
{{.i18n.Tr "notification.no_subscriptions"}} {{else}} {{template "shared/issuelist" mergeinto . "listType" "dashboard"}} From b80e40532850835ac099e166368757af8bdac4de Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 26 Sep 2021 10:01:00 +0200 Subject: [PATCH 09/36] Fix lint --- routers/web/user/notification.go | 2 +- .../notification_subscriptions.tmpl | 150 +++++++++--------- 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index f73731557535..305364042fcb 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -327,7 +327,7 @@ func NotificationSubscriptions(c *context.Context) { c.HTML(http.StatusOK, tplNotificationSubscriptions) } -// NotificationSubscriptions returns the list of watching repos +// NotificationWatching returns the list of watching repos func NotificationWatching(c *context.Context) { page := c.FormInt("page") if page < 1 { diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index f6f74cdd4fa7..e125df5bdf38 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -1,80 +1,80 @@ {{template "base/head" .}}
-
- -
- {{if eq .Status 1}} -
- -
- +
+
+ {{if eq (len .Issues) 0}} +
+ {{.i18n.Tr "notification.no_subscriptions"}} + {{else}} + {{template "shared/issuelist" mergeinto . "listType" "dashboard"}} + {{end}} + {{else}} + {{template "explore/repo_search" .}} + {{template "explore/repo_list" .}} + {{template "base/paginate" .}} + {{end}} +
+
{{template "base/footer" .}} From 511b9a8466a950b8ef023fcb7a107166de32afca Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 26 Sep 2021 10:23:06 +0200 Subject: [PATCH 10/36] Add title and remove comment --- routers/web/user/notification.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 305364042fcb..1f1ad23f13ac 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -311,6 +311,7 @@ func NotificationSubscriptions(c *context.Context) { } c.Data["Status"] = 1 + c.Data["Title"] = c.Tr("notification.subscriptions") // redirect to last page if request page is more than total pages pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5) @@ -362,13 +363,6 @@ func NotificationWatching(c *context.Context) { orderBy = models.SearchOrderByRecentUpdated } - /* - total, err := models.GetWatchingReposCount(c.User) - if err != nil { - c.ServerError("ErrGetWatchingReposCount", err) - return - } - */ repos, count, err := models.SearchRepository(&models.SearchRepoOptions{ ListOptions: db.ListOptions{ PageSize: setting.UI.User.RepoPagingNum, @@ -399,6 +393,7 @@ func NotificationWatching(c *context.Context) { c.Data["Page"] = pager c.Data["Status"] = 2 + c.Data["Title"] = c.Tr("notification.watching") c.HTML(http.StatusOK, tplNotificationSubscriptions) } From cc4392b9e7b18f733328ecc181364f4e8a853cb2 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 26 Sep 2021 12:39:36 +0200 Subject: [PATCH 11/36] Remove unused var --- routers/web/user/notification.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 1f1ad23f13ac..23840f08e8b9 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -198,16 +198,10 @@ func NotificationPurgePost(c *context.Context) { // NotificationSubscriptions returns the list of subscribed issues func NotificationSubscriptions(c *context.Context) { - var ( - page = c.FormInt("page") - perPage = c.FormInt("perPage") - ) + var page = c.FormInt("page") if page < 1 { page = 1 } - if perPage < 1 { - perPage = 20 - } viewType := c.FormString("type") sortType := c.FormString("sort") From 6b23384e7a4151091bd54a3ec75f62f69630d2e4 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 26 Sep 2021 17:09:59 +0200 Subject: [PATCH 12/36] Change field name --- models/issue.go | 10 +++++----- routers/web/user/notification.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/models/issue.go b/models/issue.go index 13557cec8649..74da931f9dd7 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1128,7 +1128,7 @@ type IssuesOptions struct { PosterID int64 MentionedID int64 ReviewRequestedID int64 - SubscribedID int64 + SubscriberID int64 MilestoneIDs []int64 ProjectID int64 ProjectBoardID int64 @@ -1226,8 +1226,8 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) { applyReviewRequestedCondition(sess, opts.ReviewRequestedID) } - if opts.SubscribedID > 0 { - applySubscribedCondition(sess, opts.SubscribedID) + if opts.SubscriberID > 0 { + applySubscribedCondition(sess, opts.SubscriberID) } if len(opts.MilestoneIDs) > 0 { @@ -1320,12 +1320,12 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) reviewRequestedID, ReviewTypeApprove, ReviewTypeReject, ReviewTypeRequest, reviewRequestedID) } -func applySubscribedCondition(sess *xorm.Session, subscribedID int64) *xorm.Session { +func applySubscribedCondition(sess *xorm.Session, subscriberID int64) *xorm.Session { return sess.And("(issue.id IN (SELECT issue_id FROM issue_watch WHERE (is_watching = ?) AND user_id = ?)) "+ "OR ((issue.id IN (SELECT issue_id FROM comment WHERE poster_id = ?)) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?)))) "+ "OR ((issue.id IN (SELECT id FROM issue WHERE poster_id = ?)) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?)))) "+ "OR (issue.repo_id IN (SELECT id FROM watch WHERE user_id = ? AND mode = ?) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?))))", - true, subscribedID, subscribedID, subscribedID, false, subscribedID, subscribedID, false, subscribedID, true, subscribedID, false) + true, subscriberID, subscriberID, subscriberID, false, subscriberID, subscriberID, false, subscriberID, true, subscriberID, false) } // CountIssuesByRepo map from repoID to number of issues matching the options diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 23840f08e8b9..1539c6811eb0 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -244,7 +244,7 @@ func NotificationSubscriptions(c *context.Context) { } count, err := models.CountIssues(&models.IssuesOptions{ - SubscribedID: c.User.ID, + SubscriberID: c.User.ID, AssigneeID: assigneeID, MentionedID: mentionedID, PosterID: posterID, @@ -259,7 +259,7 @@ func NotificationSubscriptions(c *context.Context) { PageSize: setting.UI.IssuePagingNum, Page: page, }, - SubscribedID: c.User.ID, + SubscriberID: c.User.ID, AssigneeID: assigneeID, MentionedID: mentionedID, PosterID: posterID, From 55053f634ab3728bff65c431f79775ea6b63dcc0 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Mon, 27 Sep 2021 14:18:52 +0200 Subject: [PATCH 13/36] Fix order of err check --- routers/web/user/notification.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 1539c6811eb0..3faeb2b6aa2f 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -371,14 +371,12 @@ func NotificationWatching(c *context.Context) { TopicOnly: c.FormBool("topic"), IncludeDescription: setting.UI.SearchRepoDescription, }) - - total := int(count) - c.Data["Total"] = total - if err != nil { c.ServerError("ErrSearchRepository", err) return } + total := int(count) + c.Data["Total"] = total c.Data["Repos"] = repos // redirect to last page if request page is more than total pages From a53278bd6ab001ffbbad28fd48e2630a38306c8f Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Mon, 4 Oct 2021 20:18:47 +0200 Subject: [PATCH 14/36] Filter by type --- options/locale/locale_en-US.ini | 1 + routers/web/user/notification.go | 14 ++++++ .../notification_subscriptions.tmpl | 45 ++++++++++++------- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 5f64108c2d2f..127eccc75db0 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2792,6 +2792,7 @@ mark_all_as_read = Mark all as read subscriptions = Subscriptions watching = Watching no_subscriptions = No subscriptions +type_issues_pulls = Type (Issues/Pull Requests) [gpg] default_key=Signed with default key diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 3faeb2b6aa2f..35044cc70ea1 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -243,12 +243,25 @@ func NotificationSubscriptions(c *context.Context) { assigneeID = c.User.ID } + var issueTypeBool util.OptionalBool + issueType := c.FormString("issueType") + switch issueType { + case "issues" : + issueTypeBool = util.OptionalBoolFalse + case "pulls": + issueTypeBool = util.OptionalBoolTrue + default: + issueTypeBool = util.OptionalBoolNone + } + c.Data["IssueType"] = issueType + count, err := models.CountIssues(&models.IssuesOptions{ SubscriberID: c.User.ID, AssigneeID: assigneeID, MentionedID: mentionedID, PosterID: posterID, IsClosed: showClosed, + IsPull: issueTypeBool, }) if err != nil { c.ServerError("CountIssues", err) @@ -265,6 +278,7 @@ func NotificationSubscriptions(c *context.Context) { PosterID: posterID, SortType: sortType, IsClosed: showClosed, + IsPull: issueTypeBool, }) if err != nil { c.ServerError("Issues", err) diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index e125df5bdf38..7a07fbd4861d 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -14,21 +14,34 @@
-
+
From 037ab680839d64e29b5acb04319042928ae26053 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Tue, 5 Oct 2021 15:29:19 +0200 Subject: [PATCH 15/36] Fix lint --- routers/web/user/notification.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 35044cc70ea1..760e0ecc00e9 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -246,7 +246,7 @@ func NotificationSubscriptions(c *context.Context) { var issueTypeBool util.OptionalBool issueType := c.FormString("issueType") switch issueType { - case "issues" : + case "issues": issueTypeBool = util.OptionalBoolFalse case "pulls": issueTypeBool = util.OptionalBoolTrue From 183dd9077421bb4841a5be6d1d0382fd1f7224fd Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 24 Oct 2021 19:29:44 +0200 Subject: [PATCH 16/36] Remove filter options --- options/locale/locale_en-US.ini | 1 - routers/web/user/notification.go | 27 ------------ .../notification_subscriptions.tmpl | 42 +++++++------------ 3 files changed, 14 insertions(+), 56 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3378c71ca5de..8ca1c5d6ec6a 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2827,7 +2827,6 @@ mark_all_as_read = Mark all as read subscriptions = Subscriptions watching = Watching no_subscriptions = No subscriptions -type_issues_pulls = Type (Issues/Pull Requests) [gpg] default_key=Signed with default key diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 4e93a63a5fb0..091cef55ae80 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -204,14 +204,8 @@ func NotificationSubscriptions(c *context.Context) { page = 1 } - viewType := c.FormString("type") sortType := c.FormString("sort") - types := []string{"all", "assigned", "created_by", "mentioned"} - if !util.IsStringInSlice(viewType, types, true) { - viewType = "all" - } c.Data["SortType"] = sortType - c.Data["ViewType"] = viewType state := c.FormString("state") states := []string{"all", "open", "closed"} @@ -229,21 +223,6 @@ func NotificationSubscriptions(c *context.Context) { showClosed = util.OptionalBoolFalse } - var ( - assigneeID int64 - posterID int64 - mentionedID int64 - ) - - switch viewType { - case "created_by": - posterID = c.User.ID - case "mentioned": - mentionedID = c.User.ID - case "assigned": - assigneeID = c.User.ID - } - var issueTypeBool util.OptionalBool issueType := c.FormString("issueType") switch issueType { @@ -258,9 +237,6 @@ func NotificationSubscriptions(c *context.Context) { count, err := models.CountIssues(&models.IssuesOptions{ SubscriberID: c.User.ID, - AssigneeID: assigneeID, - MentionedID: mentionedID, - PosterID: posterID, IsClosed: showClosed, IsPull: issueTypeBool, }) @@ -274,9 +250,6 @@ func NotificationSubscriptions(c *context.Context) { Page: page, }, SubscriberID: c.User.ID, - AssigneeID: assigneeID, - MentionedID: mentionedID, - PosterID: posterID, SortType: sortType, IsClosed: showClosed, IsPull: issueTypeBool, diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index 7a07fbd4861d..7da96660b294 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -17,7 +17,7 @@ {{.i18n.Tr "all"}} - + {{svg "octicon-issue-opened" 16 "mr-3"}} {{.i18n.Tr "repo.issues.open_title"}} @@ -29,33 +29,19 @@
From cb008e5d4c2e1437b7c65296fa8318d5efd50762 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 24 Oct 2021 19:31:46 +0200 Subject: [PATCH 17/36] Remove old code --- routers/web/user/notification.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 091cef55ae80..abe7e2303c47 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -301,8 +301,6 @@ func NotificationSubscriptions(c *context.Context) { c.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current())) return } - // pager.SetDefaultParams(c) - pager.AddParam(c, "type", "ViewType") pager.AddParam(c, "sort", "SortType") pager.AddParam(c, "state", "State") c.Data["Page"] = pager From b6288b5bbe1e33e17442d68dbadedf1f6d613465 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 24 Oct 2021 19:37:22 +0200 Subject: [PATCH 18/36] Fix 500 when ref is set --- routers/web/user/notification.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index abe7e2303c47..5e4840b702e0 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" + issue_service "code.gitea.io/gitea/services/issue" pull_service "code.gitea.io/gitea/services/pull" ) @@ -260,6 +261,9 @@ func NotificationSubscriptions(c *context.Context) { } c.Data["Issues"] = issues + c.Data["IssueRefEndNames"], c.Data["IssueRefURLs"] = + issue_service.GetRefEndNamesAndURLs(issues, "") + commitStatus, err := pull_service.GetIssuesLastCommitStatus(issues) if err != nil { c.ServerError("GetIssuesLastCommitStatus", err) From 9d6af4f24976e528792726176e2e92417217d4b6 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 24 Oct 2021 19:53:22 +0200 Subject: [PATCH 19/36] Allow filter by labels --- routers/web/user/notification.go | 14 ++++++++++ .../notification_subscriptions.tmpl | 28 +++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 5e4840b702e0..50fe3afdb190 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -236,10 +236,23 @@ func NotificationSubscriptions(c *context.Context) { } c.Data["IssueType"] = issueType + var labelIDs []int64 + selectedLabels := c.FormString("labels") + c.Data["Labels"] = selectedLabels + if len(selectedLabels) > 0 && selectedLabels != "0" { + var err error + labelIDs, err = base.StringsToInt64s(strings.Split(selectedLabels, ",")) + if err != nil { + c.ServerError("StringsToInt64s", err) + return + } + } + count, err := models.CountIssues(&models.IssuesOptions{ SubscriberID: c.User.ID, IsClosed: showClosed, IsPull: issueTypeBool, + LabelIDs: labelIDs, }) if err != nil { c.ServerError("CountIssues", err) @@ -254,6 +267,7 @@ func NotificationSubscriptions(c *context.Context) { SortType: sortType, IsClosed: showClosed, IsPull: issueTypeBool, + LabelIDs: labelIDs, }) if err != nil { c.ServerError("Issues", err) diff --git a/templates/user/notification/notification_subscriptions.tmpl b/templates/user/notification/notification_subscriptions.tmpl index 7da96660b294..27d5c91636d3 100644 --- a/templates/user/notification/notification_subscriptions.tmpl +++ b/templates/user/notification/notification_subscriptions.tmpl @@ -14,14 +14,14 @@ From b82aaf3acff651995d7ef17926c125229ff4ab15 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 24 Oct 2021 20:26:43 +0200 Subject: [PATCH 20/36] Improve SQL command --- models/issue.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/models/issue.go b/models/issue.go index 54a9319e7008..74153db2dd22 100644 --- a/models/issue.go +++ b/models/issue.go @@ -1320,11 +1320,12 @@ func applyReviewRequestedCondition(sess *xorm.Session, reviewRequestedID int64) } func applySubscribedCondition(sess *xorm.Session, subscriberID int64) *xorm.Session { - return sess.And("(issue.id IN (SELECT issue_id FROM issue_watch WHERE (is_watching = ?) AND user_id = ?)) "+ - "OR ((issue.id IN (SELECT issue_id FROM comment WHERE poster_id = ?)) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?)))) "+ - "OR ((issue.id IN (SELECT id FROM issue WHERE poster_id = ?)) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?)))) "+ - "OR (issue.repo_id IN (SELECT id FROM watch WHERE user_id = ? AND mode = ?) AND (NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE user_id = ? AND (is_watching = ?))))", - true, subscriberID, subscriberID, subscriberID, false, subscriberID, subscriberID, false, subscriberID, true, subscriberID, false) + return sess.And("NOT issue.id IN (SELECT issue_id FROM issue_watch WHERE is_watching = ? AND user_id = ?)", false, subscriberID). + And("(issue.id IN (SELECT issue_id FROM issue_watch WHERE is_watching = ? AND user_id = ?)) "+ + "OR (issue.id IN (SELECT issue_id FROM comment WHERE poster_id = ?)) "+ + "OR issue.poster_id = ? "+ + "OR issue.repo_id IN (SELECT id FROM watch WHERE user_id = ? AND mode = ?)", + true, subscriberID, subscriberID, subscriberID, subscriberID, true) } // CountIssuesByRepo map from repoID to number of issues matching the options From dfa31b44022d8f2d5b37a713e2ba56d1efac9420 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 24 Oct 2021 20:36:55 +0200 Subject: [PATCH 21/36] Remove unnecessary line --- templates/user/notification/notification_div.tmpl | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index ec02f4f7cd06..ed300034b430 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -12,7 +12,6 @@
- {{$.CsrfTokenHtml}} From d9da3e791d45b6e0159e13faa1c771fb1bfba7d3 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Sun, 24 Oct 2021 20:55:19 +0200 Subject: [PATCH 22/36] Update padding --- templates/user/notification/notification_div.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index ed300034b430..dddcd20202a7 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -10,7 +10,7 @@ {{.i18n.Tr "notification.read"}} -
+
- - {{if and (eq .Status 1)}} + {{if and (eq .Status 1)}}
- {{$.CsrfTokenHtml}} + {{$.CsrfTokenHtml}}
- {{end}} -
+ {{end}}
{{if eq (len .Notifications) 0}} From d7fdce7edbb7151de51bc46cc7bfe050b152c0bc Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Wed, 20 Jul 2022 13:52:43 +0200 Subject: [PATCH 33/36] Undo change --- .../user/notification/notification_div.tmpl | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index dbfef8e5e3bc..6dce7f751b3e 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -10,16 +10,16 @@ {{.locale.Tr "notification.read"}} - {{if and (eq .Status 1)}} -
- {{$.CsrfTokenHtml}} -
- -
-
- {{end}} + {{if and (eq .Status 1)}} +
+ {{$.CsrfTokenHtml}} +
+ +
+
+ {{end}}
{{if eq (len .Notifications) 0}} From 272e3b4e5a911a962a9e1b24067f777df34b5539 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Wed, 20 Jul 2022 14:44:03 +0200 Subject: [PATCH 34/36] Fix indentation --- templates/base/head_navbar.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index 50bd8eb20bec..1184d1b9af0a 100644 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -170,8 +170,8 @@ {{end}} - {{svg "octicon-bell"}} - {{.locale.Tr "notification.subscriptions"}} + {{svg "octicon-bell"}} + {{.locale.Tr "notification.subscriptions"}} {{svg "octicon-tools"}} From 595b6744aa07bab7d674dcb6c11af87b5676a97e Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Wed, 31 Aug 2022 17:39:32 +0200 Subject: [PATCH 35/36] Fix import --- routers/web/user/notification.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 79342741009f..469a8dce89d2 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -12,9 +12,8 @@ import ( "net/url" "strings" - "code.gitea.io/gitea/models" - "code.gitea.io/gitea/models/db" activities_model "code.gitea.io/gitea/models/activities" + "code.gitea.io/gitea/models/db" issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/base" From bd23b22a4a15482e677df98d1ba6b7a418e65c41 Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Mon, 26 Sep 2022 18:34:06 +0200 Subject: [PATCH 36/36] Remove var --- routers/web/user/notification.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/web/user/notification.go b/routers/web/user/notification.go index 469a8dce89d2..b4753a603e8a 100644 --- a/routers/web/user/notification.go +++ b/routers/web/user/notification.go @@ -215,8 +215,7 @@ func NotificationSubscriptions(c *context.Context) { c.Data["SortType"] = sortType state := c.FormString("state") - states := []string{"all", "open", "closed"} - if !util.IsStringInSlice(state, states, true) { + if !util.IsStringInSlice(state, []string{"all", "open", "closed"}, true) { state = "all" } c.Data["State"] = state