added html_safe to outputed message, hide notifications number when dropdown is toggled, clear all unseen notification form count when the dropdown is toggled, generate notification only to other users

This commit is contained in:
zmagod 2016-10-03 20:31:00 +02:00
parent 1aa09a2ce2
commit c9bbab1004
6 changed files with 11 additions and 17 deletions

View file

@ -31,6 +31,7 @@
animateSpinner($('.notifications-dropdown-header'), false); animateSpinner($('.notifications-dropdown-header'), false);
} }
}); });
$('#count-notifications').hide();
}); });
} }

View file

@ -11,7 +11,7 @@ class UserNotificationsController < ApplicationController
} }
end end
end end
mark_seen_notification @recent_notifications UserNotification.seen_by_user(current_user)
end end
def unseen_notification def unseen_notification
@ -25,12 +25,4 @@ class UserNotificationsController < ApplicationController
end end
end end
end end
private
def mark_seen_notification(notifications)
notifications.each do |notification|
notification.seen_by_user(current_user)
end
end
end end

View file

@ -74,6 +74,7 @@ class Activity < ActiveRecord::Base
) )
project.users.each do |project_user| project.users.each do |project_user|
next if project_user == user
UserNotification.create(notification: notification, user: project_user) UserNotification.create(notification: notification, user: project_user)
end end
end end

View file

@ -10,11 +10,4 @@ class Notification < ActiveRecord::Base
.pluck(:checked) .pluck(:checked)
.first .first
end end
def seen_by_user(user)
user_notification = UserNotification.where(notification: self, user: user)
.first
user_notification.checked = true
user_notification.save
end
end end

View file

@ -12,4 +12,11 @@ class UserNotification < ActiveRecord::Base
def self.unseen_notification_count(user) def self.unseen_notification_count(user)
where('user_id = ? AND checked = false', user.id).count where('user_id = ? AND checked = false', user.id).count
end end
def self.seen_by_user(user)
where(user: user).map do |n|
n.checked = true
n.save
end
end
end end

View file

@ -20,7 +20,7 @@
</div> </div>
<div class="col-xs-10"> <div class="col-xs-10">
<strong><%= notification.title %></strong> <br> <strong><%= notification.title.html_safe %></strong> <br>
<%= l(notification.created_at, format: :full) %> | <%= notification.message %> <%= l(notification.created_at, format: :full) %> | <%= notification.message %>
</div> </div>
</div> </div>