notifly 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/app/assets/javascripts/{notifly.js → notifly.js.erb} +1 -0
- data/app/assets/javascripts/notifly/get_notifications.js.erb +7 -5
- data/app/assets/javascripts/notifly/read_notifications.js.erb +21 -3
- data/app/assets/javascripts/notifly/real_time.js.erb +26 -0
- data/app/controllers/notifly/notifications_controller.rb +1 -1
- data/app/models/notifly/notification.rb +8 -3
- data/app/views/notifly/layouts/_notification.html.erb +5 -3
- data/app/views/notifly/layouts/_notifly.html.erb +1 -1
- data/app/views/notifly/notifications/index.js.erb +6 -6
- data/app/views/notifly/templates/notifications/_default.html.erb +1 -1
- data/config/routes.rb +2 -2
- data/lib/generators/notifly/install/templates/config/initializers/notifly.rb +3 -0
- data/lib/notifly.rb +8 -0
- data/lib/services/action_view_helper.rb +19 -0
- data/lib/services/notification_channel.rb +19 -0
- metadata +48 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 199c4354275abe7fdd5dfbc605a68a17205477ec
|
4
|
+
data.tar.gz: 83ab9a0f55faaba7ff98f6fbf6e68919fbf8d963
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e78062c032b1bab6bb4ca30983d91ce80564051deac0ba68dc044aa9d49012f8aa828684bedeb154e450abc1b348e46b3ed6bcd0747ac9cbfa93873181e97b8e
|
7
|
+
data.tar.gz: bbb624c480c39326c2fef39a1b5028223c08a7220ba4aec51241cd3bdea3b19b10cfdf84b40a7df5fe10d17eba3a8743a0bb6939ad81cfb8eef775544d451e30
|
data/README.md
CHANGED
@@ -187,6 +187,10 @@ You can access the notifications using the following methods:
|
|
187
187
|
- unseen: used on `Notifly::Notifications` and `#notifly_notifications` to show **only** unseen notifications
|
188
188
|
- not_only-mail: used on `Notifly::Notifications` and `#notifly_notifications` to remove notification that are **mail only**
|
189
189
|
|
190
|
+
### Websocket
|
191
|
+
|
192
|
+
If you want to use websocket just install the gem [websocket-rails](https://github.com/websocket-rails/websocket-rails/wiki/Installation-and-Setup) and change the notifly's configuration
|
193
|
+
at `config/initializers/notifly.rb`
|
190
194
|
|
191
195
|
## Front-end
|
192
196
|
|
@@ -249,7 +253,8 @@ Notifications and Mails are rendered with their templates. They use a simple def
|
|
249
253
|
template but if you want to change or create new ones run the generate above
|
250
254
|
with the option that you want or create them in `app/views/notifly/templates/`.
|
251
255
|
Remember that notifications templates should be in `notifications` folder and
|
252
|
-
mails templates in `mails` folder
|
256
|
+
mails templates in `mails` folder and with **both** you need to use the `main_app`
|
257
|
+
to render links.
|
253
258
|
|
254
259
|
If you already have a layout and just want add our features to it, take a look
|
255
260
|
at [Adapting your layout](#adapting).
|
@@ -5,6 +5,7 @@
|
|
5
5
|
//= require 'notifly/seen_notifications'
|
6
6
|
//= require 'notifly/read_notifications'
|
7
7
|
//= require 'notifly/more_notifications'
|
8
|
+
<% require_asset 'notifly/real_time' if Notifly.websocket %>
|
8
9
|
|
9
10
|
$(document).ready(function() {
|
10
11
|
$(document).on('click', '#notifly-notifications-panel.dropdown-menu', function (e) {
|
@@ -1,6 +1,10 @@
|
|
1
1
|
<% notifly = Notifly::Engine.routes.url_helpers %>
|
2
2
|
var notiflyLastNotification, notiflyFirstNotification;
|
3
3
|
|
4
|
+
$(document).ready(function() {
|
5
|
+
_notiflyGetNotifications();
|
6
|
+
});
|
7
|
+
|
4
8
|
var _notiflyGetNotifications = function () {
|
5
9
|
var $notifly = $('#notifly');
|
6
10
|
|
@@ -19,9 +23,7 @@ var _notiflyGetNotifications = function () {
|
|
19
23
|
};
|
20
24
|
|
21
25
|
var _notiflyRepeatRequest = function () {
|
22
|
-
|
26
|
+
<% if not Notifly.websocket %>
|
27
|
+
setTimeout(_notiflyGetNotifications, <%= Notifly.timeout %>);
|
28
|
+
<% end %>
|
23
29
|
};
|
24
|
-
|
25
|
-
$(document).ready(function() {
|
26
|
-
_notiflyGetNotifications();
|
27
|
-
});
|
@@ -1,5 +1,10 @@
|
|
1
1
|
<% notifly = Notifly::Engine.routes.url_helpers %>
|
2
2
|
|
3
|
+
$(document).ready(function() {
|
4
|
+
_notiflyReadNotifications();
|
5
|
+
_notiflyReadNotificationWithLink();
|
6
|
+
});
|
7
|
+
|
3
8
|
var _notiflyReadNotifications = function () {
|
4
9
|
var $notifly = $('#notifly-mark-as-read-link');
|
5
10
|
|
@@ -17,6 +22,19 @@ var _notiflyReadNotifications = function () {
|
|
17
22
|
}
|
18
23
|
};
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
var _notiflyReadNotificationWithLink = function () {
|
26
|
+
if ($('#notifly').length > 0) {
|
27
|
+
$('#notifly').on('click', '.notifly-notification-message a', function () {
|
28
|
+
var notificationId = $(this).closest('div.notifly-notification').data('id');
|
29
|
+
|
30
|
+
$.ajax({
|
31
|
+
url: '<%= notifly.notification_toggle_read_path %>',
|
32
|
+
data: {
|
33
|
+
notification_id: notificationId,
|
34
|
+
read: true
|
35
|
+
},
|
36
|
+
type: 'PUT'
|
37
|
+
});
|
38
|
+
});
|
39
|
+
}
|
40
|
+
};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
window.dispatcher = new WebSocketRails(location.host + '/websocket');
|
2
|
+
var notiflyFirstNotification;
|
3
|
+
|
4
|
+
$(function () {
|
5
|
+
var $notifly = $('#notifly');
|
6
|
+
|
7
|
+
if ($notifly !== undefined) {
|
8
|
+
dispatcher.bind('notifly.notifications.new', _injectNotificationFrom);
|
9
|
+
}
|
10
|
+
});
|
11
|
+
|
12
|
+
var _injectNotificationFrom = function (data) {
|
13
|
+
if (data.message) {
|
14
|
+
$('#notifly-notifications-content .notifly-empty').remove();
|
15
|
+
notiflyFirstNotification = data.id;
|
16
|
+
|
17
|
+
if (!$('#notifly').hasClass('open')) {
|
18
|
+
$counter = $('#notifly-counter');
|
19
|
+
$counter.html(eval($counter.html()) + 1);
|
20
|
+
$counter.removeClass('hide');
|
21
|
+
}
|
22
|
+
|
23
|
+
return $('#notifly').find('#notifly-notifications-content')
|
24
|
+
.prepend(data.message)
|
25
|
+
}
|
26
|
+
};
|
@@ -5,23 +5,24 @@ module Notifly
|
|
5
5
|
belongs_to :receiver, polymorphic: true
|
6
6
|
|
7
7
|
before_validation :set_defaults
|
8
|
+
after_create :send_to_receiver, if: -> { Notifly.websocket }
|
8
9
|
|
9
10
|
scope :all_from, -> (receiver) { where(receiver: receiver) }
|
10
11
|
scope :unseen, -> { where(seen: false) }
|
11
12
|
scope :not_only_mail, -> { where.not(mail: 'only') }
|
12
13
|
scope :limited, -> { limit(Notifly.per_page) }
|
13
|
-
scope :ordered, -> { order('created_at DESC') }
|
14
|
+
scope :ordered, -> { order('notifly_notifications.created_at DESC') }
|
14
15
|
scope :newer, ->(than: nil) do
|
15
16
|
return ordered if than.blank?
|
16
17
|
|
17
18
|
reference = find_by(id: than)
|
18
|
-
ordered.where('created_at > ?', reference.created_at).where.not(id: reference)
|
19
|
+
ordered.where('notifly_notifications.created_at > ?', reference.created_at).where.not(id: reference)
|
19
20
|
end
|
20
21
|
scope :older, ->(than: nil) do
|
21
22
|
reference = find_by(id: than)
|
22
23
|
|
23
24
|
ordered.
|
24
|
-
where('created_at < ?', reference.created_at).
|
25
|
+
where('notifly_notifications.created_at < ?', reference.created_at).
|
25
26
|
where.not(id: reference)
|
26
27
|
end
|
27
28
|
scope :between, ->(first, last) do
|
@@ -39,5 +40,9 @@ module Notifly
|
|
39
40
|
self.kind ||= :notification
|
40
41
|
self.template ||= :default
|
41
42
|
end
|
43
|
+
|
44
|
+
def send_to_receiver
|
45
|
+
Notifly::NotificationChannel.new(self.receiver_id).trigger(self)
|
46
|
+
end
|
42
47
|
end
|
43
48
|
end
|
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
<% read = notification.read ? '' : 'notifly-notification-not-read' %>
|
4
4
|
|
5
|
-
<div id='<%= "notifly-notification-#{notification.id}" %>' class="notifly-notification <%= read %>">
|
6
|
-
|
7
|
-
|
5
|
+
<div id='<%= "notifly-notification-#{notification.id}" %>' class="notifly-notification <%= read %>" data-id="<%= notification.id %>">
|
6
|
+
<div class="notifly-notification-message">
|
7
|
+
<%= render partial: "notifly/templates/notifications/#{notification.template}",
|
8
|
+
locals: { notification: notification } %>
|
9
|
+
</div>
|
8
10
|
|
9
11
|
<span class="notifly-notification-actions">
|
10
12
|
<%= render partial: 'notifly/layouts/actions', locals: { notification: notification } %>
|
@@ -1,17 +1,17 @@
|
|
1
|
-
<% rendered_notifications = render partial: 'notifly/layouts/index',
|
2
|
-
locals: { notifications: @notifications } %>
|
3
|
-
<% last_notification = @notifications.last.try(:id) %>
|
4
|
-
<% first_notification = @notifications.first.try(:id) %>
|
5
|
-
|
6
1
|
$('#notifly-notifications-content .notifly-loading').remove();
|
7
2
|
$('#notifly-notifications-content .notifly-empty').remove();
|
8
3
|
|
9
4
|
<% if @notifications.any? %>
|
5
|
+
<% rendered_notifications = render partial: 'notifly/layouts/index',
|
6
|
+
locals: { notifications: @notifications } %>
|
7
|
+
<% last_notification = @notifications.last.try(:id) %>
|
8
|
+
<% first_notification = @notifications.first.try(:id) %>
|
10
9
|
|
11
10
|
<% if @scope_param == 'older' %>
|
12
|
-
|
11
|
+
$('#notifly-notifications-content').append("<%= j rendered_notifications %>");
|
13
12
|
notiflyLastNotification = <%= last_notification %>;
|
14
13
|
|
14
|
+
$('#notifly-notifications-content').scrollTop($('<%= "#notifly-notification-#{first_notification}" %>').offset().top);
|
15
15
|
<% else %>
|
16
16
|
$('#notifly-notifications-content').prepend("<%= j rendered_notifications %>");
|
17
17
|
notiflyFirstNotification = <%= first_notification %>;
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Notifly::Engine.routes.draw do
|
2
|
-
|
3
|
-
put :toggle_read
|
2
|
+
put '/notifications/(:notification_id)/toggle_read', to: 'notifications#toggle_read', as: :notification_toggle_read
|
4
3
|
|
4
|
+
resources :notifications, only: [:index] do
|
5
5
|
collection do
|
6
6
|
put :read
|
7
7
|
put :seen
|
data/lib/notifly.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'notifly/engine'
|
2
2
|
require 'notifly/railtie'
|
3
|
+
require 'services/notification_channel'
|
4
|
+
require 'services/action_view_helper'
|
3
5
|
require 'font-awesome-rails'
|
6
|
+
require 'websocket-rails'
|
4
7
|
|
5
8
|
module Notifly
|
6
9
|
# How many notifications per page.
|
@@ -19,9 +22,14 @@ module Notifly
|
|
19
22
|
mattr_accessor :mailer_sender
|
20
23
|
@@mailer_sender = 'change-me-at-config-initializers-notifly@exemple.com'
|
21
24
|
|
25
|
+
# Timeout used when notifly get new notifications per request
|
22
26
|
mattr_accessor :timeout
|
23
27
|
@@timeout = 10000
|
24
28
|
|
29
|
+
# Active websocket
|
30
|
+
mattr_accessor :websocket
|
31
|
+
@@websocket = false
|
32
|
+
|
25
33
|
# Default way to setup Notifly. Run rails generate notifly:install to create
|
26
34
|
# a fresh initializer with all configuration values.
|
27
35
|
def self.setup
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ActionViewHelper
|
2
|
+
attr_reader :action_view
|
3
|
+
delegate *ActionView::Base.instance_methods, to: :action_view
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
notifly_path = File.expand_path(File.dirname(File.dirname(__FILE__))) + '../../app/views/notifly'
|
7
|
+
ActionController::Base.prepend_view_path(notifly_path)
|
8
|
+
@action_view = ActionView::Base.new(ActionController::Base.view_paths)
|
9
|
+
@action_view.extend ApplicationHelper
|
10
|
+
|
11
|
+
@action_view.class_eval do
|
12
|
+
include Notifly::Engine.routes.url_helpers
|
13
|
+
|
14
|
+
def protect_against_forgery?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Notifly
|
2
|
+
class NotificationChannel
|
3
|
+
def initialize(user_id)
|
4
|
+
@user_id = user_id
|
5
|
+
@channel = WebsocketRails.users[@user_id.to_s]
|
6
|
+
@action_view = ActionViewHelper.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def trigger(notification)
|
10
|
+
@channel.send_message 'notifly.notifications.new',
|
11
|
+
{ message: render(notification), id: notification.id }
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(notification)
|
15
|
+
@action_view.render partial: 'layouts/notification',
|
16
|
+
locals: { notification: notification }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Passalini
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -59,6 +59,20 @@ dependencies:
|
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 4.2.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: coffee-rails
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.0
|
69
|
+
type: :runtime
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.0.0
|
62
76
|
- !ruby/object:Gem::Dependency
|
63
77
|
name: pg
|
64
78
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +129,34 @@ dependencies:
|
|
115
129
|
- - ">="
|
116
130
|
- !ruby/object:Gem::Version
|
117
131
|
version: '0'
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
name: websocket-rails
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.7.0
|
139
|
+
type: :development
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.7.0
|
146
|
+
- !ruby/object:Gem::Dependency
|
147
|
+
name: thin
|
148
|
+
requirement: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
type: :development
|
154
|
+
prerelease: false
|
155
|
+
version_requirements: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
118
160
|
- !ruby/object:Gem::Dependency
|
119
161
|
name: better_errors
|
120
162
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,10 +212,11 @@ files:
|
|
170
212
|
- MIT-LICENSE
|
171
213
|
- README.md
|
172
214
|
- Rakefile
|
173
|
-
- app/assets/javascripts/notifly.js
|
215
|
+
- app/assets/javascripts/notifly.js.erb
|
174
216
|
- app/assets/javascripts/notifly/get_notifications.js.erb
|
175
217
|
- app/assets/javascripts/notifly/more_notifications.js.erb
|
176
218
|
- app/assets/javascripts/notifly/read_notifications.js.erb
|
219
|
+
- app/assets/javascripts/notifly/real_time.js.erb
|
177
220
|
- app/assets/javascripts/notifly/seen_notifications.js.erb
|
178
221
|
- app/assets/javascripts/notifly_dropdown.js
|
179
222
|
- app/assets/stylesheets/notifly.css
|
@@ -215,6 +258,8 @@ files:
|
|
215
258
|
- lib/notifly/models/notifiable.rb
|
216
259
|
- lib/notifly/models/options/fly.rb
|
217
260
|
- lib/notifly/railtie.rb
|
261
|
+
- lib/services/action_view_helper.rb
|
262
|
+
- lib/services/notification_channel.rb
|
218
263
|
- lib/tasks/notifly_tasks.rake
|
219
264
|
- vendor/assets/javascripts/tinycon.js
|
220
265
|
- vendor/assets/javascripts/twitter/bootstrap/dropdown.js
|