it-logica-application-backbone 1.2.17 → 1.2.18
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/views/helpers/editable_table/_build_table_checkbox_functions.html.erb +7 -2
- data/it-logica-application-backbone.gemspec +2 -1
- data/lib/controller_mixins/csv_instance_methods.rb +64 -0
- data/lib/initializers/initialize.rb +4 -0
- data/lib/model_mixins/import_csv_class_methods.rb +56 -0
- metadata +15 -14
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.18
|
@@ -41,8 +41,13 @@
|
|
41
41
|
Exportovat výběr do CSV</a>
|
42
42
|
|
43
43
|
<a href="#" class="btn" onclick="if (confirm('Tato operace může trvat několik minut v této době prosím neobnovujte stránku. Maximální počet řádků pro tisk je 10000. Chcete pokračovat?')){submit_form_in_new_window('<%= settings[:form_id] %>', '___display_method___', 'print');} return false;"><i class="icon-print"></i>
|
44
|
-
|
44
|
+
Tisknout vše dle filtrace</a>
|
45
45
|
<a href="#" class="btn" onclick="if (confirm('Tato operace může trvat několik minut v této době prosím neobnovujte stránku. Maximální počet řádků pro export je 50000. Chcete pokračovat?')){submit_form_in_new_window('<%= settings[:form_id] %>', '___export_method___', 'csv');} return false;"><i class="icon-download-alt"></i>
|
46
|
-
|
46
|
+
Exportovat vše do CSV dle filtrace</a>
|
47
|
+
|
48
|
+
<% unless @settings[:import_csv_path].blank? %>
|
49
|
+
<a target="_blank" style="float:right" href="<%= @settings[:import_csv_path] %>" class="btn"><i class="icon-circle-arrow-up"></i>
|
50
|
+
Import</a>
|
51
|
+
<% end %>
|
47
52
|
<% end %>
|
48
53
|
<% end %>
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "it-logica-application-backbone"
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.18"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ladas"]
|
@@ -516,6 +516,7 @@ Gem::Specification.new do |s|
|
|
516
516
|
"lib/controller_mixins/table_settings_interface.rb",
|
517
517
|
"lib/initializers/initialize.rb",
|
518
518
|
"lib/it-logica-application-backbone.rb",
|
519
|
+
"lib/model_mixins/import_csv_class_methods.rb",
|
519
520
|
"lib/model_mixins/ladas_html_entities.rb",
|
520
521
|
"lib/model_mixins/ladas_string_extensions.rb",
|
521
522
|
"lib/model_mixins/table_builder_class_methods.rb",
|
@@ -1,3 +1,4 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
module ControllerMixins
|
2
3
|
module CsvInstanceMethods
|
3
4
|
require 'csv'
|
@@ -50,5 +51,68 @@ module ControllerMixins
|
|
50
51
|
end
|
51
52
|
data_for_csv
|
52
53
|
end
|
54
|
+
|
55
|
+
|
56
|
+
def make_import_csv(model_class, import_settings = nil)
|
57
|
+
if request.post? && params[:file].present?
|
58
|
+
infile = params[:file].read
|
59
|
+
@successful_creates = 0
|
60
|
+
@errors = []
|
61
|
+
@label_header = []
|
62
|
+
header = []
|
63
|
+
|
64
|
+
white_list = model_class.get_white_list(import_settings)
|
65
|
+
|
66
|
+
row_number = 0
|
67
|
+
CSV.parse(infile, :encoding => "UTF-8", :col_sep => "\t") do |row|
|
68
|
+
row_number += 1
|
69
|
+
|
70
|
+
# SKIP: header
|
71
|
+
if row_number == 1
|
72
|
+
header = model_class.build_header_from_csv(row, white_list)
|
73
|
+
next
|
74
|
+
end
|
75
|
+
|
76
|
+
if row_number == 2
|
77
|
+
@label_header = model_class.build_header_from_csv(row, white_list)
|
78
|
+
next
|
79
|
+
end
|
80
|
+
|
81
|
+
row_data = model_class.build_record_from_csv(row, header, white_list)
|
82
|
+
|
83
|
+
|
84
|
+
row_obj = model_class.new(row_data)
|
85
|
+
|
86
|
+
if row_obj.save
|
87
|
+
@successful_creates += 1
|
88
|
+
else
|
89
|
+
error_message = ""
|
90
|
+
row_obj.errors.full_messages.each do |msg|
|
91
|
+
error_message += ". " unless error_message.blank?
|
92
|
+
error_message += msg
|
93
|
+
end
|
94
|
+
|
95
|
+
@errors << {:row_number => row_number, :row => row, :error_message => error_message}
|
96
|
+
end
|
97
|
+
# build_from_csv method will map customer attributes &
|
98
|
+
# build new customer record
|
99
|
+
#customer = Customer.build_from_csv(row)
|
100
|
+
## Save upon valid
|
101
|
+
## otherwise collect error records to export
|
102
|
+
#if customer.valid?
|
103
|
+
# customer.save
|
104
|
+
#else
|
105
|
+
# errs << row
|
106
|
+
#end
|
107
|
+
end
|
108
|
+
|
109
|
+
render :action => :import_csv
|
110
|
+
else
|
111
|
+
flash[:error] = "Musíte vybrat soubor pro import "
|
112
|
+
redirect_to :action => :import_csv
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
53
117
|
end
|
54
118
|
end
|
@@ -14,6 +14,8 @@ require 'model_mixins/table_settings_interface'
|
|
14
14
|
require "model_mixins/ladas_string_extensions"
|
15
15
|
require "model_mixins/ladas_html_entities"
|
16
16
|
|
17
|
+
require "model_mixins/import_csv_class_methods"
|
18
|
+
|
17
19
|
|
18
20
|
require 'controller_mixins/renderer_instance_methods'
|
19
21
|
require 'controller_mixins/csv_instance_methods'
|
@@ -34,6 +36,8 @@ module Initializers
|
|
34
36
|
|
35
37
|
ActiveRecord::Base.send :extend, ModelMixins::TableBuilderClassMethods
|
36
38
|
ActiveRecord::Base.send :extend, ModelMixins::TableSettingsInterface
|
39
|
+
|
40
|
+
ActiveRecord::Base.send :extend, ModelMixins::ImportCsvClassMethods
|
37
41
|
|
38
42
|
|
39
43
|
String.send :include, ModelMixins::LadasStringExtensions
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module ModelMixins
|
2
|
+
module ImportCsvClassMethods
|
3
|
+
def build_record_from_csv(row, header, white_list)
|
4
|
+
record_hash = {}
|
5
|
+
row.each_with_index do |value, index|
|
6
|
+
unless value.blank?
|
7
|
+
#case header[index]
|
8
|
+
# when "name"
|
9
|
+
# subject = AcquisitionSubject.find_by_name(value)
|
10
|
+
# record_hash[:acquisition_subject_id] = subject.id if !subject.blank? && white_list.include?("acquisition_subject_id")
|
11
|
+
# when "acquisition_subject_status"
|
12
|
+
# status = AcquisitionSubject.status_id(value)
|
13
|
+
# record_hash[header[index]] = status.to_s.force_encoding("UTF-8") if !status.blank? && white_list.include?(header[index])
|
14
|
+
# when "price", "end_price_on_square_m", "payed_in_deposit", "area"
|
15
|
+
# value.gsub!(",", ".") # desetinna tecka
|
16
|
+
# numbers = value.scan /[-+]?\d*\.?\d+/
|
17
|
+
# price = numbers*""
|
18
|
+
# record_hash[header[index]] = price.force_encoding("UTF-8") if !price.blank? && white_list.include?(header[index])
|
19
|
+
# when "code"
|
20
|
+
# currency = Currency.find_by_code(value)
|
21
|
+
# record_hash[:currency_id] = currency.id if !currency.blank? && white_list.include?("currency_id")
|
22
|
+
# when "date_of_signature", "maturity_by_ks", "end_date_by_ks"
|
23
|
+
# datetime = DateTime.parse(value)
|
24
|
+
# record_hash[header[index]] = datetime if !datetime.blank? && white_list.include?(header[index])
|
25
|
+
# else
|
26
|
+
record_hash[header[index]] = value.force_encoding("UTF-8") if white_list.include?(header[index])
|
27
|
+
#end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
record_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_header_from_csv(row, white_list)
|
34
|
+
header = row
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_white_list(import_settings = nil)
|
38
|
+
white_list = []
|
39
|
+
except = import_settings.blank? ? nil : import_settings[:except]
|
40
|
+
only = import_settings.blank? ? nil : import_settings[:only]
|
41
|
+
|
42
|
+
attr_accessible[:default].each do |v|
|
43
|
+
white_list << v if !v.blank?
|
44
|
+
end
|
45
|
+
|
46
|
+
unless only.blank?
|
47
|
+
white_list &= only # intersect
|
48
|
+
end
|
49
|
+
|
50
|
+
unless except.blank?
|
51
|
+
white_list -= except # difference
|
52
|
+
end
|
53
|
+
white_list
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: it-logica-application-backbone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.18
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-11-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: htmlentities
|
16
|
-
requirement: &
|
16
|
+
requirement: &75648380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *75648380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &75648080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *75648080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rdoc
|
38
|
-
requirement: &
|
38
|
+
requirement: &75647720 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.12'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *75647720
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
|
-
requirement: &
|
49
|
+
requirement: &75647320 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.1.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *75647320
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &75646850 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.8.4
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *75646850
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &75646510 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *75646510
|
80
80
|
description: longer description of your gem
|
81
81
|
email: ladislav.smola@it-logica.cz
|
82
82
|
executables: []
|
@@ -584,6 +584,7 @@ files:
|
|
584
584
|
- lib/controller_mixins/table_settings_interface.rb
|
585
585
|
- lib/initializers/initialize.rb
|
586
586
|
- lib/it-logica-application-backbone.rb
|
587
|
+
- lib/model_mixins/import_csv_class_methods.rb
|
587
588
|
- lib/model_mixins/ladas_html_entities.rb
|
588
589
|
- lib/model_mixins/ladas_string_extensions.rb
|
589
590
|
- lib/model_mixins/table_builder_class_methods.rb
|
@@ -617,7 +618,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
617
618
|
version: '0'
|
618
619
|
segments:
|
619
620
|
- 0
|
620
|
-
hash:
|
621
|
+
hash: 381236147
|
621
622
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
622
623
|
none: false
|
623
624
|
requirements:
|