diff --git a/conf/locale/locale_en-US.ini b/conf/locale/locale_en-US.ini index 3ecd1b3e8..e5bd93e18 100644 --- a/conf/locale/locale_en-US.ini +++ b/conf/locale/locale_en-US.ini @@ -1208,3 +1208,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/conf/locale/locale_pt-BR.ini b/conf/locale/locale_pt-BR.ini index 99aaa4572..95a7db12f 100644 --- a/conf/locale/locale_pt-BR.ini +++ b/conf/locale/locale_pt-BR.ini @@ -1199,3 +1199,9 @@ 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/models/notification.go b/models/notification.go index f46f27b12..3f6cc6cb7 100644 --- a/models/notification.go +++ b/models/notification.go @@ -151,3 +151,34 @@ func getIssueNotification(e Engine, userID, issueID int64) (*Notification, error Get(notification) return notification, err } + +// NotificationsForUser returns notifications for a given user and status +func NotificationsForUser(user *User, status NotificationStatus) ([]*Notification, error) { + return notificationsForUser(x, user, status) +} +func notificationsForUser(e Engine, user *User, status NotificationStatus) (notifications []*Notification, err error) { + err = e. + Where("user_id = ?", user.ID). + And("status = ?", status). + OrderBy("updated_unix DESC"). + Find(¬ifications) + return +} + +// GetRepo returns the repo of the notification +func (n *Notification) GetRepo() (repo *Repository, err error) { + repo = new(Repository) + _, err = x. + Where("id = ?", n.RepoID). + Get(repo) + return +} + +// GetIssue returns the issue of the notification +func (n *Notification) GetIssue() (issue *Issue, err error) { + issue = new(Issue) + _, err = x. + Where("id = ?", n.IssueID). + Get(issue) + return +} diff --git a/public/css/index.css b/public/css/index.css index a05802118..f7be3a52f 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -2691,6 +2691,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 index dc4a9d5ec..74be2b85e 100644 --- a/routers/user/notification.go +++ b/routers/user/notification.go @@ -1,10 +1,39 @@ 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" +) + // Notifications is the notifications page func Notifications(c *context.Context) { - panic("Not implemented") + 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 1d405fba3..a76655696 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/user/notification/notification.tmpl b/templates/user/notification/notification.tmpl new file mode 100644 index 000000000..84e16eec9 --- /dev/null +++ b/templates/user/notification/notification.tmpl @@ -0,0 +1,68 @@ +{{template "base/head" .}} + +
+
+

{{.i18n.Tr "notification.notifications"}}

+ + +
+ {{if eq (len .Notifications) 0}} + {{if eq .Status 1}} + {{.i18n.Tr "notification.no_unread"}} + {{else}} + {{.i18n.Tr "notification.no_read"}} + {{end}} + {{else}} +
+ {{range $notification := .Notifications}} + {{$issue := $notification.GetIssue}} + {{$repo := $notification.GetRepo}} + {{$repoOwner := $repo.MustOwner}} + + + {{end}} +
+ {{end}} +
+
+
+ +{{template "base/footer" .}}