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
@@ -0,0 +1,3 @@
1
+ <h2><%= t("edit_#{snake_case_model_name}_title") %></h2>
2
+
3
+ <%= render partial: "form" %>
@@ -0,0 +1,3 @@
1
+ <h2><%= t("new_#{snake_case_model_name}_title") %></h2>
2
+
3
+ <%= render partial: "form" %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>CrujCrujCruj</title>
5
+ <%= stylesheet_link_tag "cruj_cruj_cruj/application", media: "all" %>
6
+ <%= javascript_include_tag "cruj_cruj_cruj/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,91 @@
1
+ pt-BR:
2
+ true_field: Sim
3
+ false_field: Não
4
+ all_field: Todos
5
+ label_principal: 'Atribuído para'
6
+ label_issue_status: 'Status'
7
+ label_type: Tipo
8
+
9
+ project_name_cont: Nome do projeto contém
10
+ tracker_name_cont: Nome do tipo da tarefa contém
11
+ custom_field_name_cont: Nome do campo customizado contém
12
+ group_lastname_cont: Nome do grupo contém
13
+ issue_status_name_cont: Nome do status de contém
14
+ status_from_name_cont: Nome do status de contém
15
+ status_to_name_cont: Nome do status para contém
16
+ custom_field_value_cont: Valor do campo customizado contém
17
+ principal_firstname_or_principal_lastname_cont: 'Atribuído para contém'
18
+ type_cont: Tipo contém
19
+
20
+ export_template_label: "Exportar Template"
21
+ import_template_label: "Importar Template"
22
+
23
+ ransack:
24
+ search: "pesquisar"
25
+ predicate: "predicado"
26
+ and: "e"
27
+ or: "ou"
28
+ any: "algum"
29
+ all: "todos"
30
+ combinator: "combinador"
31
+ attribute: "atributo"
32
+ value: "valor"
33
+ condition: "condição"
34
+ sort: "classificar"
35
+ asc: "ascendente"
36
+ desc: "descendente"
37
+ predicates:
38
+ eq: "igual"
39
+ eq_any: "igual a algum"
40
+ eq_all: "igual a todos"
41
+ not_eq: "não é igual a"
42
+ not_eq_any: "não é igual a algum"
43
+ not_eq_all: "não é igual a todos"
44
+ matches: "corresponde"
45
+ matches_any: "corresponde a algum"
46
+ matches_all: "corresponde a todos"
47
+ does_not_match: "não corresponde"
48
+ does_not_match_any: "não corresponde a algum"
49
+ does_not_match_all: "não corresponde a todos"
50
+ lt: "menor que"
51
+ lt_any: "menor que algum"
52
+ lt_all: "menor que todos"
53
+ lteq: "menor ou igual a"
54
+ lteq_any: "menor ou igual a algum"
55
+ lteq_all: "menor ou igual a todos"
56
+ gt: "maior que"
57
+ gt_any: "maior que algum"
58
+ gt_all: "maior que todos"
59
+ gteq: "maior que ou igual a"
60
+ gteq_any: "maior que ou igual a algum"
61
+ gteq_all: "maior que ou igual a todos"
62
+ in: "em"
63
+ in_any: "em algum"
64
+ in_all: "em todos"
65
+ not_in: "não em"
66
+ not_in_any: "não em algum"
67
+ not_in_all: "não em todos"
68
+ cont: "contém"
69
+ cont_any: "contém algum"
70
+ cont_all: "contém todos"
71
+ not_cont: "não contém"
72
+ not_cont_any: "não contém algum"
73
+ not_cont_all: "não contém todos"
74
+ start: "começa com"
75
+ start_any: "começa com algum"
76
+ start_all: "começa com todos"
77
+ not_start: "não começa com"
78
+ not_start_any: "não começa com algum"
79
+ not_start_all: "não começa com algum"
80
+ end: "termina com"
81
+ end_any: "termina com algum"
82
+ end_all: "termina com todos"
83
+ not_end: "não termina com"
84
+ not_end_any: "não termina com algum"
85
+ not_end_all: "não termina com todos"
86
+ 'true': "é verdadeiro"
87
+ 'false': "é falso"
88
+ present: "está presente"
89
+ blank: "está em branco"
90
+ 'null': "é nullo"
91
+ not_null: "não é nulo"
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ CrujCrujCruj::Engine.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ module CrujCrujCruj
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,161 @@
1
+ #encoding: utf-8
2
+ module CrujCrujCruj
3
+ module Services
4
+ class ImportRules
5
+
6
+ def self.export_template(fields, data)
7
+ package = Axlsx::Package.new
8
+ workbook = package.workbook
9
+
10
+ parameters_sheet_name = 'PARAMETERS'
11
+
12
+ workbook.add_worksheet(name: 'TEMPLATE') do |sheet|
13
+ title = sheet.styles.add_style(bg_color: 'FF007E7A', fg_color: 'FFFFFFFF', sz: 12, b: true, border: {style: :thin, color: 'FF000000'})
14
+
15
+ fields.each_with_index do |field, idx|
16
+ validation = field[:data_validation][:validation]
17
+ allow_blank = field[:data_validation][:allow_blank]
18
+ add_data_validation(sheet, idx + 1, validation, allow_blank, parameters_sheet_name) if validation
19
+ end
20
+
21
+ sheet.add_row (([:id] |fields.map { |field| field[:field_name] }).map { |t| I18n.t("#{t}_label") }), style: title
22
+
23
+ data.map { |resource| [resource.id].concat(fields.map { |field| resource_field_value(resource, field) }) }.each do |row|
24
+ sheet.add_row row, types: row.map{ |_| :string }
25
+ end
26
+ end
27
+
28
+ create_validations(fields, workbook, parameters_sheet_name)
29
+
30
+ filename = "tmp/template_#{Time.zone.now.strftime('%Y%m%d%H%M%S')}.xlsx"
31
+ package.serialize(filename)
32
+ filename
33
+ end
34
+
35
+ def self.import(file, fields, clazz)
36
+ spreadsheet = Roo::Spreadsheet.open(file.path, extension: :xlsx)
37
+
38
+ errors = []
39
+
40
+ if Rails::VERSION::MAJOR < 4
41
+ invalid_rows = validate_id_array(spreadsheet, clazz)
42
+ else
43
+ invalid_rows = validate_id(spreadsheet, clazz)
44
+ end
45
+ errors << I18n.t(:column_invalid_rows, column: :id, rows: invalid_rows.first(25).join(', ')) unless invalid_rows.blank?
46
+
47
+ fields.each_with_index do |field, idx|
48
+ col = idx + 1
49
+ unless field[:data_validation][:allow_blank]
50
+ invalid_rows = validate_not_blank(col, spreadsheet)
51
+ errors << I18n.t(:column_invalid_rows, column: field[:field_name], rows: invalid_rows.first(25).join(', ')) unless invalid_rows.blank?
52
+ end
53
+
54
+ if field[:data_validation][:validation]
55
+ invalid_rows = validate_in_array(col, field_validation_values(field), spreadsheet)
56
+ errors << I18n.t(:column_invalid_rows, column: field[:field_name], rows: invalid_rows.first(25).join(', ')) unless invalid_rows.blank?
57
+ end
58
+ end
59
+
60
+ return errors unless errors.blank?
61
+
62
+
63
+ (2..spreadsheet.last_row).each do |i|
64
+ row = spreadsheet.row(i)
65
+ id = row[0]
66
+ resource = id ? clazz.find(id) : clazz.new
67
+
68
+ fields.each_with_index do |field, idx|
69
+ resource.send("#{field[:field_name]}=", row_value(row, idx+1, field, spreadsheet))
70
+ resource.save!
71
+ end
72
+ end
73
+
74
+ {}
75
+ end
76
+
77
+ protected
78
+
79
+
80
+ def self.add_data_validation(sheet, column_number, validation, allowBlank, parameters_sheet_name)
81
+ column_letter = number2column(column_number)
82
+ values_size = validation.is_a?(Array) ? validation.size : validation[:clazz].all.count
83
+ sheet.add_data_validation("#{column_letter}2:#{column_letter}1048576", type: :list, allowBlank: allowBlank, formula1: "#{parameters_sheet_name}!$#{column_letter}$2:$#{column_letter}$#{values_size+1}")
84
+ end
85
+
86
+ def self.create_validations(fields, workbook, parameters_sheet_name)
87
+ workbook.add_worksheet(name: parameters_sheet_name) do |sheet|
88
+ sheet.add_row [:id] | fields.map { |field| field[:field_name] }
89
+
90
+ cols_values = [[]].concat(fields.map { |field| field_validation_values(field) })
91
+
92
+ cols_values.map { |values| values.size }.max.times do |i|
93
+ row = cols_values.map { |v| v[i] }
94
+ sheet.add_row row, types: row.map{ |_| :string }
95
+ end
96
+ end
97
+ end
98
+
99
+ def self.resource_field_value(resource, field)
100
+ if field[:data_validation][:validation] && !field[:data_validation][:validation].is_a?(Array)
101
+ relation = resource.send(field[:field_name])
102
+ relation ? relation.send(field[:data_validation][:validation][:field]) : nil
103
+ else
104
+ resource.send(field[:field_name])
105
+ end
106
+ end
107
+
108
+ def self.field_validation_values(field)
109
+ if field[:data_validation][:validation]
110
+ if field[:data_validation][:validation].is_a?(Array)
111
+ field[:data_validation][:validation]
112
+ elsif Rails::VERSION::MAJOR < 4
113
+ field[:data_validation][:validation][:clazz].order((field[:data_validation][:validation][:field])).map(&field[:data_validation][:validation][:field])
114
+ else
115
+ field[:data_validation][:validation][:clazz].all.order(field[:data_validation][:validation][:field]).pluck(field[:data_validation][:validation][:field])
116
+ end
117
+ else
118
+ []
119
+ end
120
+ end
121
+
122
+ def self.number2column(number)
123
+ Hash.new {|hash,key| hash[key] = hash[key - 1].next }.merge({0 => "A"})[number]
124
+ end
125
+
126
+ def self.validate_id(spreadsheet, clazz)
127
+ validate_in_array(0, clazz.all.pluck(:id).map(&:to_s), spreadsheet)
128
+ end
129
+
130
+ def self.validate_id_array(spreadsheet, clazz)
131
+ validate_in_array(0, clazz.all.map(&:id).map(&:to_s), spreadsheet)
132
+ end
133
+
134
+ def self.validate_not_blank(col, spreadsheet)
135
+ (2..spreadsheet.last_row)
136
+ .map { |i| {i => !spreadsheet.row(i)[col].blank? } }
137
+ .select { |e| !e.values.first }
138
+ .map { |e| e.keys.first }
139
+ end
140
+
141
+ def self.validate_in_array(col, array, spreadsheet)
142
+ (2..spreadsheet.last_row)
143
+ .map { |i| { i => (spreadsheet.row(i)[col].blank? || array.map(&:to_s).map(&:downcase).include?(spreadsheet.row(i)[col].to_s.downcase)) } }
144
+ .select { |e| !e.values.first }
145
+ .map { |e| e.keys.first }
146
+ end
147
+
148
+ def self.fetch(row, col, spreadsheet)
149
+ spreadsheet.celltype(row, col + 1) == :float ? spreadsheet.send(:cell_to_csv, row, col + 1, spreadsheet.default_sheet) : row[col]
150
+ end
151
+
152
+ def self.row_value(row, col, field, spreadsheet)
153
+ if field[:data_validation][:validation] && !field[:data_validation][:validation].is_a?(Array)
154
+ field[:data_validation][:validation][:clazz].send("find_by_#{field[:data_validation][:validation][:field]}", fetch(row, col, spreadsheet))
155
+ else
156
+ fetch(row, col, spreadsheet)
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,3 @@
1
+ module CrujCrujCruj
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "cruj_cruj_cruj/engine"
2
+ require "cruj_cruj_cruj/services/import_rules"
3
+
4
+ module CrujCrujCruj
5
+ require "ransack"
6
+ require 'kaminari'
7
+ require 'roo'
8
+ require 'axlsx'
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cruj_cruj_cruj do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class CrujCrujCrujTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, CrujCrujCruj
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -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,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end