active-list 5.0.1 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README.rdoc +2 -40
  2. metadata +19 -130
  3. checksums.yaml +0 -7
  4. data/VERSION +0 -1
  5. data/app/assets/images/active-list.png +0 -0
  6. data/app/assets/images/active-list.svg +0 -415
  7. data/app/assets/javascripts/active_list.jquery.js +0 -136
  8. data/app/assets/stylesheets/active_list.css.scss +0 -7
  9. data/app/assets/stylesheets/active_list/background.scss +0 -39
  10. data/app/assets/stylesheets/active_list/minimal.scss +0 -87
  11. data/app/assets/stylesheets/active_list/theme.scss +0 -189
  12. data/lib/active-list.rb +0 -1
  13. data/lib/active_list.rb +0 -43
  14. data/lib/active_list/action_pack.rb +0 -46
  15. data/lib/active_list/definition.rb +0 -17
  16. data/lib/active_list/definition/abstract_column.rb +0 -54
  17. data/lib/active_list/definition/action_column.rb +0 -76
  18. data/lib/active_list/definition/association_column.rb +0 -80
  19. data/lib/active_list/definition/attribute_column.rb +0 -58
  20. data/lib/active_list/definition/check_box_column.rb +0 -17
  21. data/lib/active_list/definition/data_column.rb +0 -88
  22. data/lib/active_list/definition/empty_column.rb +0 -10
  23. data/lib/active_list/definition/field_column.rb +0 -20
  24. data/lib/active_list/definition/status_column.rb +0 -10
  25. data/lib/active_list/definition/table.rb +0 -159
  26. data/lib/active_list/definition/text_field_column.rb +0 -10
  27. data/lib/active_list/exporters.rb +0 -28
  28. data/lib/active_list/exporters/abstract_exporter.rb +0 -55
  29. data/lib/active_list/exporters/csv_exporter.rb +0 -32
  30. data/lib/active_list/exporters/excel_csv_exporter.rb +0 -38
  31. data/lib/active_list/exporters/open_document_spreadsheet_exporter.rb +0 -82
  32. data/lib/active_list/generator.rb +0 -122
  33. data/lib/active_list/generator/finder.rb +0 -150
  34. data/lib/active_list/helpers.rb +0 -33
  35. data/lib/active_list/rails/engine.rb +0 -13
  36. data/lib/active_list/renderers.rb +0 -25
  37. data/lib/active_list/renderers/abstract_renderer.rb +0 -29
  38. data/lib/active_list/renderers/simple_renderer.rb +0 -356
  39. data/locales/eng.yml +0 -25
  40. data/locales/fra.yml +0 -25
@@ -1,10 +0,0 @@
1
- module ActiveList
2
-
3
- module Definition
4
-
5
- class EmptyColumn < AbstractColumn
6
- end
7
-
8
- end
9
-
10
- end
@@ -1,20 +0,0 @@
1
- module ActiveList
2
-
3
- module Definition
4
-
5
- class FieldColumn < AbstractColumn
6
- attr_reader :form_name
7
-
8
- def initialize(table, name, options = {})
9
- super(table, name, options)
10
- @form_name = options.delete(:form_name)
11
- end
12
-
13
- def header_code
14
- "#{@table.model.name}.human_attribute_name('#{@name}')"
15
- end
16
- end
17
-
18
- end
19
-
20
- end
@@ -1,10 +0,0 @@
1
- module ActiveList
2
-
3
- module Definition
4
-
5
- class StatusColumn < AttributeColumn
6
- end
7
-
8
- end
9
-
10
- end
@@ -1,159 +0,0 @@
1
- module ActiveList
2
-
3
- module Definition
4
-
5
- class Table
6
- attr_reader :name, :model, :options, :id, :columns, :parameters
7
-
8
- def initialize(name, model = nil, options = {})
9
- @name = name
10
- @model = model || name.to_s.classify.constantize
11
- @options = options
12
- @paginate = !(@options[:pagination]==:none || @options[:paginate].is_a?(FalseClass))
13
- @options[:renderer] ||= :simple_renderer
14
- @options[:per_page] = 20 if @options[:per_page].to_i <= 0
15
- @options[:page] = 1 if @options[:page].to_i <= 0
16
- @columns = []
17
- @id = ActiveList.new_uid
18
- end
19
-
20
- def new_column_id
21
- @current_column_id ||= 0
22
- id = @current_column_id.to_s(36).to_sym
23
- @current_column_id += 1
24
- return id
25
- end
26
-
27
- def model_columns
28
- @model.columns_hash.values
29
- end
30
-
31
- def sortable_columns
32
- @columns.select{|c| c.sortable?}
33
- end
34
-
35
- def exportable_columns
36
- @columns.select{|c| c.exportable?}
37
- end
38
-
39
- def children
40
- @columns.map(&:child)
41
- end
42
-
43
- def paginate?
44
- @paginate
45
- end
46
-
47
- # Retrieves all columns in database
48
- def table_columns
49
- cols = self.model_columns.map(&:name)
50
- @columns.select{|c| c.is_a? DataColumn and cols.include? c.name.to_s}
51
- end
52
-
53
- def data_columns
54
- @columns.select{|c| c.is_a? DataColumn}
55
- end
56
-
57
- def hidden_columns
58
- self.data_columns.select(&:hidden?)
59
- end
60
-
61
- # Compute includes Hash
62
- def reflections
63
- hash = []
64
- for column in self.columns
65
- if column.respond_to?(:reflection)
66
- unless hash.detect{|r| r.name == column.reflection.name }
67
- hash << column.reflection
68
- end
69
- end
70
- end
71
- return hash
72
- end
73
-
74
-
75
- # Add a new method in Table which permit to define text_field columns
76
- def text_field(name, options = {})
77
- add :text_field, name, options
78
- end
79
-
80
- # Add a new method in Table which permit to define check_box columns
81
- def check_box(name, options = {})
82
- add :check_box, name, options
83
- end
84
-
85
- # Add a new method in Table which permit to define action columns
86
- def action(name, options = {})
87
- add :action, name, options
88
- end
89
-
90
- # # Add a new method in Table which permit to define data columns
91
- # def attribute(name, options = {})
92
- # add :attribute, name, options
93
- # end
94
-
95
- # # Add a column referencing an association
96
- # def association(name, options = {})
97
- # options[:through] ||= name
98
- # add :association, name, options
99
- # end
100
-
101
- # Add a new method in Table which permit to define data columns
102
- def column(name, options = {})
103
- if @model.reflect_on_association(name)
104
- options[:through] ||= name
105
- add :association, name, options
106
- elsif @model.reflect_on_association(options[:through])
107
- options[:label_method] ||= name
108
- add :association, name, options
109
- else
110
- add :attribute, name, options
111
- end
112
- end
113
-
114
- def status(*args)
115
- options = args.extract_options!
116
- name = args.shift || :status
117
- add :status, name, options
118
- end
119
-
120
-
121
- def load_default_columns
122
- for column in self.model_columns
123
- reflections = @model.reflections.values.select{|r| r.macro == :belongs_to and r.foreign_key.to_s == column.name.to_s}
124
- if reflections.size == 1
125
- reflection = reflections.first
126
- columns = reflection.class_name.constantize.columns.collect{ |c| c.name.to_s }
127
- self.column([:label, :name, :code, :number].detect{ |l| columns.include?(l.to_s) }, :through => reflection.name, :url => true)
128
- else
129
- self.column(column.name)
130
- end
131
- end
132
- return true
133
- end
134
-
135
- private
136
-
137
- # Checks and add column
138
- def add(type, name, options = {})
139
- klass = "ActiveList::Definition::#{type.to_s.camelcase}Column".constantize rescue nil
140
- if klass and klass < AbstractColumn
141
- unless name.is_a?(Symbol)
142
- raise ArgumentError, "Name of a column must be a Symbol (got #{name.inspect})."
143
- end
144
- if @columns.detect{|c| c.name == name}
145
- raise ArgumentError, "Column name must be unique. #{name.inspect} is already used in #{self.name}"
146
- end
147
- @columns << klass.new(self, name, options)
148
- else
149
- raise ArgumentError, "Invalid column type: #{type.inspect}"
150
- end
151
- end
152
-
153
-
154
- end
155
-
156
-
157
- end
158
-
159
- end
@@ -1,10 +0,0 @@
1
- module ActiveList
2
-
3
- module Definition
4
-
5
- class TextFieldColumn < FieldColumn
6
- end
7
-
8
- end
9
-
10
- end
@@ -1,28 +0,0 @@
1
- # require 'active_support/core_ext/module/attribute_accessors'
2
- module ActiveList
3
-
4
- module Exporters
5
-
6
- def self.hash
7
- ActiveList.exporters
8
- end
9
-
10
- autoload :AbstractExporter, 'active_list/exporters/abstract_exporter'
11
- autoload :OpenDocumentSpreadsheetExporter, 'active_list/exporters/open_document_spreadsheet_exporter'
12
- autoload :CsvExporter, 'active_list/exporters/csv_exporter'
13
- autoload :ExcelCsvExporter, 'active_list/exporters/excel_csv_exporter'
14
- end
15
-
16
- mattr_reader :exporters
17
- @@exporters = {}
18
-
19
- def self.register_exporter(name, exporter)
20
- raise ArgumentError.new("ActiveList::Exporters::AbstractExporter expected (got #{exporter.name}/#{exporter.ancestors.inspect})") unless exporter < ActiveList::Exporters::AbstractExporter
21
- @@exporters[name] = exporter
22
- end
23
-
24
- end
25
-
26
- ActiveList.register_exporter(:ods, ActiveList::Exporters::OpenDocumentSpreadsheetExporter)
27
- ActiveList.register_exporter(:csv, ActiveList::Exporters::CsvExporter)
28
- ActiveList.register_exporter(:xcsv, ActiveList::Exporters::ExcelCsvExporter)
@@ -1,55 +0,0 @@
1
- module ActiveList
2
-
3
- module Exporters
4
-
5
- class AbstractExporter
6
-
7
- attr_reader :table, :generator
8
-
9
- def initialize(generator)
10
- @generator = generator
11
- @table = generator.table
12
- end
13
-
14
- def file_extension
15
- "txt"
16
- end
17
-
18
- def mime_type
19
- Mime::TEXT
20
- end
21
-
22
- def send_data_code
23
- raise NotImplementedError, "#{self.class.name}#format_data_code is not implemented."
24
- end
25
-
26
- def columns_headers(options={})
27
- headers, columns = [], table.exportable_columns
28
- for column in columns
29
- datum = column.header_code
30
- headers << (options[:encoding] ? datum+".to_s.encode('#{options[:encoding]}')" : datum)
31
- end
32
- return headers
33
- end
34
-
35
- def columns_to_array(nature, options={})
36
- columns = table.exportable_columns
37
-
38
- array = []
39
- record = options[:record] || 'record_of_the_death'
40
- for column in columns
41
- if column.is_a?(ActiveList::Definition::AbstractColumn)
42
- if nature == :header
43
- datum = column.header_code
44
- else
45
- datum = column.exporting_datum_code(record)
46
- end
47
- array << (options[:encoding] ? datum+".to_s.encode('#{options[:encoding]}')" : datum)
48
- end
49
- end
50
- return array
51
- end
52
-
53
- end
54
- end
55
- end
@@ -1,32 +0,0 @@
1
- module ActiveList
2
-
3
- module Exporters
4
-
5
- class CsvExporter < AbstractExporter
6
-
7
- def file_extension
8
- "csv"
9
- end
10
-
11
- def mime_type
12
- Mime::CSV
13
- end
14
-
15
- def send_data_code
16
- record = "r"
17
- code = generator.select_data_code(paginate: false)
18
- code << "data = ActiveList::CSV.generate do |csv|\n"
19
- code << " csv << [#{columns_to_array(:header).join(', ')}]\n"
20
- code << " for #{record} in #{generator.records_variable_name}\n"
21
- code << " csv << [#{columns_to_array(:body, record: record).join(', ')}]\n"
22
- code << " end\n"
23
- code << "end\n"
24
- code << "send_data(data, type: #{self.mime_type.to_s.inspect}, disposition: 'inline', filename: #{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i,'_') + '.#{self.file_extension}')\n"
25
- return code.c
26
- end
27
-
28
- end
29
-
30
- end
31
-
32
- end
@@ -1,38 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- # Register XCSV format unless is already set
4
- Mime::Type.register("text/csv", :xcsv) unless defined? Mime::XCSV
5
-
6
- module ActiveList
7
-
8
- module Exporters
9
-
10
- class ExcelCsvExporter < CsvExporter
11
-
12
- def file_extension
13
- "csv"
14
- end
15
-
16
- def mime_type
17
- Mime::XCSV
18
- end
19
-
20
- def send_data_code
21
- record = "r"
22
- code = generator.select_data_code(paginate: false)
23
- encoding = "CP1252"
24
- code << "data = ActiveList::CSV.generate(:col_sep => ';') do |csv|\n"
25
- code << " csv << [#{columns_to_array(:header, encoding: encoding).join(', ')}]\n"
26
- code << " for #{record} in #{generator.records_variable_name}\n"
27
- code << " csv << [#{columns_to_array(:body, record: record, encoding: encoding).join(', ')}]\n"
28
- code << " end\n"
29
- code << "end\n"
30
- code << "send_data(data, type: #{self.mime_type.to_s.inspect}, disposition: 'inline', filename: #{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i,'_')+'.#{self.file_extension}')\n"
31
- return code.c
32
- end
33
-
34
- end
35
-
36
- end
37
-
38
- end
@@ -1,82 +0,0 @@
1
- # encoding: UTF-8
2
- require 'zip'
3
-
4
- # Register ODS format unless is already set
5
- Mime::Type.register("application/vnd.oasis.opendocument.spreadsheet", :ods) unless defined? Mime::ODS
6
-
7
- module ActiveList
8
-
9
- module Exporters
10
-
11
- class OpenDocumentSpreadsheetExporter < AbstractExporter
12
-
13
- DATE_ELEMENTS = {
14
- "m" => "<number:month number:style=\"long\"/>",
15
- "d" => "<number:day number:style=\"long\"/>",
16
- "Y" => "<number:year/>"
17
- }
18
-
19
- def file_extension
20
- "ods"
21
- end
22
-
23
- def mime_type
24
- Mime::ODS
25
- end
26
-
27
- def send_data_code
28
- xml_escape = "to_s.gsub('&', '&amp;').gsub('\\'', '&apos;').gsub('<', '&lt;').gsub('>', '&gt;')"
29
- xml_escape << ".force_encoding('US-ASCII')" if xml_escape.respond_to?(:force_encoding)
30
- record = "r"
31
- code = generator.select_data_code(paginate: false)
32
- code << "name = #{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i, '_')\n"
33
- code << "file = ::Rails.root.join('tmp', 'export', 'active_list', name + rand.to_s+'.#{self.file_extension}')\n"
34
- code << "FileUtils.mkdir_p(file.dirname)\n"
35
- code << "Zip::OutputStream.open(file) do |zile|\n"
36
- # MimeType in first place
37
- code << " zile.put_next_entry('mimetype', nil, nil, Zip::Entry::STORED)\n"
38
- code << " zile << '#{self.mime_type}'\n"
39
-
40
- # Manifest
41
- code << " zile.put_next_entry('META-INF/manifest.xml')\n"
42
- code << " zile << ('<?xml version=\"1.0\" encoding=\"UTF-8\"?><manifest:manifest xmlns:manifest=\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\"><manifest:file-entry manifest:media-type=\"#{self.mime_type}\" manifest:full-path=\"/\"/><manifest:file-entry manifest:media-type=\"text/xml\" manifest:full-path=\"content.xml\"/></manifest:manifest>')\n"
43
- code << " zile.put_next_entry('content.xml')\n"
44
-
45
- 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"
46
- # Styles
47
- code << " zile << ('<office:automatic-styles>"+
48
- "<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>"+
49
- "<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>"+
50
- "<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\"/>"+
51
- "</office:automatic-styles>')\n"
52
-
53
- # Tables
54
- code << " zile << ('<office:body><office:spreadsheet><table:table table:name=\"'+#{table.model.name}.model_name.human.#{xml_escape}+'\">')\n"
55
- code << " zile << ('<table:table-column table:number-columns-repeated=\"#{table.exportable_columns.size}\"/>')\n"
56
- code << " zile << ('<table:table-header-rows><table:table-row>"+columns_headers.collect{|h| "<table:table-cell table:style-name=\"header\" office:value-type=\"string\"><text:p>'+(#{h}).#{xml_escape}+'</text:p></table:table-cell>"}.join+"</table:table-row></table:table-header-rows>')\n"
57
- code << " for #{record} in #{generator.records_variable_name}\n"
58
- code << " zile << ('<table:table-row>"+table.exportable_columns.collect do |column|
59
- "<table:table-cell"+(if column.numeric? or column.datatype==:decimal
60
- " office:value-type=\"float\" office:value=\"'+(#{column.datum_code(record)}).#{xml_escape}+'\""
61
- elsif column.datatype==:boolean
62
- " office:value-type=\"boolean\" office:boolean-value=\"'+(#{column.datum_code(record)}).#{xml_escape}+'\""
63
- elsif column.datatype==:date
64
- " office:value-type=\"date\" table:style-name=\"ce1\" office:date-value=\"'+(#{column.datum_code(record)}).#{xml_escape}+'\""
65
- else
66
- " office:value-type=\"string\""
67
- end)+"><text:p>'+("+column.exporting_datum_code(record, true)+").#{xml_escape}+'</text:p></table:table-cell>"
68
- end.join+"</table:table-row>')\n"
69
- code << " end\n"
70
- code << " zile << ('</table:table></office:spreadsheet></office:body></office:document-content>')\n"
71
- code << "end\n"
72
- code << "send_file(file, stream: false, type: #{self.mime_type.to_s.inspect}, disposition: 'inline', filename: name+'.#{self.file_extension}')\n"
73
- code << "File.delete(file)\n" # Removes tmp files before they explode the disk
74
- # raise code
75
- return code
76
- end
77
-
78
- end
79
-
80
- end
81
-
82
- end