Commit 174b1847 by tady

通知view修正

parent e15ce817
...@@ -21,3 +21,5 @@ ...@@ -21,3 +21,5 @@
_.mixin(_.string.exports()); _.mixin(_.string.exports());
// $('[data-toggle="tooltip"]').tooltip();
// $('[data-toggle="popover"]').popover();
...@@ -26,3 +26,7 @@ a .text-link { ...@@ -26,3 +26,7 @@ a .text-link {
a:visited .text-link { a:visited .text-link {
color: #609; color: #609;
} }
.popover {
max-width: 400px;
}
...@@ -4,5 +4,4 @@ class UserDecorator < Draper::Decorator ...@@ -4,5 +4,4 @@ class UserDecorator < Draper::Decorator
def draft_count def draft_count
model.posts.where(is_draft: true).count model.posts.where(is_draft: true).count
end end
end end
...@@ -37,6 +37,8 @@ class Comment < ActiveRecord::Base ...@@ -37,6 +37,8 @@ class Comment < ActiveRecord::Base
def notify_watchers! def notify_watchers!
post.watchers.each do |watcher| post.watchers.each do |watcher|
next if watcher == author
watcher.push_notification(post.decorate.show_path, "#{author.name}さんが「#{post.title}」にコメントしました。") watcher.push_notification(post.decorate.show_path, "#{author.name}さんが「#{post.title}」にコメントしました。")
end end
end end
......
...@@ -122,6 +122,8 @@ class Post < ActiveRecord::Base ...@@ -122,6 +122,8 @@ class Post < ActiveRecord::Base
def notify_watchers! def notify_watchers!
watchers.each do |watcher| watchers.each do |watcher|
next if watcher == author
watcher.push_notification(decorate.show_path, "#{author.name}さんが「#{title}」を編集しました") watcher.push_notification(decorate.show_path, "#{author.name}さんが「#{title}」を編集しました")
end end
end end
......
...@@ -24,6 +24,11 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation" ...@@ -24,6 +24,11 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
ul.nav.navbar-nav.navbar-right ul.nav.navbar-nav.navbar-right
li li
a#notifications data-container="body" data-toggle="popover" data-placement="bottom"
span.glyphicon.glyphicon-flag
- if current_user.notifications.unread.any?
span.badge = current_user.notifications.unread.count
li
form form
a.btn.btn-primary.navbar-btn href=new_post_path a.btn.btn-primary.navbar-btn href=new_post_path
| New Post&nbsp;&nbsp; | New Post&nbsp;&nbsp;
...@@ -46,21 +51,24 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation" ...@@ -46,21 +51,24 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
li.divider li.divider
li li
a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut a href=destroy_user_session_path data-method="delete" rel="nofollow" SignOut
li.dropdown
a.dropdown-toggle data-toggle="dropdown" script#notification-content type="text/template"
| 通知
- if current_user.notifications.unread.any?
span.badge = current_user.notifications.unread.count
b.caret
ul.dropdown-menu
- if current_user.notifications.unread.any? - if current_user.notifications.unread.any?
h4 通知一覧
.list-group
- current_user.notifications.unread.each do |notification| - current_user.notifications.unread.each do |notification|
li a.list-group-item href=notification_bridge_path(notification.id)
a href=notification_bridge_path(notification.id) spen.small
| [#{notification.created_at.strftime('%m/%d %H:%M')}]&nbsp;
= notification.body = notification.body
- else - else
li h4 通知はありません
a 通知はありません
- content_for :footer_js do
javascript:
$('#notifications').popover({
html: true,
content: $('#notification-content').html()
});
...@@ -32,6 +32,13 @@ describe Notification do ...@@ -32,6 +32,13 @@ describe Notification do
expect(@bob.notifications.size).to eq(1) expect(@bob.notifications.size).to eq(1)
end end
it "not notifies on post edited by him" do
@bob.watch!(post: @post)
@post.reload
@post.update!(title: @post.title + ' [New!]', author: @bob)
expect(@bob.notifications.size).to eq(0)
end
it "notifies on post commented" do it "notifies on post commented" do
@bob.watch!(post: @post) @bob.watch!(post: @post)
expect(@bob.watching?(post: @post)).to be_truthy expect(@bob.watching?(post: @post)).to be_truthy
...@@ -41,6 +48,13 @@ describe Notification do ...@@ -41,6 +48,13 @@ describe Notification do
expect(@bob.notifications.size).to eq(1) expect(@bob.notifications.size).to eq(1)
end end
it "not notifies on post commented by him" do
@bob.watch!(post: @post)
@post.reload
@post.comments.create!(author: @bob, body: 'new comment')
expect(@bob.notifications.size).to eq(0)
end
it "set watch on user create a new post" do it "set watch on user create a new post" do
new_post = Post.create!(author: @bob, title: 'title', body: 'body') new_post = Post.create!(author: @bob, title: 'title', body: 'body')
expect(@bob.watching?(post: new_post)).to be_truthy expect(@bob.watching?(post: new_post)).to be_truthy
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment