mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 21:24:23 +08:00
mark all seen notifications
This commit is contained in:
parent
7807bd37cd
commit
2ee02ec472
6 changed files with 65 additions and 8 deletions
|
@ -21,12 +21,14 @@
|
|||
url: button.attr('data-href'),
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
beforeSend: animateSpinner($('.notifications-dropdown-header'), true),
|
||||
success: function(data) {
|
||||
$('.notifications-dropdown-header')
|
||||
.nextAll('li.notification')
|
||||
.remove();
|
||||
$('.notifications-dropdown-header')
|
||||
.after(data.html);
|
||||
animateSpinner($('.notifications-dropdown-header'), false)
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -40,7 +42,13 @@
|
|||
dataType: 'json',
|
||||
success: function(data) {
|
||||
notificationCount.html('');
|
||||
if ( data.notificationNmber > 0 ) {
|
||||
notificationCount.html(data.notificationNmber);
|
||||
notificationCount.show();
|
||||
} else {
|
||||
notificationCount.hide()
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ table {
|
|||
padding-right: 4px;
|
||||
position: fixed;
|
||||
z-index: 999999;
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,14 +110,35 @@ table {
|
|||
border-bottom: 1px solid $color-alto;
|
||||
padding-bottom: 10px;
|
||||
padding-top: 10px;
|
||||
|
||||
&:hover{
|
||||
background-color: $color-concrete;
|
||||
}
|
||||
}
|
||||
|
||||
.unseen {
|
||||
border-left: 4px solid $color-theme-primary;
|
||||
}
|
||||
|
||||
.text-center {
|
||||
margin-left: 10px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.assignment {
|
||||
background-color: $color-theme-primary;
|
||||
border-radius: 50%;
|
||||
color: $color-wild-sand;
|
||||
font-size: 15px;
|
||||
padding: 7px;
|
||||
}
|
||||
|
||||
.system_message {
|
||||
background-color: $color-theme-secondary;
|
||||
border-radius: 50%;
|
||||
color: $color-wild-sand;
|
||||
font-size: 13px;
|
||||
padding: 7px 10px;
|
||||
}
|
||||
|
||||
.notifications-dropdown-header {
|
||||
|
|
|
@ -11,10 +11,11 @@ class UserNotificationsController < ApplicationController
|
|||
}
|
||||
end
|
||||
end
|
||||
mark_seen_notification @recent_notifications
|
||||
end
|
||||
|
||||
def unseen_notification
|
||||
@number = UserNotification.unseen_notification(current_user)
|
||||
@number = UserNotification.unseen_notification_count(current_user)
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
|
@ -24,4 +25,12 @@ class UserNotificationsController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mark_seen_notification(notifications)
|
||||
notifications.each do |notification|
|
||||
notification.seen_by_user(current_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,4 +4,17 @@ class Notification < ActiveRecord::Base
|
|||
belongs_to :generator_user, class_name: 'User'
|
||||
|
||||
enum type_of: [:assignment, :recent_changes, :system_message]
|
||||
|
||||
def already_seen(user)
|
||||
UserNotification.where(notification: self, user: user)
|
||||
.pluck(:checked)
|
||||
.first
|
||||
end
|
||||
|
||||
def seen_by_user(user)
|
||||
user_notification = UserNotification.where(notification: self, user: user)
|
||||
.first
|
||||
user_notification.checked = true
|
||||
user_notification.save
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ class UserNotification < ActiveRecord::Base
|
|||
.limit(10)
|
||||
end
|
||||
|
||||
def self.unseen_notification(user)
|
||||
def self.unseen_notification_count(user)
|
||||
where('user_id = ? AND checked = false', user.id).count
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<% @recent_notifications.each do |notification| %>
|
||||
<li class="notification">
|
||||
<li class="notification <%= 'unseen' unless notification.already_seen(current_user) %>">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="col-xs-2">
|
||||
<% if notification.type_of == 'recent_changes' %>
|
||||
<div class="text-center">
|
||||
<%= image_tag avatar_path(notification.generator_user, :icon_small), class: "avatar" %>
|
||||
<%= image_tag avatar_path(notification.generator_user, :icon_small), class: 'avatar' %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if notification.type_of == 'assignment' %>
|
||||
|
@ -12,8 +12,13 @@
|
|||
<span class="assignment"><%= fa_icon 'newspaper-o' %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if notification.type_of == 'system_message' %>
|
||||
<div class="text-center">
|
||||
<span class="system_message"><i class="glyphicon glyphicon-tower" aria-hidden="true"></i></span>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="col-xs-10">
|
||||
<strong><%= notification.title %></strong> <br>
|
||||
<%= l(notification.created_at, format: :full) %> | <%= notification.message %>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue