@gudhub/core 1.0.57 → 1.0.58
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/ghconstructor.js +79 -54
- package/GUDHUB/GHConstructor/interpritate.js +90 -0
- package/GUDHUB/Storage/ModulesList.js +4 -0
- package/GUDHUB/Storage/Storage.js +1 -0
- package/GUDHUB/Utils/Utils.js +2 -2
- package/GUDHUB/Utils/get_date/get_date.test.js +12 -0
- package/GUDHUB/Utils/merge_objects/merge_objects.js +2 -0
- package/GUDHUB/Utils/nested_list/nested_list.js +6 -10
- package/GUDHUB/Utils/nested_list/nested_list.test.js +37 -0
- package/GUDHUB/gudhub.js +22 -0
- package/package.json +1 -1
- package/umd/library.min.js +9 -7
- package/umd/library.min.js.map +1 -1
|
@@ -11,6 +11,57 @@ let $q = {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/*************** FAKE ANGULAR ***************/
|
|
15
|
+
// It's needed when we eval() angular code.
|
|
16
|
+
|
|
17
|
+
let factoryReturns = {};
|
|
18
|
+
|
|
19
|
+
let angular = {
|
|
20
|
+
module() {
|
|
21
|
+
return angular;
|
|
22
|
+
},
|
|
23
|
+
directive() {
|
|
24
|
+
return angular;
|
|
25
|
+
},
|
|
26
|
+
factory(name, args) {
|
|
27
|
+
try {
|
|
28
|
+
if(typeof args === 'object') {
|
|
29
|
+
factoryReturns[name] = args[args.length - 1]($q);
|
|
30
|
+
} else {
|
|
31
|
+
factoryReturns[name] = args($q);
|
|
32
|
+
}
|
|
33
|
+
} catch(error) {
|
|
34
|
+
console.log('Errror in data type: ', name);
|
|
35
|
+
console.log(error);
|
|
36
|
+
}
|
|
37
|
+
return angular;
|
|
38
|
+
},
|
|
39
|
+
service() {
|
|
40
|
+
return angular;
|
|
41
|
+
},
|
|
42
|
+
run() {
|
|
43
|
+
return angular;
|
|
44
|
+
},
|
|
45
|
+
filter() {
|
|
46
|
+
return angular;
|
|
47
|
+
},
|
|
48
|
+
controller() {
|
|
49
|
+
return angular;
|
|
50
|
+
},
|
|
51
|
+
value() {
|
|
52
|
+
return angular;
|
|
53
|
+
},
|
|
54
|
+
element() {
|
|
55
|
+
return angular;
|
|
56
|
+
},
|
|
57
|
+
injector() {
|
|
58
|
+
return angular;
|
|
59
|
+
},
|
|
60
|
+
invoke() {
|
|
61
|
+
return angular;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
14
65
|
export class GHConstructor {
|
|
15
66
|
constructor() {
|
|
16
67
|
this.cache = [];
|
|
@@ -23,7 +74,7 @@ export class GHConstructor {
|
|
|
23
74
|
// If not, check if module is in cache. If not, create new instance and put loading to modules query.
|
|
24
75
|
// If yes, return module from cache.
|
|
25
76
|
|
|
26
|
-
getInstance(module_id) {
|
|
77
|
+
async getInstance(module_id) {
|
|
27
78
|
return new Promise(async (resolve) => {
|
|
28
79
|
if (this.modulesQueue[module_id]) {
|
|
29
80
|
return this.modulesQueue[module_id].then(() => {
|
|
@@ -64,8 +115,8 @@ export class GHConstructor {
|
|
|
64
115
|
|
|
65
116
|
/*************** CREATE INSTANCE ***************/
|
|
66
117
|
// Get angular module and module's code.
|
|
67
|
-
// Then
|
|
68
|
-
// Finally, creating instance of module, using functions from angular module and
|
|
118
|
+
// Then eval() module's code.
|
|
119
|
+
// Finally, creating instance of module, using functions from angular module and evaled code.
|
|
69
120
|
|
|
70
121
|
async createInstance(module_id) {
|
|
71
122
|
let module_url = gudhub.storage.getModuleUrl(module_id);
|
|
@@ -78,14 +129,8 @@ export class GHConstructor {
|
|
|
78
129
|
|
|
79
130
|
let module = await axios.get(module_url);
|
|
80
131
|
module = module.data;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let obj;
|
|
84
|
-
try {
|
|
85
|
-
eval('obj = ' + returningObject);
|
|
86
|
-
} catch(error) {
|
|
87
|
-
console.log(`Error in ghconstructor (${module_id})`, error);
|
|
88
|
-
}
|
|
132
|
+
|
|
133
|
+
eval(module);
|
|
89
134
|
|
|
90
135
|
let result = {
|
|
91
136
|
type: module_id,
|
|
@@ -141,7 +186,7 @@ export class GHConstructor {
|
|
|
141
186
|
|
|
142
187
|
getInterpretation: function (value, field, dataType, interpretation_id, itemId, appId) {
|
|
143
188
|
return new Promise(async (resolve) => {
|
|
144
|
-
let currentDataType =
|
|
189
|
+
let currentDataType = angularModule;
|
|
145
190
|
|
|
146
191
|
let interpr_arr = await currentDataType.getInterpretation(value, field, dataType, interpretation_id, itemId, appId);
|
|
147
192
|
if (interpr_arr) {
|
|
@@ -158,17 +203,36 @@ export class GHConstructor {
|
|
|
158
203
|
});
|
|
159
204
|
},
|
|
160
205
|
|
|
206
|
+
//*************** GET INTERPRETATION V2 ****************//
|
|
207
|
+
|
|
208
|
+
getInterpretationNew: function(value, interpretation_id, dataType, field, itemId, appId) {
|
|
209
|
+
return new Promise(async (resolve) => {
|
|
210
|
+
let currentDataType = factoryReturns[module_id];
|
|
211
|
+
|
|
212
|
+
try {
|
|
213
|
+
let interpr_arr = await currentDataType.getInterpretationNew(value, appId, itemId, field, dataType);
|
|
214
|
+
let data = interpr_arr.find((item) => item.id == interpretation_id) || interpr_arr.find((item) => item.id == 'default');
|
|
215
|
+
|
|
216
|
+
let result = await data.content()
|
|
217
|
+
|
|
218
|
+
resolve({ html: result });
|
|
219
|
+
} catch(error) {
|
|
220
|
+
console.log(`ERROR IN ${module_id}`, error);
|
|
221
|
+
resolve({ html: '<span>no interpretation</span>' })
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
|
|
161
226
|
//*************** GET INTERPRETATED VALUE ****************//
|
|
162
227
|
|
|
163
228
|
getInterpretatedValue: function (field_value, field_model, appId, itemId) {
|
|
164
229
|
return new Promise(async (resolve) => {
|
|
165
|
-
let getInterpretatedValueFunction =
|
|
230
|
+
let getInterpretatedValueFunction = factoryReturns[module_id].getInterpretatedValue;
|
|
166
231
|
if (getInterpretatedValueFunction) {
|
|
167
232
|
let value = await getInterpretatedValueFunction(field_value, field_model, appId, itemId);
|
|
168
233
|
resolve(value);
|
|
169
234
|
} else {
|
|
170
|
-
|
|
171
|
-
resolve(value);
|
|
235
|
+
resolve(field_value);
|
|
172
236
|
}
|
|
173
237
|
});
|
|
174
238
|
},
|
|
@@ -206,43 +270,4 @@ export class GHConstructor {
|
|
|
206
270
|
|
|
207
271
|
return result;
|
|
208
272
|
}
|
|
209
|
-
|
|
210
|
-
/*************** PARSE MODULE ***************/
|
|
211
|
-
// Firstly, it's find factory with provided name.
|
|
212
|
-
// Then it's parsing factory's code, by counting open and closed brackets.
|
|
213
|
-
// Then returns object, which originally must be returned by factory.
|
|
214
|
-
|
|
215
|
-
parseModule(module, module_id) {
|
|
216
|
-
let factoryStart = module.indexOf(`.factory('${module_id}',`);
|
|
217
|
-
if(factoryStart === -1) {
|
|
218
|
-
factoryStart = module.indexOf(`.factory("${module_id}",`);
|
|
219
|
-
}
|
|
220
|
-
if(factoryStart !== -1) {
|
|
221
|
-
let factory = module.substring(factoryStart, module.length);
|
|
222
|
-
let returnStart = factory.indexOf('return');
|
|
223
|
-
let returningObject = factory.substring(returnStart, factory.length);
|
|
224
|
-
let firstBracket = returningObject.indexOf('{');
|
|
225
|
-
returningObject = returningObject.substring(firstBracket, returningObject.length);
|
|
226
|
-
let openBrackets = 0;
|
|
227
|
-
let closeBrackets = 0;
|
|
228
|
-
let returnEnd = 0;
|
|
229
|
-
for (let i = 0; i < returningObject.length; i++) {
|
|
230
|
-
if (returningObject[i] === '{') {
|
|
231
|
-
openBrackets++;
|
|
232
|
-
}
|
|
233
|
-
if (returningObject[i] === '}') {
|
|
234
|
-
closeBrackets++;
|
|
235
|
-
}
|
|
236
|
-
if (openBrackets === closeBrackets && i >= firstBracket) {
|
|
237
|
-
returnEnd = i;
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
returningObject = returningObject.substring(0, returnEnd + 1);
|
|
242
|
-
return returningObject;
|
|
243
|
-
} else {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
273
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export class Interpritate {
|
|
2
|
+
constructor(gudhub) {
|
|
3
|
+
this.gudhub = gudhub;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/*********************** GET INTERPRETATION OBJ ***********************/
|
|
7
|
+
|
|
8
|
+
getInterpretationObj(fieldDataModel, defaultFieldDataModel, src, containerId) {
|
|
9
|
+
var currentIntrpr = {};
|
|
10
|
+
|
|
11
|
+
var defaultIntrprObj = defaultFieldDataModel.data_model.interpretation.find(function (interpritation) {
|
|
12
|
+
return interpritation.src == src;
|
|
13
|
+
}) || defaultFieldDataModel.data_model.interpretation.find(function (interpritation) {
|
|
14
|
+
return interpritation.src == 'table';
|
|
15
|
+
}) || { id: 'default' };
|
|
16
|
+
|
|
17
|
+
if (fieldDataModel.data_model && fieldDataModel.data_model.interpretation) {
|
|
18
|
+
// To detect interpretation we use (container_id), if there is not (container_id) we use (src)
|
|
19
|
+
currentIntrpr = fieldDataModel.data_model.interpretation.find(function (interpritation) {
|
|
20
|
+
return interpritation.src == containerId;
|
|
21
|
+
}) || fieldDataModel.data_model.interpretation.find(function (interpritation) {
|
|
22
|
+
return interpritation.src == src;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return gudhub.mergeObjects(defaultIntrprObj, currentIntrpr);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*********************** GET INTERPRETATION ***********************/
|
|
29
|
+
|
|
30
|
+
getInterpretation(value, field, dataType, source, itemId, appId, containerId) {
|
|
31
|
+
const self = this;
|
|
32
|
+
return new Promise(async (resolve, reject) => {
|
|
33
|
+
/*-- By default we use 'data_type' from field but in case if field is undefined we use 'dataType' from attribute*/
|
|
34
|
+
var data_type = field && field.data_type ? field.data_type : dataType;
|
|
35
|
+
|
|
36
|
+
/*---- Constructing Data Object ----*/
|
|
37
|
+
if (data_type) {
|
|
38
|
+
/*-- if we have data_type then we construct new data object to interpritate value*/
|
|
39
|
+
gudhub.ghconstructor.getInstance(data_type).then(function (data) {
|
|
40
|
+
var interpretationObj = self.getInterpretationObj(field, data.getTemplate().model, source, containerId);
|
|
41
|
+
data.getInterpretationNew(value, interpretationObj.id, data_type, field, itemId, appId).then(function (result) {
|
|
42
|
+
// console.log(result, interpretationObj)
|
|
43
|
+
|
|
44
|
+
resolve(gudhub.mergeObjects(result, interpretationObj));
|
|
45
|
+
}, function (error) {
|
|
46
|
+
reject();
|
|
47
|
+
});
|
|
48
|
+
}, function (error) { });
|
|
49
|
+
|
|
50
|
+
} else {
|
|
51
|
+
/*-- if we don't have data_type then we run defaultInterpretation function*/
|
|
52
|
+
resolve(this.getDefaultInterpretation(value, field));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/*********************** GET DEFAULT INTERPRETATION ***********************/
|
|
58
|
+
|
|
59
|
+
getDefaultInterpretation(value, options) {
|
|
60
|
+
var result = value;
|
|
61
|
+
|
|
62
|
+
if (options) {
|
|
63
|
+
/*-- Iterating through options from data_model to find a nave for selected*/
|
|
64
|
+
options.forEach(item => {
|
|
65
|
+
if(item.value == value && value != '') {
|
|
66
|
+
result = item.name;
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/********************* GET INTERPRETATION BY ID *********************/
|
|
74
|
+
|
|
75
|
+
getInterpretationById(appId, itemId, fieldId, interpretationId) {
|
|
76
|
+
return new Promise(async (resolve) => {
|
|
77
|
+
let fieldValue = await this.gudhub.getFieldValue(appId, itemId, fieldId);
|
|
78
|
+
let fieldModel = await this.gudhub.getField(appId, fieldId);
|
|
79
|
+
this.gudhub.ghconstructor.getInstance(fieldModel.data_type).then(async (instance) => {
|
|
80
|
+
let interpretatedValue = await instance.getInterpretationNew(fieldValue, interpretationId, fieldModel.data_type, fieldModel, itemId, appId);
|
|
81
|
+
if(interpretatedValue.html == '<span>no interpretation</span>') {
|
|
82
|
+
resolve(fieldValue);
|
|
83
|
+
} else {
|
|
84
|
+
resolve(interpretatedValue.html);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
@@ -405,5 +405,9 @@ export default function generateModulesList(async_modules_path, file_server_url)
|
|
|
405
405
|
name: "vs_code",
|
|
406
406
|
url: file_server_url + '/' + async_modules_path + "vs_code_data.js"
|
|
407
407
|
},
|
|
408
|
+
{
|
|
409
|
+
name: "nested_list",
|
|
410
|
+
url: file_server_url + '/' + async_modules_path + "nested_list_data.js"
|
|
411
|
+
},
|
|
408
412
|
]
|
|
409
413
|
}
|
package/GUDHUB/Utils/Utils.js
CHANGED
|
@@ -139,8 +139,8 @@ export class Utils {
|
|
|
139
139
|
return mergeChunks(chunks);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
jsonConstructor(scheme,
|
|
143
|
-
return compiler(scheme,
|
|
142
|
+
jsonConstructor(scheme, item, variables){
|
|
143
|
+
return compiler(scheme, item, this, variables)
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
compareAppsItemsLists(items_list1, items_list2, callback) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import should from "should";
|
|
2
|
+
// import add from "date-fns/subYears/index.js";
|
|
2
3
|
import {GudHub} from '../../gudhub.js';
|
|
4
|
+
import { subYears } from "date-fns";
|
|
3
5
|
|
|
4
6
|
describe("GET DATE", function () {
|
|
5
7
|
const gudhub = new GudHub();
|
|
@@ -73,6 +75,15 @@ describe("GET DATE", function () {
|
|
|
73
75
|
result.should.equal(false);
|
|
74
76
|
});
|
|
75
77
|
|
|
78
|
+
it('CHECK IF DATE IN THIS WEEK / Compare this wednesday with wednesday two years ago', function(){
|
|
79
|
+
let day = gudhub.getDate('this_wednesday');
|
|
80
|
+
let dayTwoYearsBefore = subYears(day, 2);
|
|
81
|
+
|
|
82
|
+
// console.log(dayTwoYearsBefore);
|
|
83
|
+
let result = gudhub.checkRecurringDate(dayTwoYearsBefore, 'week');
|
|
84
|
+
result.should.equal(true);
|
|
85
|
+
});
|
|
86
|
+
|
|
76
87
|
it("CHECK IF DATE IN THIS MONTH", function() {
|
|
77
88
|
let today = new Date();
|
|
78
89
|
let result = gudhub.checkRecurringDate(today, 'month');
|
|
@@ -83,4 +94,5 @@ describe("GET DATE", function () {
|
|
|
83
94
|
result = gudhub.checkRecurringDate(twoMonthsLater, 'month');
|
|
84
95
|
result.should.equal(false);
|
|
85
96
|
});
|
|
97
|
+
|
|
86
98
|
});
|
|
@@ -63,6 +63,8 @@ function mergeObject(target, source, optionsArgument) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
function deepmerge(target, source, optionsArgument) {
|
|
66
|
+
target = target !== undefined ? target : {};
|
|
67
|
+
source = source !== undefined ? source : {};
|
|
66
68
|
var array = Array.isArray(source);
|
|
67
69
|
var options = optionsArgument || { arrayMerge: defaultArrayMerge }
|
|
68
70
|
var arrayMerge = options.arrayMerge || defaultArrayMerge
|
|
@@ -36,16 +36,12 @@ export function makeNestedList(arr, id, parent_id, children_property, priority_p
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function sortChildrensByPriority(unsorted_array) {
|
|
39
|
-
unsorted_array.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
});
|
|
39
|
+
unsorted_array.sort( (a, b) => a[priority] - b[priority])
|
|
40
|
+
unsorted_array.forEach(element => {
|
|
41
|
+
if(element[children]) {
|
|
42
|
+
sortChildrensByPriority(element[children])
|
|
43
|
+
}
|
|
44
|
+
})
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
if(priority) {
|
|
@@ -24,6 +24,11 @@ describe("NESTED LIST", function () {
|
|
|
24
24
|
nestedList[0].custom_children_array_name[1].title.should.equal('Child 1');
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
+
it('Should sort nested list parents by priority', function () {
|
|
28
|
+
let nestedList = gudhub.makeNestedList(parentInput, 'id', 'parent_id', 'children', 'priority');
|
|
29
|
+
nestedList[0].title.should.equal('Nineth');
|
|
30
|
+
})
|
|
31
|
+
|
|
27
32
|
});
|
|
28
33
|
|
|
29
34
|
let input = [
|
|
@@ -145,4 +150,36 @@ let complicatedInput = [
|
|
|
145
150
|
parent_id: "26553.2884361",
|
|
146
151
|
title: "Child of second parent"
|
|
147
152
|
}
|
|
153
|
+
]
|
|
154
|
+
let parentInput = [
|
|
155
|
+
{
|
|
156
|
+
"id": "27026.2937695",
|
|
157
|
+
"parent_id": "",
|
|
158
|
+
"title": "First",
|
|
159
|
+
"priority": "1"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"id": "27026.2937708",
|
|
163
|
+
"parent_id": "",
|
|
164
|
+
"title": "Second",
|
|
165
|
+
"priority": "4"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"id": "27026.3009942",
|
|
169
|
+
"parent_id": "",
|
|
170
|
+
"title": "Eighth",
|
|
171
|
+
"priority": "3"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"id": "27026.3009943",
|
|
175
|
+
"parent_id": "",
|
|
176
|
+
"title": "Tenth",
|
|
177
|
+
"priority": "2"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"id": "27026.3108354",
|
|
181
|
+
"parent_id": "",
|
|
182
|
+
"title": "Nineth",
|
|
183
|
+
"priority": "0"
|
|
184
|
+
}
|
|
148
185
|
]
|
package/GUDHUB/gudhub.js
CHANGED
|
@@ -12,6 +12,7 @@ import { FieldProcessor } from "./FieldProcessor/FieldProcessor.js";
|
|
|
12
12
|
import { FileManager } from "./FileManager/FileManager.js";
|
|
13
13
|
import { ChunksManager } from "./ChunksManager/ChunksManager.js";
|
|
14
14
|
import { DocumentManager } from "./DocumentManager/DocumentManager.js";
|
|
15
|
+
import { Interpritate } from './GHConstructor/interpritate.js'
|
|
15
16
|
import { IS_WEB } from "./consts.js";
|
|
16
17
|
|
|
17
18
|
export class GudHub {
|
|
@@ -28,6 +29,7 @@ export class GudHub {
|
|
|
28
29
|
}
|
|
29
30
|
) {
|
|
30
31
|
this.ghconstructor = new GHConstructor();
|
|
32
|
+
this.interpritate = new Interpritate(this);
|
|
31
33
|
this.pipeService = new PipeService();
|
|
32
34
|
this.storage = new Storage(options.async_modules_path, options.file_server_url);
|
|
33
35
|
this.util = new Utils(this);
|
|
@@ -148,6 +150,26 @@ export class GudHub {
|
|
|
148
150
|
return this.ghconstructor.initAngularInjector(injector);
|
|
149
151
|
}
|
|
150
152
|
|
|
153
|
+
/******************* INTERPRITATE *******************/
|
|
154
|
+
|
|
155
|
+
getInterpretation(value, field, dataType, source, itemId, appId, containerId) {
|
|
156
|
+
return this.interpritate.getInterpretation(
|
|
157
|
+
value,
|
|
158
|
+
field,
|
|
159
|
+
dataType,
|
|
160
|
+
source,
|
|
161
|
+
itemId,
|
|
162
|
+
appId,
|
|
163
|
+
containerId
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/******************* GET INTERPRETATION BY ID *******************/
|
|
168
|
+
|
|
169
|
+
getInterpretationById(appId, itemId, fieldId, interpretationId) {
|
|
170
|
+
return this.interpritate.getInterpretationById(appId, itemId, fieldId, interpretationId);
|
|
171
|
+
}
|
|
172
|
+
|
|
151
173
|
//============ FILTER ==========//
|
|
152
174
|
filter(items, filter_list) {
|
|
153
175
|
return this.util.filter(items, filter_list);
|