rexport 0.5.4 → 1.0.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 +5 -5
- data/Rakefile +6 -34
- data/app/views/export_filters/_export_filter.html.erb +2 -2
- data/app/views/export_items/_export_item.html.erb +2 -2
- 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 +6 -6
- 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 +25 -56
- data/lib/rexport/export_filter_methods.rb +46 -24
- data/lib/rexport/export_item_methods.rb +29 -34
- data/lib/rexport/export_methods.rb +161 -208
- data/lib/rexport/exports_controller_methods.rb +22 -28
- data/lib/rexport/rexport_model.rb +33 -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 +29 -33
- data/test/unit/data_field_test.rb +11 -11
- data/test/unit/data_fields_test.rb +137 -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 +185 -59
- data/test/unit/rexport_model_test.rb +12 -12
- data/test/unit/tree_node_test.rb +20 -20
- metadata +14 -26
- 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: 2d78c303332bc96efaf4f0a9548db0a0604250e48089e512cc7d106853c47efb
|
4
|
+
data.tar.gz: 32469341766f9e0a262ce8d16fb0872172d0190f9b03c0023af81ecf7f2cd5f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb5f6249a4cb8903d7c2b713c9857da2b959094879c9f7ba1acbd92130c37ff073de275d7fc36841c44adab534917b87c2c6246fa055b57f334d025b784e264
|
7
|
+
data.tar.gz: 18f5b364174c6f3b0f24b50f82b7a9a39484d2e0147437eec923a25074442c6dd7d45dd082832fb6fd731a459610a27710852551183a9c036e7f546332d48a67
|
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
|
@@ -3,6 +3,6 @@
|
|
3
3
|
<td><%= export_item.rexport_field %></td>
|
4
4
|
<td class="table_icons">
|
5
5
|
<%= link_to(image_tag('icon_edit.gif'), edit_export_item_path(export_item)) if @export.modifiable? %>
|
6
|
-
<%= link_to_delete(export_item, :
|
6
|
+
<%= link_to_delete(export_item, text: false) if @export.modifiable? %>
|
7
7
|
</td>
|
8
|
-
</tr>
|
8
|
+
</tr>
|
@@ -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>
|
@@ -3,8 +3,8 @@
|
|
3
3
|
<h4>Options</h4>
|
4
4
|
<ul>
|
5
5
|
<li><%= link_to("#{image_tag('icon_edit.gif')} Edit".html_safe, edit_export_path(@export)) if @export.modifiable? %></li>
|
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), :
|
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
|
-
<%= content_tag :tbody, {:
|
33
|
-
<%= render :
|
32
|
+
<%= content_tag :tbody, {id: 'export_items'}.merge(@export.modifiable? ? {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
|
-
<%= content_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).', :
|
37
|
+
<%= content_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') if @export.modifiable? %>
|
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') if export.modifiable? %>
|
29
|
+
<%= link_to_delete(export, text: false) if export.modifiable? %>
|
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,33 +1,11 @@
|
|
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
6
|
# Returns hash of exportable data items
|
30
7
|
def rexport_fields
|
8
|
+
@rexport_fields ||= nil
|
31
9
|
unless @rexport_fields
|
32
10
|
@rexport_fields = HashWithIndifferentAccess.new
|
33
11
|
initialize_rexport_fields
|
@@ -37,7 +15,7 @@ module Rexport #:nodoc:
|
|
37
15
|
|
38
16
|
# Returns sorted array of rexport DataFields
|
39
17
|
def rexport_fields_array
|
40
|
-
rexport_fields.
|
18
|
+
rexport_fields.values.sort
|
41
19
|
end
|
42
20
|
|
43
21
|
# Adds a data item to rexport_fields
|
@@ -48,7 +26,7 @@ module Rexport #:nodoc:
|
|
48
26
|
# Adds associated methods to rexport_fields
|
49
27
|
# :associations - an association or arrary of associations
|
50
28
|
# :methods - a method or array of methods
|
51
|
-
# :filter - if true will send :
|
29
|
+
# :filter - if true will send type: :association to add_report_field
|
52
30
|
def add_association_methods(options = {})
|
53
31
|
options.stringify_keys!
|
54
32
|
options.assert_valid_keys(%w(associations methods filter))
|
@@ -63,7 +41,7 @@ module Rexport #:nodoc:
|
|
63
41
|
|
64
42
|
associations.each do |association|
|
65
43
|
methods.each do |method|
|
66
|
-
add_rexport_field("#{association}_#{method}", :
|
44
|
+
add_rexport_field("#{association}_#{method}", method: "#{association}.#{method}", type: type)
|
67
45
|
end
|
68
46
|
end
|
69
47
|
end
|
@@ -71,7 +49,7 @@ module Rexport #:nodoc:
|
|
71
49
|
# Removes files from rexport_fields
|
72
50
|
# useful to remove content columns you don't want included in exports
|
73
51
|
def remove_rexport_fields(*fields)
|
74
|
-
fields.flatten.each {|field| rexport_fields.delete(field.to_s)}
|
52
|
+
fields.flatten.each { |field| rexport_fields.delete(field.to_s) }
|
75
53
|
end
|
76
54
|
|
77
55
|
# Returns an array of export methods corresponding with field_names
|
@@ -96,11 +74,10 @@ module Rexport #:nodoc:
|
|
96
74
|
|
97
75
|
# Returns the export method for a given field_name
|
98
76
|
def get_rexport_method(field_name)
|
99
|
-
raise NoMethodError unless rexport_fields[field_name] or dynamic_rexport_fields[field_name]
|
100
77
|
if rexport_fields[field_name]
|
101
78
|
rexport_fields[field_name].method
|
102
79
|
else
|
103
|
-
|
80
|
+
raise NoMethodError
|
104
81
|
end
|
105
82
|
end
|
106
83
|
|
@@ -111,40 +88,32 @@ module Rexport #:nodoc:
|
|
111
88
|
|
112
89
|
private
|
113
90
|
|
114
|
-
# Adds content columns
|
115
|
-
# for client defined initialization
|
91
|
+
# Adds content columns rexport_fields, includes callback
|
92
|
+
# initialize_local_rexport_fields for client defined initialization
|
116
93
|
def initialize_rexport_fields
|
117
|
-
|
118
|
-
add_rexport_field(f.name, :type => f.type)
|
119
|
-
end
|
94
|
+
content_columns.each { |field| add_rexport_field(field.name, type: field.type) }
|
120
95
|
initialize_local_rexport_fields if respond_to?(:initialize_local_rexport_fields)
|
121
96
|
end
|
122
|
-
|
123
|
-
def dynamic_rexport_fields
|
124
|
-
respond_to?(:initialize_dynamic_rexport_fields) ? initialize_dynamic_rexport_fields : {}
|
125
|
-
end
|
126
97
|
end
|
127
98
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
else value.to_s
|
140
|
-
end
|
99
|
+
# Return an array of formatted export values for the passed methods
|
100
|
+
def export(*methods)
|
101
|
+
methods.flatten.map do |method|
|
102
|
+
case value = (eval("self.#{method}", binding) rescue nil)
|
103
|
+
when Date, Time
|
104
|
+
value.strftime("%m/%d/%y")
|
105
|
+
when TrueClass
|
106
|
+
'Y'
|
107
|
+
when FalseClass
|
108
|
+
'N'
|
109
|
+
else value.to_s
|
141
110
|
end
|
142
111
|
end
|
112
|
+
end
|
143
113
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
end
|
114
|
+
# Returns string indicating this field is undefined
|
115
|
+
def undefined_rexport_field
|
116
|
+
'UNDEFINED EXPORT FIELD'
|
148
117
|
end
|
149
118
|
end
|
150
119
|
end
|
@@ -1,34 +1,56 @@
|
|
1
1
|
module Rexport #:nodoc:
|
2
2
|
module ExportFilterMethods
|
3
|
-
|
4
|
-
base.class_eval do
|
5
|
-
include InstanceMethods
|
3
|
+
extend ActiveSupport::Concern
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
included do
|
6
|
+
belongs_to :export
|
7
|
+
validates_presence_of :filter_field
|
8
|
+
end
|
9
|
+
|
10
|
+
def display_value
|
11
|
+
filter_on_associated_object? ? associated_object_value : value
|
12
|
+
end
|
13
|
+
|
14
|
+
def attributes_for_copy
|
15
|
+
attributes.slice('filter_field', 'value')
|
10
16
|
end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
return '
|
21
|
-
begin
|
22
|
-
object = association.klass.find(value)
|
23
|
-
return object.respond_to?(:name) ? object.name : object.to_s
|
24
|
-
rescue ActiveRecord::RecordNotFound
|
25
|
-
return 'ASSOCIATED OBJECT NOT FOUND'
|
26
|
-
end
|
18
|
+
private
|
19
|
+
|
20
|
+
def associated_object_value
|
21
|
+
return 'UNDEFINED ASSOCIATION' unless filter_association
|
22
|
+
begin
|
23
|
+
object = filter_association.klass.find(value)
|
24
|
+
return object.respond_to?(:name) ? object.name : object.to_s
|
25
|
+
rescue ActiveRecord::RecordNotFound
|
26
|
+
return 'ASSOCIATED OBJECT NOT FOUND'
|
27
27
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
end
|
29
|
+
|
30
|
+
def filter_association
|
31
|
+
@filter_on_assocation ||= find_filter_association
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_filter_association
|
35
|
+
belongs_to_associations.detect do |association|
|
36
|
+
association.foreign_key == filter_foreign_key
|
31
37
|
end
|
32
38
|
end
|
39
|
+
|
40
|
+
def belongs_to_associations
|
41
|
+
export.get_klass_from_path(filter_path).reflect_on_all_associations(:belongs_to)
|
42
|
+
end
|
43
|
+
|
44
|
+
def filter_path
|
45
|
+
filter_field.split('.')[0..-2]
|
46
|
+
end
|
47
|
+
|
48
|
+
def filter_foreign_key
|
49
|
+
filter_field.split('.').last
|
50
|
+
end
|
51
|
+
|
52
|
+
def filter_on_associated_object?
|
53
|
+
filter_field[/_id$/]
|
54
|
+
end
|
33
55
|
end
|
34
56
|
end
|