@gudhub/core 1.1.13 → 1.1.14
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.
- package/GUDHUB/GHConstructor/createAngularModuleInstance.js +26 -1
- package/GUDHUB/GHConstructor/createClassInstance.js +152 -137
- package/GUDHUB/GHConstructor/ghconstructor.js +9 -2
- package/GUDHUB/GHConstructor/ghconstructor.test.js +66 -0
- package/GUDHUB/Utils/AppsTemplateService/AppsTemplateService.js +74 -66
- package/GUDHUB/Utils/json_constructor/json_constructor.js +1 -1
- package/GUDHUB/Utils/json_constructor/json_constructor.test.js +62 -0
- package/package.json +4 -2
- package/umd/library.min.js +5 -5
- package/umd/library.min.js.map +1 -1
|
@@ -106,13 +106,37 @@ export default async function createAngularModuleInstance(module_id, module_url,
|
|
|
106
106
|
|
|
107
107
|
} else {
|
|
108
108
|
|
|
109
|
+
const proxy = new Proxy(nodeWindow, {
|
|
110
|
+
get: (target, property) => {
|
|
111
|
+
return target[property]
|
|
112
|
+
},
|
|
113
|
+
set: (target, property, value) => {
|
|
114
|
+
target[property] = value;
|
|
115
|
+
global[property] = value;
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
109
120
|
// If node's global object don't have window and it's methods yet - set it.
|
|
110
121
|
if (!global.hasOwnProperty('window')) {
|
|
111
|
-
global.window =
|
|
122
|
+
global.window = proxy;
|
|
112
123
|
global.document = nodeWindow.document;
|
|
113
124
|
global.Element = nodeWindow.Element;
|
|
125
|
+
global.CharacterData = nodeWindow.CharacterData;
|
|
126
|
+
global.this = proxy;
|
|
127
|
+
global.self = proxy;
|
|
128
|
+
global.Blob = nodeWindow.Blob;
|
|
129
|
+
global.Node = nodeWindow.Node;
|
|
114
130
|
global.navigator = nodeWindow.navigator;
|
|
115
131
|
global.HTMLElement = nodeWindow.HTMLElement;
|
|
132
|
+
global.XMLHttpRequest = nodeWindow.XMLHttpRequest;
|
|
133
|
+
global.WebSocket = nodeWindow.WebSocket;
|
|
134
|
+
global.crypto = nodeWindow.crypto;
|
|
135
|
+
global.DOMParser = nodeWindow.DOMParser;
|
|
136
|
+
global.Symbol = nodeWindow.Symbol;
|
|
137
|
+
global.document.queryCommandSupported = (command) => {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
116
140
|
global.angular = angular;
|
|
117
141
|
}
|
|
118
142
|
|
|
@@ -131,6 +155,7 @@ export default async function createAngularModuleInstance(module_id, module_url,
|
|
|
131
155
|
module = await import(/* webpackIgnore: true */encodedCode);
|
|
132
156
|
} catch (err) {
|
|
133
157
|
console.log(`Error while importing module: ${module_id}`);
|
|
158
|
+
console.log(err);
|
|
134
159
|
}
|
|
135
160
|
|
|
136
161
|
// Modules always exports classes as default, so we create new class instance.
|
|
@@ -5,183 +5,198 @@ export default async function createClassInstance(module_id, js_url, css_url, no
|
|
|
5
5
|
|
|
6
6
|
try {
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// Check if there is url to javascript file of module
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// Import module using dynamic import
|
|
15
|
-
|
|
16
|
-
let downloadModule = (url) => {
|
|
17
|
-
if (!IS_WEB && !global.hasOwnProperty('window')) {
|
|
18
|
-
global.window = nodeWindow;
|
|
19
|
-
global.document = nodeWindow.document;
|
|
20
|
-
global.Element = nodeWindow.Element;
|
|
21
|
-
global.navigator = nodeWindow.navigator;
|
|
22
|
-
global.HTMLElement = nodeWindow.HTMLElement;
|
|
10
|
+
if (!js_url) {
|
|
11
|
+
console.error(`JS link must be provided for this data type - ${module_id}`);
|
|
23
12
|
}
|
|
24
|
-
return new Promise(async (resolve) => {
|
|
25
|
-
let moduleData = await axios.get(url).catch(err => {
|
|
26
|
-
console.log(`Failed to fetch: ${url} in ghconstructor. Module id: ${module_id}`);
|
|
27
|
-
})
|
|
28
13
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
// Import module using dynamic import
|
|
15
|
+
|
|
16
|
+
let downloadModule = (url) => {
|
|
17
|
+
if (!IS_WEB && !global.hasOwnProperty('window')) {
|
|
18
|
+
global.window = proxy;
|
|
19
|
+
global.document = nodeWindow.document;
|
|
20
|
+
global.Element = nodeWindow.Element;
|
|
21
|
+
global.CharacterData = nodeWindow.CharacterData;
|
|
22
|
+
global.this = proxy;
|
|
23
|
+
global.self = proxy;
|
|
24
|
+
global.Blob = nodeWindow.Blob;
|
|
25
|
+
global.Node = nodeWindow.Node;
|
|
26
|
+
global.navigator = nodeWindow.navigator;
|
|
27
|
+
global.HTMLElement = nodeWindow.HTMLElement;
|
|
28
|
+
global.XMLHttpRequest = nodeWindow.XMLHttpRequest;
|
|
29
|
+
global.WebSocket = nodeWindow.WebSocket;
|
|
30
|
+
global.crypto = nodeWindow.crypto;
|
|
31
|
+
global.DOMParser = nodeWindow.DOMParser;
|
|
32
|
+
global.Symbol = nodeWindow.Symbol;
|
|
33
|
+
global.document.queryCommandSupported = (command) => {
|
|
34
|
+
console.log('QUERY COMMAND SUPPORTED: ', command);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
global.angular = angular;
|
|
38
|
+
}
|
|
39
|
+
return new Promise(async (resolve) => {
|
|
40
|
+
let moduleData = await axios.get(url).catch(err => {
|
|
41
|
+
console.log(`Failed to fetch: ${url} in ghconstructor. Module id: ${module_id}`);
|
|
42
|
+
})
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
let encodedJs = encodeURIComponent(moduleData.data);
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
let dataUri = 'data:text/javascript;charset=utf-8,' + encodedJs;
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
console.log(`Error while importing module: ${module_id}`);
|
|
45
|
-
console.log(err);
|
|
46
|
-
}
|
|
48
|
+
resolve(dataUri);
|
|
49
|
+
})
|
|
50
|
+
}
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
let moduleData = await downloadModule(js_url);
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
let module;
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
try {
|
|
57
|
+
module = await import(/* webpackIgnore: true */moduleData);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.log(`Error while importing module: ${module_id}`);
|
|
60
|
+
console.log(err);
|
|
61
|
+
}
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
const linkTag = document.createElement('link');
|
|
57
|
-
linkTag.href = css_url;
|
|
58
|
-
linkTag.setAttribute('data-module', module_id);
|
|
59
|
-
linkTag.setAttribute('rel', 'stylesheet');
|
|
60
|
-
document.getElementsByTagName('head')[0].appendChild(linkTag);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let result = {
|
|
64
|
-
type: module_id,
|
|
63
|
+
// Creating class from imported module
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
let importedClass = new module.default(module_id);
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return importedClass.getTemplate(ref, changeFieldName, displayFieldNameChecked, field_model, appId, itemId);
|
|
71
|
-
},
|
|
67
|
+
// Check if there is url to css file of module
|
|
68
|
+
// If true, and there is no css for this data type, than create link tag to this css in head
|
|
72
69
|
|
|
73
|
-
|
|
70
|
+
if (css_url && IS_WEB) {
|
|
71
|
+
const linkTag = document.createElement('link');
|
|
72
|
+
linkTag.href = css_url;
|
|
73
|
+
linkTag.setAttribute('data-module', module_id);
|
|
74
|
+
linkTag.setAttribute('rel', 'stylesheet');
|
|
75
|
+
document.getElementsByTagName('head')[0].appendChild(linkTag);
|
|
76
|
+
}
|
|
74
77
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let getValueFunction = importedClass.getDefaultValue;
|
|
78
|
-
if (getValueFunction) {
|
|
79
|
-
let value = await getValueFunction(fieldModel, valuesArray, itemsList, currentAppId);
|
|
80
|
-
resolve(value);
|
|
81
|
-
} else {
|
|
82
|
-
resolve(null);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
},
|
|
78
|
+
let result = {
|
|
79
|
+
type: module_id,
|
|
86
80
|
|
|
87
|
-
|
|
81
|
+
//*************** GET TEMPLATE ****************//
|
|
88
82
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
getTemplate: function (ref, changeFieldName, displayFieldName, field_model, appId, itemId) {
|
|
84
|
+
let displayFieldNameChecked = displayFieldName === 'false' ? false : true;
|
|
85
|
+
return importedClass.getTemplate(ref, changeFieldName, displayFieldNameChecked, field_model, appId, itemId);
|
|
86
|
+
},
|
|
92
87
|
|
|
93
|
-
|
|
88
|
+
//*************** GET DEFAULT VALUE ****************//
|
|
89
|
+
|
|
90
|
+
getDefaultValue: function (fieldModel, valuesArray, itemsList, currentAppId) {
|
|
91
|
+
return new Promise(async (resolve) => {
|
|
92
|
+
let getValueFunction = importedClass.getDefaultValue;
|
|
93
|
+
if (getValueFunction) {
|
|
94
|
+
let value = await getValueFunction(fieldModel, valuesArray, itemsList, currentAppId);
|
|
95
|
+
resolve(value);
|
|
96
|
+
} else {
|
|
97
|
+
resolve(null);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
},
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return importedClass.filter.getSearchOptions(fieldModel);
|
|
100
|
-
}
|
|
101
|
-
return [];
|
|
102
|
+
//*************** GET SETTINGS ****************//
|
|
103
|
+
|
|
104
|
+
getSettings: function (scope, settingType, fieldModels) {
|
|
105
|
+
return importedClass.getSettings(scope, settingType, fieldModels);
|
|
102
106
|
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
|
|
108
|
+
//*************** FILTER****************//
|
|
109
|
+
|
|
110
|
+
filter: {
|
|
111
|
+
getSearchOptions: function (fieldModel) {
|
|
112
|
+
let d_type = importedClass;
|
|
113
|
+
if (d_type.filter && d_type.filter.getSearchOptions) {
|
|
114
|
+
return importedClass.filter.getSearchOptions(fieldModel);
|
|
115
|
+
}
|
|
108
116
|
return [];
|
|
117
|
+
},
|
|
118
|
+
getDropdownValues: function () {
|
|
119
|
+
let d_type = importedClass;
|
|
120
|
+
if (d_type.filter && d_type.filter.getDropdownValues) {
|
|
121
|
+
return d_type.filter.getDropdownValues();
|
|
122
|
+
} else {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
109
125
|
}
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
//*************** GET INTERPRETATION ****************//
|
|
126
|
+
},
|
|
114
127
|
|
|
115
|
-
|
|
116
|
-
return new Promise(async (resolve) => {
|
|
117
|
-
let currentDataType = importedClass;
|
|
128
|
+
//*************** GET INTERPRETATION ****************//
|
|
118
129
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
let
|
|
130
|
+
getInterpretation: function (value, interpretation_id, dataType, field, itemId, appId) {
|
|
131
|
+
return new Promise(async (resolve) => {
|
|
132
|
+
let currentDataType = importedClass;
|
|
122
133
|
|
|
123
|
-
|
|
134
|
+
try {
|
|
135
|
+
let interpr_arr = await currentDataType.getInterpretation(value, appId, itemId, field, dataType);
|
|
136
|
+
let data = interpr_arr.find((item) => item.id == interpretation_id) || interpr_arr.find((item) => item.id == 'default');
|
|
124
137
|
|
|
125
|
-
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.log(`ERROR IN ${module_id}`, error);
|
|
128
|
-
resolve({ html: '<span>no interpretation</span>' })
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
},
|
|
138
|
+
let result = await data.content()
|
|
132
139
|
|
|
133
|
-
|
|
140
|
+
resolve({ html: result });
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.log(`ERROR IN ${module_id}`, error);
|
|
143
|
+
resolve({ html: '<span>no interpretation</span>' })
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
},
|
|
134
147
|
|
|
135
|
-
|
|
136
|
-
return importedClass.getInterpretation(field_value, appId, itemId, field);
|
|
137
|
-
},
|
|
148
|
+
//*************** GET INTERPRETATIONS LIST ****************//
|
|
138
149
|
|
|
139
|
-
|
|
150
|
+
getInterpretationsList: function (field_value, appId, itemId, field) {
|
|
151
|
+
return importedClass.getInterpretation(field_value, appId, itemId, field);
|
|
152
|
+
},
|
|
140
153
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
let
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
//*************** GET INTERPRETATED VALUE ****************//
|
|
155
|
+
|
|
156
|
+
getInterpretatedValue: function (field_value, field_model, appId, itemId) {
|
|
157
|
+
return new Promise(async (resolve) => {
|
|
158
|
+
let getInterpretatedValueFunction = importedClass.getInterpretatedValue;
|
|
159
|
+
if (getInterpretatedValueFunction) {
|
|
160
|
+
let value = await getInterpretatedValueFunction(field_value, field_model, appId, itemId);
|
|
161
|
+
resolve(value);
|
|
162
|
+
} else {
|
|
163
|
+
resolve(field_value);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
},
|
|
152
167
|
|
|
153
|
-
|
|
168
|
+
//*************** EXTEND CONTROLLER ****************//
|
|
154
169
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
170
|
+
extendController: function (actionScope) {
|
|
171
|
+
importedClass.getActionScope(actionScope);
|
|
172
|
+
},
|
|
158
173
|
|
|
159
|
-
|
|
174
|
+
//*************** RUN ACTION ****************//
|
|
160
175
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
176
|
+
runAction: function (scope) {
|
|
177
|
+
try {
|
|
178
|
+
importedClass.runAction(scope);
|
|
179
|
+
} catch (e) {
|
|
165
180
|
|
|
166
|
-
|
|
167
|
-
|
|
181
|
+
}
|
|
182
|
+
},
|
|
168
183
|
|
|
169
|
-
|
|
184
|
+
//*************** GET WINDOW SCOPE ****************//
|
|
170
185
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
186
|
+
getWindowScope: function (windowScope) {
|
|
187
|
+
return importedClass.getWindowScope(windowScope);
|
|
188
|
+
},
|
|
174
189
|
|
|
175
|
-
|
|
190
|
+
//*************** GET WINDOW HTML ****************//
|
|
176
191
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
192
|
+
getWindowHTML: function (scope) {
|
|
193
|
+
return importedClass.getWindowHTML(scope);
|
|
194
|
+
},
|
|
195
|
+
}
|
|
181
196
|
|
|
182
|
-
|
|
197
|
+
return result;
|
|
183
198
|
|
|
184
|
-
} catch(err) {
|
|
199
|
+
} catch (err) {
|
|
185
200
|
console.log(err);
|
|
186
201
|
console.log(`Failed in createClassInstance (ghconstructor). Module id: ${module_id}. JS url: ${js_url}`);
|
|
187
202
|
}
|
|
@@ -69,6 +69,11 @@ export class GHConstructor {
|
|
|
69
69
|
|
|
70
70
|
async createInstance(module_id) {
|
|
71
71
|
let module = this.gudhub.storage.getModuleUrl(module_id);
|
|
72
|
+
|
|
73
|
+
if(!module) {
|
|
74
|
+
console.log(`Cannot find module: ${module_id}`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
72
77
|
|
|
73
78
|
let result;
|
|
74
79
|
if (module.type === 'angular') {
|
|
@@ -77,8 +82,10 @@ export class GHConstructor {
|
|
|
77
82
|
result = await createClassInstance(module_id, module.js, module.css, this.nodeWindow);
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
if(result) {
|
|
86
|
+
this.pupToCache(result);
|
|
87
|
+
}
|
|
88
|
+
|
|
82
89
|
return result;
|
|
83
90
|
}
|
|
84
91
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// import should from "should";
|
|
2
|
+
// import sinon from "sinon";
|
|
3
|
+
// import {GudHub} from './../gudhub.js';
|
|
4
|
+
// import { JSDOM } from 'jsdom';
|
|
5
|
+
|
|
6
|
+
// describe("GHConstructor", () => {
|
|
7
|
+
|
|
8
|
+
// before(() => {
|
|
9
|
+
// sinon.stub(console, 'info') // disable console.info
|
|
10
|
+
// sinon.stub(console, 'warn') // disable console.warn
|
|
11
|
+
// sinon.stub(console, 'error') // disable console.error
|
|
12
|
+
// // sinon.stub(console, 'log') // disable console.error
|
|
13
|
+
// })
|
|
14
|
+
|
|
15
|
+
// it('CREATE INSTANCES FOR ALL DATA TYPES', async () => {
|
|
16
|
+
// const gudhub = new GudHub('o5A10WgXdFpvzJYt0tp6gQaIqF52vPqlbONtjq6yvCSaqr7AtDHGzIS6/9uqJgNhw0Bh5ttE8ft2xQ5xaZ5fHA==', {
|
|
17
|
+
// server_url: 'https://gudhub.com/GudHub_Test',
|
|
18
|
+
// async_modules_path: 'build/async_modules_node/',
|
|
19
|
+
// file_server_url: 'http://localhost:8080'
|
|
20
|
+
// });
|
|
21
|
+
|
|
22
|
+
// const jsdom = new JSDOM('', {
|
|
23
|
+
// url: 'http://localhost:1234',
|
|
24
|
+
// runScripts: 'dangerously'
|
|
25
|
+
// });
|
|
26
|
+
|
|
27
|
+
// const { window } = jsdom;
|
|
28
|
+
|
|
29
|
+
// gudhub.ghconstructor.initJsdomWindow(window);
|
|
30
|
+
|
|
31
|
+
// let instance = await gudhub.ghconstructor.getInstance('vs_code');
|
|
32
|
+
|
|
33
|
+
// if(instance) {
|
|
34
|
+
// console.log('DONE!');
|
|
35
|
+
// }
|
|
36
|
+
|
|
37
|
+
// // let modulesList = gudhub.storage.modulesList;
|
|
38
|
+
// // let modulesObj = {};
|
|
39
|
+
|
|
40
|
+
// // modulesList.forEach(item => {
|
|
41
|
+
// // modulesObj[item.name] = false
|
|
42
|
+
// // });
|
|
43
|
+
|
|
44
|
+
// // const promises = [];
|
|
45
|
+
|
|
46
|
+
// // for(let i = 0; i < modulesList.length; i++) {
|
|
47
|
+
// // promises.push(new Promise(async (resolve) => {
|
|
48
|
+
// // try {
|
|
49
|
+
// // gudhub.ghconstructor.getInstance(modulesList[i].name).then(() => {
|
|
50
|
+
// // modulesObj[modulesList[i].name] = true;
|
|
51
|
+
// // })
|
|
52
|
+
// // resolve(true);
|
|
53
|
+
// // } catch(err) {
|
|
54
|
+
// // console.log('ERR!');
|
|
55
|
+
// // resolve(false);
|
|
56
|
+
// // }
|
|
57
|
+
// // }));
|
|
58
|
+
// // }
|
|
59
|
+
|
|
60
|
+
// // Promise.all(promises).then(() => {
|
|
61
|
+
// // console.log('ALL DONE!');
|
|
62
|
+
// // console.log('MODULES: ', modulesObj);
|
|
63
|
+
// // });
|
|
64
|
+
|
|
65
|
+
// });
|
|
66
|
+
// });
|
|
@@ -23,7 +23,7 @@ export default class AppsTemplateService {
|
|
|
23
23
|
})
|
|
24
24
|
}).then(success => {
|
|
25
25
|
self.createItems(success, maxNumberOfInsstalledItems, (status) => {
|
|
26
|
-
if(typeof status === 'string') {
|
|
26
|
+
if (typeof status === 'string') {
|
|
27
27
|
currentStep += 1;
|
|
28
28
|
progressCallback.call(this, {
|
|
29
29
|
percent: currentStep * stepPercents,
|
|
@@ -51,67 +51,67 @@ export default class AppsTemplateService {
|
|
|
51
51
|
|
|
52
52
|
create_apps.forEach(app => {
|
|
53
53
|
promises.push(new Promise(app_resolve => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
self.gudhub.getApp(self._searchOldAppId(app.app_id, self.appsConnectingMap.apps)).then(result_app => {
|
|
55
|
+
callback ? callback.call(this, `GET APP: ${result_app.app_name} (Items steps)`) : null;
|
|
56
|
+
let source_app = JSON.parse(JSON.stringify(result_app));
|
|
57
|
+
let items = source_app.items_list.map(item => {
|
|
58
|
+
return {
|
|
59
|
+
index_number: item.index_number,
|
|
60
|
+
item_id: 0,
|
|
61
|
+
fields: []
|
|
62
|
+
}
|
|
63
|
+
}).filter((item, index) => index <= MAX_NUMBER_OF_INSTALLED_ITEMS);
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
self.gudhub.addNewItems(app.app_id, items).then(items => {
|
|
66
|
+
callback ? callback.call(this, `ADD NEW ITEMS: ${result_app.app_name} (Items steps)`) : null;
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
if (items.length === 0) {
|
|
69
|
+
callback ? callback.call(this, `NO ITEMS TO REPLACE VALUE: ${result_app.app_name} (Items steps)`) : null;
|
|
70
|
+
app_resolve();
|
|
71
|
+
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
app.items_list = items;
|
|
74
|
+
self._updateMap(app.items_list, source_app.items_list);
|
|
75
|
+
self._addFieldValue(source_app.items_list, app.items_list, self.appsConnectingMap);
|
|
76
|
+
|
|
77
|
+
createsItems.push(app);
|
|
78
|
+
|
|
79
|
+
if (self.appsConnectingMap.apps.length === createsItems.length) {
|
|
80
|
+
createsItems.forEach(app => {
|
|
81
|
+
app.items_list.forEach(item => {
|
|
82
|
+
item.fields.forEach(field_item => {
|
|
83
|
+
self.appsConnectingMap.fields.forEach(field_map => {
|
|
84
|
+
if (field_item.field_id === field_map.old_field_id) {
|
|
85
|
+
field_item.field_id = field_map.new_field_id;
|
|
86
|
+
field_item.element_id = field_map.new_field_id;
|
|
87
|
+
}
|
|
88
|
+
})
|
|
88
89
|
})
|
|
89
90
|
})
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
self.deleteField(createsItems);
|
|
94
|
+
|
|
95
|
+
self.replaceValue(createsItems, self.appsConnectingMap).then(() => {
|
|
96
|
+
callback ? callback.call(this, `REPLACE VALUE: ${result_app.app_name} (Items steps)`) : null;
|
|
97
|
+
createsItems.forEach(created_app => {
|
|
98
|
+
let newItems = created_app.items_list.map(item => {
|
|
99
|
+
item.fields.forEach(field => {
|
|
100
|
+
delete field.data_id;
|
|
101
|
+
});
|
|
102
|
+
return item;
|
|
101
103
|
});
|
|
102
|
-
return item;
|
|
103
|
-
});
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
self.gudhub.updateItems(created_app.app_id, newItems).then(() => {
|
|
106
|
+
app_resolve();
|
|
107
|
+
})
|
|
107
108
|
})
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
111
112
|
});
|
|
112
|
-
});
|
|
113
|
-
})
|
|
114
|
-
});
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
115
|
|
|
116
116
|
Promise.all(promises).then(() => {
|
|
117
117
|
let apps = create_apps.map(app => {
|
|
@@ -144,24 +144,32 @@ export default class AppsTemplateService {
|
|
|
144
144
|
self._replaceValueItemRef(app, field_of_list, map);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
allPromises.push(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
allPromises.push(new Promise(resolve => {
|
|
148
|
+
self.gudhub.ghconstructor.getInstance(field_of_list.data_type).then(data => {
|
|
149
|
+
if(typeof data === 'undefined') {
|
|
150
|
+
console.log('ERROR WHILE GETTING INSTANCE OF ', field_of_list.data_type);
|
|
151
|
+
resolve({
|
|
152
|
+
type: field_of_list.data_type
|
|
153
|
+
});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (data.getTemplate().constructor == 'file') {
|
|
157
|
+
return self.gudhub.util.fileInstallerHelper(app.app_id, app.items_list, field_of_list.field_id).then(result => {
|
|
158
|
+
resolve(result);
|
|
159
|
+
});
|
|
160
|
+
} else if (data.getTemplate().constructor == 'document') {
|
|
161
|
+
self.documentInstallerHelper(app.app_id, app.items_list, field_of_list.field_id).then(result => {
|
|
162
|
+
resolve(data);
|
|
163
|
+
})
|
|
164
|
+
} else {
|
|
165
|
+
resolve(data);
|
|
166
|
+
}
|
|
155
167
|
})
|
|
156
|
-
} else {
|
|
157
|
-
return data;
|
|
158
|
-
}
|
|
159
168
|
}))
|
|
160
|
-
|
|
161
169
|
})
|
|
162
170
|
});
|
|
163
171
|
|
|
164
|
-
if(allPromises.length > 0) {
|
|
172
|
+
if (allPromises.length > 0) {
|
|
165
173
|
|
|
166
174
|
Promise.all(allPromises).then(result => {
|
|
167
175
|
resolve(result);
|