From 6069abe5fdf49cbd9a80c9df0c136587fc8601b5 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Fri, 30 Dec 2016 16:49:54 -0200 Subject: [PATCH 1/5] Notifications - Step 2 --- cmd/web.go | 4 ++ options/locale/locale_en-US.ini | 8 +++ options/locale/locale_pt-BR.ini | 8 +++ public/css/index.css | 18 +++++ public/less/_user.less | 21 ++++++ routers/user/notification.go | 54 +++++++++++++++ routers/user/setting.go | 1 - templates/base/head.tmpl | 12 ++++ templates/user/notification/notification.tmpl | 68 +++++++++++++++++++ 9 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 routers/user/notification.go create mode 100644 templates/user/notification/notification.tmpl diff --git a/cmd/web.go b/cmd/web.go index 7dfd19d64..a513f589a 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -168,6 +168,8 @@ func runWeb(ctx *cli.Context) error { bindIgnErr := binding.BindIgnErr + m.Use(user.GetNotificationCount) + // FIXME: not all routes need go through same middlewares. // Especially some AJAX requests, we can reduce middleware number to improve performance. // Routers. @@ -578,6 +580,8 @@ func runWeb(ctx *cli.Context) error { }) // ***** END: Repository ***** + m.Get("/notifications", reqSignIn, user.Notifications) + m.Group("/api", func() { apiv1.RegisterRoutes(m) }, ignSignIn) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index da2db622c..8df3995e3 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -13,6 +13,7 @@ version = Version page = Page template = Template language = Language +notifications = Notifications create_new = Create... user_profile_and_more = User profile and more signed_in_as = Signed in as @@ -1230,3 +1231,10 @@ default_message = Drop files here or click to upload. invalid_input_type = You can't upload files of this type. file_too_big = File size ({{filesize}} MB) exceeds maximum size ({{maxFilesize}} MB). remove_file = Remove file + +[notification] +notifications = Notifications +unread = Unread +read = Read +no_unread = You have no unread notifications. +no_read = You have no read notifications. diff --git a/options/locale/locale_pt-BR.ini b/options/locale/locale_pt-BR.ini index 5d9ae7a20..4893a7644 100644 --- a/options/locale/locale_pt-BR.ini +++ b/options/locale/locale_pt-BR.ini @@ -13,6 +13,7 @@ version=Versão page=Página template=Template language=Idioma +notifications = Notificações create_new=Criar... user_profile_and_more=Perfil do usuário e configurações signed_in_as=Logado como @@ -1197,3 +1198,10 @@ default_message=Arraste e solte arquivos aqui, ou clique para selecioná-los. invalid_input_type=Você não pode enviar arquivos deste tipo. file_too_big=O tamanho do arquivo ({{filesize}} MB) excede o limite máximo ({{maxFilesize}} MB). remove_file=Remover + +[notification] +notifications = Notificações +unread = Não lidas +read = Lidas +no_unread = Você não possui notificações não lidas. +no_read = Você não possui notificações lidas. diff --git a/public/css/index.css b/public/css/index.css index d64c71ca2..a8d616cc0 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -2694,6 +2694,24 @@ footer .ui.language .menu { .user.followers .follow .ui.button { padding: 8px 15px; } +.user.notification .octicon { + float: left; + font-size: 2em; +} +.user.notification .content { + float: left; + margin-left: 7px; +} +.user.notification .octicon-issue-opened, +.user.notification .octicon-git-pull-request { + color: green; +} +.user.notification .octicon-issue-closed { + color: red; +} +.user.notification .octicon-git-merge { + color: purple; +} .dashboard { padding-top: 15px; padding-bottom: 80px; diff --git a/public/less/_user.less b/public/less/_user.less index 3e37011cf..d7acc4639 100644 --- a/public/less/_user.less +++ b/public/less/_user.less @@ -74,4 +74,25 @@ } } } + + &.notification { + .octicon { + float: left; + font-size: 2em; + } + .content { + float: left; + margin-left: 7px; + } + + .octicon-issue-opened, .octicon-git-pull-request { + color: green; + } + .octicon-issue-closed { + color: red; + } + .octicon-git-merge { + color: purple; + } + } } diff --git a/routers/user/notification.go b/routers/user/notification.go new file mode 100644 index 000000000..13d2d70f8 --- /dev/null +++ b/routers/user/notification.go @@ -0,0 +1,54 @@ +package user + +import ( + "fmt" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/context" +) + +const ( + tplNotification base.TplName = "user/notification/notification" +) + +// GetNotificationCount is the middleware that sets the notification count in the context +func GetNotificationCount(c *context.Context) { + if !c.IsSigned { + return + } + + count, err := models.GetNotificationUnreadCount(c.User) + if err != nil { + c.Handle(500, "GetNotificationCount", err) + return + } + + c.Data["NotificationUnreadCount"] = count +} + +// Notifications is the notifications page +func Notifications(c *context.Context) { + var status models.NotificationStatus + switch c.Query("status") { + case "read": + status = models.NotificationStatusRead + default: + status = models.NotificationStatusUnread + } + + notifications, err := models.NotificationsForUser(c.User, status) + if err != nil { + c.Handle(500, "ErrNotificationsForUser", err) + return + } + + title := "Notifications" + if count := len(notifications); count > 0 { + title = fmt.Sprintf("(%d) %s", count, title) + } + c.Data["Title"] = title + c.Data["Status"] = status + c.Data["Notifications"] = notifications + c.HTML(200, tplNotification) +} diff --git a/routers/user/setting.go b/routers/user/setting.go index e078f8c17..a465b0cd8 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -29,7 +29,6 @@ const ( tplSettingsSocial base.TplName = "user/settings/social" tplSettingsApplications base.TplName = "user/settings/applications" tplSettingsDelete base.TplName = "user/settings/delete" - tplNotification base.TplName = "user/notification" tplSecurity base.TplName = "user/security" ) diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index fe1474251..c1f386fe7 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -82,6 +82,18 @@ {{if .IsSigned}}