listings 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 32776ce178fcb720c00b4934b817b1caf3074944
4
- data.tar.gz: 580d72bd4ab37f34a8e1547f25d0754bb296d429
2
+ SHA256:
3
+ metadata.gz: 4e4cd3fbee2a8df1a03f92b7b2253f3f015c650225c7369509dbd7635092aec1
4
+ data.tar.gz: e043d6119e93ea0ac355678326107a11617cd4b38173c66cfc9882fc480785e5
5
5
  SHA512:
6
- metadata.gz: 7206e2c4df8f2213ceab30455446de291e9cce3700b612e7e864fee6308cfb806456b0d4486d8735b51740991f7a987a449fea761338b073b3fe032df4a43665
7
- data.tar.gz: 568d4deb9319ff9dc18877b471f0e09a768445e529f804e5349ebf48a3b4cd255c5892573605b177a095fac1d69064bbabe01f56bc27ac39ff087bc5be6d9c10
6
+ metadata.gz: 64ecbd2ae0bdd670cfc3229b84fe234873d556108afbce5d74bd7568091040063dd9f620b00119d1d650a64dacdc5253626f4510ea6017825d4600a6036d076a
7
+ data.tar.gz: 3a445d1e9f502d83e19cb15a3fb5ca16ef479dee04ba9a888acb2673a4756c54bb1acb77f3ab794b0264f75efbfcf873517bbdaef6b87d0ddaa712fb29806b22
data/README.md CHANGED
@@ -243,6 +243,18 @@ It supports `title:` and a block
243
243
  end
244
244
  ```
245
245
 
246
+ A `values: :method` can be specified to avoid the select distinct over the values.
247
+
248
+ ```ruby
249
+ filter album: :name, values: :all_album_names, title: 'Album' do |album_name|
250
+ album_name.titleize
251
+ end
252
+
253
+ def all_album_names
254
+ Album.order("name").pluck("distinct name").reject(&:nil?)
255
+ end
256
+ ```
257
+
246
258
  Also `render:` option can be used to suppress the rendering of the filter, but allowing the user to filter by it. For example to filter by the id:
247
259
 
248
260
  ```ruby
@@ -9,7 +9,13 @@ module Listings
9
9
  end
10
10
 
11
11
  def values
12
- @values ||= listing.data_source.values_for_filter(field)
12
+ @values ||= begin
13
+ if method = @field_description.props[:values]
14
+ listing.send(method)
15
+ else
16
+ listing.data_source.values_for_filter(field)
17
+ end
18
+ end
13
19
  end
14
20
 
15
21
  def value_for(value)
@@ -1,3 +1,3 @@
1
1
  module Listings
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
@@ -0,0 +1 @@
1
+ { }
@@ -2,11 +2,23 @@ class TracksListing < Listings::Base
2
2
 
3
3
  model Track
4
4
 
5
- filter album: :name
5
+ # filter album: :name # this also works but will do a distinct over the mode
6
+ filter album: :name, values: :album_names
6
7
  filter album: :id, title: 'The Album Id' do |value|
7
8
  "#{value}!"
8
9
  end
9
10
  filter :order, render: false
11
+ filter :label, values: :label_values
12
+
13
+ def album_names
14
+ Album.order("name").pluck("distinct name").reject(&:nil?)
15
+ end
16
+
17
+ def label_values
18
+ res = ["red", "blue"]
19
+ res << params[:l] if params[:l]
20
+ res
21
+ end
10
22
 
11
23
  custom_filter :order_lte do |items, value|
12
24
  items.where('"order" <= ?', value.to_i)
@@ -1,6 +1,6 @@
1
1
  class Track < ActiveRecord::Base
2
2
  belongs_to :album
3
- attr_accessible :order, :title if Rails::VERSION::MAJOR == 3
3
+ attr_accessible :order, :title, :label if Rails::VERSION::MAJOR == 3
4
4
 
5
5
  scope :even, -> { where("#{table_name}.id % 2 = 0") }
6
6
 
@@ -31,6 +31,7 @@ ActiveRecord::Schema.define(:version => 20150611185922) do
31
31
  t.string "title"
32
32
  t.integer "order"
33
33
  t.integer "album_id"
34
+ t.string "label"
34
35
  t.datetime "created_at", :null => false
35
36
  t.datetime "updated_at", :null => false
36
37
  end
@@ -9,6 +9,8 @@ end
9
9
  FactoryGirl.create :album
10
10
  end
11
11
 
12
+ LABELS = %w(Green Red Blue)
13
+
12
14
  (1..10).each do |sn|
13
- FactoryGirl.create :track, album: nil
15
+ FactoryGirl.create :track, album: nil, label: LABELS[sn % LABELS.size]
14
16
  end
data/spec/dummy/spec CHANGED
@@ -1 +1 @@
1
- spec/dummy/../../spec
1
+ ../../spec
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian J. Cardiff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-02 00:00:00.000000000 Z
11
+ date: 2020-04-10 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
- version: '0'
19
+ version: 3.2.22
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
- version: '0'
26
+ version: 3.2.22
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: haml-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,30 @@ dependencies:
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 1.3.5
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 1.3.5
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-unit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rspec-rails
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -189,6 +203,7 @@ files:
189
203
  - lib/tasks/listings_tasks.rake
190
204
  - spec/dummy/README.rdoc
191
205
  - spec/dummy/Rakefile
206
+ - spec/dummy/app/assets/config/manifest.js
192
207
  - spec/dummy/app/assets/javascripts/application.js
193
208
  - spec/dummy/app/assets/stylesheets/application.css
194
209
  - spec/dummy/app/controllers/application_controller.rb
@@ -279,8 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
294
  - !ruby/object:Gem::Version
280
295
  version: '0'
281
296
  requirements: []
282
- rubyforge_project:
283
- rubygems_version: 2.6.12
297
+ rubygems_version: 3.0.3
284
298
  signing_key:
285
299
  specification_version: 4
286
300
  summary: Simple creation of listings in rails applications.
@@ -309,6 +323,7 @@ test_files:
309
323
  - spec/dummy/app/views/welcome/hash.html.haml
310
324
  - spec/dummy/app/views/welcome/tracks.html.haml
311
325
  - spec/dummy/app/views/layouts/application.html.erb
326
+ - spec/dummy/app/assets/config/manifest.js
312
327
  - spec/dummy/app/assets/javascripts/application.js
313
328
  - spec/dummy/app/assets/stylesheets/application.css
314
329
  - spec/dummy/app/helpers/posts_helper.rb