owl-cli 6.79.0 → 6.81.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,99 @@
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
+ //#import file.js
13
+
14
+ var formSpecs = @formSpecs;
15
+
16
+ var allChoices = {};
17
+
18
+ function getAllChoices(fieldSpec){
19
+ if(fieldSpec._ft==='subform'){
20
+ var fields = fieldSpec.fields;
21
+ for(var i=0;i<fields.length;i++){
22
+ var f = fields[i];
23
+ if(f._ft==='subform'){
24
+ getAllChoices(f);
25
+ }
26
+ else{
27
+ if(f._ft==='field' && f.fieldType==='choice'){
28
+ var optiosMap = {};
29
+ var options = f.options;
30
+ if(options){
31
+ for(var j=0;j<options.length;j++){
32
+ var option = options[j];
33
+ optiosMap[option[0]] = option[1];
34
+ }
35
+ allChoices[f.key] = optiosMap;
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ function tranverseFields(formSpec, callback, ctx){
44
+ formSpec.fields.forEach( function(field){
45
+ if (field[ '_ft' ] == 'field') {
46
+ callback( field, ctx );
47
+ }
48
+ else if (field[ '_ft' ] == 'subform') {
49
+ var context = { parentField: field }
50
+ tranverseFields( field, callback, context );
51
+ }
52
+ else if (field[ '_ft' ] == 'array') {
53
+ var context = { parentField: field }
54
+ tranverseFields( field, callback, context )
55
+ }
56
+ } );
57
+ }
58
+
59
+ function normalizeValue(value,spec){
60
+ if(value == null){
61
+ return null;
62
+ }
63
+ switch (spec.fieldType){
64
+ case 'string':
65
+ return 's'+value;
66
+ case 'number':
67
+ return 'n' + value;
68
+ case 'date':
69
+ return 'd'+ moment(value).toDate().getTime();
70
+ case 'choice':
71
+ for(var i=0; i<spec.options.length; i++){
72
+ var option = spec.options[i];
73
+ if(option[0]==value){
74
+ return 's'+option[1];
75
+ }
76
+ }
77
+ return 's'+value;
78
+ default:
79
+ return "s"+value;
80
+ }
81
+ }
82
+
83
+ function getExportDoc(obj){
84
+ tranverseFields(formSpecs,function(f,ctx){
85
+ if (ctx.parentField && ctx.parentField._ft == 'array') {
86
+ var items = @projectCodeService.getValue( ctx.parentField.key, obj )
87
+ if(items){
88
+ for(var i=0; i<items.length; i++){
89
+ var item = items[i];
90
+ var value = item[f.origKey];
91
+ value = normalizeValue(value,f);
92
+ item[f.origKey] = value;
93
+ }
94
+ }
95
+ }
96
+ else{
97
+ var value = @projectCodeService.getValue( f.key, obj );
98
+ value = normalizeValue(value,f);
99
+ @projectCodeService.setValue(f.key,value,obj);
100
+ }
101
+ },{});
102
+ return obj;
103
+ }
11
104
 
12
105
  function getAllDocs(searchArgs,sort,tableId,roleId,orgId,loginId,permissions){
13
106
  var keyword = searchArgs.keyword;
@@ -74,6 +167,7 @@ function getDocsByIds(ids){
74
167
  }
75
168
 
76
169
  function main(){
170
+ taskParams = JSON.parse(taskParams);
77
171
  var templateId = taskParams.templateId;
78
172
 
79
173
  var template = owl_excel_templatesService.get(templateId);
@@ -108,13 +202,21 @@ function main(){
108
202
  docs = getAllDocs(searchArgs,sort,tableId,roleId,orgId,loginId,permissions);
109
203
  }
110
204
  else{
111
- var ids = params.ids;
205
+ var ids = taskParams.ids;
112
206
  docs = getDocsByIds(ids);
113
207
  }
208
+
209
+ for(var i=0; i<docs.length; i++){
210
+ var doc = docs[i];
211
+ doc = getExportDoc(doc);
212
+ docs[i] = doc;
213
+ }
214
+
114
215
  if(template.exportType==='doc'){
115
216
  if(outputTarget==='multifile'){
116
217
  for(var i=0; i<docs.length; i++){
117
218
  var exportDoc = docs[i];
219
+
118
220
  var fileId = Excel.generateExcelFromTemplate( templateUrl, exportDoc );
119
221
  if(template.toField){
120
222
  var id=exportDoc.id;
@@ -183,7 +285,6 @@ function main(){
183
285
  name:"" + docName
184
286
  }
185
287
  }
186
-
187
288
  owl_dfilesService.add(download);
188
289
  }
189
290
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owl-cli",
3
- "version": "6.79.0",
3
+ "version": "6.81.0",
4
4
  "main": "index.js",
5
5
  "preferGlobal": true,
6
6
  "bin": {