tabulatr2 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +71 -27
- data/app/assets/javascripts/tabulatr/application.js +130 -133
- data/app/assets/stylesheets/tabulatr/application.css.scss +153 -0
- data/app/assets/stylesheets/tabulatr/bootstrap2_fixes.css.scss +24 -0
- data/app/views/tabulatr/_tabulatr_actual_table.html.slim +35 -0
- data/app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim +34 -0
- data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +84 -0
- data/app/views/tabulatr/_tabulatr_filter_menu.html.slim +30 -0
- data/app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim +24 -0
- data/app/views/tabulatr/_tabulatr_info_string.html.slim +23 -0
- data/app/views/tabulatr/_tabulatr_paginator.html.slim +24 -0
- data/app/views/tabulatr/_tabulatr_static_table.html.slim +33 -0
- data/app/views/tabulatr/_tabulatr_table.html.slim +45 -0
- data/lib/tabulatr/data/column_name_builder.rb +86 -0
- data/lib/tabulatr/data/data.rb +135 -0
- data/lib/tabulatr/data/dsl.rb +61 -0
- data/lib/tabulatr/data/filtering.rb +101 -0
- data/lib/tabulatr/data/formatting.rb +65 -0
- data/lib/tabulatr/data/invoker.rb +37 -0
- data/lib/tabulatr/data/pagination.rb +48 -0
- data/lib/tabulatr/data/proxy.rb +41 -0
- data/lib/tabulatr/{tabulatr/batch_actions.rb → data/sorting.rb} +20 -23
- data/lib/tabulatr/engine.rb +24 -1
- data/lib/tabulatr/generators/railtie.rb +33 -0
- data/lib/tabulatr/generators/resource_override.rb +35 -0
- data/lib/{generators → tabulatr/generators}/tabulatr/install_generator.rb +21 -3
- data/lib/{generators → tabulatr/generators}/tabulatr/templates/tabulatr.yml +3 -1
- data/lib/tabulatr/generators/tabulatr/templates/tabulatr_data.rb +18 -0
- data/lib/tabulatr/json_builder.rb +94 -0
- data/lib/tabulatr/rails/action_controller.rb +36 -0
- data/lib/{initializers → tabulatr/rails}/action_view.rb +6 -3
- data/lib/{initializers → tabulatr/rails}/active_record.rb +11 -19
- data/lib/tabulatr/renderer/action.rb +32 -0
- data/lib/tabulatr/{tabulatr/formattr.rb → renderer/association.rb} +19 -30
- data/lib/tabulatr/renderer/checkbox.rb +36 -0
- data/lib/tabulatr/renderer/column.rb +113 -0
- data/lib/{initializers/mark_as_localizable.rb → tabulatr/renderer/columns.rb} +13 -15
- data/lib/tabulatr/renderer/columns_from_block.rb +56 -0
- data/lib/tabulatr/renderer/renderer.rb +96 -0
- data/lib/tabulatr/utility/utility.rb +46 -0
- data/lib/tabulatr/version.rb +25 -2
- data/lib/tabulatr.rb +45 -4
- data/lib/tabulatr2.rb +1 -0
- data/spec/dummy/app/assets/stylesheets/application.css.scss +2 -2
- data/spec/dummy/app/controllers/products_controller.rb +27 -3
- data/spec/dummy/app/models/vendor.rb +1 -0
- data/spec/dummy/app/tabulatr_data/product_tabulatr_data.rb +29 -0
- data/spec/dummy/app/views/products/implicit_columns.html.erb +1 -0
- data/spec/dummy/app/views/products/one_item_per_page.html.erb +1 -1
- data/spec/dummy/app/views/products/simple_index.html.erb +6 -4
- data/spec/dummy/app/views/products/stupid_array.html.erb +1 -1
- data/spec/dummy/app/views/products/with_batch_actions.html.erb +10 -0
- data/spec/dummy/config/locales/tabulatr.yml +22 -1
- data/spec/dummy/config/routes.rb +3 -1
- data/spec/features/tabulatrs_spec.rb +53 -11
- data/tabulatr.gemspec +1 -1
- metadata +50 -42
- data/app/assets/images/tabulatr/buttons_lite_background.png +0 -0
- data/app/assets/images/tabulatr/pager_arrow_left.gif +0 -0
- data/app/assets/images/tabulatr/pager_arrow_left_off.gif +0 -0
- data/app/assets/images/tabulatr/pager_arrow_right.gif +0 -0
- data/app/assets/images/tabulatr/pager_arrow_right_off.gif +0 -0
- data/app/assets/images/tabulatr/sort_arrow_down.gif +0 -0
- data/app/assets/images/tabulatr/sort_arrow_down_off.gif +0 -0
- data/app/assets/images/tabulatr/sort_arrow_up.gif +0 -0
- data/app/assets/images/tabulatr/sort_arrow_up_off.gif +0 -0
- data/app/assets/stylesheets/tabulatr/application.css +0 -40
- data/lib/initializers/action_controller.rb +0 -13
- data/lib/tabulatr/tabulatr/adapter/active_record.rb +0 -84
- data/lib/tabulatr/tabulatr/adapter.rb +0 -55
- data/lib/tabulatr/tabulatr/data_cell.rb +0 -132
- data/lib/tabulatr/tabulatr/dummy_record.rb +0 -40
- data/lib/tabulatr/tabulatr/empty_cell.rb +0 -44
- data/lib/tabulatr/tabulatr/filter_cell.rb +0 -145
- data/lib/tabulatr/tabulatr/filter_icon.rb +0 -6
- data/lib/tabulatr/tabulatr/finder/find_for_table.rb +0 -187
- data/lib/tabulatr/tabulatr/finder.rb +0 -64
- data/lib/tabulatr/tabulatr/header_cell.rb +0 -146
- data/lib/tabulatr/tabulatr/json_builder.rb +0 -57
- data/lib/tabulatr/tabulatr/paginator.rb +0 -76
- data/lib/tabulatr/tabulatr/row_builder.rb +0 -128
- data/lib/tabulatr/tabulatr/security.rb +0 -21
- data/lib/tabulatr/tabulatr/settings.rb +0 -158
- data/lib/tabulatr/tabulatr.rb +0 -343
- data/spec/lib/tabulatr/tabulatr/finder/find_for_table_spec.rb +0 -187
- /data/lib/{generators → tabulatr/generators}/tabulatr/templates/tabulatr.rb +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2010-
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -20,11 +20,19 @@
|
|
20
20
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
|
-
|
23
|
+
|
24
|
+
module Tabulatr
|
24
25
|
module Generators
|
25
|
-
class InstallGenerator < Rails::Generators::
|
26
|
+
class InstallGenerator < Rails::Generators::NamedBase
|
26
27
|
desc "initialize tabulatr"
|
27
28
|
source_root File.expand_path('../templates', __FILE__)
|
29
|
+
check_class_collision suffix: 'TabulatrData'
|
30
|
+
|
31
|
+
argument :attributes, type: :array, default: [], banner: 'field:type field:type'
|
32
|
+
|
33
|
+
def create_tabulatr_data_file
|
34
|
+
template 'tabulatr_data.rb', File.join('app/tabulatr_data/', class_path, "#{file_name}_tabulatr_data.rb")
|
35
|
+
end
|
28
36
|
|
29
37
|
def copy_initializer_file
|
30
38
|
copy_file "tabulatr.rb", "config/initializers/tabulatr.rb"
|
@@ -39,6 +47,16 @@ class Tabulatr
|
|
39
47
|
gsub_file 'config/initializers/tabulatr.rb', 'create_ul_paginator', 'create_div_paginator'
|
40
48
|
end
|
41
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def attributes_names
|
54
|
+
[:id] + attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym }
|
55
|
+
end
|
56
|
+
|
57
|
+
def association_names
|
58
|
+
attributes.select { |attr| attr.reference? }.map { |a| a.name.to_sym }
|
59
|
+
end
|
42
60
|
end
|
43
61
|
end
|
44
62
|
end
|
@@ -5,10 +5,12 @@ en:
|
|
5
5
|
batch_actions: 'Batch actions'
|
6
6
|
count: 'Showing: %{current} of total %{total}. %{per_page} items per page.'
|
7
7
|
apply_filters: 'Apply'
|
8
|
+
search: 'Search'
|
8
9
|
de:
|
9
10
|
tabulatr:
|
10
11
|
rows_per_page: 'Ergebnisse pro Seite'
|
11
12
|
filter: 'Filter'
|
12
13
|
batch_actions: 'Batch-Aktionen'
|
13
14
|
count: 'Zeige %{current} von insgesamt %{total}. %{per_page} pro Seite.'
|
14
|
-
apply_filters: 'Anwenden'
|
15
|
+
apply_filters: 'Anwenden'
|
16
|
+
search: 'Suche'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% module_namespacing do %>
|
2
|
+
class <%= class_name %>TabulatrData < Tabulatr::Data
|
3
|
+
<% attributes = attributes_names %>
|
4
|
+
<% if class_name.constantize.table_exists? %>
|
5
|
+
<% attributes << class_name.constantize.column_names.map(&:to_sym) %>
|
6
|
+
<% end %>
|
7
|
+
<% attributes = attributes.flatten.uniq %>
|
8
|
+
<% if attributes.any? %>
|
9
|
+
search :<%= attributes.last %>
|
10
|
+
<% end %>
|
11
|
+
<% attributes.each do |a| %>
|
12
|
+
column :<%= a %>
|
13
|
+
<% end %>
|
14
|
+
<% association_names.each do |attribute| %>
|
15
|
+
association :<%= attribute %>, :id
|
16
|
+
<% end %>
|
17
|
+
end
|
18
|
+
<% end %>
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
module Tabulatr::JsonBuilder
|
25
|
+
def self.build(data, klass, requested_attributes, id="id")
|
26
|
+
if klass && ActiveModel.const_defined?(:ArraySerializer)
|
27
|
+
ActiveModel::ArraySerializer.new(data,
|
28
|
+
{ root: "data", meta: data.__pagination,
|
29
|
+
each_serializer: klass
|
30
|
+
}).as_json
|
31
|
+
else
|
32
|
+
id_included = false
|
33
|
+
attrs = build_hash_from requested_attributes, id
|
34
|
+
result = []
|
35
|
+
data.each do |f|
|
36
|
+
tmp = {}
|
37
|
+
attrs.each do |at|
|
38
|
+
insert_attribute_in_hash(at, f, tmp)
|
39
|
+
end
|
40
|
+
result << tmp
|
41
|
+
end
|
42
|
+
{ data: result, meta: data.__pagination }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def self.build_hash_from requested_attributes, id
|
49
|
+
attrs = []
|
50
|
+
id_included = false
|
51
|
+
requested_attributes.split(',').each do |par|
|
52
|
+
if par.include? ':'
|
53
|
+
relation, action = par.split(':')
|
54
|
+
attrs << {action: action, relation: relation}
|
55
|
+
else
|
56
|
+
id_included = true if par == id
|
57
|
+
attrs << {action: par}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
attrs << {action: id} unless id_included
|
61
|
+
attrs
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.insert_attribute_in_hash at, f, r={}
|
65
|
+
if at.has_key? :relation
|
66
|
+
rel = at[:relation].to_sym
|
67
|
+
action = at[:action].to_sym
|
68
|
+
# if f.class.reflect_on_association(at[:relation].to_sym).collection?
|
69
|
+
# if at[:action].to_sym == :count
|
70
|
+
# r["#{at[:relation]}:#{at[:action]}"] = f.try(at[:relation]).count
|
71
|
+
# else
|
72
|
+
# r["#{at[:relation]}:#{at[:action]}"] = f.try(at[:relation]).map(&at[:action].to_sym).join(', ')
|
73
|
+
# end
|
74
|
+
# else
|
75
|
+
# r["#{at[:relation]}:#{at[:action]}"] = f.try(at[:relation]).try(at[:action])
|
76
|
+
# end
|
77
|
+
begin
|
78
|
+
r["#{at[:relation]}:#{at[:action]}"] = f[rel][action]
|
79
|
+
rescue NoMethodError => e
|
80
|
+
raise $!, "You requested '#{at[:action]}' on '#{at[:relation]}' but
|
81
|
+
there was no such method included in your TabulatrData", $!.backtrace
|
82
|
+
end
|
83
|
+
else
|
84
|
+
begin
|
85
|
+
action = at[:action].to_sym
|
86
|
+
r[at[:action]] = f[action]
|
87
|
+
rescue NoMethodError => e
|
88
|
+
raise $!, "You requested '#{at[:action]}' but
|
89
|
+
there was no such method included in your TabulatrData", $!.backtrace
|
90
|
+
end
|
91
|
+
end
|
92
|
+
r
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
class ActionController::Base
|
25
|
+
def tabulatr_for(klaz, tabulatr_data_class: nil, serializer: nil, render_action: nil, &block)
|
26
|
+
respond_to do |format|
|
27
|
+
format.json {
|
28
|
+
records = klaz.tabulatr(tabulatr_data_class).data_for_table(params, &block)
|
29
|
+
render json: records.to_tabulatr_json(serializer)
|
30
|
+
}
|
31
|
+
format.html {
|
32
|
+
render action: render_action || action_name
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2010-
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -24,8 +24,11 @@
|
|
24
24
|
class ActionView::Base
|
25
25
|
# render the table in a view
|
26
26
|
def table_for(klass, opts={}, &block)
|
27
|
-
|
28
|
-
|
27
|
+
Tabulatr::Renderer.build_table(klass, self, opts, &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def static_table_for(records, opts={}, &block)
|
31
|
+
Tabulatr::Renderer.build_static_table(records, self, opts, &block)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2010-
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -25,24 +25,16 @@
|
|
25
25
|
# the information of the params hash as created by a Tabulatr table
|
26
26
|
if Object.const_defined? "ActiveRecord"
|
27
27
|
class ActiveRecord::Base
|
28
|
-
def self.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.tabulatr_select_attributes(more={})
|
41
|
-
maps = tabulatr_name_mappings.merge(more)
|
42
|
-
return nil if maps.blank?
|
43
|
-
"#{table_name}.*, " + maps.map do |name, mapping|
|
44
|
-
%{#{mapping} AS "#{name}"}
|
45
|
-
end.join(", ")
|
28
|
+
def self.tabulatr(tabulatr_data_class = nil)
|
29
|
+
return tabulatr_data_class.new(self) if tabulatr_data_class
|
30
|
+
begin
|
31
|
+
klaz = self.respond_to?(:klass) ? self.klass : self
|
32
|
+
"#{klaz.name}TabulatrData".constantize.new(self)
|
33
|
+
rescue NameError => e
|
34
|
+
puts e.message
|
35
|
+
# TODO: Better message
|
36
|
+
raise "No class `#{klaz.name}TabulatrData' defined. Explanation here."
|
37
|
+
end
|
46
38
|
end
|
47
39
|
end
|
48
40
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
class Tabulatr::Renderer::Action < Tabulatr::Renderer::Column
|
25
|
+
def human_name
|
26
|
+
header
|
27
|
+
end
|
28
|
+
|
29
|
+
def coltype() 'action' end
|
30
|
+
def column?() false end
|
31
|
+
def action?() true end
|
32
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2010-
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -21,35 +21,24 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
class Tabulatr::Renderer::Association < Tabulatr::Renderer::Column
|
25
|
+
def human_name
|
26
|
+
header ||
|
27
|
+
klass.reflect_on_association(table_name.to_sym).klass.model_name.human + ' ' +
|
28
|
+
klass.reflect_on_association(table_name.to_sym).klass.human_attribute_name(name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def coltype() 'association' end
|
32
|
+
def column?() false end
|
33
|
+
def association?() true end
|
34
|
+
|
35
|
+
def principal_value(record)
|
36
|
+
v = record.send(table_name)
|
37
|
+
if v && v.respond_to?(:to_a) && map
|
38
|
+
v.map(&:"#{name}")
|
32
39
|
else
|
33
|
-
|
40
|
+
v.try(name)
|
34
41
|
end
|
35
42
|
end
|
36
|
-
|
37
|
-
|
38
|
-
("%.2f €" % x).gsub(".", ",")
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.dollar(x)
|
42
|
-
"$ %.2f" % x
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.percent(x)
|
46
|
-
("%.2f&thinspace;%%" % 100.0*x).gsub(".", ",")
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.lamp(x, mapping)
|
50
|
-
s = mapping[x].to_s
|
51
|
-
return "?" unless %w{g y r n}.member?(s)
|
52
|
-
image_tag("tabulatr/#{s}state.gif").html_safe
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
class Tabulatr::Renderer::Checkbox < Tabulatr::Renderer::Column
|
25
|
+
def human_name
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def coltype() 'checkbox' end
|
30
|
+
def column?() false end
|
31
|
+
def checkbox?() true end
|
32
|
+
|
33
|
+
def value_for(record, view)
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
class Tabulatr::Renderer::Column
|
25
|
+
include ActiveModel::Model
|
26
|
+
|
27
|
+
attr_accessor *%i{name header width align valign wrap type th_html filter_html
|
28
|
+
filter checkbox_value checkbox_label filter_width range_filter_symbol
|
29
|
+
sortable format_methods table_name block klass format map}
|
30
|
+
|
31
|
+
def self.from(
|
32
|
+
name: nil,
|
33
|
+
table_name: nil,
|
34
|
+
header: false,
|
35
|
+
width: false,
|
36
|
+
align: false,
|
37
|
+
valign: false,
|
38
|
+
wrap: true,
|
39
|
+
type: :string,
|
40
|
+
th_html: false,
|
41
|
+
filter_html: false,
|
42
|
+
filter: true,
|
43
|
+
checkbox_value: '1',
|
44
|
+
checkbox_label: '',
|
45
|
+
sortable: true,
|
46
|
+
format: nil,
|
47
|
+
map: true,
|
48
|
+
klass: nil,
|
49
|
+
&block)
|
50
|
+
b = block_given? ? block : nil
|
51
|
+
self.new(
|
52
|
+
name: name,
|
53
|
+
table_name: table_name,
|
54
|
+
header: header,
|
55
|
+
width: width,
|
56
|
+
align: align,
|
57
|
+
valign: valign,
|
58
|
+
wrap: wrap,
|
59
|
+
type: type,
|
60
|
+
th_html: th_html,
|
61
|
+
filter_html: filter_html,
|
62
|
+
filter: filter,
|
63
|
+
checkbox_value: checkbox_value,
|
64
|
+
checkbox_label: checkbox_label,
|
65
|
+
sortable: sortable,
|
66
|
+
format: format,
|
67
|
+
map: map,
|
68
|
+
klass: klass,
|
69
|
+
block: b
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def klassname() @_klassname ||= @klass.name.underscore end
|
74
|
+
def human_name() header || klass.human_attribute_name(name) end
|
75
|
+
def sort_param() "#{klassname}_sort" end
|
76
|
+
def full_name() [table_name, name].compact.join(":") end
|
77
|
+
def coltype() 'column' end
|
78
|
+
|
79
|
+
def column?() true end
|
80
|
+
def association?() false end
|
81
|
+
def checkbox?() false end
|
82
|
+
def action?() false end
|
83
|
+
|
84
|
+
def value_for(record, view)
|
85
|
+
if block
|
86
|
+
return view.instance_exec(record, &block)
|
87
|
+
end
|
88
|
+
val = principal_value(record) or return ''
|
89
|
+
|
90
|
+
if format.present? && val.respond_to?(:to_a)
|
91
|
+
val.map do |v|
|
92
|
+
case format
|
93
|
+
when Symbol then view.send(format, v)
|
94
|
+
when String then format % v
|
95
|
+
when Proc then format.(v)
|
96
|
+
else val
|
97
|
+
end
|
98
|
+
end
|
99
|
+
elsif format.present?
|
100
|
+
case format
|
101
|
+
when Symbol then view.send(format, val)
|
102
|
+
when String then format % val
|
103
|
+
when Proc then format.(val)
|
104
|
+
else val
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def principal_value(record)
|
110
|
+
record.send name
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2010-
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -21,23 +21,21 @@
|
|
21
21
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
22
|
#++
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
class Tabulatr::Renderer::Columns < ::Array
|
25
|
+
|
26
|
+
attr_accessor :klass
|
27
|
+
|
28
|
+
def initialize(klass)
|
29
|
+
super()
|
30
|
+
@klass = klass
|
29
31
|
end
|
30
32
|
|
31
|
-
def
|
32
|
-
|
33
|
+
def filtered_columns
|
34
|
+
self.select &:filter
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
end
|
37
|
+
def class_name
|
38
|
+
@klass.name.underscore
|
39
|
+
end
|
39
40
|
|
40
|
-
class Symbol
|
41
|
-
include MarkAsLocalizable
|
42
41
|
end
|
43
|
-
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
class Tabulatr::Renderer
|
25
|
+
class ColumnsFromBlock
|
26
|
+
attr_accessor :columns, :klass
|
27
|
+
|
28
|
+
def initialize(klass)
|
29
|
+
@klass = klass
|
30
|
+
@columns ||= Columns.new(klass)
|
31
|
+
end
|
32
|
+
|
33
|
+
def column(name, opts={}, &block)
|
34
|
+
@columns << Column.from(opts.merge(klass: klass, name: name), &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def association(table_name, name, opts={}, &block)
|
38
|
+
@columns << Association.from(opts.merge(klass: klass, name: name, table_name: table_name), &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
def checkbox(opts={})
|
42
|
+
@columns << Checkbox.from(opts.merge(klass: klass, filter: false, sortable: false))
|
43
|
+
end
|
44
|
+
|
45
|
+
def action(opts={}, &block)
|
46
|
+
@columns << Action.from(opts.merge(klass: klass, filter: false, sortable: false), &block)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.process(klass, &block)
|
50
|
+
i = self.new(klass)
|
51
|
+
yield(i)
|
52
|
+
c = i.columns
|
53
|
+
c
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|