Added route showing all notifications

This commit is contained in:
Eduard Urbach 2018-03-01 23:18:29 +01:00
parent 40ea58dffe
commit 700bf089bf
4 changed files with 43 additions and 4 deletions

View File

@ -144,7 +144,8 @@ func Configure(app *aero.Application) {
l.Page("/group/:id/forum", group.Forum)
// Notifications
l.Page("/notifications", notifications.All)
l.Page("/notifications", notifications.ByUser)
l.Page("/notifications/all", notifications.All)
// User profiles
l.Page("/user", user.Get)
@ -162,7 +163,7 @@ func Configure(app *aero.Application) {
l.Page("/user/:nick/animelist/dropped", animelist.FilterByStatus(arn.AnimeListStatusDropped))
l.Page("/user/:nick/animelist/anime/:id", animelistitem.Get)
l.Page("/user/:nick/recommended/anime", recommended.Anime)
l.Page("/user/:nick/notifications", notifications.All)
l.Page("/user/:nick/notifications", notifications.ByUser)
// Anime list
l.Page("/animelist/watching", home.FilterByStatus(arn.AnimeListStatusWatching))

View File

@ -13,8 +13,8 @@ import (
const maxNotifications = 30
// All shows all notifications sent so far.
func All(ctx *aero.Context) string {
// ByUser shows all notifications sent to the given user.
func ByUser(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
@ -44,3 +44,24 @@ func All(ctx *aero.Context) string {
return ctx.HTML(components.Notifications(notifications, viewUser, user))
}
// All shows all notifications.
func All(ctx *aero.Context) string {
notifications, err := arn.AllNotifications()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Could not retrieve notification list", err)
}
// Sort by date
sort.Slice(notifications, func(i, j int) bool {
return notifications[i].Created > notifications[j].Created
})
// Limit results
if len(notifications) > maxNotifications {
notifications = notifications[:maxNotifications]
}
return ctx.HTML(components.AllNotifications(notifications))
}

View File

@ -12,6 +12,17 @@ component Notifications(notifications []*arn.Notification, viewUser *arn.User, u
each notification in notifications
Notification(notification)
component AllNotifications(notifications []*arn.Notification)
h1 All notifications
.notifications-container
.notifications
each notification in notifications
Notification(notification)
.notification-user
a.ajax(href=notification.User().Link())= notification.User().Nick
component Notification(notification *arn.Notification)
a.notification(href=notification.Link, target="_blank", data-seen=notification.Seen)
.notification-icon
@ -19,6 +30,7 @@ component Notification(notification *arn.Notification)
.notification-info
h3.notification-title= notification.Title
.notification-footer
p.notification-text= notification.Message
.notification-date.utc-date(data-date=notification.Created)

View File

@ -15,6 +15,11 @@
position relative
opacity 0.25
.notification-user
text-align right
margin-bottom 0.5rem
font-size 0.9rem
.notification[data-seen=""]
opacity 1.0