smart_listing 1.0.0 → 1.1.0

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.
data/lib/smart_listing.rb CHANGED
@@ -2,7 +2,7 @@ require 'smart_listing/config'
2
2
  require "smart_listing/engine"
3
3
  require "kaminari"
4
4
 
5
- # Fix parsing nester params
5
+ # Fix parsing nested params
6
6
  module Kaminari
7
7
  module Helpers
8
8
  class Tag
@@ -21,17 +21,13 @@ end
21
21
 
22
22
  module SmartListing
23
23
  class Base
24
- if Rails.env.development?
25
- DEFAULT_PAGE_SIZES = [3, 10, 20, 50, 100]
26
- else
27
- DEFAULT_PAGE_SIZES = [10, 20, 50, 100]
28
- end
29
-
30
24
  attr_reader :name, :collection, :options, :per_page, :sort, :page, :partial, :count
31
25
 
32
26
  def initialize name, collection, options = {}
33
27
  @name = name
34
28
 
29
+ config_profile = options.delete(:config_profile)
30
+
35
31
  @options = {
36
32
  :partial => @name, # SmartListing partial name
37
33
  :sort_attributes => :implicit, # allow implicitly setting sort attributes
@@ -39,11 +35,11 @@ module SmartListing
39
35
  :href => nil, # set SmartListing target url (in case when different than current url)
40
36
  :remote => true, # SmartListing is remote by default
41
37
  :callback_href => nil, # set SmartListing callback url (in case when different than current url)
42
- }.merge(SmartListing.config.global_options).merge(options)
38
+ }.merge(SmartListing.config(config_profile).global_options).merge(options)
43
39
 
44
40
  if @options[:array]
45
41
  @collection = collection.to_a
46
- else
42
+ else
47
43
  @collection = collection
48
44
  end
49
45
  end
@@ -53,7 +49,7 @@ module SmartListing
53
49
 
54
50
  @page = get_param :page
55
51
  @per_page = !get_param(:per_page) || get_param(:per_page).empty? ? (@options[:memorize_per_page] && get_param(:per_page, cookies).to_i > 0 ? get_param(:per_page, cookies).to_i : page_sizes.first) : get_param(:per_page).to_i
56
- @per_page = page_sizes.first unless page_sizes.include?(@per_page)
52
+ @per_page = page_sizes.first unless page_sizes.include?(@per_page) || (unlimited_per_page? && @per_page == 0)
57
53
 
58
54
  @sort = parse_sort(get_param(:sort)) || @options[:default_sort]
59
55
  sort_keys = (@options[:sort_attributes] == :implicit ? @sort.keys.collect{|s| [s, s]} : @options[:sort_attributes])
@@ -64,9 +60,11 @@ module SmartListing
64
60
  @count = @count.length if @count.is_a?(Hash)
65
61
 
66
62
  # Reset @page if greater than total number of pages
67
- no_pages = (@count.to_f / @per_page.to_f).ceil.to_i
68
- if @page.to_i > no_pages
69
- @page = no_pages
63
+ if @per_page > 0
64
+ no_pages = (@count.to_f / @per_page.to_f).ceil.to_i
65
+ if @page.to_i > no_pages
66
+ @page = no_pages
67
+ end
70
68
  end
71
69
 
72
70
  if @options[:array]
@@ -90,8 +88,8 @@ module SmartListing
90
88
  else
91
89
  (yval <=> xval) || (yval && !xval ? 1 : -1)
92
90
  end
93
- end
94
- end
91
+ end
92
+ end
95
93
  end
96
94
  if @options[:paginate] && @per_page > 0
97
95
  @collection = ::Kaminari.paginate_array(@collection).page(@page).per(@per_page)
@@ -101,6 +99,7 @@ module SmartListing
101
99
  end
102
100
  else
103
101
  # let's sort by all attributes
102
+ #
104
103
  @collection = @collection.order(sort_keys.collect{|s| "#{s[1]} #{@sort[s[0]]}" if @sort[s[0]]}.compact) if @sort && @sort.any?
105
104
 
106
105
  if @options[:paginate] && @per_page > 0
@@ -149,6 +148,10 @@ module SmartListing
149
148
  @options[:kaminari_options]
150
149
  end
151
150
 
151
+ def sort_dirs
152
+ @options[:sort_dirs]
153
+ end
154
+
152
155
  def all_params overrides = {}
153
156
  ap = {base_param => {}}
154
157
  @options[:param_names].each do |k, v|
metadata CHANGED
@@ -1,117 +1,208 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_listing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sology
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: coffee-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: kaminari
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 0.15.1
47
+ version: 0.16.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.15.1
54
+ version: 0.16.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: jquery-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bootstrap-sass
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: sqlite3
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - ">="
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: capybara
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: capybara-webkit
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: database_cleaner
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
60
144
  - !ruby/object:Gem::Version
61
145
  version: '0'
62
146
  type: :development
63
147
  prerelease: false
64
148
  version_requirements: !ruby/object:Gem::Requirement
65
149
  requirements:
66
- - - ">="
150
+ - - '>='
67
151
  - !ruby/object:Gem::Version
68
152
  version: '0'
69
- description:
153
+ description: Ruby on Rails data listing gem with built-in sorting, filtering and in-place
154
+ editing.
70
155
  email:
71
156
  - contact@sology.eu
72
157
  executables: []
73
158
  extensions: []
74
159
  extra_rdoc_files: []
75
160
  files:
76
- - LICENSE
77
- - README.md
78
- - Rakefile
79
- - app/assets/javascripts/smart_listing.coffee.erb
80
- - app/helpers/smart_listing/application_helper.rb
81
- - app/helpers/smart_listing/helper.rb
82
- - app/views/kaminari/smart_listing/_first_page.html.erb
161
+ - app/views/kaminari/smart_listing/_paginator.html.erb
83
162
  - app/views/kaminari/smart_listing/_gap.html.erb
84
- - app/views/kaminari/smart_listing/_last_page.html.erb
85
- - app/views/kaminari/smart_listing/_next_page.html.erb
86
163
  - app/views/kaminari/smart_listing/_page.html.erb
87
- - app/views/kaminari/smart_listing/_paginator.html.erb
88
164
  - app/views/kaminari/smart_listing/_prev_page.html.erb
89
- - app/views/smart_listing/_action_custom.html.erb
90
- - app/views/smart_listing/_action_delete.html.erb
91
- - app/views/smart_listing/_action_edit.html.erb
92
- - app/views/smart_listing/_action_show.html.erb
93
- - app/views/smart_listing/_item_new.html.erb
94
- - app/views/smart_listing/_pagination_per_page_link.html.erb
95
- - app/views/smart_listing/_pagination_per_page_links.html.erb
96
- - app/views/smart_listing/_sortable.html.erb
97
- - app/views/smart_listing/_update_list.js.erb
98
- - app/views/smart_listing/item/_create.js.erb
165
+ - app/views/kaminari/smart_listing/_first_page.html.erb
166
+ - app/views/kaminari/smart_listing/_next_page.html.erb
167
+ - app/views/kaminari/smart_listing/_last_page.html.erb
168
+ - app/views/smart_listing/item/_new.js.erb
99
169
  - app/views/smart_listing/item/_create_continue.js.erb
100
- - app/views/smart_listing/item/_destroy.js.erb
101
170
  - app/views/smart_listing/item/_edit.js.erb
102
- - app/views/smart_listing/item/_new.js.erb
171
+ - app/views/smart_listing/item/_create.js.erb
103
172
  - app/views/smart_listing/item/_remove.js.erb
104
173
  - app/views/smart_listing/item/_update.js.erb
105
- - config/locales/en.yml
174
+ - app/views/smart_listing/item/_destroy.js.erb
175
+ - app/views/smart_listing/_pagination_per_page_links.html.erb
176
+ - app/views/smart_listing/create.js.erb
177
+ - app/views/smart_listing/_action_custom.html.erb
178
+ - app/views/smart_listing/_update_list.js.erb
179
+ - app/views/smart_listing/edit.js.erb
180
+ - app/views/smart_listing/_pagination_per_page_link.html.erb
181
+ - app/views/smart_listing/update.js.erb
182
+ - app/views/smart_listing/_action_delete.html.erb
183
+ - app/views/smart_listing/_item_new.html.erb
184
+ - app/views/smart_listing/index.js.erb
185
+ - app/views/smart_listing/new.js.erb
186
+ - app/views/smart_listing/_sortable.html.erb
187
+ - app/views/smart_listing/_action_edit.html.erb
188
+ - app/views/smart_listing/_action_show.html.erb
189
+ - app/views/smart_listing/destroy.js.erb
190
+ - app/assets/javascripts/smart_listing.coffee.erb
191
+ - app/helpers/smart_listing/application_helper.rb
192
+ - app/helpers/smart_listing/helper.rb
106
193
  - config/routes.rb
107
- - lib/generators/smart_listing/install_generator.rb
108
- - lib/generators/smart_listing/templates/initializer.rb
109
- - lib/generators/smart_listing/views_generator.rb
110
- - lib/smart_listing.rb
194
+ - config/locales/en.yml
195
+ - lib/tasks/smart_list_tasks.rake
111
196
  - lib/smart_listing/config.rb
112
197
  - lib/smart_listing/engine.rb
113
198
  - lib/smart_listing/version.rb
114
- - lib/tasks/smart_list_tasks.rake
199
+ - lib/generators/smart_listing/views_generator.rb
200
+ - lib/generators/smart_listing/install_generator.rb
201
+ - lib/generators/smart_listing/templates/initializer.rb
202
+ - lib/smart_listing.rb
203
+ - LICENSE
204
+ - Rakefile
205
+ - README.md
115
206
  homepage: https://github.com/Sology/smart_listing
116
207
  licenses:
117
208
  - MIT
@@ -122,17 +213,17 @@ require_paths:
122
213
  - lib
123
214
  required_ruby_version: !ruby/object:Gem::Requirement
124
215
  requirements:
125
- - - ">="
216
+ - - '>='
126
217
  - !ruby/object:Gem::Version
127
218
  version: '0'
128
219
  required_rubygems_version: !ruby/object:Gem::Requirement
129
220
  requirements:
130
- - - ">="
221
+ - - '>='
131
222
  - !ruby/object:Gem::Version
132
223
  version: '0'
133
224
  requirements: []
134
225
  rubyforge_project:
135
- rubygems_version: 2.2.0
226
+ rubygems_version: 2.1.10
136
227
  signing_key:
137
228
  specification_version: 4
138
229
  summary: SmartListing helps creating sortable lists of ActiveRecord collections with