it-logica-application-backbone 1.3.22 → 1.3.23

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.22
1
+ 1.3.23
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "it-logica-application-backbone"
8
- s.version = "1.3.22"
8
+ s.version = "1.3.23"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ladas"]
12
- s.date = "2013-05-06"
12
+ s.date = "2013-08-05"
13
13
  s.description = "longer description of your gem"
14
14
  s.email = "ladislav.smola@it-logica.cz"
15
15
  s.extra_rdoc_files = [
@@ -35,16 +35,42 @@ module ControllerMixins
35
35
  data_for_csv = []
36
36
  header_of_names = []
37
37
  header_of_labels = []
38
+
39
+ excluded_columns = []
38
40
  settings[:columns].each do |c|
39
- header_of_names << c[:name].to_s.encode(encoding, "UTF-8")
40
- header_of_labels << c[:label].to_s.encode(encoding, "UTF-8")
41
+ excluded_columns << "#{c[:table]}_#{c[:name]}" if c[:csv_excluded] unless c.blank?
42
+ end
43
+
44
+ # add column names header
45
+ if settings[:csv].blank? || (!settings[:csv].blank? && !settings[:csv][:exclude_names])
46
+ settings[:columns].each do |c|
47
+
48
+ next if excluded_columns.include?("#{c[:table]}_#{c[:name]}")
49
+
50
+ header_of_names << c[:name].to_s.encode(encoding, "UTF-8")
51
+ end
52
+ data_for_csv << header_of_names
53
+ end
54
+
55
+ # add column labels header
56
+ if settings[:csv].blank? || (!settings[:csv].blank? && !settings[:csv][:exclude_labels])
57
+ settings[:columns].each do |c|
58
+
59
+ next if excluded_columns.include?("#{c[:table]}_#{c[:name]}")
60
+
61
+ header_of_labels << c[:label].to_s.encode(encoding, "UTF-8")
62
+ end
63
+ data_for_csv << header_of_labels
41
64
  end
42
- data_for_csv << header_of_names
43
- data_for_csv << header_of_labels
44
65
 
66
+ # add data without excluded columns
45
67
  settings[:data].each do |c|
46
68
  row = []
47
69
  c.each_pair do |name, value|
70
+
71
+ next if excluded_columns.include?(name.to_s)
72
+ next if name == 'row_id' && settings[:csv][:exclude_row_id] unless settings[:csv].blank?
73
+
48
74
  if value.kind_of?(Hash)
49
75
  val = value[:title].blank? ? "" : value[:title]
50
76
  row << val.to_s.encode(encoding, "UTF-8")
@@ -56,6 +82,7 @@ module ControllerMixins
56
82
  data_for_csv << row
57
83
  end
58
84
  data_for_csv
85
+
59
86
  end
60
87
 
61
88
 
@@ -93,11 +93,13 @@ module ControllerMixins
93
93
  case export_method
94
94
  when "csv"
95
95
  @settings = class_obj.prepare_settings(logged_user, data, @settings, default_params, nil, 50000)
96
- generate_and_return_csv(get_data_for_csv_from_settings(@settings))
96
+ generate_and_return_csv(get_data_for_csv_from_settings(@settings),
97
+ (@settings.blank? || @settings[:csv].blank? || @settings[:csv][:name].blank?) ? 'export.csv' : @settings[:csv][:name])
97
98
  when "csv_by_checkboxes"
98
99
  settings[:filter_method] = "only_by_checkboxes"
99
100
  @settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
100
- generate_and_return_csv(get_data_for_csv_from_settings(@settings))
101
+ generate_and_return_csv(get_data_for_csv_from_settings(@settings),
102
+ (@settings.blank? || @settings[:csv].blank? || @settings[:csv][:name].blank?) ? 'export.csv' : @settings[:csv][:name])
101
103
  else
102
104
 
103
105
  settings = class_obj.prepare_settings(logged_user, data, settings, default_params)
@@ -14,7 +14,7 @@ class TableSettings
14
14
  # @param [Symbol] model
15
15
  #
16
16
  def initialize(model)
17
- @settings = {:columns => [], :row => {}, :default => {}}
17
+ @settings = {:columns => [], :row => {}, :default => {}, :csv => {}}
18
18
  @model = model
19
19
  @default_table = table_name_from_model(model)
20
20
 
@@ -171,6 +171,31 @@ class TableSettings
171
171
  @settings[:default][:per_page] = number
172
172
  end
173
173
 
174
+ # CSV export - filename
175
+ def csv_name(name = 'export.csv')
176
+ @settings[:csv][:name] = name
177
+
178
+ self
179
+ end
180
+
181
+ # CSV export - exclude header row with column names
182
+ def csv_exclude_names(exclude = true)
183
+ @settings[:csv][:exclude_names] = exclude
184
+ self
185
+ end
186
+
187
+ # CSV export - exclude header row with column labels
188
+ def csv_exclude_labels(exclude = true)
189
+ @settings[:csv][:exclude_labels] = exclude
190
+ self
191
+ end
192
+
193
+ # CSV export - exclude row_id column
194
+ def csv_exclude_row_id(exclude = true)
195
+ @settings[:csv][:exclude_row_id] = exclude
196
+ self
197
+ end
198
+
174
199
  def filter_path(path)
175
200
  @settings[:filter_path] = path
176
201
 
@@ -115,6 +115,12 @@ class TableSettings
115
115
  @column_hash[:inactive_filter] = bool
116
116
  self
117
117
  end
118
+
119
+ # Set if column is excluded from csv export
120
+ def csv_excluded(bool = false)
121
+ @column_hash[:csv_excluded] = bool
122
+ self
123
+ end
118
124
  end
119
125
 
120
126
  class CustomColumn < Column
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.3.22
4
+ version: 1.3.23
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: htmlentities
@@ -668,7 +668,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
668
668
  version: '0'
669
669
  segments:
670
670
  - 0
671
- hash: 755924244209213329
671
+ hash: 985655048161230968
672
672
  required_rubygems_version: !ruby/object:Gem::Requirement
673
673
  none: false
674
674
  requirements: