Skip to content

Commit 7da3f89

Browse files
committed
First version of page to see notifications
1 parent a9844ae commit 7da3f89

File tree

8 files changed

+181
-2
lines changed

8 files changed

+181
-2
lines changed

conf/locale/locale_en-US.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,3 +1208,10 @@ default_message = Drop files here or click to upload.
12081208
invalid_input_type = You can't upload files of this type.
12091209
file_too_big = File size ({{filesize}} MB) exceeds maximum size ({{maxFilesize}} MB).
12101210
remove_file = Remove file
1211+
1212+
[notification]
1213+
notifications = Notifications
1214+
unread = Unread
1215+
read = Read
1216+
no_unread = You have no unread notifications.
1217+
no_read = You have no read notifications.

conf/locale/locale_pt-BR.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,9 @@ invalid_input_type=Você não pode enviar arquivos deste tipo.
11991199
file_too_big=O tamanho do arquivo ({{filesize}} MB) excede o limite máximo ({{maxFilesize}} MB).
12001200
remove_file=Remover
12011201

1202+
[notification]
1203+
notifications = Notificações
1204+
unread = Não lidas
1205+
read = Lidas
1206+
no_unread = Você não possui notificações não lidas.
1207+
no_read = Você não possui notificações lidas.

models/notification.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,34 @@ func getIssueNotification(e Engine, userID, issueID int64) (*Notification, error
151151
Get(notification)
152152
return notification, err
153153
}
154+
155+
// NotificationsForUser returns notifications for a given user and status
156+
func NotificationsForUser(user *User, status NotificationStatus) ([]*Notification, error) {
157+
return notificationsForUser(x, user, status)
158+
}
159+
func notificationsForUser(e Engine, user *User, status NotificationStatus) (notifications []*Notification, err error) {
160+
err = e.
161+
Where("user_id = ?", user.ID).
162+
And("status = ?", status).
163+
OrderBy("updated_unix DESC").
164+
Find(&notifications)
165+
return
166+
}
167+
168+
// GetRepo returns the repo of the notification
169+
func (n *Notification) GetRepo() (repo *Repository, err error) {
170+
repo = new(Repository)
171+
_, err = x.
172+
Where("id = ?", n.RepoID).
173+
Get(repo)
174+
return
175+
}
176+
177+
// GetIssue returns the issue of the notification
178+
func (n *Notification) GetIssue() (issue *Issue, err error) {
179+
issue = new(Issue)
180+
_, err = x.
181+
Where("id = ?", n.IssueID).
182+
Get(issue)
183+
return
184+
}

public/css/index.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,24 @@ footer .ui.language .menu {
26912691
.user.followers .follow .ui.button {
26922692
padding: 8px 15px;
26932693
}
2694+
.user.notification .octicon {
2695+
float: left;
2696+
font-size: 2em;
2697+
}
2698+
.user.notification .content {
2699+
float: left;
2700+
margin-left: 7px;
2701+
}
2702+
.user.notification .octicon-issue-opened,
2703+
.user.notification .octicon-git-pull-request {
2704+
color: green;
2705+
}
2706+
.user.notification .octicon-issue-closed {
2707+
color: red;
2708+
}
2709+
.user.notification .octicon-git-merge {
2710+
color: purple;
2711+
}
26942712
.dashboard {
26952713
padding-top: 15px;
26962714
padding-bottom: 80px;

public/less/_user.less

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,25 @@
7474
}
7575
}
7676
}
77+
78+
&.notification {
79+
.octicon {
80+
float: left;
81+
font-size: 2em;
82+
}
83+
.content {
84+
float: left;
85+
margin-left: 7px;
86+
}
87+
88+
.octicon-issue-opened, .octicon-git-pull-request {
89+
color: green;
90+
}
91+
.octicon-issue-closed {
92+
color: red;
93+
}
94+
.octicon-git-merge {
95+
color: purple;
96+
}
97+
}
7798
}

routers/user/notification.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
package user
22

33
import (
4+
"fmt"
5+
6+
"code.gitea.io/gitea/models"
7+
"code.gitea.io/gitea/modules/base"
48
"code.gitea.io/gitea/modules/context"
59
)
610

11+
const (
12+
tplNotification base.TplName = "user/notification/notification"
13+
)
14+
715
// Notifications is the notifications page
816
func Notifications(c *context.Context) {
9-
panic("Not implemented")
17+
var status models.NotificationStatus
18+
switch c.Query("status") {
19+
case "read":
20+
status = models.NotificationStatusRead
21+
default:
22+
status = models.NotificationStatusUnread
23+
}
24+
25+
notifications, err := models.NotificationsForUser(c.User, status)
26+
if err != nil {
27+
c.Handle(500, "ErrNotificationsForUser", err)
28+
return
29+
}
30+
31+
title := "Notifications"
32+
if count := len(notifications); count > 0 {
33+
title = fmt.Sprintf("(%d) %s", count, title)
34+
}
35+
c.Data["Title"] = title
36+
c.Data["Status"] = status
37+
c.Data["Notifications"] = notifications
38+
c.HTML(200, tplNotification)
1039
}

routers/user/setting.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const (
2929
tplSettingsSocial base.TplName = "user/settings/social"
3030
tplSettingsApplications base.TplName = "user/settings/applications"
3131
tplSettingsDelete base.TplName = "user/settings/delete"
32-
tplNotification base.TplName = "user/notification"
3332
tplSecurity base.TplName = "user/security"
3433
)
3534

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{{template "base/head" .}}
2+
3+
<div class="user notification">
4+
<div class="ui container">
5+
<h1 class="ui header">{{.i18n.Tr "notification.notifications"}}</h1>
6+
7+
<div class="ui top attached tabular menu">
8+
<a href="/notifications?status=unread">
9+
<div class="{{if eq .Status 1}}active{{end}} item">
10+
{{.i18n.Tr "notification.unread"}}
11+
{{if eq .Status 1}}
12+
<div class="ui label">{{len .Notifications}}</div>
13+
{{end}}
14+
</div>
15+
</a>
16+
<a href="/notifications?status=read">
17+
<div class="{{if eq .Status 2}}active{{end}} item">
18+
{{.i18n.Tr "notification.read"}}
19+
{{if eq .Status 2}}
20+
<div class="ui label">{{len .Notifications}}</div>
21+
{{end}}
22+
</div>
23+
</a>
24+
</div>
25+
<div class="ui bottom attached active tab segment">
26+
{{if eq (len .Notifications) 0}}
27+
{{if eq .Status 1}}
28+
{{.i18n.Tr "notification.no_unread"}}
29+
{{else}}
30+
{{.i18n.Tr "notification.no_read"}}
31+
{{end}}
32+
{{else}}
33+
<div class="ui relaxed divided list">
34+
{{range $notification := .Notifications}}
35+
{{$issue := $notification.GetIssue}}
36+
{{$repo := $notification.GetRepo}}
37+
{{$repoOwner := $repo.MustOwner}}
38+
39+
<div class="item">
40+
<a href="{{$.AppSubUrl}}/{{$repoOwner.Name}}/{{$repo.Name}}/issues/{{$issue.Index}}">
41+
{{if and $issue.IsPull}}
42+
{{if $issue.IsClosed}}
43+
<i class="octicon octicon-git-merge"></i>
44+
{{else}}
45+
<i class="octicon octicon-git-pull-request"></i>
46+
{{end}}
47+
{{else}}
48+
{{if $issue.IsClosed}}
49+
<i class="octicon octicon-issue-closed"></i>
50+
{{else}}
51+
<i class="octicon octicon-issue-opened"></i>
52+
{{end}}
53+
{{end}}
54+
55+
<div class="content">
56+
<div class="header">{{$repoOwner.Name}}/{{$repo.Name}}</div>
57+
<div class="description">{{$issue.Title}}</div>
58+
</div>
59+
</a>
60+
</div>
61+
{{end}}
62+
</div>
63+
{{end}}
64+
</div>
65+
</div>
66+
</div>
67+
68+
{{template "base/footer" .}}

0 commit comments

Comments
 (0)