@gudhub/core 1.0.50 → 1.0.53
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/{Processors/AppProcessor → AppProcessor}/AppProcessor.js +1 -1
- package/GUDHUB/{Processors/AppProcessor → AppProcessor}/AppProcessor.test.js +1 -1
- package/GUDHUB/{Processors/AppProcessor → AppProcessor}/AppProcessorMocks.js +0 -0
- package/GUDHUB/{Managers/ChunksManager → ChunksManager}/ChunksManager.js +0 -0
- package/GUDHUB/{Managers/ChunksManager → ChunksManager}/ChunksManager.test.js +1 -1
- package/GUDHUB/{Managers/DocumentManager → DocumentManager}/DocumentManager.js +0 -0
- package/GUDHUB/{Processors/FieldProcessor → FieldProcessor}/FieldProcessor.js +44 -1
- package/GUDHUB/{Processors/FieldProcessor → FieldProcessor}/FieldProcessor.test.js +1 -1
- package/GUDHUB/{Processors/FieldProcessor → FieldProcessor}/Untitled-1.json +0 -0
- package/GUDHUB/{Processors/FieldProcessor → FieldProcessor}/field_processor.md +0 -0
- package/GUDHUB/{Managers/FileManager → FileManager}/FileManager.js +0 -0
- package/GUDHUB/{Managers/FileManager → FileManager}/file_manager.test.js +1 -1
- package/GUDHUB/GHConstructor/ghconstructor.js +238 -0
- package/GUDHUB/{Processors/ItemProcessor → ItemProcessor}/ItemProcessor.js +1 -1
- package/GUDHUB/{Processors/ItemProcessor → ItemProcessor}/item_processor.md +0 -0
- package/GUDHUB/Storage/ModulesList.js +413 -0
- package/GUDHUB/Storage/Storage.js +12 -1
- package/GUDHUB/gudhub.js +19 -12
- package/package.json +1 -1
- package/umd/library.min.js +21 -21
- package/umd/library.min.js.map +1 -1
- package/GUDHUB/Managers/managers.js +0 -5
- package/GUDHUB/Processors/processors.js +0 -5
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export class FieldProcessor {
|
|
2
|
-
constructor(storage, req, appProcessor, itemProcessor) {
|
|
2
|
+
constructor(storage, req, appProcessor, itemProcessor, pipeService) {
|
|
3
3
|
this.storage = storage;
|
|
4
4
|
this.req = req;
|
|
5
5
|
this.appProcessor = appProcessor;
|
|
6
6
|
this.itemProcessor = itemProcessor;
|
|
7
|
+
this.pipeService = pipeService;
|
|
8
|
+
this.fieldListeners();
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
deleteFieldApi(field_id) {
|
|
@@ -136,4 +138,45 @@ export class FieldProcessor {
|
|
|
136
138
|
await this.setFieldValueApi(app_id, item_id, field_id, field_value);
|
|
137
139
|
this.updateFieldValue(app_id, item_id, field_id, field_value);
|
|
138
140
|
}
|
|
141
|
+
|
|
142
|
+
fieldListeners() {
|
|
143
|
+
this.pipeService.onRoot('gh_value_get', {}, async (event, data) => {
|
|
144
|
+
if(data.app_id && data.item_id && data.field_id) {
|
|
145
|
+
let field_value = await this.getFieldValue(data.app_id, data.item_id, data.field_id);
|
|
146
|
+
this.pipeService.emit('gh_value_get', data, field_value);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
this.pipeService.onRoot('gh_value_set', {}, async (event, data) => {
|
|
151
|
+
if(data.item_id) {
|
|
152
|
+
this.setFieldValue(data.app_id, data.item_id, data.field_id, data.new_value);
|
|
153
|
+
delete data.new_value;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
this.pipeService.onRoot('gh_model_get', {}, async (event, data) => {
|
|
158
|
+
try {
|
|
159
|
+
let field_model = await this.getField(data.app_id, data.field_id);
|
|
160
|
+
this.pipeService.emit('gh_model_get', data, field_model)
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.log('Field model: ', error);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
this.pipeService.onRoot('gh_model_update', {}, async (event, data) => {
|
|
167
|
+
let field_model = await this.updateField(data.app_id, data.field_model);
|
|
168
|
+
this.pipeService.emit('gh_model_update', { app_id: data.app_id, field_id: data.field_id }, field_model);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
this.pipeService.onRoot('gh_models_get', {}, async (event, data) => {
|
|
172
|
+
let field_models = await this.getFieldModels(data.app_id);
|
|
173
|
+
this.pipeService.emit('gh_models_get', data, field_models);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
this.pipeService.onRoot('gh_model_delete', {}, async (event, data) => {
|
|
177
|
+
let status = await this.deleteField(data.app_id, data.field_id);
|
|
178
|
+
this.pipeService.emit('gh_model_delete', data, status);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
139
182
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
/*************** FAKE ANGULAR $Q ***************/
|
|
4
|
+
// It's needed when we eval() angular code.
|
|
5
|
+
|
|
6
|
+
let $q = {
|
|
7
|
+
when: function (a) {
|
|
8
|
+
return new Promise(resolve => {
|
|
9
|
+
resolve(a);
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class GHConstructor {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.cache = [];
|
|
17
|
+
this.modulesQueue = {};
|
|
18
|
+
this.angularInjector;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/*************** GET INSTANCE ***************/
|
|
22
|
+
// Firstly, check if module is loading right now in modules query.
|
|
23
|
+
// If not, check if module is in cache. If not, create new instance and put loading to modules query.
|
|
24
|
+
// If yes, return module from cache.
|
|
25
|
+
|
|
26
|
+
getInstance(module_id) {
|
|
27
|
+
return new Promise(async (resolve) => {
|
|
28
|
+
if (this.modulesQueue[module_id]) {
|
|
29
|
+
return this.modulesQueue[module_id].then(() => {
|
|
30
|
+
resolve(this.getCached(module_id));
|
|
31
|
+
});
|
|
32
|
+
} else if (!this.cache.find(module => module.type === module_id)) {
|
|
33
|
+
this.modulesQueue[module_id] = this.createInstance(module_id);
|
|
34
|
+
this.modulesQueue[module_id].then(() => {
|
|
35
|
+
resolve(this.getCached(module_id));
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
resolve(this.getCached(module_id));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/*************** PUT TO CACHE ***************/
|
|
44
|
+
// Just pushing module to cache.
|
|
45
|
+
|
|
46
|
+
pupToCache(module) {
|
|
47
|
+
this.cache.push(module);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*************** GET CACHED ***************/
|
|
51
|
+
// Find module in cache and return it.
|
|
52
|
+
|
|
53
|
+
getCached(module_id) {
|
|
54
|
+
return this.cache.find(module => module.type === module_id);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/*************** INIT ANGULAR INJECTOR ***************/
|
|
58
|
+
// Saves angular injector to this.angularInjector.
|
|
59
|
+
// It's needed to correctly takes module's functions, that uses angular services.
|
|
60
|
+
|
|
61
|
+
initAngularInjector(angularInjector) {
|
|
62
|
+
this.angularInjector = angularInjector;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/*************** CREATE INSTANCE ***************/
|
|
66
|
+
// Get angular module and module's code.
|
|
67
|
+
// Then parsing module's code.
|
|
68
|
+
// Finally, creating instance of module, using functions from angular module and parsed code.
|
|
69
|
+
|
|
70
|
+
async createInstance(module_id) {
|
|
71
|
+
let module_url = gudhub.storage.getModuleUrl(module_id);
|
|
72
|
+
let angularModule = await this.angularInjector.get(module_id);
|
|
73
|
+
let module = await axios.get(module_url);
|
|
74
|
+
module = module.data;
|
|
75
|
+
let returningObject = this.parseModule(module, module_id);
|
|
76
|
+
if(!returningObject) return false;
|
|
77
|
+
let obj;
|
|
78
|
+
eval('obj = ' + returningObject);
|
|
79
|
+
|
|
80
|
+
let result = {
|
|
81
|
+
type: module_id,
|
|
82
|
+
|
|
83
|
+
//*************** GET TEMPLATE ****************//
|
|
84
|
+
|
|
85
|
+
getTemplate: function (ref, changeFieldName, displayFieldName, field_model, appId, itemId) {
|
|
86
|
+
let displayFieldNameChecked = displayFieldName === 'false' ? false : true;
|
|
87
|
+
return obj.getTemplate(ref, changeFieldName, displayFieldNameChecked, field_model, appId, itemId);
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
//*************** GET DEFAULT VALUE ****************//
|
|
91
|
+
|
|
92
|
+
getDefaultValue: function (fieldModel, valuesArray, itemsList, currentAppId) {
|
|
93
|
+
return new Promise(async (resolve) => {
|
|
94
|
+
let getValueFunction = obj.getDefaultValue;
|
|
95
|
+
if (getValueFunction) {
|
|
96
|
+
let value = await getValueFunction(fieldModel, valuesArray, itemsList, currentAppId);
|
|
97
|
+
resolve(value);
|
|
98
|
+
} else {
|
|
99
|
+
resolve(null);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
//*************** GET SETTINGS ****************//
|
|
105
|
+
|
|
106
|
+
getSettings: function (scope, settingType, fieldModels) {
|
|
107
|
+
return angularModule.getSettings(scope, settingType, fieldModels);
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
//*************** FILTER****************//
|
|
111
|
+
|
|
112
|
+
filter: {
|
|
113
|
+
getSearchOptions: function (fieldModel) {
|
|
114
|
+
let d_type = obj;
|
|
115
|
+
if (d_type.filter && d_type.filter.getSearchOptions) {
|
|
116
|
+
return obj.filter.getSearchOptions(fieldModel);
|
|
117
|
+
}
|
|
118
|
+
return [];
|
|
119
|
+
},
|
|
120
|
+
getDropdownValues: function () {
|
|
121
|
+
let d_type = obj;
|
|
122
|
+
if (d_type.filter && d_type.filter.getDropdownValues) {
|
|
123
|
+
return d_type.filter.getDropdownValues();
|
|
124
|
+
} else {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
//*************** GET INTERPRETATION ****************//
|
|
131
|
+
|
|
132
|
+
getInterpretation: function (value, field, dataType, interpretation_id, itemId, appId) {
|
|
133
|
+
return new Promise(async (resolve) => {
|
|
134
|
+
let currentDataType = obj;
|
|
135
|
+
|
|
136
|
+
let interpr_arr = await currentDataType.getInterpretation(value, field, dataType, interpretation_id, itemId, appId);
|
|
137
|
+
if (interpr_arr) {
|
|
138
|
+
let data = interpr_arr.find((item) => item.id == interpretation_id) || interpr_arr.find((item) => item.id == 'default');
|
|
139
|
+
|
|
140
|
+
resolve({
|
|
141
|
+
html: data.html
|
|
142
|
+
})
|
|
143
|
+
} else {
|
|
144
|
+
resolve({
|
|
145
|
+
html: '<span>error(from constructor)</span>'
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
//*************** GET INTERPRETATED VALUE ****************//
|
|
152
|
+
|
|
153
|
+
getInterpretatedValue: function (field_value, field_model, appId, itemId) {
|
|
154
|
+
return new Promise(async (resolve) => {
|
|
155
|
+
let getInterpretatedValueFunction = obj.getInterpretatedValue;
|
|
156
|
+
if (getInterpretatedValueFunction) {
|
|
157
|
+
let value = await getInterpretatedValueFunction(field_value, field_model, appId, itemId);
|
|
158
|
+
resolve(value);
|
|
159
|
+
} else {
|
|
160
|
+
let value = await gudhub.getFieldValue(appId, itemId, field_model.id);
|
|
161
|
+
resolve(value);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
//*************** EXTEND CONTROLLER ****************//
|
|
167
|
+
|
|
168
|
+
extendController: function (actionScope) {
|
|
169
|
+
angularModule.getActionScope(actionScope);
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
//*************** RUN ACTION ****************//
|
|
173
|
+
|
|
174
|
+
runAction: function (scope) {
|
|
175
|
+
try {
|
|
176
|
+
angularModule.runAction(scope);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
//*************** GET WINDOW SCOPE ****************//
|
|
183
|
+
|
|
184
|
+
getWindowScope: function (windowScope) {
|
|
185
|
+
return angularModule.getWindowScope(windowScope);
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
//*************** GET WINDOW HTML ****************//
|
|
189
|
+
|
|
190
|
+
getWindowHTML: function (scope) {
|
|
191
|
+
return angularModule.getWindowHTML(scope);
|
|
192
|
+
},
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
this.pupToCache(result);
|
|
196
|
+
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/*************** PARSE MODULE ***************/
|
|
201
|
+
// Firstly, it's find factory with provided name.
|
|
202
|
+
// Then it's parsing factory's code, by counting open and closed brackets.
|
|
203
|
+
// Then returns object, which originally must be returned by factory.
|
|
204
|
+
|
|
205
|
+
parseModule(module, module_id) {
|
|
206
|
+
let factoryStart = module.indexOf(`.factory('${module_id}',`);
|
|
207
|
+
if(factoryStart === -1) {
|
|
208
|
+
factoryStart = module.indexOf(`.factory("${module_id}",`);
|
|
209
|
+
}
|
|
210
|
+
if(factoryStart !== -1) {
|
|
211
|
+
let factory = module.substring(factoryStart, module.length);
|
|
212
|
+
let returnStart = factory.indexOf('return');
|
|
213
|
+
let returningObject = factory.substring(returnStart, factory.length);
|
|
214
|
+
let firstBracket = returningObject.indexOf('{');
|
|
215
|
+
returningObject = returningObject.substring(firstBracket, returningObject.length);
|
|
216
|
+
let openBrackets = 0;
|
|
217
|
+
let closeBrackets = 0;
|
|
218
|
+
let returnEnd = 0;
|
|
219
|
+
for (let i = 0; i < returningObject.length; i++) {
|
|
220
|
+
if (returningObject[i] === '{') {
|
|
221
|
+
openBrackets++;
|
|
222
|
+
}
|
|
223
|
+
if (returningObject[i] === '}') {
|
|
224
|
+
closeBrackets++;
|
|
225
|
+
}
|
|
226
|
+
if (openBrackets === closeBrackets && i >= firstBracket) {
|
|
227
|
+
returnEnd = i;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
returningObject = returningObject.substring(0, returnEnd + 1);
|
|
232
|
+
return returningObject;
|
|
233
|
+
} else {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
}
|
|
File without changes
|