TEST : First implementation of notification with Action Cable : alert message
This commit is contained in:
parent
f98bb90f08
commit
c533bb0a88
7 changed files with 48 additions and 2 deletions
23
app/assets/javascripts/channels/notifications.js
Normal file
23
app/assets/javascripts/channels/notifications.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
App.messages = App.cable.subscriptions.create('NotificationsChannel', {
|
||||
received: function (data) {
|
||||
|
||||
if (window.location.href.indexOf('backoffice') !== -1) {
|
||||
$("#notification_alert").html(data['message']);
|
||||
slideIn_notification_alert();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function slideIn_notification_alert (){
|
||||
$("#notification_alert").animate({
|
||||
right: '20px'
|
||||
}, 250);
|
||||
|
||||
setTimeout(slideOut_notification_alert, 3500);
|
||||
}
|
||||
|
||||
function slideOut_notification_alert (){
|
||||
$("#notification_alert").animate({
|
||||
right: '-250px'
|
||||
}, 200);
|
||||
}
|
12
app/assets/stylesheets/notification_alert.scss
Normal file
12
app/assets/stylesheets/notification_alert.scss
Normal file
|
@ -0,0 +1,12 @@
|
|||
#notification_alert {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: -250px;
|
||||
|
||||
z-index: 1000;
|
||||
|
||||
width: 250px;
|
||||
height: 80px;
|
||||
|
||||
border: solid black 1px;
|
||||
}
|
5
app/channels/notifications_channel.rb
Normal file
5
app/channels/notifications_channel.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class NotificationsChannel < ApplicationCable::Channel
|
||||
def subscribed
|
||||
stream_from 'notifications'
|
||||
end
|
||||
end
|
|
@ -1,8 +1,14 @@
|
|||
class Notification < ActiveRecord::Base
|
||||
belongs_to :dossier
|
||||
|
||||
after_save :broadcast_notification
|
||||
|
||||
enum type_notif: {
|
||||
commentaire: 'commentaire'
|
||||
}
|
||||
|
||||
def broadcast_notification
|
||||
ActionCable.server.broadcast 'notifications',
|
||||
message: "Nouveau commentaire posté sur le dossier #{self.dossier.id}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
= image_tag('marianne_small.png', class: 'logo')
|
||||
%div.col-lg-6.no-padding#tps-title
|
||||
TPS
|
||||
.badge.progress-bar-danger
|
||||
= Notification.where(already_read: false).count
|
||||
|
||||
%div.col-lg-10.col-md-10.no-padding
|
||||
%div#navbar-body
|
||||
|
|
1
app/views/layouts/_notifications_alert.html.haml
Normal file
1
app/views/layouts/_notifications_alert.html.haml
Normal file
|
@ -0,0 +1 @@
|
|||
#notification_alert.alert.alert-success
|
|
@ -50,6 +50,7 @@
|
|||
%i.fa.fa-times{style:'position: fixed; top: 10; right: 30; color: white;'}
|
||||
|
||||
= render partial: 'layouts/switch_devise_profile_module'
|
||||
= render partial: 'layouts/notifications_alert'
|
||||
|
||||
= render partial: 'layouts/footer', locals: {main_container_size: main_container_size}
|
||||
= render partial: 'layouts/google_analytics'
|
||||
|
|
Loading…
Add table
Reference in a new issue