mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-18 20:09:26 +00:00
Improve notification pager (#9821)
Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
This commit is contained in:
parent
2f3a602b3c
commit
b641c68fee
|
@ -61,6 +61,19 @@ func Notifications(c *context.Context) {
|
||||||
status = models.NotificationStatusUnread
|
status = models.NotificationStatusUnread
|
||||||
}
|
}
|
||||||
|
|
||||||
|
total, err := models.GetNotificationCount(c.User, status)
|
||||||
|
if err != nil {
|
||||||
|
c.ServerError("ErrGetNotificationCount", 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?q=%s&page=%d", c.Query("q"), pager.Paginater.Current()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
statuses := []models.NotificationStatus{status, models.NotificationStatusPinned}
|
statuses := []models.NotificationStatus{status, models.NotificationStatusPinned}
|
||||||
notifications, err := models.NotificationsForUser(c.User, statuses, page, perPage)
|
notifications, err := models.NotificationsForUser(c.User, statuses, page, perPage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -87,12 +100,6 @@ func Notifications(c *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
total, err := models.GetNotificationCount(c.User, status)
|
|
||||||
if err != nil {
|
|
||||||
c.ServerError("ErrGetNotificationCount", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
title := c.Tr("notifications")
|
title := c.Tr("notifications")
|
||||||
if status == models.NotificationStatusUnread && total > 0 {
|
if status == models.NotificationStatusUnread && total > 0 {
|
||||||
title = fmt.Sprintf("(%d) %s", total, title)
|
title = fmt.Sprintf("(%d) %s", total, title)
|
||||||
|
@ -102,7 +109,6 @@ func Notifications(c *context.Context) {
|
||||||
c.Data["Status"] = status
|
c.Data["Status"] = status
|
||||||
c.Data["Notifications"] = notifications
|
c.Data["Notifications"] = notifications
|
||||||
|
|
||||||
pager := context.NewPagination(int(total), perPage, page, 5)
|
|
||||||
pager.SetDefaultParams(c)
|
pager.SetDefaultParams(c)
|
||||||
c.Data["Page"] = pager
|
c.Data["Page"] = pager
|
||||||
|
|
||||||
|
@ -134,7 +140,7 @@ func NotificationStatusPost(c *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/notifications", setting.AppSubURL)
|
url := fmt.Sprintf("%s/notifications?page=%s", setting.AppSubURL, c.Query("page"))
|
||||||
c.Redirect(url, 303)
|
c.Redirect(url, 303)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@
|
||||||
{{$.CsrfTokenHtml}}
|
{{$.CsrfTokenHtml}}
|
||||||
<input type="hidden" name="notification_id" value="{{$notification.ID}}" />
|
<input type="hidden" name="notification_id" value="{{$notification.ID}}" />
|
||||||
<input type="hidden" name="status" value="read" />
|
<input type="hidden" name="status" value="read" />
|
||||||
|
<input type="hidden" name="page" value="{{$.Page.Paginater.Current}}" />
|
||||||
<button class="ui mini button" title='{{$.i18n.Tr "notification.mark_as_read"}}'>
|
<button class="ui mini button" title='{{$.i18n.Tr "notification.mark_as_read"}}'>
|
||||||
<i class="octicon octicon-check"></i>
|
<i class="octicon octicon-check"></i>
|
||||||
</button>
|
</button>
|
||||||
|
@ -97,6 +98,7 @@
|
||||||
{{$.CsrfTokenHtml}}
|
{{$.CsrfTokenHtml}}
|
||||||
<input type="hidden" name="notification_id" value="{{$notification.ID}}" />
|
<input type="hidden" name="notification_id" value="{{$notification.ID}}" />
|
||||||
<input type="hidden" name="status" value="unread" />
|
<input type="hidden" name="status" value="unread" />
|
||||||
|
<input type="hidden" name="page" value="{{$.Page.Paginater.Current}}" />
|
||||||
<button class="ui mini button" title='{{$.i18n.Tr "notification.mark_as_unread"}}'>
|
<button class="ui mini button" title='{{$.i18n.Tr "notification.mark_as_unread"}}'>
|
||||||
<i class="octicon octicon-bell"></i>
|
<i class="octicon octicon-bell"></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in a new issue