rexport 0.5.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.rdoc +1 -1
- data/Rakefile +6 -34
- data/app/views/export_filters/_export_filter.html.erb +2 -2
- data/app/views/export_items/_export_item.html.erb +4 -4
- data/app/views/exports/_edit.html.erb +2 -2
- data/app/views/exports/_filters.html.erb +1 -1
- data/app/views/exports/_form.html.erb +6 -6
- data/app/views/exports/_rexport_model.html.erb +1 -1
- data/app/views/exports/_show.html.erb +7 -7
- data/app/views/exports/edit.html.erb +1 -1
- data/app/views/exports/index.html.erb +5 -5
- data/app/views/exports/new.html.erb +2 -2
- data/app/views/exports/show.html.erb +1 -1
- data/config/routes.rb +6 -6
- data/db/migrate/20091105182959_create_export_tables.rb +3 -3
- data/lib/rexport.rb +3 -1
- data/lib/rexport/data_field.rb +17 -0
- data/lib/rexport/data_fields.rb +17 -133
- data/lib/rexport/export_filter_methods.rb +46 -24
- data/lib/rexport/export_filters_controller_methods.rb +8 -4
- data/lib/rexport/export_item_methods.rb +29 -34
- data/lib/rexport/export_items_controller_methods.rb +13 -13
- data/lib/rexport/export_methods.rb +160 -208
- data/lib/rexport/exports_controller_methods.rb +34 -35
- data/lib/rexport/rexport_model.rb +118 -0
- data/lib/rexport/tree_node.rb +13 -16
- data/lib/rexport/version.rb +1 -1
- data/test/factories.rb +58 -53
- data/test/test_helper.rb +36 -39
- data/test/unit/data_field_test.rb +11 -11
- data/test/unit/data_fields_test.rb +53 -95
- data/test/unit/export_filter_methods_test.rb +37 -0
- data/test/unit/export_item_methods_test.rb +21 -0
- data/test/unit/export_methods_test.rb +181 -59
- data/test/unit/rexport_model_test.rb +122 -20
- data/test/unit/tree_node_test.rb +20 -20
- metadata +25 -38
- data/test/jenkins.bash +0 -3
- data/test/log/test.log +0 -3891
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4b74f494058f073c3dbb32d53a74274bce5223f64d09c75ed971e9b0c2ba27a0
|
4
|
+
data.tar.gz: 7b4eec86b8a911ce049bc8205f656fa0904d4b5f405eeb1475a07e6cdfe658e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9437e26f118ac7e267faa26e5b662d4391e09462501955b1d6c93e6eda8ceddf6c61a8c5e498b531d4da8e3eb6761984901e5b944f59f8dabc7bad288bd4f13c
|
7
|
+
data.tar.gz: 7287f82ee398f49c45a424d0a7538127d96bdfb3cb5e6160cc9d19b72eca2688976af71db0731f898f6d5c73147c4de9954fc086ea6faccfe6f61800b8351210
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,38 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'rdoc/task'
|
9
|
-
rescue LoadError
|
10
|
-
require 'rdoc/rdoc'
|
11
|
-
require 'rake/rdoctask'
|
12
|
-
RDoc::Task = Rake::RDocTask
|
13
|
-
end
|
14
|
-
|
15
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
-
rdoc.rdoc_dir = 'rdoc'
|
17
|
-
rdoc.title = 'Rexport'
|
18
|
-
rdoc.options << '--line-numbers'
|
19
|
-
rdoc.rdoc_files.include('README.rdoc')
|
20
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Bundler::GemHelper.install_tasks
|
27
|
-
|
28
|
-
require 'rake/testtask'
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
29
3
|
|
30
4
|
Rake::TestTask.new(:test) do |t|
|
31
|
-
t.libs <<
|
32
|
-
t.libs <<
|
33
|
-
t.
|
34
|
-
t.verbose = false
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
35
8
|
end
|
36
9
|
|
37
|
-
|
38
|
-
task :default => :test
|
10
|
+
task default: :test
|
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
<%= tag.tr(id: dom_id(export_item), class: "handle") do %>
|
2
2
|
<td class="row_title"><%= export_item.name %></td>
|
3
3
|
<td><%= export_item.rexport_field %></td>
|
4
4
|
<td class="table_icons">
|
5
|
-
<%= link_to(image_tag('icon_edit.gif'), edit_export_item_path(export_item))
|
6
|
-
<%= link_to_delete(export_item, :
|
5
|
+
<%= link_to(image_tag('icon_edit.gif'), edit_export_item_path(export_item)) %>
|
6
|
+
<%= link_to_delete(export_item, text: false) %>
|
7
7
|
</td>
|
8
|
-
|
8
|
+
<% end %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div id="rexport">
|
2
2
|
<%= form_for(@export) do |f| %>
|
3
3
|
<%= f.error_messages %>
|
4
|
-
|
4
|
+
|
5
5
|
<div class="export_base_info">
|
6
6
|
<%= f.label :name %>
|
7
7
|
<%= f.text_field :name %>
|
@@ -11,13 +11,13 @@
|
|
11
11
|
<%= f.text_area :description %>
|
12
12
|
</div>
|
13
13
|
|
14
|
-
<%= render :
|
15
|
-
|
14
|
+
<%= render partial: 'local_form', locals: { form: f } %>
|
15
|
+
|
16
16
|
<h3>Export Items</h3>
|
17
|
-
<%= render :
|
18
|
-
|
17
|
+
<%= render partial: 'rexport_model', collection: @export.rexport_models %>
|
18
|
+
|
19
19
|
<%= f.hidden_field :model_class_name %>
|
20
|
-
|
20
|
+
|
21
21
|
<div>
|
22
22
|
<%= f.submit 'Save Export' %>
|
23
23
|
</div>
|
@@ -2,9 +2,9 @@
|
|
2
2
|
<div id="custom_export_options">
|
3
3
|
<h4>Options</h4>
|
4
4
|
<ul>
|
5
|
-
<li><%= link_to("#{image_tag('icon_edit.gif')} Edit".html_safe, edit_export_path(@export))
|
6
|
-
<li><%= link_to "#{image_tag('icon_export.png')} Export".html_safe, export_path(@export, :
|
7
|
-
<li><%= link_to "#{image_tag('icon_copy.png')} Copy".html_safe, exports_path(:original_export_id => @export.id), :
|
5
|
+
<li><%= link_to("#{image_tag('icon_edit.gif')} Edit".html_safe, edit_export_path(@export)) %></li>
|
6
|
+
<li><%= link_to "#{image_tag('icon_export.png')} Export".html_safe, export_path(@export, format: :csv) %></li>
|
7
|
+
<li><%= link_to "#{image_tag('icon_copy.png')} Copy".html_safe, exports_path(:original_export_id => @export.id), method: :post %></li>
|
8
8
|
</ul>
|
9
9
|
</div>
|
10
10
|
<div class="show_export_info">
|
@@ -29,14 +29,14 @@
|
|
29
29
|
<th class='action_icons'> </th>
|
30
30
|
</tr>
|
31
31
|
</thead>
|
32
|
-
<%=
|
33
|
-
<%= render :
|
32
|
+
<%= tag.tbody(id: 'export_items', class: 'sortable', 'data-url' => export_item_sorting_path) do %>
|
33
|
+
<%= render partial: @export.export_items.ordered %>
|
34
34
|
<% end %>
|
35
35
|
</table>
|
36
36
|
|
37
|
-
<%=
|
37
|
+
<%= tag.p('Drag and drop the rows in the table above to re-order the export data left to right in the output (see sample below).', class: 'instructions') %>
|
38
38
|
|
39
|
-
<%= render(:
|
39
|
+
<%= render(partial: 'filters') unless @export.export_filters.blank? %>
|
40
40
|
|
41
41
|
<div class='scrolling'>
|
42
42
|
<table>
|
@@ -1 +1 @@
|
|
1
|
-
<%= render :
|
1
|
+
<%= render partial: 'edit' %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= form_for Export.new, :
|
1
|
+
<%= form_for Export.new, url: new_export_path, html: {method: :get} do |f| %>
|
2
2
|
<fieldset>
|
3
3
|
<legend>Create New Export</legend>
|
4
4
|
<div class='dropdown'>
|
@@ -23,10 +23,10 @@
|
|
23
23
|
<td class='description'><%= export.description %></td>
|
24
24
|
<td><%= print_date export.created_at %></td>
|
25
25
|
<td class="table_icons">
|
26
|
-
<%= link_to_export export_path(export, :
|
27
|
-
<%= link_to_show export, :
|
28
|
-
<%= link_to(image_tag('icon_edit.gif'), edit_export_path(export), :
|
29
|
-
<%= link_to_delete(export, :
|
26
|
+
<%= link_to_export export_path(export, format: :csv), text: false %>
|
27
|
+
<%= link_to_show export, text: false %>
|
28
|
+
<%= link_to(image_tag('icon_edit.gif'), edit_export_path(export), title: 'Edit') %>
|
29
|
+
<%= link_to_delete(export, text: false) %>
|
30
30
|
</td>
|
31
31
|
</tr>
|
32
32
|
<% end %>
|
@@ -1 +1 @@
|
|
1
|
-
<%= render :
|
1
|
+
<%= render partial: 'show' %>
|
data/config/routes.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
# singleton resources
|
3
|
-
resource :export_item_sorting, :
|
4
|
-
|
3
|
+
resource :export_item_sorting, only: :update
|
4
|
+
|
5
5
|
# collection resources
|
6
|
-
resources :export_items, :
|
7
|
-
resources :export_filters, :
|
6
|
+
resources :export_items, only: %i(edit update destroy)
|
7
|
+
resources :export_filters, only: %i(edit update destroy)
|
8
8
|
resources :exports do
|
9
|
-
resources :export_filters, :
|
9
|
+
resources :export_filters, only: :new
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class CreateExportTables < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
create_table "export_filters", :
|
3
|
+
create_table "export_filters", force: true do |t|
|
4
4
|
t.integer "export_id"
|
5
5
|
t.string "field"
|
6
6
|
t.string "value"
|
@@ -8,7 +8,7 @@ class CreateExportTables < ActiveRecord::Migration
|
|
8
8
|
t.datetime "updated_at"
|
9
9
|
end
|
10
10
|
|
11
|
-
create_table "export_items", :
|
11
|
+
create_table "export_items", force: true do |t|
|
12
12
|
t.integer "export_id"
|
13
13
|
t.integer "position"
|
14
14
|
t.string "name"
|
@@ -17,7 +17,7 @@ class CreateExportTables < ActiveRecord::Migration
|
|
17
17
|
t.datetime "updated_at"
|
18
18
|
end
|
19
19
|
|
20
|
-
create_table "exports", :
|
20
|
+
create_table "exports", force: true do |t|
|
21
21
|
t.string "name"
|
22
22
|
t.string "model_class_name"
|
23
23
|
t.text "description"
|
data/lib/rexport.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rexport/data_field'
|
1
2
|
require 'rexport/data_fields'
|
2
3
|
require 'rexport/export_filter_methods'
|
3
4
|
require 'rexport/export_filters_controller_methods'
|
@@ -6,12 +7,13 @@ require 'rexport/export_item_sortings_controller_methods'
|
|
6
7
|
require 'rexport/export_items_controller_methods'
|
7
8
|
require 'rexport/export_methods'
|
8
9
|
require 'rexport/exports_controller_methods'
|
10
|
+
require 'rexport/rexport_model'
|
9
11
|
require 'rexport/tree_node'
|
10
12
|
|
11
13
|
module Rexport
|
14
|
+
SAMPLE_SIZE = 5
|
12
15
|
|
13
16
|
class Engine < ::Rails::Engine
|
14
17
|
config.paths['app/views'] << File.join(File.dirname(__FILE__),'../app/views')
|
15
18
|
end
|
16
|
-
|
17
19
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rexport
|
2
|
+
class DataField
|
3
|
+
include Comparable
|
4
|
+
attr_accessor :name, :method, :type
|
5
|
+
|
6
|
+
# Stores the name and method of the export data item
|
7
|
+
def initialize(name, options = {})
|
8
|
+
self.name = name.to_s
|
9
|
+
self.method = options[:method].blank? ? self.name : options[:method].to_s
|
10
|
+
self.type = options[:type]
|
11
|
+
end
|
12
|
+
|
13
|
+
def <=>(rf)
|
14
|
+
self.name <=> rf.name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rexport/data_fields.rb
CHANGED
@@ -1,150 +1,34 @@
|
|
1
1
|
module Rexport #:nodoc:
|
2
|
-
|
3
|
-
# Stores the name and method of the export data item
|
4
|
-
class DataField
|
5
|
-
include Comparable
|
6
|
-
attr_accessor :name, :method, :type
|
7
|
-
|
8
|
-
def initialize(name, options = {})
|
9
|
-
self.name = name.to_s
|
10
|
-
self.method = options[:method].blank? ? self.name : options[:method].to_s
|
11
|
-
self.type = options[:type]
|
12
|
-
end
|
13
|
-
|
14
|
-
def <=>(rf)
|
15
|
-
self.name <=> rf.name
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
2
|
module DataFields
|
20
|
-
|
21
|
-
base.extend( ClassMethods )
|
22
|
-
base.class_eval do
|
23
|
-
include InstanceMethods
|
24
|
-
prepend ClassMethods
|
25
|
-
end
|
26
|
-
end
|
3
|
+
extend ActiveSupport::Concern
|
27
4
|
|
28
5
|
module ClassMethods
|
29
|
-
# Returns
|
30
|
-
def rexport_fields
|
31
|
-
unless @rexport_fields
|
32
|
-
@rexport_fields = HashWithIndifferentAccess.new
|
33
|
-
initialize_rexport_fields
|
34
|
-
end
|
35
|
-
@rexport_fields
|
36
|
-
end
|
37
|
-
|
38
|
-
# Returns sorted array of rexport DataFields
|
39
|
-
def rexport_fields_array
|
40
|
-
rexport_fields.merge(dynamic_rexport_fields).values.sort
|
41
|
-
end
|
42
|
-
|
43
|
-
# Adds a data item to rexport_fields
|
44
|
-
def add_rexport_field(name, options = {})
|
45
|
-
rexport_fields[name.to_s] = DataField.new(name, options)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Adds associated methods to rexport_fields
|
49
|
-
# :associations - an association or arrary of associations
|
50
|
-
# :methods - a method or array of methods
|
51
|
-
# :filter - if true will send :type => :association to add_report_field
|
52
|
-
def add_association_methods(options = {})
|
53
|
-
options.stringify_keys!
|
54
|
-
options.assert_valid_keys(%w(associations methods filter))
|
55
|
-
|
56
|
-
methods = options.reverse_merge('methods' => 'name')['methods']
|
57
|
-
methods = [methods] if methods.kind_of?(String)
|
58
|
-
|
59
|
-
associations = options['associations']
|
60
|
-
associations = [associations] if associations.kind_of?(String)
|
61
|
-
|
62
|
-
type = options['filter'] ? :association : nil
|
63
|
-
|
64
|
-
associations.each do |association|
|
65
|
-
methods.each do |method|
|
66
|
-
add_rexport_field("#{association}_#{method}", :method => "#{association}.#{method}", :type => type)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Removes files from rexport_fields
|
72
|
-
# useful to remove content columns you don't want included in exports
|
73
|
-
def remove_rexport_fields(*fields)
|
74
|
-
fields.flatten.each {|field| rexport_fields.delete(field.to_s)}
|
75
|
-
end
|
76
|
-
|
77
|
-
# Returns an array of export methods corresponding with field_names
|
78
|
-
def get_rexport_methods(*field_names)
|
79
|
-
field_names.flatten.map do |f|
|
80
|
-
begin
|
81
|
-
components = f.to_s.split('.')
|
82
|
-
field_name = components.pop
|
83
|
-
components.push(get_klass_from_associations(components).get_rexport_method(field_name)) * '.'
|
84
|
-
rescue NoMethodError
|
85
|
-
'undefined_rexport_field'
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Returns the associated class by following the associations
|
6
|
+
# Returns the associated class by following the chain of associations
|
91
7
|
def get_klass_from_associations(*associations)
|
92
8
|
associations.flatten!
|
93
9
|
return self if associations.empty?
|
94
10
|
reflect_on_association(associations.shift.to_sym).klass.get_klass_from_associations(associations)
|
95
11
|
end
|
96
|
-
|
97
|
-
# Returns the export method for a given field_name
|
98
|
-
def get_rexport_method(field_name)
|
99
|
-
raise NoMethodError unless rexport_fields[field_name] or dynamic_rexport_fields[field_name]
|
100
|
-
if rexport_fields[field_name]
|
101
|
-
rexport_fields[field_name].method
|
102
|
-
else
|
103
|
-
dynamic_rexport_fields[field_name].method
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def reset_column_information
|
108
|
-
@rexport_fields = nil
|
109
|
-
super
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
# Adds content columns and columns ending in "_count" to rexport_fields, includes callback initialize_local_rexport_fields
|
115
|
-
# for client defined initialization
|
116
|
-
def initialize_rexport_fields
|
117
|
-
(content_columns + columns.select {|c| c.name =~ /_count$/}).each do |f|
|
118
|
-
add_rexport_field(f.name, :type => f.type)
|
119
|
-
end
|
120
|
-
initialize_local_rexport_fields if respond_to?(:initialize_local_rexport_fields)
|
121
|
-
end
|
122
|
-
|
123
|
-
def dynamic_rexport_fields
|
124
|
-
respond_to?(:initialize_dynamic_rexport_fields) ? initialize_dynamic_rexport_fields : {}
|
125
|
-
end
|
126
12
|
end
|
127
13
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
else value.to_s
|
140
|
-
end
|
14
|
+
# Return an array of formatted export values for the passed methods
|
15
|
+
def export(*methods)
|
16
|
+
methods.flatten.map do |method|
|
17
|
+
case value = (eval("self.#{method}", binding) rescue nil)
|
18
|
+
when Date, Time
|
19
|
+
value.strftime("%m/%d/%y")
|
20
|
+
when TrueClass
|
21
|
+
'Y'
|
22
|
+
when FalseClass
|
23
|
+
'N'
|
24
|
+
else value.to_s
|
141
25
|
end
|
142
26
|
end
|
27
|
+
end
|
143
28
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
29
|
+
# Returns string indicating this field is undefined
|
30
|
+
def undefined_rexport_field
|
31
|
+
'UNDEFINED EXPORT FIELD'
|
148
32
|
end
|
149
33
|
end
|
150
34
|
end
|