owl-cli 6.78.0 → 6.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,100 @@
8
8
  //#import $owl_dfiles:services/modelService.jsx
9
9
  //#import $owl_task_info:services/modelService.jsx
10
10
  //#import $owl_excel_templates:services/modelService.jsx
11
+ //#import excel.js
12
+
13
+ var formSpecs = @formSpecs;
14
+
15
+ var allChoices = {};
16
+
17
+ function getAllChoices(fieldSpec){
18
+ if(fieldSpec._ft==='subform'){
19
+ var fields = fieldSpec.fields;
20
+ for(var i=0;i<fields.length;i++){
21
+ var f = fields[i];
22
+ if(f._ft==='subform'){
23
+ getAllChoices(f);
24
+ }
25
+ else{
26
+ if(f._ft==='field' && f.fieldType==='choice'){
27
+ var optiosMap = {};
28
+ var options = f.options;
29
+ if(options){
30
+ for(var j=0;j<options.length;j++){
31
+ var option = options[j];
32
+ optiosMap[option[0]] = option[1];
33
+ }
34
+ allChoices[f.key] = optiosMap;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+
43
+
44
+ function tranverseFields(formSpec, callback, ctx){
45
+ formSpec.fields.forEach( function(field){
46
+ if (field[ '_ft' ] == 'field') {
47
+ callback( field, ctx );
48
+ }
49
+ else if (field[ '_ft' ] == 'subform') {
50
+ var context = { parentField: field }
51
+ tranverseFields( field, callback, context );
52
+ }
53
+ else if (field[ '_ft' ] == 'array') {
54
+ var context = { parentField: field }
55
+ tranverseFields( field, callback, context )
56
+ }
57
+ } );
58
+ }
59
+
60
+ function normalizeValue(value,spec){
61
+ if(value == null){
62
+ return null;
63
+ }
64
+ switch (spec.fieldType){
65
+ case 'string':
66
+ return 's'+value;
67
+ case 'number':
68
+ return 'n' + value;
69
+ case 'date':
70
+ return 'd'+ moment(value).toDate().getTime();
71
+ case 'choice':
72
+ for(var i=0; i<spec.options.length; i++){
73
+ var option = spec.options[i];
74
+ if(option[0]==value){
75
+ return 's'+option[1];
76
+ }
77
+ }
78
+ return 's'+value;
79
+ default:
80
+ return "s"+value;
81
+ }
82
+ }
83
+
84
+ function getExportDoc(obj){
85
+ tranverseFields(formSpecs,function(f,ctx){
86
+ if (ctx.parentField && ctx.parentField._ft == 'array') {
87
+ var items = @projectCodeService.getValue( ctx.parentField.key, obj )
88
+ if(items){
89
+ for(var i=0; i<items.length; i++){
90
+ var item = items[i];
91
+ var value = item[f.origKey];
92
+ value = normalizeValue(value,f);
93
+ item[f.origKey] = value;
94
+ }
95
+ }
96
+ }
97
+ else{
98
+ var value = @projectCodeService.getValue( f.key, obj );
99
+ value = normalizeValue(value,f);
100
+ @projectCodeService.setValue(f.key,value,obj);
101
+ }
102
+ },{});
103
+ return obj;
104
+ }
11
105
 
12
106
  function getAllDocs(searchArgs,sort,tableId,roleId,orgId,loginId,permissions){
13
107
  var keyword = searchArgs.keyword;
@@ -74,6 +168,8 @@ function getDocsByIds(ids){
74
168
  }
75
169
 
76
170
  function main(){
171
+ taskParams = JSON.parse(taskParams);
172
+ var templateId = taskParams.templateId;
77
173
 
78
174
  var template = owl_excel_templatesService.get(templateId);
79
175
  if(!template || !template.template){
@@ -107,13 +203,21 @@ function main(){
107
203
  docs = getAllDocs(searchArgs,sort,tableId,roleId,orgId,loginId,permissions);
108
204
  }
109
205
  else{
110
- var ids = params.ids;
206
+ var ids = taskParams.ids;
111
207
  docs = getDocsByIds(ids);
112
208
  }
209
+
210
+ for(var i=0; i<docs.length; i++){
211
+ var doc = docs[i];
212
+ doc = getExportDoc(doc);
213
+ docs[i] = doc;
214
+ }
215
+
113
216
  if(template.exportType==='doc'){
114
217
  if(outputTarget==='multifile'){
115
218
  for(var i=0; i<docs.length; i++){
116
219
  var exportDoc = docs[i];
220
+
117
221
  var fileId = Excel.generateExcelFromTemplate( templateUrl, exportDoc );
118
222
  if(template.toField){
119
223
  var id=exportDoc.id;
@@ -182,7 +286,6 @@ function main(){
182
286
  name:"" + docName
183
287
  }
184
288
  }
185
-
186
289
  owl_dfilesService.add(download);
187
290
  }
188
291
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owl-cli",
3
- "version": "6.78.0",
3
+ "version": "6.80.0",
4
4
  "main": "index.js",
5
5
  "preferGlobal": true,
6
6
  "bin": {