@gudhub/core 1.1.13 → 1.1.16
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/AppProcessor/AppProcessor.js +24 -1
- package/GUDHUB/FieldProcessor/FieldProcessor.js +7 -11
- package/GUDHUB/FieldProcessor/FieldProcessor.test.js +30 -1
- package/GUDHUB/GHConstructor/createAngularModuleInstance.js +28 -3
- package/GUDHUB/GHConstructor/createClassInstance.js +153 -138
- package/GUDHUB/GHConstructor/ghconstructor.js +11 -4
- package/GUDHUB/GHConstructor/ghconstructor.test.js +66 -0
- package/GUDHUB/ItemProcessor/ItemProcessor.js +16 -5
- package/GUDHUB/ItemProcessor/ItemProcessor.test.js +76 -0
- package/GUDHUB/PipeService/PipeService.test.js +9 -9
- package/GUDHUB/Storage/ModulesList.js +3 -2
- 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 +79 -2
- package/GUDHUB/config.js +4 -2
- package/GUDHUB/gudhub.js +3 -3
- package/Readme.md +347 -365
- package/fake_server/fake_java_server.js +63 -20
- package/package.json +5 -2
- package/umd/library.min.js +11 -11
- package/umd/library.min.js.map +1 -1
|
@@ -105,6 +105,16 @@ export class AppProcessor {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
saveAppInStorage(app) {
|
|
108
|
+
|
|
109
|
+
app.items_object = {};
|
|
110
|
+
|
|
111
|
+
for(let item = 0; item < app.items_list.length; item++) {
|
|
112
|
+
app.items_object[app.items_list[item].item_id] = {};
|
|
113
|
+
for(let field = 0; field < app.items_list[item].fields.length; field++) {
|
|
114
|
+
app.items_object[app.items_list[item].item_id][app.items_list[item].fields[field].field_id] = app.items_list[item].fields[field];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
108
118
|
const storageApp = this.storage.getApp(app.app_id);
|
|
109
119
|
if (storageApp) {
|
|
110
120
|
app.from_apps_list = storageApp.from_apps_list;
|
|
@@ -122,6 +132,7 @@ export class AppProcessor {
|
|
|
122
132
|
app.items_list = storageApp.items_list;
|
|
123
133
|
app.file_list = storageApp.file_list;
|
|
124
134
|
app.from_apps_list = storageApp.from_apps_list;
|
|
135
|
+
app.items_object =storageApp.items_object;
|
|
125
136
|
this.storage.updateApp(app);
|
|
126
137
|
//-- Sending updates for Views Updates
|
|
127
138
|
this.pipeService.emit(
|
|
@@ -167,6 +178,15 @@ export class AppProcessor {
|
|
|
167
178
|
try {
|
|
168
179
|
const app = await this.getAppApi(app_id);
|
|
169
180
|
if (app) {
|
|
181
|
+
app.items_object = {};
|
|
182
|
+
|
|
183
|
+
for(let item = 0; item < app.items_list.length; item++) {
|
|
184
|
+
app.items_object[app.items_list[item].item_id] = {};
|
|
185
|
+
for(let field = 0; field < app.items_list[item].fields.length; field++) {
|
|
186
|
+
app.items_object[app.items_list[item].item_id][app.items_list[item].fields[field].field_id] = app.items_list[item].fields[field];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
170
190
|
this.storage.updateApp(app);
|
|
171
191
|
}
|
|
172
192
|
} catch (err) {
|
|
@@ -254,7 +274,9 @@ export class AppProcessor {
|
|
|
254
274
|
}
|
|
255
275
|
}
|
|
256
276
|
|
|
257
|
-
|
|
277
|
+
// This code for trash must be changed
|
|
278
|
+
// return trash ? app : {...app, items_list: app.items_list.filter(item => !item.trash)};
|
|
279
|
+
return app;
|
|
258
280
|
}
|
|
259
281
|
|
|
260
282
|
async updateApp(app) {
|
|
@@ -282,6 +304,7 @@ export class AppProcessor {
|
|
|
282
304
|
|
|
283
305
|
async createNewApp(app) {
|
|
284
306
|
const newApp = await this.createNewAppApi(app);
|
|
307
|
+
newApp.items_object = {};
|
|
285
308
|
this.addNewAppToStorage(newApp);
|
|
286
309
|
return newApp;
|
|
287
310
|
}
|
|
@@ -77,11 +77,13 @@ export class FieldProcessor {
|
|
|
77
77
|
item.fields.forEach((field) => {
|
|
78
78
|
if (field.field_id == field_id) {
|
|
79
79
|
field.field_value = field_value;
|
|
80
|
+
app.items_object[item.item_id][field.field_id] = field;
|
|
80
81
|
}
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
});
|
|
84
85
|
this.storage.updateApp(app);
|
|
86
|
+
return field_value;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
async getField(app_id, field_id) {
|
|
@@ -116,16 +118,10 @@ export class FieldProcessor {
|
|
|
116
118
|
let fieldValue = null;
|
|
117
119
|
const app = await this.appProcessor.getApp(app_id);
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(field) => field.field_id == field_id
|
|
124
|
-
);
|
|
125
|
-
if (fundedField) {
|
|
126
|
-
fieldValue = fundedField.field_value;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
121
|
+
try {
|
|
122
|
+
fieldValue = app.items_object[item_id][field_id].field_value;
|
|
123
|
+
} catch(err) {
|
|
124
|
+
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
return fieldValue;
|
|
@@ -136,7 +132,7 @@ export class FieldProcessor {
|
|
|
136
132
|
return;
|
|
137
133
|
}
|
|
138
134
|
await this.setFieldValueApi(app_id, item_id, field_id, field_value);
|
|
139
|
-
this.updateFieldValue(app_id, item_id, field_id, field_value);
|
|
135
|
+
return this.updateFieldValue(app_id, item_id, field_id, field_value);
|
|
140
136
|
}
|
|
141
137
|
|
|
142
138
|
fieldListeners() {
|
|
@@ -10,7 +10,36 @@ describe("FIELD PROCESSOR", async function() {
|
|
|
10
10
|
var fieldModel = await gudhub.getField(16259, 254055);
|
|
11
11
|
fieldModel.data_type.should.equal('text');
|
|
12
12
|
(typeof fieldModel).should.equal('object');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('GET FIELD VALUE / should return a field value', async () => {
|
|
16
|
+
let value = await gudhub.getFieldValue(16259, 1064673, 254055);
|
|
17
|
+
value.should.equal('Hall up');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('UPDATE FIELD AND GET NEW VALUE / should return new field value', async () => {
|
|
21
|
+
await gudhub.setFieldValue(16259, 1064673, 254055, 'Updated value');
|
|
22
|
+
let value = await gudhub.getFieldValue(16259, 1064673, 254055);
|
|
23
|
+
value.should.equal('Updated value');
|
|
13
24
|
})
|
|
14
25
|
|
|
26
|
+
it('CREATE ITEM AND SET IT VALUE / should return new value of new item', async () => {
|
|
27
|
+
let items = await gudhub.addNewItems(16259, newItems);
|
|
28
|
+
let item_id = items[0].item_id;
|
|
29
|
+
|
|
30
|
+
await gudhub.setFieldValue(16259, item_id, 254056, 'Big Fish Tank');
|
|
31
|
+
|
|
32
|
+
let value = await gudhub.getFieldValue(16259, item_id, 254056);
|
|
33
|
+
|
|
34
|
+
value.should.equal('Big Fish Tank');
|
|
35
|
+
});
|
|
36
|
+
|
|
15
37
|
|
|
16
|
-
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const newItems = [
|
|
41
|
+
{
|
|
42
|
+
item_id: 0,
|
|
43
|
+
fields: []
|
|
44
|
+
},
|
|
45
|
+
]
|
|
@@ -73,7 +73,7 @@ let angular = {
|
|
|
73
73
|
/*** TODO ***/
|
|
74
74
|
// Need to make angular modules instances creation similar to pure js classes.
|
|
75
75
|
|
|
76
|
-
export default async function createAngularModuleInstance(module_id, module_url, angularInjector, nodeWindow) {
|
|
76
|
+
export default async function createAngularModuleInstance(gudhub, module_id, module_url, angularInjector, nodeWindow) {
|
|
77
77
|
|
|
78
78
|
try {
|
|
79
79
|
|
|
@@ -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.
|
|
@@ -196,7 +221,7 @@ export default async function createAngularModuleInstance(module_id, module_url,
|
|
|
196
221
|
let currentDataType = importedClass;
|
|
197
222
|
|
|
198
223
|
try {
|
|
199
|
-
let interpr_arr = await currentDataType.getInterpretation(value, appId, itemId, field, dataType);
|
|
224
|
+
let interpr_arr = await currentDataType.getInterpretation(gudhub, value, appId, itemId, field, dataType);
|
|
200
225
|
let data = interpr_arr.find((item) => item.id == interpretation_id) || interpr_arr.find((item) => item.id == 'default');
|
|
201
226
|
|
|
202
227
|
let result = await data.content()
|
|
@@ -1,187 +1,202 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { IS_WEB } from './../consts.js';
|
|
3
3
|
|
|
4
|
-
export default async function createClassInstance(module_id, js_url, css_url, nodeWindow) {
|
|
4
|
+
export default async function createClassInstance(gudhub, module_id, js_url, css_url, nodeWindow) {
|
|
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(gudhub, 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,16 +69,23 @@ 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') {
|
|
75
|
-
result = await createAngularModuleInstance(module_id, module.url, this.angularInjector, this.nodeWindow);
|
|
80
|
+
result = await createAngularModuleInstance(this.gudhub, module_id, module.url, this.angularInjector, this.nodeWindow);
|
|
76
81
|
} else if(module.type === 'class') {
|
|
77
|
-
result = await createClassInstance(module_id, module.js, module.css, this.nodeWindow);
|
|
82
|
+
result = await createClassInstance(this.gudhub, 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
|
+
// });
|