iquest-simple_table 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/iquest/simple_table/table_builder.rb +26 -20
- data/lib/iquest/simple_table/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 487255feccbbd18459b41325c4ba0072301ba4bb
|
4
|
+
data.tar.gz: 9d767604c918f80dbb629f0ce226bde0bd1d73c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ccec335f52588138657eb6e79bc2829d254fd3ae64995a739d65ac96a090dd3dcc1fa29457f4591c485fc814e2a432980c43b585653dc5adaff8c0156b8b0a8
|
7
|
+
data.tar.gz: e8f96ccfcb6517d44164d16a4a3600a3d9b8604225b68ddae6d00b79a562564248a9f2fbeeb46ca237d3415634176aceb8d09ca450e5a6d56ad583de886205af
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.0.0-p576
|
@@ -3,10 +3,10 @@ require 'ransack_simple_form'
|
|
3
3
|
module Iquest
|
4
4
|
module SimpleTable
|
5
5
|
class TableBuilder
|
6
|
-
attr_reader :parent, :table_id, :columns, :collection, :search_form, :actions, :
|
6
|
+
attr_reader :parent, :table_id, :columns, :collection, :search_form, :actions, :collection_actions
|
7
7
|
delegate :capture, :content_tag, :link_to, :paginate, :page_entries_info, :params, to: :parent
|
8
8
|
delegate :sort_link, :search_form_for, to: :parent
|
9
|
-
delegate :polymorphic_path, :polymorphic_url,
|
9
|
+
delegate :polymorphic_path, :polymorphic_url, to: :parent
|
10
10
|
delegate :l, :t, to: :parent
|
11
11
|
|
12
12
|
def initialize(parent, collection_or_search, options = {})
|
@@ -22,37 +22,35 @@ module Iquest
|
|
22
22
|
@search = search
|
23
23
|
@collection = search.result
|
24
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
|
25
|
+
options[:search_url] ||= polymorphic_path(collection_or_search.map {|o| o.is_a?(Ransack::Search) ? o.klass : o})
|
27
26
|
elsif collection_or_search.is_a?(Array) && (collection = collection_or_search.detect {|o| o.is_a?(ActiveRecord::Relation) || o.is_a?(ActiveRecord::AssociationRelation)})
|
28
27
|
@collection = collection
|
29
|
-
@klass = @collection.klass
|
30
|
-
options[:new_url] ||= new_polymorphic_path(collection_or_search.map {|o| o.is_a?(ActiveRecord::Relation) || o.is_a?(ActiveRecord::AssociationRelation)}) rescue NoMethodError
|
28
|
+
@klass = @collection.klass
|
31
29
|
else
|
32
30
|
raise TypeError, 'ActiveRecord::Relation, ActiveRecord::AssociationRelation or Ransack::Search expected'
|
33
31
|
end
|
34
32
|
apply_pagination
|
35
33
|
#draper
|
36
34
|
@collection = @collection.decorate if @collection.respond_to?(:decorate)
|
37
|
-
options[:search_url] ||= polymorphic_path(@klass) rescue NoMethodError
|
38
|
-
options[:new_url] ||= new_polymorphic_path(@klass) rescue NoMethodError
|
35
|
+
options[:search_url] ||= polymorphic_path(@klass) rescue NoMethodError
|
39
36
|
@options = options
|
40
37
|
@table_id = "table_#{self.object_id}".parameterize
|
41
38
|
@columns = {}.with_indifferent_access
|
42
39
|
@actions = []
|
40
|
+
@collection_actions = []
|
43
41
|
@search_input_default_options = {label: false, placeholder: false}.with_indifferent_access
|
44
42
|
end
|
45
43
|
|
46
44
|
def column(*args, &block)
|
47
45
|
attr = args.first
|
48
46
|
options = args.extract_options!
|
49
|
-
search = options.delete(:search)
|
47
|
+
search = options.delete(:search)
|
50
48
|
@columns[attr] = options
|
51
49
|
if @search
|
52
50
|
@columns[attr][:label] ||= Ransack::Translate.attribute(attr.to_s.tr('.','_'), context: @search.context)
|
53
51
|
else
|
54
52
|
@columns[attr][:label] ||= @klass.human_attribute_name(attr)
|
55
|
-
end
|
53
|
+
end
|
56
54
|
#iniciaizce search options
|
57
55
|
if search.is_a?(Symbol) || search.is_a?(String)
|
58
56
|
@columns[attr][:search] = {search.to_sym => {}}
|
@@ -62,6 +60,7 @@ module Iquest
|
|
62
60
|
@columns[attr][:search] = search
|
63
61
|
end
|
64
62
|
@columns[attr][:formatter] ||= block if block_given?
|
63
|
+
@columns[attr][:sort] ||= attr.to_s.tr('.','_') #sort link attr
|
65
64
|
end
|
66
65
|
|
67
66
|
def action(*args, &block)
|
@@ -71,11 +70,18 @@ module Iquest
|
|
71
70
|
@actions << options
|
72
71
|
end
|
73
72
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
73
|
+
def collection_action(*args, &block)
|
74
|
+
action = args.first
|
75
|
+
if action.is_a? String
|
76
|
+
@collection_actions << action
|
77
|
+
elsif block_given?
|
78
|
+
@collection_actions << block.call
|
79
|
+
end
|
77
80
|
end
|
78
81
|
|
82
|
+
def new_link(*args, &block)
|
83
|
+
ActiveSupport::Deprecation.warn("Iquest::SimpleTable#new_link does nothing. Use collection_action")
|
84
|
+
end
|
79
85
|
|
80
86
|
def search_link(*args, &block)
|
81
87
|
@search_button = block if block_given?
|
@@ -134,13 +140,13 @@ module Iquest
|
|
134
140
|
rendered_columns = columns.map do |col, opts|
|
135
141
|
render_column_label(col)
|
136
142
|
end.join.html_safe
|
137
|
-
|
143
|
+
render_collection_actions + rendered_columns
|
138
144
|
end
|
139
145
|
end
|
140
146
|
|
141
|
-
def
|
142
|
-
content_tag :th, class:'
|
143
|
-
@
|
147
|
+
def render_collection_actions
|
148
|
+
content_tag :th, class:'collection-actions' do
|
149
|
+
@collection_actions.join.html_safe
|
144
150
|
end
|
145
151
|
end
|
146
152
|
|
@@ -208,10 +214,10 @@ module Iquest
|
|
208
214
|
def render_label(column)
|
209
215
|
attr = column
|
210
216
|
options = @columns[attr]
|
211
|
-
|
212
217
|
label = options[:label] || attr.to_s
|
213
|
-
|
214
|
-
|
218
|
+
sort = options[:sort]
|
219
|
+
if @search && sort
|
220
|
+
sort_link(@search, sort, label, method: search_action)
|
215
221
|
else
|
216
222
|
label
|
217
223
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iquest-simple_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ransack_simple_form
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.1.0
|
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: 0.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
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: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Simple table helper
|
@@ -59,8 +59,8 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
-
|
63
|
-
-
|
62
|
+
- .gitignore
|
63
|
+
- .ruby-version
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
@@ -81,17 +81,17 @@ require_paths:
|
|
81
81
|
- lib
|
82
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- -
|
84
|
+
- - '>='
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- -
|
89
|
+
- - '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.4.2
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Simple table helper, taht supports filtering through Ransack
|