active_list 6.7.3 → 6.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_list.rb +7 -7
- data/lib/active_list/definition/abstract_column.rb +3 -3
- data/lib/active_list/definition/action_column.rb +7 -7
- data/lib/active_list/definition/association_column.rb +15 -15
- data/lib/active_list/definition/attribute_column.rb +14 -16
- data/lib/active_list/definition/data_column.rb +16 -11
- data/lib/active_list/definition/table.rb +3 -3
- data/lib/active_list/exporters/abstract_exporter.rb +6 -6
- data/lib/active_list/exporters/open_document_spreadsheet_exporter.rb +7 -7
- data/lib/active_list/generator/finder.rb +5 -5
- data/lib/active_list/helpers.rb +8 -8
- data/lib/active_list/rails/integration.rb +1 -1
- data/lib/active_list/renderers/abstract_renderer.rb +2 -2
- data/lib/active_list/renderers/simple_renderer.rb +16 -19
- data/lib/active_list/version.rb +1 -1
- data/test/dummy/app/controllers/contacts_controller.rb +0 -1
- data/test/dummy/db/schema.rb +17 -19
- data/test/test_helper.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0fee98280d5ca65c397076a72d92e766296dae7
|
4
|
+
data.tar.gz: 8067cd16ede90cdee14e3dff5283835dfad8a27f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58efa00509d17a9f49db4671b2ea07490ef7a2b0ee5a5ebac748412ae8ba978f1fa4f7c8788d4e923861ce35e20449e03a51196ec761695661a70adbdfc24358
|
7
|
+
data.tar.gz: 5418a1860ad6ef8e6d6eacc0dec5a7f3a7e588734c728e9a4e4dd36ee4d5e925f0b5bbd8e9d426a3f91d629153abd07c7d577ea46a1e9ed7171fd5110f99b86b
|
data/lib/active_list.rb
CHANGED
@@ -24,11 +24,11 @@ module ActiveList
|
|
24
24
|
# Set the temporary directory
|
25
25
|
# Pathname or callable are acceptable
|
26
26
|
def self.temporary_directory=(dir)
|
27
|
-
if dir.respond_to?(:call) || dir.is_a?(Pathname)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
@@temporary_directory = if dir.respond_to?(:call) || dir.is_a?(Pathname)
|
28
|
+
dir
|
29
|
+
else
|
30
|
+
Pathname(dir)
|
31
|
+
end
|
32
32
|
end
|
33
33
|
|
34
34
|
# Returns the temporary directory
|
@@ -45,7 +45,7 @@ module ActiveList
|
|
45
45
|
|
46
46
|
def self.register_renderer(name, renderer)
|
47
47
|
unless renderer < ActiveList::Renderers::AbstractRenderer
|
48
|
-
|
48
|
+
raise ArgumentError, 'A renderer must be ActiveList::Renderers::Renderer'
|
49
49
|
end
|
50
50
|
@@renderers[name] = renderer
|
51
51
|
end
|
@@ -55,7 +55,7 @@ module ActiveList
|
|
55
55
|
|
56
56
|
def self.register_exporter(name, exporter)
|
57
57
|
unless exporter < ActiveList::Exporters::AbstractExporter
|
58
|
-
|
58
|
+
raise ArgumentError, "ActiveList::Exporters::AbstractExporter expected (got #{exporter.name}/#{exporter.ancestors.inspect})"
|
59
59
|
end
|
60
60
|
@@exporters[name] = exporter
|
61
61
|
end
|
@@ -12,7 +12,7 @@ module ActiveList
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def header_code
|
15
|
-
|
15
|
+
raise NotImplementedError, "#{self.class.name}#header_code is not implemented."
|
16
16
|
end
|
17
17
|
|
18
18
|
def hidden?
|
@@ -41,11 +41,11 @@ module ActiveList
|
|
41
41
|
@id
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
alias sort_id name
|
45
45
|
|
46
46
|
def check_options!(options, *keys)
|
47
47
|
for key in options.keys
|
48
|
-
|
48
|
+
raise ArgumentError, "Key :#{key} is unexpected. (Expecting: #{keys.to_sentence})"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -4,9 +4,9 @@ module ActiveList
|
|
4
4
|
class ActionColumn < AbstractColumn
|
5
5
|
include ActiveList::Helpers
|
6
6
|
|
7
|
-
ID_PLACEHOLDER = '##IDS##'
|
7
|
+
ID_PLACEHOLDER = '##IDS##'.freeze
|
8
8
|
|
9
|
-
USE_MODES = [:none, :single, :many, :both]
|
9
|
+
USE_MODES = [:none, :single, :many, :both].freeze
|
10
10
|
|
11
11
|
attr_reader :use_mode
|
12
12
|
|
@@ -14,7 +14,7 @@ module ActiveList
|
|
14
14
|
super(table, name, options)
|
15
15
|
@use_mode = (@options.delete(:on) || :single).to_sym
|
16
16
|
unless USE_MODES.include?(@use_mode)
|
17
|
-
|
17
|
+
raise "Invalid use mode: #{@use_mode.inspect}"
|
18
18
|
end
|
19
19
|
if @name.to_s == 'destroy' && !@options.key?(:method)
|
20
20
|
@options[:method] = :delete
|
@@ -40,7 +40,7 @@ module ActiveList
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def global?
|
43
|
-
|
43
|
+
use_none? || use_many?
|
44
44
|
end
|
45
45
|
|
46
46
|
def header_code
|
@@ -67,7 +67,7 @@ module ActiveList
|
|
67
67
|
action = @name
|
68
68
|
format = @options[:format] ? ", format: '#{@options[:format]}'" : ''
|
69
69
|
if @options[:remote]
|
70
|
-
|
70
|
+
raise StandardError, 'Sure to use :remote ?'
|
71
71
|
# remote_options = @options.dup
|
72
72
|
# remote_options['data-confirm'] = "#{@options[:confirm].inspect}.tl".c unless @options[:confirm].nil?
|
73
73
|
# remote_options.delete :remote
|
@@ -81,10 +81,10 @@ module ActiveList
|
|
81
81
|
# code += ")"
|
82
82
|
elsif @options[:actions]
|
83
83
|
unless use_single?
|
84
|
-
|
84
|
+
raise StandardError, 'Only compatible with single actions'
|
85
85
|
end
|
86
86
|
unless @options[:actions].is_a? Hash
|
87
|
-
|
87
|
+
raise StandardError, ':actions parameter have to be a Hash.'
|
88
88
|
end
|
89
89
|
cases = []
|
90
90
|
for expected, url in @options[:actions]
|
@@ -6,7 +6,7 @@ module ActiveList
|
|
6
6
|
def initialize(table, name, options = {})
|
7
7
|
super(table, name, options)
|
8
8
|
unless @options[:through]
|
9
|
-
|
9
|
+
raise ArgumentError, 'Option :through must be given'
|
10
10
|
end
|
11
11
|
reflection_name = @options.delete(:through).to_sym
|
12
12
|
if @reflection = @table.model.reflect_on_association(reflection_name)
|
@@ -15,23 +15,23 @@ module ActiveList
|
|
15
15
|
elsif @reflection.macro == :has_one
|
16
16
|
# Do some stuff
|
17
17
|
else
|
18
|
-
|
18
|
+
raise ArgumentError, "Only belongs_to are usable. Can't handle: #{reflection.macro} :#{reflection.name}."
|
19
19
|
end
|
20
20
|
else
|
21
|
-
|
21
|
+
raise UnknownReflection, "Reflection #{reflection_name} cannot be found for #{table.model.name}."
|
22
22
|
end
|
23
23
|
unless klass = begin
|
24
24
|
@reflection.class_name.constantize
|
25
25
|
rescue
|
26
26
|
nil
|
27
27
|
end
|
28
|
-
|
28
|
+
raise StandardError, "Given reflection #{reflection_name} seems to be invalid"
|
29
29
|
end
|
30
30
|
columns_def = klass.columns_hash.keys.map(&:to_sym)
|
31
31
|
unless @label_method = @options.delete(:label_method)
|
32
32
|
columns = columns_def + @reflection.class_name.constantize.instance_methods.map(&:to_sym)
|
33
33
|
unless @label_method = LABELS_COLUMNS.detect { |m| columns.include?(m) }
|
34
|
-
|
34
|
+
raise ArgumentError, ":label_method option must be given for association #{name}. (#{columns.inspect})"
|
35
35
|
end
|
36
36
|
end
|
37
37
|
unless @sort_column = @options.delete(:sort)
|
@@ -48,16 +48,16 @@ module ActiveList
|
|
48
48
|
# Code for rows
|
49
49
|
def datum_code(record = 'record_of_the_death', child = false)
|
50
50
|
code = ''
|
51
|
-
if child
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
code = if child
|
52
|
+
'nil'
|
53
|
+
# if @options[:children].is_a?(FalseClass)
|
54
|
+
# code = "nil"
|
55
|
+
# else
|
56
|
+
# code = "#{record}.#{table.options[:children]}.#{@reflection.name}.#{@options[:children] || @label_method}"
|
57
|
+
# end
|
58
|
+
else
|
59
|
+
"(#{record}.#{@reflection.name} ? #{record}.#{@reflection.name}.#{@label_method} : nil)"
|
60
|
+
end
|
61
61
|
code.c
|
62
62
|
end
|
63
63
|
|
@@ -7,13 +7,11 @@ module ActiveList
|
|
7
7
|
super(table, name, options)
|
8
8
|
@label_method = (options[:label_method] || @name).to_sym
|
9
9
|
unless @sort_column = options[:sort]
|
10
|
-
if @table.model.columns_hash[@label_method.to_s]
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@sort_column = nil
|
16
|
-
end
|
10
|
+
@sort_column = if @table.model.columns_hash[@label_method.to_s]
|
11
|
+
@label_method
|
12
|
+
elsif @table.model.columns_hash[@name.to_s]
|
13
|
+
@name
|
14
|
+
end
|
17
15
|
end
|
18
16
|
@computation_method = options[:on_select]
|
19
17
|
@column = @table.model.columns_hash[@label_method.to_s]
|
@@ -22,15 +20,15 @@ module ActiveList
|
|
22
20
|
# Code for rows
|
23
21
|
def datum_code(record = 'record_of_the_death', child = false)
|
24
22
|
code = ''
|
25
|
-
if child
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
code = if child
|
24
|
+
if @options[:children].is_a?(FalseClass)
|
25
|
+
'nil'
|
26
|
+
else
|
27
|
+
"#{record}.#{table.options[:children]}.#{@options[:children] || @label_method}"
|
28
|
+
end
|
29
|
+
else
|
30
|
+
"#{record}.#{@label_method}"
|
31
|
+
end
|
34
32
|
code.c
|
35
33
|
end
|
36
34
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveList
|
2
2
|
module Definition
|
3
3
|
class DataColumn < AbstractColumn
|
4
|
-
LABELS_COLUMNS = [:full_name, :label, :name, :number, :coordinate]
|
4
|
+
LABELS_COLUMNS = [:full_name, :label, :name, :number, :coordinate].freeze
|
5
5
|
|
6
6
|
def header_code
|
7
7
|
if @options[:label]
|
@@ -19,12 +19,7 @@ module ActiveList
|
|
19
19
|
elsif datatype == :date
|
20
20
|
datum = "(#{datum}.nil? ? '' : #{datum}.l)"
|
21
21
|
elsif datatype == :decimal && !noview
|
22
|
-
currency =
|
23
|
-
if currency = options[:currency]
|
24
|
-
currency = currency[:body] if currency.is_a?(Hash)
|
25
|
-
currency = :currency if currency.is_a?(TrueClass)
|
26
|
-
currency = "#{record}.#{currency}".c if currency.is_a?(Symbol)
|
27
|
-
end
|
22
|
+
currency = currency_for(record)
|
28
23
|
datum = "(#{datum}.nil? ? '' : #{datum}.l(#{'currency: ' + currency.inspect if currency}))"
|
29
24
|
elsif @name.to_s.match(/(^|\_)currency$/) && datatype == :string
|
30
25
|
datum = "(Nomen::Currencies[#{datum}] ? Nomen::Currencies[#{datum}].human_name : '')"
|
@@ -32,7 +27,7 @@ module ActiveList
|
|
32
27
|
datum = "(Nomen::Countries[#{datum}] ? Nomen::Countries[#{datum}].human_name : '')"
|
33
28
|
elsif @name.to_s.match(/(^|\_)language$/) && datatype == :string
|
34
29
|
datum = "(Nomen::Languages[#{datum}] ? Nomen::Languages[#{datum}].human_name : '')"
|
35
|
-
elsif
|
30
|
+
elsif enumerize?
|
36
31
|
datum = "(#{datum}.nil? ? '' : #{datum}.text)"
|
37
32
|
end
|
38
33
|
datum
|
@@ -47,6 +42,16 @@ module ActiveList
|
|
47
42
|
false
|
48
43
|
end
|
49
44
|
|
45
|
+
def currency_for(record)
|
46
|
+
currency = options[:currency]
|
47
|
+
if currency
|
48
|
+
currency = currency[:body] if currency.is_a?(Hash)
|
49
|
+
currency = :currency if currency.is_a?(TrueClass)
|
50
|
+
currency = "#{record}.#{currency}".c if currency.is_a?(Symbol)
|
51
|
+
end
|
52
|
+
currency
|
53
|
+
end
|
54
|
+
|
50
55
|
def state_machine?
|
51
56
|
false
|
52
57
|
end
|
@@ -67,9 +72,9 @@ module ActiveList
|
|
67
72
|
|
68
73
|
# Check if a column is sortable
|
69
74
|
def sortable?
|
70
|
-
|
75
|
+
true
|
71
76
|
# not self.action? and
|
72
|
-
|
77
|
+
# !options[:through] && !@column.nil?
|
73
78
|
end
|
74
79
|
|
75
80
|
# Generate code in order to get the (foreign) record of the column
|
@@ -78,7 +83,7 @@ module ActiveList
|
|
78
83
|
end
|
79
84
|
|
80
85
|
def sort_expression
|
81
|
-
|
86
|
+
raise NotImplementedError, 'sort_expression must be implemented'
|
82
87
|
end
|
83
88
|
end
|
84
89
|
end
|
@@ -158,14 +158,14 @@ module ActiveList
|
|
158
158
|
end
|
159
159
|
if klass && klass < AbstractColumn
|
160
160
|
unless name.is_a?(Symbol)
|
161
|
-
|
161
|
+
raise ArgumentError, "Name of a column must be a Symbol (got #{name.inspect})."
|
162
162
|
end
|
163
163
|
if @columns.detect { |c| c.name == name }
|
164
|
-
|
164
|
+
raise ArgumentError, "Column name must be unique. #{name.inspect} is already used in #{self.name}"
|
165
165
|
end
|
166
166
|
@columns << klass.new(self, name, options)
|
167
167
|
else
|
168
|
-
|
168
|
+
raise ArgumentError, "Invalid column type: #{type.inspect}"
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|
@@ -17,7 +17,7 @@ module ActiveList
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def send_data_code
|
20
|
-
|
20
|
+
raise NotImplementedError, "#{self.class.name}#format_data_code is not implemented."
|
21
21
|
end
|
22
22
|
|
23
23
|
def columns_headers(options = {})
|
@@ -37,11 +37,11 @@ module ActiveList
|
|
37
37
|
record = options[:record] || 'record_of_the_death'
|
38
38
|
for column in columns
|
39
39
|
next unless column.is_a?(ActiveList::Definition::AbstractColumn)
|
40
|
-
if nature == :header
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
datum = if nature == :header
|
41
|
+
column.header_code
|
42
|
+
else
|
43
|
+
column.exporting_datum_code(record)
|
44
|
+
end
|
45
45
|
array << (options[:encoding] ? datum + ".to_s.encode('#{options[:encoding]}', invalid: :replace, undef: :replace)" : datum)
|
46
46
|
end
|
47
47
|
array
|
@@ -8,10 +8,10 @@ module ActiveList
|
|
8
8
|
module Exporters
|
9
9
|
class OpenDocumentSpreadsheetExporter < AbstractExporter
|
10
10
|
DATE_ELEMENTS = {
|
11
|
-
'm' =>
|
12
|
-
'd' =>
|
11
|
+
'm' => '<number:month number:style="long"/>',
|
12
|
+
'd' => '<number:day number:style="long"/>',
|
13
13
|
'Y' => '<number:year/>'
|
14
|
-
}
|
14
|
+
}.freeze
|
15
15
|
|
16
16
|
def file_extension
|
17
17
|
'ods'
|
@@ -42,9 +42,9 @@ module ActiveList
|
|
42
42
|
code << " zile << ('<?xml version=\"1.0\" encoding=\"UTF-8\"?><office:document-content xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:presentation=\"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\" xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\" xmlns:math=\"http://www.w3.org/1998/Math/MathML\" xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\" xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\" xmlns:ooo=\"http://openoffice.org/2004/office\" xmlns:ooow=\"http://openoffice.org/2004/writer\" xmlns:oooc=\"http://openoffice.org/2004/calc\" xmlns:dom=\"http://www.w3.org/2001/xml-events\" xmlns:xforms=\"http://www.w3.org/2002/xforms\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:field=\"urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:field:1.0\" office:version=\"1.1\"><office:scripts/>')\n"
|
43
43
|
# Styles
|
44
44
|
code << " zile << ('<office:automatic-styles>"\
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
'<style:style style:name="co1" style:family="table-column"><style:table-column-properties fo:break-before="auto" style:use-optimal-column-width="true"/></style:style>'\
|
46
|
+
'<style:style style:name="header" style:family="table-cell"><style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/></style:style>'\
|
47
|
+
'<number:date-style style:name="K4D" number:automatic-order="true"><number:text>' + ::I18n.translate('date.formats.default').gsub(/\%./) { |x| '</number:text>' + DATE_ELEMENTS[x[1..1]] + '<number:text>' } + '</number:text></number:date-style><style:style style:name="ce1" style:family="table-cell" style:data-style-name="K4D"/>'\
|
48
48
|
"</office:automatic-styles>')\n"
|
49
49
|
|
50
50
|
# Tables
|
@@ -60,7 +60,7 @@ module ActiveList
|
|
60
60
|
elsif column.datatype == :date
|
61
61
|
" office:value-type=\"date\" table:style-name=\"ce1\" office:date-value=\"'+(#{column.datum_code(record)}).#{xml_escape}+'\""
|
62
62
|
else
|
63
|
-
|
63
|
+
' office:value-type="string"'
|
64
64
|
end) + "><text:p>'+(" + column.exporting_datum_code(record, true) + ").#{xml_escape}+'</text:p></table:table-cell>"
|
65
65
|
end.join + "</table:table-row>')\n"
|
66
66
|
code << " end\n"
|
@@ -11,10 +11,10 @@ module ActiveList
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class_name = @table.model.name
|
14
|
-
class_name = "(controller_name != '#{class_name.tableize}' ? controller_name.to_s.classify.constantize : #{class_name})" if
|
14
|
+
class_name = "(controller_name != '#{class_name.tableize}' ? controller_name.to_s.classify.constantize : #{class_name})" if collection?
|
15
15
|
|
16
16
|
# Find data
|
17
|
-
query_code =
|
17
|
+
query_code = class_name.to_s
|
18
18
|
query_code << scope_code if scope_code
|
19
19
|
query_code << ".select(#{select_code})" if select_code
|
20
20
|
query_code << ".where(#{conditions_code})" unless @table.options[:conditions].blank?
|
@@ -90,12 +90,12 @@ module ActiveList
|
|
90
90
|
code << conditions[1..-1].collect { |p| ', ' + sanitize_condition(p) }.join if conditions.size > 1
|
91
91
|
code << ']'
|
92
92
|
when Symbol # Method
|
93
|
-
|
93
|
+
raise 'What?' # Amazingly explicit.
|
94
94
|
# code << conditions.first.to_s + '('
|
95
95
|
# code << conditions[1..-1].collect { |p| sanitize_condition(p) }.join(', ') if conditions.size > 1
|
96
96
|
# code << ')'
|
97
97
|
else
|
98
|
-
|
98
|
+
raise ArgumentError, 'First element of an Array can only be String or Symbol.'
|
99
99
|
end
|
100
100
|
when Hash # SQL
|
101
101
|
code << '{' + conditions.collect { |key, value| key.to_s + ': ' + sanitize_condition(value) }.join(',') + '}'
|
@@ -106,7 +106,7 @@ module ActiveList
|
|
106
106
|
when String
|
107
107
|
code << conditions.inspect
|
108
108
|
else
|
109
|
-
|
109
|
+
raise ArgumentError, "Unsupported type for conditions: #{conditions.inspect}"
|
110
110
|
end
|
111
111
|
code
|
112
112
|
end
|
data/lib/active_list/helpers.rb
CHANGED
@@ -2,29 +2,29 @@ module ActiveList
|
|
2
2
|
module Helpers
|
3
3
|
def recordify!(value, record_name)
|
4
4
|
if value.is_a?(Symbol)
|
5
|
-
|
5
|
+
record_name + '.' + value.to_s
|
6
6
|
elsif value.is_a?(CodeString)
|
7
|
-
|
7
|
+
'(' + value.gsub(/RECORD/, record_name) + ')'
|
8
8
|
else
|
9
|
-
|
9
|
+
raise ArgumentError, 'CodeString or Symbol must be given to be recordified)'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def recordify(value, record_name)
|
14
14
|
if value.is_a?(Symbol)
|
15
|
-
|
15
|
+
record_name + '.' + value.to_s
|
16
16
|
elsif value.is_a?(CodeString)
|
17
|
-
|
17
|
+
'(' + value.gsub(/RECORD/, record_name) + ')'
|
18
18
|
else
|
19
|
-
|
19
|
+
value.inspect
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def urlify(value, record_name)
|
24
24
|
if value.is_a?(CodeString)
|
25
|
-
|
25
|
+
'(' + value.gsub(/RECORD/, record_name) + ')'
|
26
26
|
else
|
27
|
-
|
27
|
+
value.inspect
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -29,7 +29,7 @@ module ActiveList
|
|
29
29
|
begin
|
30
30
|
helper_method = "_#{kontroller.controller_name}_#{__method__}_#{name || kontroller.controller_name}_tag".to_sym
|
31
31
|
kontroller = kontroller.superclass
|
32
|
-
end until
|
32
|
+
end until respond_to?(helper_method)
|
33
33
|
send(helper_method, options, &block)
|
34
34
|
end
|
35
35
|
end
|
@@ -13,11 +13,11 @@ module ActiveList
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def remote_update_code
|
16
|
-
|
16
|
+
raise NotImplementedError, "#{self.class.name}#remote_update_code is not implemented."
|
17
17
|
end
|
18
18
|
|
19
19
|
def build_data_code
|
20
|
-
|
20
|
+
raise NotImplementedError, "#{self.class.name}#build_table_code is not implemented."
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -16,7 +16,7 @@ module ActiveList
|
|
16
16
|
text: :txt,
|
17
17
|
time: :tim,
|
18
18
|
timestamp: :dtt
|
19
|
-
}
|
19
|
+
}.freeze
|
20
20
|
|
21
21
|
def remote_update_code
|
22
22
|
code = "if params[:column] && params[:visibility]\n"
|
@@ -77,7 +77,7 @@ module ActiveList
|
|
77
77
|
code << " computation_row << '<td></td>'\n" if table.selectable?
|
78
78
|
table.columns.each do |column|
|
79
79
|
value = ''
|
80
|
-
code <<
|
80
|
+
code << ' computation_row << "<td'
|
81
81
|
if column.computable?
|
82
82
|
code << " data-list-result-for='#{column.short_id}'"
|
83
83
|
value = "<div><span><strong>#{I18n.translate("list.results.#{column.computation_method}")}:</strong></span>"
|
@@ -86,7 +86,7 @@ module ActiveList
|
|
86
86
|
if column.is_a? ActiveList::Definition::DataColumn
|
87
87
|
code << "\#\{' class=\"#{column.short_id}' + (#{var_name(:params)}[:hidden_columns].include?(:#{column.name}) ? ' hidden\"' : '\"')\}"
|
88
88
|
end
|
89
|
-
code <<
|
89
|
+
code << '>'
|
90
90
|
code << value
|
91
91
|
code << "</td>\"\n"
|
92
92
|
end
|
@@ -139,7 +139,7 @@ module ActiveList
|
|
139
139
|
def columns_to_cells(nature, options = {})
|
140
140
|
code = ''
|
141
141
|
unless [:body, :children].include?(nature)
|
142
|
-
|
142
|
+
raise ArgumentError, 'Nature is invalid'
|
143
143
|
end
|
144
144
|
record = options[:record] || 'record_of_the_death'
|
145
145
|
if table.selectable?
|
@@ -263,7 +263,7 @@ module ActiveList
|
|
263
263
|
list = [5, 10, 20, 50, 100, 200]
|
264
264
|
list << table.options[:per_page].to_i if table.options[:per_page].to_i > 0
|
265
265
|
list = list.uniq.sort
|
266
|
-
menu <<
|
266
|
+
menu << '<li class="parent">'
|
267
267
|
menu << "<a class=\"pages\"><i></i>' + h('list.items_per_page'.t) + '</a><ul>"
|
268
268
|
for n in list
|
269
269
|
menu << "<li data-list-change-page-size=\"#{n}\" '+(#{var_name(:params)}[:per_page] == #{n} ? ' class=\"check\"' : '') + '><a><i></i>' + h('list.x_per_page'.t(count: #{n})) + '</a></li>"
|
@@ -272,7 +272,7 @@ module ActiveList
|
|
272
272
|
end
|
273
273
|
|
274
274
|
# Column selector
|
275
|
-
menu <<
|
275
|
+
menu << '<li class="parent">'
|
276
276
|
menu << "<a class=\"columns\"><i></i>' + h('list.columns'.t) + '</a><ul>"
|
277
277
|
for column in table.data_columns
|
278
278
|
menu << "<li data-list-toggle-column=\"#{column.name}\" class=\"' + (#{var_name(:params)}[:hidden_columns].include?(:#{column.name}) ? 'unchecked' : 'checked') + '\"><a><i></i>' + h(#{column.header_code}) + '</a></li>"
|
@@ -280,9 +280,9 @@ module ActiveList
|
|
280
280
|
menu << '</ul></li>'
|
281
281
|
|
282
282
|
# Separator
|
283
|
-
menu <<
|
283
|
+
menu << '<li class="separator"></li>'
|
284
284
|
# Exports
|
285
|
-
|
285
|
+
ActiveList.exporters.each do |format, _exporter|
|
286
286
|
menu << "<li class=\"export export-#{format}\">' + link_to(content_tag(:i) + h('list.export_as'.t(exported: :#{format}.t(scope: 'list.export.formats'))), params.merge(action: :#{generator.controller_method_name}, sort: #{var_name(:params)}[:sort], dir: #{var_name(:params)}[:dir], format: '#{format}')) + '</li>"
|
287
287
|
end
|
288
288
|
menu << '</ul></span>'
|
@@ -293,20 +293,17 @@ module ActiveList
|
|
293
293
|
# and pagination management
|
294
294
|
def header_code
|
295
295
|
code = ''
|
296
|
-
if table.columns.any? { |column| column.is_a?(ActiveList::Definition::DataColumn) && column.options[:currency] }
|
297
|
-
code << "currency = Nomen::Currencies[#{generator.records_variable_name}.first.currency] if #{generator.records_variable_name}.any?\n"
|
298
|
-
end
|
299
296
|
code << "'<thead><tr>"
|
300
|
-
code <<
|
301
|
-
|
297
|
+
code << '<th class="list-selector"></th>' if table.selectable?
|
298
|
+
table.columns.each do |column|
|
302
299
|
next if column.is_a?(ActiveList::Definition::ActionColumn) && !column.use_single?
|
303
300
|
code << "<th data-list-column=\"#{column.sort_id}\""
|
304
301
|
code << " data-list-column-cells=\"#{column.short_id}\""
|
305
302
|
code << " data-list-column-sort=\"'+(#{var_name(:params)}[:sort] != '#{column.sort_id}' ? 'asc' : #{var_name(:params)}[:dir] == 'asc' ? 'desc' : 'asc')+'\"" if column.sortable?
|
306
303
|
code << " data-list-column-computation=\"#{column.computation_method}\"" if column.computable?
|
307
|
-
if column.is_a?(ActiveList::Definition::DataColumn) && column.options[:currency]
|
308
|
-
|
309
|
-
code << " data-list-column-currency-precision=\"' + (
|
304
|
+
if table.selectable? && column.is_a?(ActiveList::Definition::DataColumn) && column.options[:currency] &&
|
305
|
+
code << " data-list-column-currency-symbol=\"' + (#{generator.records_variable_name}.any? ? Nomen::Currency.find(#{column.currency_for(generator.records_variable_name + '.first').inspect} || 'EUR').symbol.to_s : '') + '\""
|
306
|
+
code << " data-list-column-currency-precision=\"' + (#{generator.records_variable_name}.any? ? Nomen::Currency.find(#{column.currency_for(generator.records_variable_name + '.first').inspect} || 'EUR').precision.to_s : '') + '\""
|
310
307
|
end
|
311
308
|
code << " class=\"#{column_classes(column, true, true)}\""
|
312
309
|
code << '>'
|
@@ -342,13 +339,13 @@ module ActiveList
|
|
342
339
|
|
343
340
|
if table.paginate?
|
344
341
|
pagination = ''
|
345
|
-
current_page =
|
346
|
-
last_page =
|
342
|
+
current_page = var_name(:page).to_s
|
343
|
+
last_page = var_name(:last).to_s
|
347
344
|
|
348
345
|
pagination << "<span class=\"list-pagination\" data-list-ref=\"#{uid}\">"
|
349
346
|
pagination << "<span class=\"status\">' + 'list.pagination.x_to_y_of_total'.t(x: (#{var_name(:offset)} + (#{var_name(:count)} > 0 ? 1 : 0)), y: ((#{var_name(:last)} == #{var_name(:page)}) ? #{var_name(:count)} : #{var_name(:offset)} + #{var_name(:limit)}), total: #{var_name(:count)}) + '</span>"
|
350
347
|
|
351
|
-
pagination <<
|
348
|
+
pagination << '<span class="paginator">'
|
352
349
|
pagination << "<a href=\"#\" data-list-move-to-page=\"' + (#{current_page} - 1).to_s + '\" class=\"btn previous-page\"' + (#{current_page} != 1 ? '' : ' disabled=\"true\"') + '><i></i>' + ::I18n.translate('list.pagination.previous') + '</a>"
|
353
350
|
|
354
351
|
x = '@@PAGE-NUMBER@@'
|
data/lib/active_list/version.rb
CHANGED
data/test/dummy/db/schema.rb
CHANGED
@@ -11,26 +11,24 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
15
|
-
|
16
|
-
|
17
|
-
t.
|
18
|
-
t.
|
19
|
-
t.string
|
20
|
-
t.string
|
21
|
-
t.
|
22
|
-
t.datetime
|
23
|
-
t.datetime "updated_at", null: false
|
14
|
+
ActiveRecord::Schema.define(version: 20_120_510_134_500) do
|
15
|
+
create_table 'contacts', force: :cascade do |t|
|
16
|
+
t.integer 'person_id'
|
17
|
+
t.text 'address'
|
18
|
+
t.string 'phone'
|
19
|
+
t.string 'fax'
|
20
|
+
t.string 'country'
|
21
|
+
t.datetime 'created_at', null: false
|
22
|
+
t.datetime 'updated_at', null: false
|
24
23
|
end
|
25
24
|
|
26
|
-
create_table
|
27
|
-
t.string
|
28
|
-
t.date
|
29
|
-
t.decimal
|
30
|
-
t.decimal
|
31
|
-
t.string
|
32
|
-
t.datetime
|
33
|
-
t.datetime
|
25
|
+
create_table 'people', force: :cascade do |t|
|
26
|
+
t.string 'name'
|
27
|
+
t.date 'born_on'
|
28
|
+
t.decimal 'height'
|
29
|
+
t.decimal 'balance_amount'
|
30
|
+
t.string 'currency'
|
31
|
+
t.datetime 'created_at', null: false
|
32
|
+
t.datetime 'updated_at', null: false
|
34
33
|
end
|
35
|
-
|
36
34
|
end
|
data/test/test_helper.rb
CHANGED
@@ -7,7 +7,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
7
7
|
require 'active_list'
|
8
8
|
dummy_path = Pathname.new(__FILE__).dirname.join('dummy')
|
9
9
|
|
10
|
-
ENV[
|
10
|
+
ENV['BUNDLE_GEMFILE'] = ''
|
11
11
|
Kernel.system("cd #{dummy_path} && bundle install && bundle exec rake db:drop db:create db:migrate db:seed RAILS_ENV=test")
|
12
12
|
|
13
13
|
# CURRENT FILE :: test/test_helper.rb
|
@@ -27,8 +27,8 @@ module ActionView
|
|
27
27
|
module Nomen
|
28
28
|
class Currencies
|
29
29
|
def self.[](_)
|
30
|
-
klass = Struct.const_defined?(:Currency) ? Struct::Currency : Struct.new(
|
31
|
-
|
30
|
+
klass = Struct.const_defined?(:Currency) ? Struct::Currency : Struct.new('Currency', :precision, :symbol)
|
31
|
+
klass.new(2, '€')
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|