iquest-simple_table 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c2515e68e953d71334346a39882b4c87fea41e0
4
- data.tar.gz: a4b6c8d37e62d7be30c2db9fa3ada611fb88e811
3
+ metadata.gz: 3467bc3b3a8172ad4006627cd80ffb16dfdbf42e
4
+ data.tar.gz: 9d71f5bb3bdc5128fa08045607867da425d401f3
5
5
  SHA512:
6
- metadata.gz: 773fe0f2d6ce65ba68b658fb89b9b5b9fd980b0c3ef4da5dd3de46434e2c36b903bb4c7c2e51168fa0483565ee8d31c68df3f876eda8c25bab403cdc626af69c
7
- data.tar.gz: 753562dafe62da179dbaf3783d69fae03bd22e9a6eb6c1bf51e9199e9a59a9169613b97b1055111dc37e5b7568e5fc854c7024fa7b8f78312c78f263a666ae8d
6
+ metadata.gz: 346741660d4b9430f19bfaf492aa8e460104d80cac706dc0d6f43a5d5a8e661f9556ce037da4bb5111099373668def71535d46114eecadf5666117e667ab0aa4
7
+ data.tar.gz: 7275110d69aaa202aa2cb6297c820b6f440c92e7d67fd8db56539c544ffa2a155a024611bd168276af16a07380442c85822c07b5857fc4c642656c3bd99a7db3
@@ -18,12 +18,24 @@ module Iquest
18
18
  elsif collection_or_search.is_a? ActiveRecord::Relation
19
19
  @collection = collection_or_search
20
20
  @klass = @collection.klass
21
+ elsif collection_or_search.is_a?(Array) && (search = collection_or_search.detect {|o| o.is_a?(Ransack::Search)})
22
+ @search = search
23
+ @collection = search.result
24
+ @klass = @collection.klass
25
+ options[:search_url] ||= polymorphic_path(collection_or_search.map {|o| o.is_a?(Ransack::Search) ? o.klass : o})
26
+ options[:new_url] ||= new_polymorphic_path(collection_or_search.map {|o| o.is_a?(Ransack::Search) ? o.klass : o}) rescue NoMethodError
27
+ elsif collection_or_search.is_a?(Array) && (collection = collection_or_search.detect {|o| o.is_a?(ActiveRecord::Relation)})
28
+ @collection = collection
29
+ @klass = @collection.klass
30
+ options[:new_url] ||= new_polymorphic_path(collection_or_search.map {|o| o.is_a?(ActiveRecord::Relation)}) rescue NoMethodError
21
31
  else
22
32
  raise TypeError, 'ActiveRecord::Relation or Ransack::Search expected'
23
33
  end
24
34
  apply_pagination
25
35
  #draper
26
36
  @collection = @collection.decorate if @collection.respond_to?(:decorate)
37
+ options[:search_url] ||= polymorphic_path(@klass)
38
+ options[:new_url] ||= new_polymorphic_path(@klass) rescue NoMethodError
27
39
  @options = options
28
40
  @table_id = "table_#{self.object_id}".parameterize
29
41
  @columns = {}.with_indifferent_access
@@ -60,7 +72,8 @@ module Iquest
60
72
  end
61
73
 
62
74
  def new_link(*args, &block)
63
- @new_link = block if block_given?
75
+ @new_link = args.first if args.first
76
+ @new_link = block.call if block_given?
64
77
  end
65
78
 
66
79
 
@@ -104,7 +117,7 @@ module Iquest
104
117
  include RansackSimpleForm::FormHelper
105
118
 
106
119
  def render_table_with_search
107
- ransack_simple_form_for @search do |f|
120
+ ransack_simple_form_for @search, url: @options[:search_url] do |f|
108
121
  @search_form = f
109
122
  render_table_without_search
110
123
  end
@@ -127,7 +140,7 @@ module Iquest
127
140
 
128
141
  def render_new_link
129
142
  content_tag :th, class:'new-link' do
130
- @new_link || (link_to t('simple_table.new', default: 'new'), new_polymorphic_url(@klass), class: "btn btn-primary")
143
+ @new_link || (link_to t('simple_table.new', default: 'new'), @options[:new_url], class: "btn btn-primary" if @options[:new_url])
131
144
  end
132
145
  end
133
146
 
@@ -1,5 +1,5 @@
1
1
  module Iquest
2
2
  module SimpleTable
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iquest-simple_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Dusanek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ransack_simple_form