cruj_cruj_cruj_visagio 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/javascripts/cruj_cruj_cruj/application.js +13 -0
  6. data/app/assets/stylesheets/cruj_cruj_cruj/application.css +15 -0
  7. data/app/controllers/cruj_cruj_cruj_controller.rb +267 -0
  8. data/app/helpers/search_helper.rb +0 -0
  9. data/app/views/cruj_cruj_cruj/_filters.html.erb +32 -0
  10. data/app/views/cruj_cruj_cruj/_import_export_template.html.erb +16 -0
  11. data/app/views/cruj_cruj_cruj/_list_table.html.erb +43 -0
  12. data/app/views/cruj_cruj_cruj/edit.html.erb +3 -0
  13. data/app/views/cruj_cruj_cruj/new.html.erb +3 -0
  14. data/app/views/layouts/cruj_cruj_cruj/application.html.erb +14 -0
  15. data/config/locales/pt-BR.yml +91 -0
  16. data/config/routes.rb +2 -0
  17. data/lib/cruj_cruj_cruj/engine.rb +4 -0
  18. data/lib/cruj_cruj_cruj/services/import_rules.rb +161 -0
  19. data/lib/cruj_cruj_cruj/version.rb +3 -0
  20. data/lib/cruj_cruj_cruj_visagio.rb +9 -0
  21. data/lib/tasks/cruj_cruj_cruj_tasks.rake +4 -0
  22. data/test/cruj_cruj_cruj_test.rb +7 -0
  23. data/test/dummy/README.rdoc +28 -0
  24. data/test/dummy/Rakefile +6 -0
  25. data/test/dummy/app/assets/javascripts/application.js +13 -0
  26. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  27. data/test/dummy/app/controllers/application_controller.rb +5 -0
  28. data/test/dummy/app/helpers/application_helper.rb +2 -0
  29. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/test/dummy/bin/bundle +3 -0
  31. data/test/dummy/bin/rails +4 -0
  32. data/test/dummy/bin/rake +4 -0
  33. data/test/dummy/bin/setup +29 -0
  34. data/test/dummy/config.ru +4 -0
  35. data/test/dummy/config/application.rb +26 -0
  36. data/test/dummy/config/boot.rb +5 -0
  37. data/test/dummy/config/database.yml +25 -0
  38. data/test/dummy/config/environment.rb +5 -0
  39. data/test/dummy/config/environments/development.rb +41 -0
  40. data/test/dummy/config/environments/production.rb +79 -0
  41. data/test/dummy/config/environments/test.rb +42 -0
  42. data/test/dummy/config/initializers/assets.rb +11 -0
  43. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  44. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  45. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  46. data/test/dummy/config/initializers/inflections.rb +16 -0
  47. data/test/dummy/config/initializers/mime_types.rb +4 -0
  48. data/test/dummy/config/initializers/session_store.rb +3 -0
  49. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  50. data/test/dummy/config/locales/en.yml +23 -0
  51. data/test/dummy/config/routes.rb +4 -0
  52. data/test/dummy/config/secrets.yml +22 -0
  53. data/test/dummy/public/404.html +67 -0
  54. data/test/dummy/public/422.html +67 -0
  55. data/test/dummy/public/500.html +66 -0
  56. data/test/dummy/public/favicon.ico +0 -0
  57. data/test/integration/navigation_test.rb +8 -0
  58. data/test/test_helper.rb +21 -0
  59. metadata +222 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0168f1b620e8207bca74b3c0a791f80c21f0a17bb4543f2cdc1871bb5577898c'
4
+ data.tar.gz: ca650d8c1767bfaebe1079b7a0b6cbcf95d6c8c18227912561338e3955ac619b
5
+ SHA512:
6
+ metadata.gz: c2f5b03e537b40992b01017eb286b0597103b030bd73ed7c1e6ad6c0bfc72ac88a516f8ba95c95ed4add4ca2ddffcba93d2dc017671b6a97778f2d43b111249d
7
+ data.tar.gz: a05acf1be2b6de81bd052faf4b9b4d789337f58c9ed4f6120aeda477cebd6255c7a4bf730a1b4c3c56de2dc6d83065af8ec8be0c1ffaf4f1505080a18188a233
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Visagio
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = CrujCrujCruj
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'CrujCrujCruj'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,267 @@
1
+ class CrujCrujCrujController < ApplicationController
2
+ include ActionView::Helpers::NumberHelper
3
+
4
+ before_filter :before_index , only: [:index]
5
+ before_filter :before_new , only: [:new]
6
+ before_filter :before_create, only: [:create]
7
+ before_filter :before_edit , only: [:edit]
8
+ before_filter :before_update, only: [:update]
9
+ before_filter :before_destroy, only: [:destroy]
10
+
11
+ before_filter :find_all_resources, only: [:index]
12
+ before_filter :build_resource , only: [:new, :create]
13
+ before_filter :find_resource , only: [:edit, :update, :destroy]
14
+
15
+ helper_method :namespace_url, :namespaces, :model_class, :snake_case_model_name,
16
+ :resource_url,
17
+ :index_attributes, :exclude_index_attributes,
18
+ :index_filter_attributes, :exclude_index_filter_attributes,
19
+ :associations_names, :format_field,
20
+ :filter_for
21
+
22
+ def index; end
23
+ def new; end
24
+
25
+ def create
26
+ if @resource.save
27
+ redirect_to(action: :index, notice: l("#{snake_case_model_name}_create_success_message"))
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ def edit; end
34
+
35
+ def update
36
+ if @resource.update_attributes(safe_parameters)
37
+ redirect_to(action: :index, notice: l("#{snake_case_model_name}_edit_success_message"))
38
+ else
39
+ render action: 'edit'
40
+ end
41
+ rescue ActiveRecord::RecordNotFound
42
+ render_404
43
+ end
44
+
45
+ def destroy
46
+ @resource.destroy
47
+ redirect_to action: :index, notice: l("#{snake_case_model_name}_delete_success_message")
48
+ end
49
+
50
+ def export_template
51
+ @q = model_class.ransack(params[:q])
52
+ @q.sorts = default_sort if @q.sorts.blank?
53
+
54
+ filename = CrujCrujCruj::Services::ImportRules.export_template(form_fields, @q.result)
55
+ send_file(filename, filename: l(:export_template_filename), type: "application/vnd.ms-excel")
56
+ end
57
+
58
+ def import
59
+ if params[:file].blank?
60
+ redirect_to url_for(action: :index, controller: params[:controller]), {flash: {error: l(:no_file_to_import_error_message)}}
61
+ return
62
+ end
63
+
64
+ errors = CrujCrujCruj::Services::ImportRules.import(params[:file], form_fields, model_class)
65
+
66
+ if errors.blank?
67
+ redirect_to url_for(action: :index, controller: params[:controller]), notice: l(:import_success_message)
68
+ return
69
+ end
70
+ redirect_to url_for(action: :index, controller: params[:controller]), flash: { import_errors: errors.join('<br />') }
71
+ end
72
+
73
+ protected
74
+
75
+ def before_index; end
76
+ def before_new; end
77
+ def before_create; end
78
+ def before_edit; end
79
+ def before_update; end
80
+ def before_destroy; end
81
+
82
+ def find_all_resources
83
+ @q = model_class.ransack(params[:q])
84
+ @q.sorts = default_sort if @q.sorts.blank?
85
+ @resources = @q.result.page(params[:page])
86
+ end
87
+
88
+ def build_resource
89
+ @resource = if params[snake_case_model_name]
90
+ model_class.new(safe_parameters)
91
+ else
92
+ model_class.new
93
+ end
94
+ end
95
+
96
+ def safe_parameters
97
+ params.require(snake_case_model_name).permit!
98
+ end
99
+
100
+ def find_resource
101
+ @resource = model_class.find(params[:id])
102
+ rescue ActiveRecord::RecordNotFound
103
+ render_404
104
+ end
105
+
106
+ def form_fields
107
+ []
108
+ end
109
+
110
+ def namespace_url
111
+ []
112
+ end
113
+
114
+ def namespaces
115
+ params[:controller].split('/')[0..-2]
116
+ end
117
+
118
+ def model_name
119
+ if @resource
120
+ @resource.class.name
121
+ else
122
+ self.class.name.sub(/Controller$/, '').singularize
123
+ end
124
+ end
125
+
126
+ def model_class
127
+ model_name.constantize
128
+ end
129
+
130
+ def snake_case_model_name
131
+ model_name.split('::')[-1].gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym
132
+ end
133
+
134
+ def resource_url(resource)
135
+ if Rails::VERSION::MAJOR >= 4
136
+ namespace_url + [resource] + [ resource.respond_to?(:type) ? {"type" => resource.type} : {} ]
137
+ else
138
+ namespace_url + [resource]
139
+ end
140
+ end
141
+
142
+ def index_attributes
143
+ @index_attributes ||= associations_names(:belongs_to) | model_class.attribute_names
144
+ end
145
+
146
+ def exclude_index_attributes
147
+ %w(^id$ _id created_at updated_at)
148
+ end
149
+
150
+ def index_filter_attributes
151
+ index_attributes.map { |ia| filter_for(ia) }
152
+ end
153
+
154
+ def default_sort
155
+ index_filter_attributes.map { |ifa| ifa.is_a?(Array) ? "#{ifa[0].split('_')[0..-2].join("_")} asc" : "#{ifa.split('_')[0..-2].join("_")} asc" }
156
+ end
157
+
158
+ def exclude_index_filter_attributes
159
+ exclude_index_attributes
160
+ end
161
+
162
+ def associations_names(association)
163
+ model_class.reflect_on_all_associations(association).reject { |value| value.options.key?(:through) }.map(&:name)
164
+ end
165
+
166
+ def format_field(field, possible_values)
167
+ if possible_values.blank?
168
+ send("format_field_#{field.class.name.downcase}", field)
169
+ else
170
+ possible_values[send("format_field_#{field.class.name.downcase}", field)]
171
+ end
172
+ rescue
173
+ field.name
174
+ end
175
+
176
+ def format_field_nilclass(field)
177
+ ''
178
+ end
179
+
180
+ def format_field_string(field)
181
+ field
182
+ end
183
+
184
+ def format_field_trueclass(field)
185
+ t(:true_field)
186
+ end
187
+
188
+ def format_field_falseclass(field)
189
+ t(:false_field)
190
+ end
191
+
192
+ def format_field_fixnum(field)
193
+ number_with_delimiter(field)
194
+ end
195
+
196
+ def format_field_integer(field)
197
+ number_with_delimiter(field)
198
+ end
199
+
200
+ def format_field_float(field)
201
+ number_with_precision(field)
202
+ end
203
+
204
+ def filter_for(attribute)
205
+ if attribute.is_a? Array
206
+ send("filter_for_enum", attribute[0], attribute[1])
207
+ elsif column = model_class.columns_hash[attribute.to_s]
208
+ send("filter_for_#{column.type}", attribute)
209
+ else
210
+ send("filter_for_#{attribute}")
211
+ end
212
+ rescue
213
+ "#{attribute}_cont"
214
+ end
215
+
216
+ def filter_for_boolean(attribute)
217
+ "#{attribute}_true"
218
+ end
219
+
220
+ def filter_for_project
221
+ "project_name_cont"
222
+ end
223
+
224
+ def filter_for_tracker
225
+ "tracker_name_cont"
226
+ end
227
+
228
+ def filter_for_group
229
+ "group_lastname_cont"
230
+ end
231
+
232
+ def filter_for_status
233
+ "status_name_cont"
234
+ end
235
+
236
+ def filter_for_issue_status
237
+ "issue_status_name_cont"
238
+ end
239
+
240
+ def filter_for_status_to
241
+ "status_to_name_cont"
242
+ end
243
+
244
+ def filter_for_status_from
245
+ "status_from_name_cont"
246
+ end
247
+
248
+ def filter_for_custom_field
249
+ "custom_field_name_cont"
250
+ end
251
+
252
+ def filter_for_author
253
+ "author_firstname_or_author_lastname_cont"
254
+ end
255
+
256
+ def filter_for_principal
257
+ "principal_firstname_or_principal_lastname_cont"
258
+ end
259
+
260
+ def filter_for_role
261
+ "role_name_cont"
262
+ end
263
+
264
+ def filter_for_enum(attribute, values)
265
+ ["#{attribute}_eq", values]
266
+ end
267
+ end
File without changes
@@ -0,0 +1,32 @@
1
+ <%= search_form_for @q do |f| %>
2
+ <fieldset style="display:table;border-spacing:10px;">
3
+ <% index_filter_attributes
4
+ .reject { |filter_attribute| exclude_index_filter_attributes.find { |eifa| (filter_attribute.is_a?(Array) ? filter_attribute[0] : filter_attribute ) =~ /#{eifa}/ } }
5
+ .in_groups_of(5, false).each do |filter_attributes| %>
6
+ <div class="fields" style="display:table-row">
7
+
8
+ <% filter_attributes.each do |filter_attribute| %>
9
+ <div class="field" style="display:table-cell">
10
+ <% attribute_name = filter_attribute.is_a?(Array) ? filter_attribute[0] : filter_attribute %>
11
+ <% attribute_values = filter_attribute.is_a?(Array) ? filter_attribute[1] : [] %>
12
+
13
+ <label> <b><%= t(attribute_name) %>:</b></label><br />
14
+ <% if !attribute_values.blank? %>
15
+ <%= f.select attribute_name, attribute_values.map { |k,v| [v,k] }, { include_blank: t(:all_field), selected: params[:q] ? params[:q][attribute_name] : '' } %>
16
+ <% elsif attribute_name =~ /true/ %>
17
+ <%= f.select attribute_name, [[t(:true_field), 1], [t(:false_field), 0]], { include_blank: t(:all_field), selected: params[:q] ? params[:q][attribute_name] : '' } %>
18
+ <% elsif attribute_name =~ /cont/ %>
19
+ <%= f.search_field attribute_name %>
20
+ <% else %>
21
+ <%= render "#{attribute_name}_filter" %>
22
+ <% end %>
23
+ <br /><br />
24
+ </div>
25
+ <% end %>
26
+ <br /><br />
27
+ </div>
28
+ <% end %>
29
+
30
+ <%= f.submit %>
31
+ </fieldset>
32
+ <% end %>
@@ -0,0 +1,16 @@
1
+ <div>
2
+ <div style="float: left;">
3
+ <%= link_to l("link_to_new_#{snake_case_model_name}"), url_for(action: :new, controller: params[:controller]) %>
4
+ </div>
5
+
6
+ <div style="float: right;">
7
+ <%= form_tag url_for(action: :export_template, controller: params[:controller], q: params[:q]), style: 'margin-right: 10px' do %>
8
+ <%= submit_tag l(:export_template_label) %>
9
+ <% end %>
10
+
11
+ <%= form_tag url_for(action: :import, controller: params[:controller]), multipart: true do %>
12
+ <%= file_field_tag :file %>
13
+ <%= submit_tag l(:import_template_label) %>
14
+ <% end %>
15
+ </div>
16
+ </div>
@@ -0,0 +1,43 @@
1
+ <div style="clear: both;">
2
+ <%if !@resources.empty? %>
3
+ <div class="autoscroll">
4
+ <table class="list resources">
5
+ <tr>
6
+ <% index_attributes.each do |index_attribute| %>
7
+ <% unless exclude_index_attributes.find { |eia| index_attribute =~ /#{eia}/ } %>
8
+ <th>
9
+ <%= l("label_#{index_attribute.is_a?(Array) ? index_attribute[0] : index_attribute}") %>
10
+ </th>
11
+ <% end %>
12
+ <% end %>
13
+ <th></th>
14
+ <th></th>
15
+ </tr>
16
+
17
+ <% @resources.each do |resource| %>
18
+ <tr>
19
+ <% index_attributes.each do |index_attribute| %>
20
+ <% attribute_name = index_attribute.is_a?(Array) ? index_attribute[0] : index_attribute %>
21
+ <% attribute_values = index_attribute.is_a?(Array) ? index_attribute[1] : [] %>
22
+
23
+ <% unless exclude_index_attributes.select { |eia| attribute_name =~ /#{eia}/ }.first %>
24
+ <td>
25
+ <%= format_field(resource.send(attribute_name), attribute_values) %>
26
+ </td>
27
+ <% end %>
28
+ <% end %>
29
+
30
+ <td><%= link_to l(:button_edit) , url_for([:edit] | resource_url(resource)) %></td>
31
+ <td><%= link_to l(:button_delete), url_for(resource_url(resource)), confirm: l(:access_delete_confirmation_message), method: :delete %></td>
32
+ </tr>
33
+ <% end %>
34
+ </table>
35
+ </div>
36
+
37
+ <%= paginate @resources %>
38
+
39
+ <br />
40
+ <% else %>
41
+ <h3> <%= l("no_#{snake_case_model_name}_message")%> </h1>
42
+ <% end %>
43
+ </div>