sp-excel-loader 0.3.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +661 -0
  4. data/README.md +8 -0
  5. data/lib/sp-excel-loader.rb +6 -0
  6. data/lib/sp/excel/loader.rb +61 -0
  7. data/lib/sp/excel/loader/jrxml/band.rb +80 -0
  8. data/lib/sp/excel/loader/jrxml/band_container.rb +229 -0
  9. data/lib/sp/excel/loader/jrxml/box.rb +75 -0
  10. data/lib/sp/excel/loader/jrxml/casper_checkbox.rb +97 -0
  11. data/lib/sp/excel/loader/jrxml/casper_combo.rb +86 -0
  12. data/lib/sp/excel/loader/jrxml/casper_date.rb +54 -0
  13. data/lib/sp/excel/loader/jrxml/casper_radio_button.rb +48 -0
  14. data/lib/sp/excel/loader/jrxml/casper_text_field.rb +157 -0
  15. data/lib/sp/excel/loader/jrxml/client_combo_text_field.rb +72 -0
  16. data/lib/sp/excel/loader/jrxml/excel_to_jrxml.rb +1183 -0
  17. data/lib/sp/excel/loader/jrxml/extensions.rb +330 -0
  18. data/lib/sp/excel/loader/jrxml/field.rb +65 -0
  19. data/lib/sp/excel/loader/jrxml/group.rb +71 -0
  20. data/lib/sp/excel/loader/jrxml/image.rb +63 -0
  21. data/lib/sp/excel/loader/jrxml/jasper.rb +228 -0
  22. data/lib/sp/excel/loader/jrxml/parameter.rb +73 -0
  23. data/lib/sp/excel/loader/jrxml/pen.rb +97 -0
  24. data/lib/sp/excel/loader/jrxml/property.rb +52 -0
  25. data/lib/sp/excel/loader/jrxml/property_expression.rb +52 -0
  26. data/lib/sp/excel/loader/jrxml/report_element.rb +92 -0
  27. data/lib/sp/excel/loader/jrxml/static_text.rb +59 -0
  28. data/lib/sp/excel/loader/jrxml/style.rb +99 -0
  29. data/lib/sp/excel/loader/jrxml/text_field.rb +83 -0
  30. data/lib/sp/excel/loader/jrxml/variable.rb +77 -0
  31. data/lib/sp/excel/loader/json_to_xlsx.rb +159 -0
  32. data/lib/sp/excel/loader/model_exporter.rb +249 -0
  33. data/lib/sp/excel/loader/payrollexporter.rb +168 -0
  34. data/lib/sp/excel/loader/rubyxl_table_patch.rb +91 -0
  35. data/lib/sp/excel/loader/version.rb +26 -0
  36. data/lib/sp/excel/loader/workbookloader.rb +480 -0
  37. data/spec/calc_spec.rb +87 -0
  38. data/spec/model.xls +0 -0
  39. metadata +151 -0
@@ -0,0 +1,97 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class CasperCheckbox < CasperTextField
27
+
28
+ def validation_regexp
29
+ /\A\$CB{(\$[PFV]{.+}),(.+),(.+)}\z/
30
+ end
31
+
32
+ def attachment
33
+ 'checkbox'
34
+ end
35
+
36
+ #
37
+ # check box: $CB{<field_name>,<unchecked>,<checked>}
38
+ #
39
+ def initialize (a_generator, a_expression)
40
+ super(a_generator, a_expression)
41
+
42
+ # validade expression and extract components
43
+ values = validation_regexp.match a_expression.delete(' ')
44
+ if values.nil? or values.size != 4
45
+ raise "Invalid checkbox expression: '#{a_expression}'"
46
+ else
47
+ field_expr = values[1]
48
+ off_value = convert_type(values[2])
49
+ on_value = convert_type(values[3])
50
+ end
51
+
52
+ a_generator.declare_expression_entities(a_expression)
53
+
54
+ # get or guess the expression type
55
+ @binding = a_generator.bindings[field_expr]
56
+ if not @binding.nil?
57
+ type = @binding.java_class
58
+ if type != @value_types[0]
59
+ raise "Checked value '#{on_value}' type #{@value_types[0]} does not match the binding type #{type} (#{a_expression})"
60
+ end
61
+ if type != @value_types[1]
62
+ raise "Checked value '#{off_value}' type #{@value_types[1]} does not match the binding type #{type} (#{a_expression})"
63
+ end
64
+ else
65
+ raise "Checkbox expression '#{a_expression}' requires a binding for expr '#{field_expr}'".yellow
66
+ end
67
+ update_tooltip()
68
+
69
+ @casper_binding[:editable] = {
70
+ is: @binding.editable,
71
+ patch: {
72
+ field: {
73
+ name: field_expr[3..-2]
74
+ }
75
+ }
76
+ }
77
+
78
+ @casper_binding[:attachment] = {
79
+ type: attachment,
80
+ version: 2,
81
+ value: {
82
+ type: type,
83
+ on: on_value.to_s,
84
+ off: off_value.to_s
85
+ }
86
+ }
87
+
88
+ @text_field_expression = "#{field_expr} == #{on_value} ? \"X\" : \"\""
89
+
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,86 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class CasperCombo < CasperTextField
27
+
28
+ def initialize (a_generator, a_expression)
29
+ super(a_generator, a_expression)
30
+
31
+ if @binding.cc_field_name[0] != '['
32
+ field_name = @binding.cc_field_name
33
+ fields = [ @binding.cc_field_id, @binding.cc_field_name ]
34
+ else
35
+ field_name = @binding.cc_field_name[1..-2]
36
+ fields = @binding.cc_field_name[1..-2].split(',').each { |e| e.strip! }
37
+ end
38
+
39
+ if @binding.respond_to?(:html)
40
+ html = @binding.html
41
+ else
42
+ if fields.size == 1
43
+ html = "<div class=\"normal\"><div class=\"main\">[[#{fields[0]}]]</div></div>"
44
+ else
45
+ html = "<div class=\"normal\"><div class=\"left\">[[#{fields[0]}]]</div><div class=\"main\">[[#{fields[1]}]]</div></div>"
46
+ end
47
+ end
48
+
49
+ if @binding.respond_to?(:cc_field_patch) and @binding.cc_field_patch != ''
50
+ patch_name = @binding.cc_field_patch
51
+ else
52
+ patch_name = @binding.id[3..-2]
53
+ end
54
+
55
+ @casper_binding[:editable] = {
56
+ is: @binding.editable,
57
+ patch: {
58
+ field: {
59
+ type: @binding.java_class,
60
+ name: patch_name
61
+ }
62
+ }
63
+ }
64
+
65
+ @casper_binding[:attachment] = {
66
+ type: 'dropDownList',
67
+ version: 2,
68
+ controller: 'client',
69
+ route: @binding.uri.gsub('"', '""'),
70
+ display: fields,
71
+ html: html
72
+ }
73
+
74
+ if @binding.respond_to?(:allow_clear)
75
+ unless @binding.allow_clear.nil? or not @binding.allow_clear
76
+ @casper_binding[:attachment][:allowClear] = @binding.allow_clear
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class CasperDate < CasperTextField
27
+
28
+ def initialize (a_generator, a_expression)
29
+ super(a_generator, a_expression)
30
+ a_generator.declare_expression_entities(a_expression)
31
+
32
+ @casper_binding[:editable] = {
33
+ patch: {
34
+ field: {
35
+ pattern: 'yyyy-MM-dd'
36
+ }
37
+ }
38
+ }
39
+
40
+ @casper_binding[:attachment] = {
41
+ type: 'datePicker',
42
+ version: 2
43
+ }
44
+
45
+ @text_field_expression = "DateFormat.parse(#{a_expression},\"yyyy-MM-dd\")"
46
+ @pattern_expression = '$P{i18n_date_format}'
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class CasperRadioButton < CasperCheckbox
27
+
28
+ def validation_regexp
29
+ /\A\$RB{(\$[PFV]{.+}),(.+),(.+)}\z/
30
+ end
31
+
32
+ def attachment
33
+ 'radioButton'
34
+ end
35
+
36
+ #
37
+ # Radio Button: $RB{<field_name>,<unchecked>,<checked>}
38
+ #
39
+ def initialize (a_generator, a_expression)
40
+ super(a_generator, a_expression)
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,157 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class CasperTextField < TextField
27
+
28
+ attr_reader :casper_binding
29
+
30
+ def initialize (a_generator, a_expression)
31
+ super(Array.new, nil, nil)
32
+ @value_types = Array.new
33
+ @casper_binding = {}
34
+ @generator = a_generator
35
+ @binding = @generator.bindings[a_expression]
36
+
37
+ @generator.declare_expression_entities(a_expression)
38
+ @text_field_expression = a_expression
39
+
40
+ unless @binding.nil?
41
+ if @binding.respond_to? :presentation
42
+ pattern = @binding.presentation.format
43
+ if pattern != nil and not pattern.empty?
44
+ if pattern.include? '$P{' or pattern.include? '$F{' or pattern.include? '$V{'
45
+ @pattern_expression = pattern
46
+ else
47
+ @pattern = pattern
48
+ end
49
+ end
50
+ end
51
+
52
+ if @binding.respond_to? :editable
53
+ @casper_binding[:editable] = { is: @binding.editable }
54
+ end
55
+
56
+ end
57
+ update_tooltip()
58
+ end
59
+
60
+ def update_tooltip ()
61
+
62
+ if not @binding.nil?
63
+ if @binding.respond_to? :tooltip
64
+ tooltip = @binding.tooltip
65
+ if not tooltip.nil? and not tooltip.empty?
66
+ @generator.declare_expression_entities(tooltip.strip)
67
+ @casper_binding[:hint] = { expression: tooltip.strip }
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ def convert_type (a_value)
75
+ case a_value.to_s
76
+ when /\A".+"\z/
77
+ rv = a_value[1..-1]
78
+ @value_types << 'java.lang.String'
79
+ when 'true'
80
+ rv = true
81
+ @value_types << 'java.lang.Boolean'
82
+ when 'false'
83
+ rv = false
84
+ @value_types << 'java.lang.Boolean'
85
+ when /([+-])?\d+/
86
+ rv = Integer(a_value) rescue nil
87
+ @value_types << 'java.lang.Integer'
88
+ else
89
+ rv = Float(a_value) rescue nil
90
+ @value_types << 'java.lang.Double'
91
+ end
92
+ if rv.nil?
93
+ raise "Unable to convert value #{a_value} to json"
94
+ end
95
+ rv
96
+ end
97
+
98
+ def to_xml (a_node)
99
+ puts '======================================================================================='
100
+ puts "TextField = '#{@text_field_expression}'"
101
+ puts "Pattern Exp = '#{@pattern_expression}'" unless @pattern_expression.nil? or @pattern_expression.empty?
102
+ puts "Pattern = '#{@pattern}'" unless @pattern.nil? or @pattern.empty?
103
+ if @casper_binding.size != 0
104
+ puts 'casper-binding:'
105
+ ap @casper_binding
106
+ @report_element.properties << Property.new('casper.binding', @casper_binding.to_json)
107
+ end
108
+ super(a_node)
109
+ end
110
+
111
+ def editable_conditional (a_value)
112
+ @casper_binding[:editable] ||= {}
113
+ @casper_binding[:editable][:conditionals] ||= {}
114
+ @casper_binding[:editable][:conditionals][:is] = a_value
115
+ end
116
+
117
+ def disabled_conditional (a_value)
118
+ @casper_binding[:editable] ||= {}
119
+ @casper_binding[:editable][:conditionals] ||= {}
120
+ @casper_binding[:editable][:conditionals][:disabled] = a_value
121
+ end
122
+
123
+ def locked_conditional (a_value)
124
+ @casper_binding[:editable] ||= {}
125
+ @casper_binding[:editable][:conditionals] ||= {}
126
+ @casper_binding[:editable][:conditionals][:locked] = a_value
127
+ end
128
+
129
+ def enabled_conditional (a_value)
130
+ @casper_binding[:editable] ||= {}
131
+ @casper_binding[:editable][:conditionals] ||= {}
132
+ @casper_binding[:editable][:conditionals][:enabled] = a_value
133
+ end
134
+
135
+ def style_expression (a_value)
136
+ @casper_binding[:style] ||= {}
137
+ @casper_binding[:style][:overload] ||= {}
138
+ @casper_binding[:style][:overload][:condition] = a_value
139
+ end
140
+
141
+ def reload_if_changed (a_value)
142
+ @casper_binding[:editable] ||= {}
143
+ @casper_binding[:editable][:conditionals] ||= {}
144
+ @casper_binding[:editable][:conditionals][:reload] = a_value == 'true' ? true : false
145
+ end
146
+
147
+ def editable_expression (a_value)
148
+ @casper_binding[:editable] ||= {}
149
+ @casper_binding[:editable][:expression] = a_value
150
+ end
151
+
152
+ end
153
+
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2011-2016 Cloudware S.A. All rights reserved.
4
+ #
5
+ # This file is part of sp-excel-loader.
6
+ #
7
+ # sp-excel-loader is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Affero General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # sp-excel-loader is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General Public License
18
+ # along with sp-excel-loader. If not, see <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ module Sp
22
+ module Excel
23
+ module Loader
24
+ module Jrxml
25
+
26
+ class ClientComboTextField < TextField
27
+
28
+ def initialize (a_binding, a_generator)
29
+ super(Array.new, a_binding.presentation.format, nil)
30
+
31
+ @report_element.properties << Property.new('epaper.casper.text.field.editable' , 'true')
32
+ @report_element.properties << Property.new('epaper.casper.text.field.load.uri' , a_binding.uri)
33
+ @report_element.properties << Property.new('epaper.casper.text.field.attach' , 'drop-down_list')
34
+ @report_element.properties << Property.new('epaper.casper.text.field.attach.drop-down_list.controller' , 'client')
35
+ if a_binding.cc_field_name[0] != '['
36
+ @report_element.properties << Property.new('epaper.casper.text.field.attach.drop-down_list.controller.display' , "[#{a_binding.cc_field_id},#{a_binding.cc_field_name}]")
37
+ else
38
+ @report_element.properties << Property.new('epaper.casper.text.field.attach.drop-down_list.controller.display' , a_binding.cc_field_name)
39
+ end
40
+ @report_element.properties << Property.new('epaper.casper.text.field.attach.drop-down_list.field.id' , a_binding.cc_field_id)
41
+ if a_binding.cc_field_name[0] == '['
42
+ @report_element.properties << Property.new('epaper.casper.text.field.attach.drop-down_list.field.name' , a_binding.cc_field_name[1..-2])
43
+ else
44
+ @report_element.properties << Property.new('epaper.casper.text.field.attach.drop-down_list.field.name' , a_binding.cc_field_name)
45
+ end
46
+ @report_element.properties << Property.new('epaper.casper.text.field.attach.drop-down_list.controller.pick.first_if_empty', 'false')
47
+ if a_binding.respond_to?(:cc_field_patch) and a_binding.cc_field_patch != ''
48
+ @report_element.properties << Property.new('epaper.casper.text.field.patch.name' , a_binding.cc_field_patch)
49
+ else
50
+ @report_element.properties << Property.new('epaper.casper.text.field.patch.name' , a_binding.id[3..-2])
51
+ end
52
+ @report_element.properties << Property.new('epaper.casper.text.field.patch.type' , a_binding.java_class)
53
+
54
+ unless a_binding.tooltip.nil? or a_binding.tooltip.empty?
55
+ @report_element.properties << PropertyExpression.new('epaper.casper.text.field.hint.expression', a_binding.tooltip)
56
+ a_generator.declare_expression_entities(a_binding.tooltip)
57
+ end
58
+
59
+ if a_binding.respond_to?(:allow_clear)
60
+ unless a_binding.allow_clear.nil? or !a_binding.allow_clear
61
+ @report_element.properties << Property.new('epaper.casper.text.field.attach.drop-down_list.controller.add.empty_line', a_binding.allow_clear)
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end