-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Notifications - Step 2 #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andreynering
merged 5 commits into
go-gitea:master
from
andreynering:notifications-step-2
Jan 5, 2017
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6069abe
Notifications - Step 2
andreynering 341a3b5
Do not get count on /api routers
andreynering f59672a
More fine graned colors
andreynering 545ba2e
Showing index in front of issue title
andreynering b354cf3
Add pagination for notifications
andreynering File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,4 +74,25 @@ | |
} | ||
} | ||
} | ||
|
||
&.notification { | ||
.octicon { | ||
float: left; | ||
font-size: 2em; | ||
} | ||
.content { | ||
float: left; | ||
margin-left: 7px; | ||
} | ||
|
||
.octicon-issue-opened, .octicon-git-pull-request { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't these defined somewhere already that we can reuse? (for the activity/dashboard feed) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. |
||
color: #21ba45; | ||
} | ||
.octicon-issue-closed { | ||
color: #d01919; | ||
} | ||
.octicon-git-merge { | ||
color: #a333c8; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package user | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/Unknwon/paginater" | ||
|
||
"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 strings.HasPrefix(c.Req.URL.Path, "/api") { | ||
return | ||
} | ||
|
||
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 ( | ||
keyword = c.Query("q") | ||
status models.NotificationStatus | ||
page = c.QueryInt("page") | ||
perPage = c.QueryInt("perPage") | ||
) | ||
if page < 1 { | ||
page = 1 | ||
} | ||
if perPage < 1 { | ||
perPage = 20 | ||
} | ||
|
||
switch keyword { | ||
case "read": | ||
status = models.NotificationStatusRead | ||
default: | ||
status = models.NotificationStatusUnread | ||
} | ||
|
||
notifications, err := models.NotificationsForUser(c.User, status, page, perPage) | ||
if err != nil { | ||
c.Handle(500, "ErrNotificationsForUser", err) | ||
return | ||
} | ||
|
||
total, err := models.GetNotificationCount(c.User, status) | ||
if err != nil { | ||
c.Handle(500, "ErrGetNotificationCount", err) | ||
return | ||
} | ||
|
||
title := "Notifications" | ||
if count := len(notifications); count > 0 { | ||
title = fmt.Sprintf("(%d) %s", count, title) | ||
} | ||
c.Data["Title"] = title | ||
c.Data["Keyword"] = keyword | ||
c.Data["Status"] = status | ||
c.Data["Notifications"] = notifications | ||
c.Data["Page"] = paginater.New(int(total), perPage, page, 5) | ||
c.HTML(200, tplNotification) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{{template "base/head" .}} | ||
|
||
<div class="user notification"> | ||
<div class="ui container"> | ||
<h1 class="ui header">{{.i18n.Tr "notification.notifications"}}</h1> | ||
|
||
<div class="ui top attached tabular menu"> | ||
<a href="/notifications?q=unread"> | ||
<div class="{{if eq .Status 1}}active{{end}} item"> | ||
{{.i18n.Tr "notification.unread"}} | ||
{{if eq .Status 1}} | ||
<div class="ui label">{{len .Notifications}}</div> | ||
{{end}} | ||
</div> | ||
</a> | ||
<a href="/notifications?q=read"> | ||
<div class="{{if eq .Status 2}}active{{end}} item"> | ||
{{.i18n.Tr "notification.read"}} | ||
{{if eq .Status 2}} | ||
<div class="ui label">{{len .Notifications}}</div> | ||
{{end}} | ||
</div> | ||
</a> | ||
</div> | ||
<div class="ui bottom attached active tab segment"> | ||
{{if eq (len .Notifications) 0}} | ||
{{if eq .Status 1}} | ||
{{.i18n.Tr "notification.no_unread"}} | ||
{{else}} | ||
{{.i18n.Tr "notification.no_read"}} | ||
{{end}} | ||
{{else}} | ||
<div class="ui relaxed divided list"> | ||
{{range $notification := .Notifications}} | ||
{{$issue := $notification.GetIssue}} | ||
{{$repo := $notification.GetRepo}} | ||
{{$repoOwner := $repo.MustOwner}} | ||
|
||
<div class="item"> | ||
<a href="{{$.AppSubUrl}}/{{$repoOwner.Name}}/{{$repo.Name}}/issues/{{$issue.Index}}"> | ||
{{if and $issue.IsPull}} | ||
{{if $issue.IsClosed}} | ||
<i class="octicon octicon-git-merge"></i> | ||
{{else}} | ||
<i class="octicon octicon-git-pull-request"></i> | ||
{{end}} | ||
{{else}} | ||
{{if $issue.IsClosed}} | ||
<i class="octicon octicon-issue-closed"></i> | ||
{{else}} | ||
<i class="octicon octicon-issue-opened"></i> | ||
{{end}} | ||
{{end}} | ||
|
||
<div class="content"> | ||
<div class="header">{{$repoOwner.Name}}/{{$repo.Name}}</div> | ||
<div class="description">#{{$issue.Index}} - {{$issue.Title}}</div> | ||
</div> | ||
</a> | ||
</div> | ||
{{end}} | ||
</div> | ||
{{end}} | ||
</div> | ||
|
||
{{template "base/paginate" .}} | ||
</div> | ||
</div> | ||
|
||
{{template "base/footer" .}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this add unnecessary overhead for endpoints like
/api
that will never use it? :)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^, Only UI route group need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done