active_list 6.5.1 → 6.6.0
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 +4 -4
- data/lib/active_list.rb +11 -11
- data/lib/active_list/definition.rb +0 -2
- data/lib/active_list/definition/abstract_column.rb +4 -9
- data/lib/active_list/definition/action_column.rb +49 -57
- data/lib/active_list/definition/association_column.rb +26 -28
- data/lib/active_list/definition/attribute_column.rb +6 -11
- data/lib/active_list/definition/check_box_column.rb +0 -5
- data/lib/active_list/definition/data_column.rb +17 -24
- data/lib/active_list/definition/empty_column.rb +0 -4
- data/lib/active_list/definition/field_column.rb +0 -4
- data/lib/active_list/definition/status_column.rb +0 -4
- data/lib/active_list/definition/table.rb +31 -37
- data/lib/active_list/definition/text_field_column.rb +0 -4
- data/lib/active_list/exporters.rb +0 -4
- data/lib/active_list/exporters/abstract_exporter.rb +15 -19
- data/lib/active_list/exporters/csv_exporter.rb +5 -11
- data/lib/active_list/exporters/excel_csv_exporter.rb +7 -13
- data/lib/active_list/exporters/open_document_spreadsheet_exporter.rb +29 -35
- data/lib/active_list/generator.rb +27 -32
- data/lib/active_list/generator/finder.rb +35 -50
- data/lib/active_list/helpers.rb +6 -8
- data/lib/active_list/rails/engine.rb +3 -3
- data/lib/active_list/rails/integration.rb +2 -10
- data/lib/active_list/renderers.rb +0 -4
- data/lib/active_list/renderers/abstract_renderer.rb +2 -7
- data/lib/active_list/renderers/simple_renderer.rb +58 -71
- data/lib/active_list/version.rb +1 -3
- data/test/active_list_test.rb +4 -6
- data/test/code_generation_test.rb +0 -2
- data/test/dummy/Gemfile +1 -2
- data/test/dummy/app/controllers/contacts_controller.rb +10 -10
- data/test/dummy/app/controllers/people_controller.rb +10 -11
- data/test/dummy/config.ru +1 -1
- data/test/dummy/config/application.rb +2 -2
- data/test/dummy/config/boot.rb +1 -1
- data/test/dummy/config/environments/test.rb +6 -3
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/test/dummy/db/seeds.rb +5 -5
- data/test/dummy/script/rails +2 -2
- data/test/people_controller_test.rb +11 -15
- data/test/table_test.rb +0 -1
- data/test/test_helper.rb +6 -7
- metadata +3 -4
@@ -1,7 +1,5 @@
|
|
1
1
|
module ActiveList
|
2
|
-
|
3
2
|
module Definition
|
4
|
-
|
5
3
|
class CheckBoxColumn < FieldColumn
|
6
4
|
attr_reader :form_value
|
7
5
|
|
@@ -9,9 +7,6 @@ module ActiveList
|
|
9
7
|
super(table, name, options)
|
10
8
|
@form_value = options.delete(:form_value)
|
11
9
|
end
|
12
|
-
|
13
10
|
end
|
14
|
-
|
15
11
|
end
|
16
|
-
|
17
12
|
end
|
@@ -1,9 +1,6 @@
|
|
1
1
|
module ActiveList
|
2
|
-
|
3
2
|
module Definition
|
4
|
-
|
5
3
|
class DataColumn < AbstractColumn
|
6
|
-
|
7
4
|
LABELS_COLUMNS = [:full_name, :label, :name, :number, :coordinate]
|
8
5
|
|
9
6
|
def header_code
|
@@ -15,30 +12,30 @@ module ActiveList
|
|
15
12
|
end
|
16
13
|
|
17
14
|
# Code for exportation
|
18
|
-
def exporting_datum_code(record='record_of_the_death', noview=false)
|
19
|
-
datum =
|
20
|
-
if
|
15
|
+
def exporting_datum_code(record = 'record_of_the_death', noview = false)
|
16
|
+
datum = datum_code(record)
|
17
|
+
if datatype == :boolean
|
21
18
|
datum = "(#{datum} ? ::I18n.translate('list.export.true_value') : ::I18n.translate('list.export.false_value'))"
|
22
|
-
elsif
|
19
|
+
elsif datatype == :date
|
23
20
|
datum = "(#{datum}.nil? ? '' : #{datum}.l)"
|
24
|
-
elsif
|
21
|
+
elsif datatype == :decimal && !noview
|
25
22
|
currency = nil
|
26
|
-
if currency =
|
23
|
+
if currency = options[:currency]
|
27
24
|
currency = currency[:body] if currency.is_a?(Hash)
|
28
25
|
currency = :currency if currency.is_a?(TrueClass)
|
29
26
|
currency = "#{record}.#{currency}".c if currency.is_a?(Symbol)
|
30
27
|
end
|
31
28
|
datum = "(#{datum}.nil? ? '' : #{datum}.l(#{'currency: ' + currency.inspect if currency}))"
|
32
|
-
elsif @name.to_s.match(/(^|\_)currency$/)
|
29
|
+
elsif @name.to_s.match(/(^|\_)currency$/) && datatype == :string
|
33
30
|
datum = "(Nomen::Currencies[#{datum}] ? Nomen::Currencies[#{datum}].human_name : '')"
|
34
|
-
elsif @name.to_s.match(/(^|\_)country$/)
|
31
|
+
elsif @name.to_s.match(/(^|\_)country$/) && datatype == :string
|
35
32
|
datum = "(Nomen::Countries[#{datum}] ? Nomen::Countries[#{datum}].human_name : '')"
|
36
|
-
elsif @name.to_s.match(/(^|\_)language$/)
|
33
|
+
elsif @name.to_s.match(/(^|\_)language$/) && datatype == :string
|
37
34
|
datum = "(Nomen::Languages[#{datum}] ? Nomen::Languages[#{datum}].human_name : '')"
|
38
35
|
elsif self.enumerize?
|
39
36
|
datum = "(#{datum}.nil? ? '' : #{datum}.text)"
|
40
37
|
end
|
41
|
-
|
38
|
+
datum
|
42
39
|
end
|
43
40
|
|
44
41
|
# Returns the data type of the column if the column is in the database
|
@@ -46,17 +43,16 @@ module ActiveList
|
|
46
43
|
@options[:datatype] || (@column ? @column.type : nil)
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
46
|
def enumerize?
|
51
|
-
|
47
|
+
false
|
52
48
|
end
|
53
49
|
|
54
50
|
def state_machine?
|
55
|
-
|
51
|
+
false
|
56
52
|
end
|
57
|
-
|
53
|
+
|
58
54
|
def numeric?
|
59
|
-
[:decimal, :integer, :float, :numeric].include?
|
55
|
+
[:decimal, :integer, :float, :numeric].include? datatype
|
60
56
|
end
|
61
57
|
|
62
58
|
# Returns the size/length of the column if the column is in the database
|
@@ -73,20 +69,17 @@ module ActiveList
|
|
73
69
|
def sortable?
|
74
70
|
return true
|
75
71
|
# not self.action? and
|
76
|
-
|
72
|
+
!options[:through] && !@column.nil?
|
77
73
|
end
|
78
74
|
|
79
75
|
# Generate code in order to get the (foreign) record of the column
|
80
76
|
def record_expr(record = 'record_of_the_death')
|
81
|
-
|
77
|
+
record
|
82
78
|
end
|
83
79
|
|
84
80
|
def sort_expression
|
85
|
-
|
81
|
+
fail NotImplementedError, 'sort_expression must be implemented'
|
86
82
|
end
|
87
|
-
|
88
83
|
end
|
89
|
-
|
90
84
|
end
|
91
|
-
|
92
85
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module ActiveList
|
2
|
-
|
3
2
|
module Definition
|
4
|
-
|
5
3
|
class Table
|
6
4
|
attr_reader :name, :model, :options, :id, :columns, :parameters
|
7
5
|
|
@@ -9,7 +7,7 @@ module ActiveList
|
|
9
7
|
@name = name
|
10
8
|
@model = model || name.to_s.classify.constantize
|
11
9
|
@options = options
|
12
|
-
@paginate = !(@options[:pagination]
|
10
|
+
@paginate = !(@options[:pagination] == :none || @options[:paginate].is_a?(FalseClass))
|
13
11
|
@options[:renderer] ||= :simple_renderer
|
14
12
|
@options[:per_page] = 20 if @options[:per_page].to_i <= 0
|
15
13
|
@options[:page] = 1 if @options[:page].to_i <= 0
|
@@ -19,9 +17,9 @@ module ActiveList
|
|
19
17
|
|
20
18
|
def new_column_id
|
21
19
|
@current_column_id ||= 0
|
22
|
-
id = @current_column_id.to_s(36).to_sym
|
20
|
+
id = @current_column_id.to_s # (36).to_sym
|
23
21
|
@current_column_id += 1
|
24
|
-
|
22
|
+
id
|
25
23
|
end
|
26
24
|
|
27
25
|
def model_columns
|
@@ -29,11 +27,11 @@ module ActiveList
|
|
29
27
|
end
|
30
28
|
|
31
29
|
def sortable_columns
|
32
|
-
@columns.select
|
30
|
+
@columns.select(&:sortable?)
|
33
31
|
end
|
34
32
|
|
35
33
|
def exportable_columns
|
36
|
-
@columns.select
|
34
|
+
@columns.select(&:exportable?)
|
37
35
|
end
|
38
36
|
|
39
37
|
def children
|
@@ -62,36 +60,34 @@ module ActiveList
|
|
62
60
|
|
63
61
|
# Retrieves all columns in database
|
64
62
|
def table_columns
|
65
|
-
cols =
|
66
|
-
@columns.select{|c| c.is_a?
|
63
|
+
cols = model_columns.map(&:name)
|
64
|
+
@columns.select { |c| c.is_a?(DataColumn) && cols.include?(c.name.to_s) }
|
67
65
|
end
|
68
66
|
|
69
67
|
def data_columns
|
70
|
-
@columns.select{|c| c.is_a? DataColumn}
|
68
|
+
@columns.select { |c| c.is_a? DataColumn }
|
71
69
|
end
|
72
70
|
|
73
71
|
def action_columns
|
74
|
-
@columns.select{|c| c.is_a? ActionColumn}
|
72
|
+
@columns.select { |c| c.is_a? ActionColumn }
|
75
73
|
end
|
76
74
|
|
77
75
|
def hidden_columns
|
78
|
-
|
76
|
+
data_columns.select(&:hidden?)
|
79
77
|
end
|
80
78
|
|
81
79
|
# Compute includes Hash
|
82
80
|
def reflections
|
83
81
|
hash = []
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
82
|
+
columns.each do |column|
|
83
|
+
next unless column.respond_to?(:reflection)
|
84
|
+
unless hash.detect { |r| r.name == column.reflection.name }
|
85
|
+
hash << column.reflection
|
89
86
|
end
|
90
87
|
end
|
91
|
-
|
88
|
+
hash
|
92
89
|
end
|
93
90
|
|
94
|
-
|
95
91
|
# Add a new method in Table which permit to define text_field columns
|
96
92
|
def text_field(name, options = {})
|
97
93
|
add :text_field, name, options
|
@@ -123,7 +119,7 @@ module ActiveList
|
|
123
119
|
if @model.reflect_on_association(name)
|
124
120
|
options[:through] ||= name
|
125
121
|
add :association, name, options
|
126
|
-
elsif options[:through]
|
122
|
+
elsif options[:through] && @model.reflect_on_association(options[:through])
|
127
123
|
options[:label_method] ||= name
|
128
124
|
add :association, name, options
|
129
125
|
else
|
@@ -137,43 +133,41 @@ module ActiveList
|
|
137
133
|
add :status, name, options
|
138
134
|
end
|
139
135
|
|
140
|
-
|
141
136
|
def load_default_columns
|
142
|
-
for column in
|
143
|
-
reflections = @model.reflect_on_all_associations(:belongs_to).select{|r| r.foreign_key.to_s == column.name.to_s}
|
137
|
+
for column in model_columns
|
138
|
+
reflections = @model.reflect_on_all_associations(:belongs_to).select { |r| r.foreign_key.to_s == column.name.to_s }
|
144
139
|
if reflections.size == 1
|
145
140
|
reflection = reflections.first
|
146
|
-
columns = reflection.class_name.constantize.columns.collect{ |c| c.name.to_s }
|
147
|
-
self.column([:label, :name, :code, :number].detect{ |l| columns.include?(l.to_s) }, :
|
141
|
+
columns = reflection.class_name.constantize.columns.collect { |c| c.name.to_s }
|
142
|
+
self.column([:label, :name, :code, :number].detect { |l| columns.include?(l.to_s) }, through: reflection.name, url: true)
|
148
143
|
else
|
149
144
|
self.column(column.name.to_sym)
|
150
145
|
end
|
151
146
|
end
|
152
|
-
|
147
|
+
true
|
153
148
|
end
|
154
149
|
|
155
150
|
private
|
156
151
|
|
157
152
|
# Checks and add column
|
158
153
|
def add(type, name, options = {})
|
159
|
-
klass =
|
160
|
-
|
154
|
+
klass = begin
|
155
|
+
"ActiveList::Definition::#{type.to_s.camelcase}Column".constantize
|
156
|
+
rescue
|
157
|
+
nil
|
158
|
+
end
|
159
|
+
if klass && klass < AbstractColumn
|
161
160
|
unless name.is_a?(Symbol)
|
162
|
-
|
161
|
+
fail ArgumentError, "Name of a column must be a Symbol (got #{name.inspect})."
|
163
162
|
end
|
164
|
-
if @columns.detect{|c| c.name == name}
|
165
|
-
|
163
|
+
if @columns.detect { |c| c.name == name }
|
164
|
+
fail ArgumentError, "Column name must be unique. #{name.inspect} is already used in #{self.name}"
|
166
165
|
end
|
167
166
|
@columns << klass.new(self, name, options)
|
168
167
|
else
|
169
|
-
|
168
|
+
fail ArgumentError, "Invalid column type: #{type.inspect}"
|
170
169
|
end
|
171
170
|
end
|
172
|
-
|
173
|
-
|
174
171
|
end
|
175
|
-
|
176
|
-
|
177
172
|
end
|
178
|
-
|
179
173
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# require 'active_support/core_ext/module/attribute_accessors'
|
2
2
|
module ActiveList
|
3
|
-
|
4
3
|
module Exporters
|
5
|
-
|
6
4
|
def self.hash
|
7
5
|
ActiveList.exporters
|
8
6
|
end
|
@@ -12,6 +10,4 @@ module ActiveList
|
|
12
10
|
autoload :CsvExporter, 'active_list/exporters/csv_exporter'
|
13
11
|
autoload :ExcelCsvExporter, 'active_list/exporters/excel_csv_exporter'
|
14
12
|
end
|
15
|
-
|
16
13
|
end
|
17
|
-
|
@@ -1,9 +1,6 @@
|
|
1
1
|
module ActiveList
|
2
|
-
|
3
2
|
module Exporters
|
4
|
-
|
5
3
|
class AbstractExporter
|
6
|
-
|
7
4
|
attr_reader :table, :generator
|
8
5
|
|
9
6
|
def initialize(generator)
|
@@ -12,7 +9,7 @@ module ActiveList
|
|
12
9
|
end
|
13
10
|
|
14
11
|
def file_extension
|
15
|
-
|
12
|
+
'txt'
|
16
13
|
end
|
17
14
|
|
18
15
|
def mime_type
|
@@ -20,36 +17,35 @@ module ActiveList
|
|
20
17
|
end
|
21
18
|
|
22
19
|
def send_data_code
|
23
|
-
|
20
|
+
fail NotImplementedError, "#{self.class.name}#format_data_code is not implemented."
|
24
21
|
end
|
25
22
|
|
26
|
-
def columns_headers(options={})
|
27
|
-
headers
|
23
|
+
def columns_headers(options = {})
|
24
|
+
headers = []
|
25
|
+
columns = table.exportable_columns
|
28
26
|
for column in columns
|
29
27
|
datum = column.header_code
|
30
|
-
headers << (options[:encoding] ? datum+".to_s.encode('#{options[:encoding]}', invalid: :replace, undef: :replace)" : datum)
|
28
|
+
headers << (options[:encoding] ? datum + ".to_s.encode('#{options[:encoding]}', invalid: :replace, undef: :replace)" : datum)
|
31
29
|
end
|
32
|
-
|
30
|
+
headers
|
33
31
|
end
|
34
32
|
|
35
|
-
def columns_to_array(nature, options={})
|
33
|
+
def columns_to_array(nature, options = {})
|
36
34
|
columns = table.exportable_columns
|
37
35
|
|
38
36
|
array = []
|
39
37
|
record = options[:record] || 'record_of_the_death'
|
40
38
|
for column in columns
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
array << (options[:encoding] ? datum+".to_s.encode('#{options[:encoding]}', invalid: :replace, undef: :replace)" : datum)
|
39
|
+
next unless column.is_a?(ActiveList::Definition::AbstractColumn)
|
40
|
+
if nature == :header
|
41
|
+
datum = column.header_code
|
42
|
+
else
|
43
|
+
datum = column.exporting_datum_code(record)
|
48
44
|
end
|
45
|
+
array << (options[:encoding] ? datum + ".to_s.encode('#{options[:encoding]}', invalid: :replace, undef: :replace)" : datum)
|
49
46
|
end
|
50
|
-
|
47
|
+
array
|
51
48
|
end
|
52
|
-
|
53
49
|
end
|
54
50
|
end
|
55
51
|
end
|
@@ -1,11 +1,8 @@
|
|
1
1
|
module ActiveList
|
2
|
-
|
3
2
|
module Exporters
|
4
|
-
|
5
3
|
class CsvExporter < AbstractExporter
|
6
|
-
|
7
4
|
def file_extension
|
8
|
-
|
5
|
+
'csv'
|
9
6
|
end
|
10
7
|
|
11
8
|
def mime_type
|
@@ -13,20 +10,17 @@ module ActiveList
|
|
13
10
|
end
|
14
11
|
|
15
12
|
def send_data_code
|
16
|
-
record =
|
17
|
-
code
|
13
|
+
record = 'r'
|
14
|
+
code = generator.select_data_code(paginate: false)
|
18
15
|
code << "data = ::CSV.generate do |csv|\n"
|
19
16
|
code << " csv << [#{columns_to_array(:header).join(', ')}]\n"
|
20
17
|
code << " for #{record} in #{generator.records_variable_name}\n"
|
21
18
|
code << " csv << [#{columns_to_array(:body, record: record).join(', ')}]\n"
|
22
19
|
code << " end\n"
|
23
20
|
code << "end\n"
|
24
|
-
code << "send_data(data, type: #{
|
25
|
-
|
21
|
+
code << "send_data(data, type: #{mime_type.to_s.inspect}, disposition: 'inline', filename: #{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i, '_') + '.#{file_extension}')\n"
|
22
|
+
code.c
|
26
23
|
end
|
27
|
-
|
28
24
|
end
|
29
|
-
|
30
25
|
end
|
31
|
-
|
32
26
|
end
|
@@ -1,14 +1,11 @@
|
|
1
1
|
# Register XCSV format unless is already set
|
2
|
-
Mime::Type.register(
|
2
|
+
Mime::Type.register('text/csv', :xcsv) unless defined? Mime::XCSV
|
3
3
|
|
4
4
|
module ActiveList
|
5
|
-
|
6
5
|
module Exporters
|
7
|
-
|
8
6
|
class ExcelCsvExporter < CsvExporter
|
9
|
-
|
10
7
|
def file_extension
|
11
|
-
|
8
|
+
'csv'
|
12
9
|
end
|
13
10
|
|
14
11
|
def mime_type
|
@@ -16,21 +13,18 @@ module ActiveList
|
|
16
13
|
end
|
17
14
|
|
18
15
|
def send_data_code
|
19
|
-
record =
|
20
|
-
code
|
21
|
-
encoding =
|
16
|
+
record = 'r'
|
17
|
+
code = generator.select_data_code(paginate: false)
|
18
|
+
encoding = 'CP1252'
|
22
19
|
code << "data = ::CSV.generate(col_sep: ';') do |csv|\n"
|
23
20
|
code << " csv << [#{columns_to_array(:header, encoding: encoding).join(', ')}]\n"
|
24
21
|
code << " for #{record} in #{generator.records_variable_name}\n"
|
25
22
|
code << " csv << [#{columns_to_array(:body, record: record, encoding: encoding).join(', ')}]\n"
|
26
23
|
code << " end\n"
|
27
24
|
code << "end\n"
|
28
|
-
code << "send_data(data, type: #{
|
29
|
-
|
25
|
+
code << "send_data(data, type: #{mime_type.to_s.inspect}, disposition: 'inline', filename: #{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i,'_')+'.#{file_extension}')\n"
|
26
|
+
code.c
|
30
27
|
end
|
31
|
-
|
32
28
|
end
|
33
|
-
|
34
29
|
end
|
35
|
-
|
36
30
|
end
|