Skip to content

Commit 192045c

Browse files
committed
- Use Kaminari instead of will_paginate.
- Remove `config.per_page` config.
1 parent a4b8eb5 commit 192045c

File tree

14 files changed

+48
-31
lines changed

14 files changed

+48
-31
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
0.4.0
2+
-----
3+
4+
Break Changes:
5+
6+
- Use Kaminari instead of will_paginate.
7+
- Remove `config.per_page` config.
8+
19
0.3.0
210
-----
311

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ gem 'devise', '4.2.0'
1010
gem 'jquery-rails'
1111
gem 'mysql2'
1212
gem 'puma'
13-
gem 'bootstrap', '~> 4.0.0.alpha3.1'
13+
gem 'bootstrap', '~> 4.0.0.alpha6'
1414

1515
group :development, :test do
1616
gem 'minitest'

Gemfile.lock

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ PATH
22
remote: .
33
specs:
44
notifications (0.3.0)
5+
kaminari (>= 0.15)
56
rails (>= 4.2.0, < 5.1)
6-
will_paginate (~> 3)
77

88
GEM
99
remote: https://rubygems.org/
@@ -84,6 +84,18 @@ GEM
8484
railties (>= 4.2.0)
8585
thor (>= 0.14, < 2.0)
8686
json (2.0.3)
87+
kaminari (1.0.1)
88+
activesupport (>= 4.1.0)
89+
kaminari-actionview (= 1.0.1)
90+
kaminari-activerecord (= 1.0.1)
91+
kaminari-core (= 1.0.1)
92+
kaminari-actionview (1.0.1)
93+
actionview
94+
kaminari-core (= 1.0.1)
95+
kaminari-activerecord (1.0.1)
96+
activerecord
97+
kaminari-core (= 1.0.1)
98+
kaminari-core (1.0.1)
8799
loofah (2.0.3)
88100
nokogiri (>= 1.5.9)
89101
mail (2.6.4)
@@ -161,13 +173,12 @@ GEM
161173
websocket-driver (0.6.5)
162174
websocket-extensions (>= 0.1.0)
163175
websocket-extensions (0.1.2)
164-
will_paginate (3.1.5)
165176

166177
PLATFORMS
167178
ruby
168179

169180
DEPENDENCIES
170-
bootstrap (~> 4.0.0.alpha3.1)
181+
bootstrap (~> 4.0.0.alpha6)
171182
codecov
172183
coffee-rails
173184
devise (= 4.2.0)

app/controllers/notifications/notifications_controller.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ class NotificationsController < Notifications::ApplicationController
33
def index
44
@notifications = notifications.includes(:actor).order('id desc').page(params[:page])
55

6-
unread_ids = []
7-
@notifications.each do |n|
8-
unread_ids << n.id unless n.read?
9-
end
6+
unread_ids = @notifications.reject(&:read?).select(&:id)
107
Notification.read!(unread_ids)
118

129
@notification_groups = @notifications.group_by { |note| note.created_at.to_date }
@@ -20,6 +17,7 @@ def clean
2017
private
2118

2219
def notifications
20+
raise "You need reqiure user login for /notifications page." unless current_user
2321
Notification.where(user_id: current_user.id)
2422
end
2523
end

app/models/notification.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
class Notification < ActiveRecord::Base
33
include Notifications::Model
44

5-
self.per_page = 20
6-
75
# Write your custom methods...
86
end

app/views/notifications/notifications/_notification.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= cache(['notifications', Notifications::VERSION, notification]) do %>
22
<div id="notification-<%= notification.id %>"
33
data-id="<%= notification.id %>"
4-
class="media notification notification-<%= notification.notify_type %><%= ' unread' if !notification.read? %>">
4+
class="media notification notification-<%= notification.notify_type %><%= ' unread' unless notification.read? %>">
55
<div class="media-left">
66
<% if notification.actor_profile_url && notification.actor_avatar_url %>
77
<%= link_to image_tag(notification.actor_avatar_url), notification.actor_profile_url, title: notification.actor_name, class: 'user-avatar' %>

app/views/notifications/notifications/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
<% end %>
1919
<% end %>
2020
</div>
21-
<%= will_paginate @notifications %>
21+
<%= paginate @notifications %>
2222
</div>

lib/notifications.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
require 'notifications/engine'
33
require 'notifications/configuration'
44
require 'notifications/version'
5-
require 'will_paginate'
6-
require 'will_paginate/active_record'
5+
require 'kaminari'
76

87
module Notifications
98
class << self
109
def config
1110
return @config if defined?(@config)
1211
@config = Configuration.new
13-
@config.per_page = 32
1412
@config.user_class = 'User'
1513
@config.user_name_method = 'name'
1614
@config.user_avatar_url_method = nil

lib/notifications/configuration.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,5 @@ class Configuration
3939

4040
# authenticate_user method in your Controller, default: nil
4141
attr_accessor :authenticate_user_method
42-
43-
# pagination size, default: 32
44-
attr_accessor :per_page
4542
end
4643
end

notifications.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
1717
s.files = Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
1818

1919
s.add_dependency 'rails', '>= 4.2.0', '< 5.1'
20-
s.add_dependency 'will_paginate', '~> 3'
20+
s.add_dependency 'kaminari', '>= 0.15'
2121
end

0 commit comments

Comments
 (0)