@gudhub/core 1.1.58 → 1.1.60
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/FieldProcessor/FieldProcessor.js +11 -0
- package/GUDHUB/FieldProcessor/FieldProcessor.test.js +5 -0
- package/GUDHUB/PipeService/PipeService.test.js +1 -2
- package/GUDHUB/Utils/get_date/get_date.js +229 -7
- package/GUDHUB/Utils/json_constructor/json_constructor.js +4 -1
- package/GUDHUB/Utils/json_constructor/json_constructor.test.js +25 -1
- package/GUDHUB/config.js +1 -1
- package/GUDHUB/gudhub-https-service.js +1 -0
- package/GUDHUB/gudhub.js +4 -0
- package/package.json +1 -1
- package/umd/library.min.js +6 -6
- package/umd/library.min.js.map +1 -1
|
@@ -98,6 +98,17 @@ export class FieldProcessor {
|
|
|
98
98
|
return null;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
async getFieldIdByNameSpace(app_id, name_space) {
|
|
102
|
+
const app = await this.appProcessor.getApp(app_id);
|
|
103
|
+
if(!app) return null;
|
|
104
|
+
for(let i = 0; i < app.field_list.length; i++) {
|
|
105
|
+
if(app.field_list[i].name_space == name_space) {
|
|
106
|
+
return app.field_list[i].field_id;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
101
112
|
//!!!!! Shou Be Renamed to getFields() !!!!!!!
|
|
102
113
|
async getFieldModels(app_id) {
|
|
103
114
|
const app = await this.appProcessor.getApp(app_id);
|
|
@@ -12,6 +12,11 @@ describe("FIELD PROCESSOR", async function() {
|
|
|
12
12
|
(typeof fieldModel).should.equal('object');
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
+
it("GET FIELD ID BY NAMESPACE / should return a field id", async function() {
|
|
16
|
+
const fieldId = await gudhub.getFieldIdByNameSpace(16259, 'name');
|
|
17
|
+
fieldId.should.equal(254056);
|
|
18
|
+
});
|
|
19
|
+
|
|
15
20
|
it('GET FIELD VALUE / should return a field value', async () => {
|
|
16
21
|
let value = await gudhub.getFieldValue(16259, 1064673, 254055);
|
|
17
22
|
value.should.equal('Hall up');
|
|
@@ -68,9 +68,8 @@ describe("PipeService", () => {
|
|
|
68
68
|
gudhub
|
|
69
69
|
.emit("test", { app_id: 4, item_id: 3, field_id: 2 }, {"message" : "this is the data"})
|
|
70
70
|
.on("test", { app_id: 4, item_id: 3, field_id: 2 }, (event, data) => {
|
|
71
|
-
|
|
71
|
+
data.message.should.equal("this is the data");
|
|
72
72
|
});
|
|
73
|
-
incomeData.should.equal("this is the data");
|
|
74
73
|
});
|
|
75
74
|
|
|
76
75
|
|
|
@@ -22,7 +22,15 @@ export function populateWithDate(items, model) {
|
|
|
22
22
|
(sourceField) => sourceField.element_id == modelField.element_id
|
|
23
23
|
);
|
|
24
24
|
if (field) {
|
|
25
|
-
|
|
25
|
+
if (modelField.data_range) {
|
|
26
|
+
if(modelField.date_type.includes('calendar')) {
|
|
27
|
+
field.field_value = `${getStartDate(modelField.date_type)}:${getDate(modelField.date_type)}`
|
|
28
|
+
} else {
|
|
29
|
+
field.field_value = `${getStartDate(modelField.date_type)}:${getDate(modelField.date_type)}`
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
field.field_value = getDate(modelField.date_type);
|
|
33
|
+
}
|
|
26
34
|
} else {
|
|
27
35
|
//-- if we didn't find field in item then we add it
|
|
28
36
|
item.fields.push({
|
|
@@ -33,13 +41,152 @@ export function populateWithDate(items, model) {
|
|
|
33
41
|
}
|
|
34
42
|
});
|
|
35
43
|
});
|
|
36
|
-
|
|
37
44
|
return items;
|
|
38
45
|
}
|
|
39
46
|
|
|
47
|
+
//******************* GET START DATE *********************//
|
|
48
|
+
function getStartDate(dateType) {
|
|
49
|
+
let currentDate = new Date();
|
|
50
|
+
|
|
51
|
+
function weekTime(currentDate) {
|
|
52
|
+
var day = currentDate.getDay();
|
|
53
|
+
let numberOfDays;
|
|
54
|
+
if (dateType.includes("week_current,current")) {
|
|
55
|
+
numberOfDays = 0;
|
|
56
|
+
}
|
|
57
|
+
if (dateType.includes("week_next,future")) {
|
|
58
|
+
numberOfDays = 7;
|
|
59
|
+
}
|
|
60
|
+
if (dateType.includes("week_past,past")) {
|
|
61
|
+
numberOfDays = -7;
|
|
62
|
+
}
|
|
63
|
+
let diff = currentDate.getDate() - day + numberOfDays + (day == 0 ? -6:1);
|
|
64
|
+
return new Date(currentDate.setDate(diff));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function quarterTime(currentDate) {
|
|
68
|
+
let numberMonths;
|
|
69
|
+
let numberDays;
|
|
70
|
+
let currentQuarter = Math.floor((currentDate.getMonth() / 3));
|
|
71
|
+
let year = currentDate.getFullYear();
|
|
72
|
+
if (dateType.includes("quarter_current,current")) {
|
|
73
|
+
numberMonths = 0;
|
|
74
|
+
numberDays = 0;
|
|
75
|
+
}
|
|
76
|
+
if (dateType.includes("quarter_next,future")) {
|
|
77
|
+
numberMonths = 3;
|
|
78
|
+
numberDays = 0;
|
|
79
|
+
}
|
|
80
|
+
if (dateType.includes("quarter_past,past")) {
|
|
81
|
+
numberMonths = -3;
|
|
82
|
+
numberDays = 0;
|
|
83
|
+
}
|
|
84
|
+
return new Date(year, currentQuarter * 3 + numberMonths, 1 + numberDays);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
switch (dateType) {
|
|
88
|
+
case "week_current,current":
|
|
89
|
+
return weekTime(new Date()).getTime();
|
|
90
|
+
|
|
91
|
+
case "month_current,current":
|
|
92
|
+
return new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getTime();
|
|
93
|
+
|
|
94
|
+
case "quarter_current,current":
|
|
95
|
+
return quarterTime(new Date()).getTime();
|
|
96
|
+
|
|
97
|
+
case "year_current,current":
|
|
98
|
+
return add(new Date(currentDate.getFullYear(), 0, 1), {years: 0}).getTime();
|
|
99
|
+
|
|
100
|
+
case "week_next,future":
|
|
101
|
+
return weekTime(new Date()).getTime();
|
|
102
|
+
|
|
103
|
+
case "month_next,future":
|
|
104
|
+
return new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1).getTime();
|
|
105
|
+
|
|
106
|
+
case "quarter_next,future":
|
|
107
|
+
return quarterTime(new Date()).getTime();
|
|
108
|
+
|
|
109
|
+
case "year_next,future":
|
|
110
|
+
return add(currentDate, {days: 0}).getTime();
|
|
111
|
+
|
|
112
|
+
case "week_past,past":
|
|
113
|
+
return weekTime(new Date()).getTime();
|
|
114
|
+
|
|
115
|
+
case "month_past,past":
|
|
116
|
+
return new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1).getTime();
|
|
117
|
+
|
|
118
|
+
case "quarter_past,past":
|
|
119
|
+
return quarterTime(new Date()).getTime();
|
|
120
|
+
|
|
121
|
+
case "year_past,past":
|
|
122
|
+
return add(currentDate, {years: -1}).getTime();
|
|
123
|
+
|
|
124
|
+
case "year_past,past,calendar":
|
|
125
|
+
return add(new Date(currentDate.getFullYear(), 0, 1), {years: -1}).getTime();
|
|
126
|
+
|
|
127
|
+
case "year_future,future,calendar":
|
|
128
|
+
return add(new Date(currentDate.getFullYear() + 1, 0, 1), {years: 0}).getTime();
|
|
129
|
+
|
|
130
|
+
case "today_current,current":
|
|
131
|
+
return add(currentDate, {days: 0}).getTime();
|
|
132
|
+
|
|
133
|
+
case "tomorrow,future":
|
|
134
|
+
return add(currentDate, {days: 1}).getTime();
|
|
135
|
+
|
|
136
|
+
case "7_days_future,future":
|
|
137
|
+
return add(currentDate, {days: 0}).getTime();
|
|
138
|
+
|
|
139
|
+
case "10_days_future,future":
|
|
140
|
+
return add(currentDate, {days: 0}).getTime();
|
|
141
|
+
|
|
142
|
+
case "14_days_future,future":
|
|
143
|
+
return add(currentDate, {days: 0}).getTime();
|
|
144
|
+
|
|
145
|
+
case "30_days_future,future":
|
|
146
|
+
return add(currentDate, {days: 0}).getTime();
|
|
147
|
+
|
|
148
|
+
case "yesterday,past":
|
|
149
|
+
return add(currentDate, {days: -1}).getTime();
|
|
150
|
+
|
|
151
|
+
case "7_days_past,past":
|
|
152
|
+
return add(currentDate, {days: -7}).getTime();
|
|
153
|
+
|
|
154
|
+
case "10_days_past,past":
|
|
155
|
+
return add(currentDate, {days: -10}).getTime();
|
|
156
|
+
|
|
157
|
+
case "14_days_past,past":
|
|
158
|
+
return add(currentDate, {days: -14}).getTime();
|
|
159
|
+
|
|
160
|
+
case "30_days_past,past":
|
|
161
|
+
return add(currentDate, {days: -30}).getTime();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
40
164
|
//********************** GET DATE ************************//
|
|
41
165
|
export function getDate(queryKey) {
|
|
42
|
-
|
|
166
|
+
var date = new Date();
|
|
167
|
+
|
|
168
|
+
function getMonday(d) {
|
|
169
|
+
d = new Date(d);
|
|
170
|
+
var day = d.getDay(),
|
|
171
|
+
diff = d.getDate() - day + 6 + (day == 0 ? +6:1);
|
|
172
|
+
return new Date(d.setDate(diff));
|
|
173
|
+
}
|
|
174
|
+
function getNextWeek(d) {
|
|
175
|
+
d = new Date(d);
|
|
176
|
+
var day = d.getDay(),
|
|
177
|
+
diff = d.getDate() - day + 13 + (day == 0 ? -6:1);
|
|
178
|
+
return new Date(d.setDate(diff));
|
|
179
|
+
}
|
|
180
|
+
function getPastWeek(d) {
|
|
181
|
+
d = new Date(d);
|
|
182
|
+
var day = d.getDay(),
|
|
183
|
+
diff = d.getDate() - day - 1 + (day == 0 ? -6:1);
|
|
184
|
+
return new Date(d.setDate(diff));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let currentQuarter = Math.floor((date.getMonth() / 3));
|
|
188
|
+
let year = date.getFullYear();
|
|
189
|
+
|
|
43
190
|
switch (queryKey) {
|
|
44
191
|
|
|
45
192
|
case "next_day":
|
|
@@ -84,9 +231,84 @@ export function getDate(queryKey) {
|
|
|
84
231
|
case "this_saturday":
|
|
85
232
|
return setDay(date, 6, {weekStartsOn: 1});
|
|
86
233
|
|
|
87
|
-
case "
|
|
88
|
-
|
|
89
|
-
|
|
234
|
+
case "today_current,current":
|
|
235
|
+
return add(date, {days: 0}).getTime();
|
|
236
|
+
|
|
237
|
+
case "tomorrow,future":
|
|
238
|
+
return add(date, {days: 1}).getTime();
|
|
239
|
+
|
|
240
|
+
case "7_days_future,future":
|
|
241
|
+
return add(date, {days: 7}).getTime();
|
|
242
|
+
|
|
243
|
+
case "10_days_future,future":
|
|
244
|
+
return add(date, {days: 10}).getTime();
|
|
245
|
+
|
|
246
|
+
case "14_days_future,future":
|
|
247
|
+
return add(date, {days: 14}).getTime();
|
|
248
|
+
|
|
249
|
+
case "30_days_future,future":
|
|
250
|
+
return add(date, {days: 30}).getTime();
|
|
251
|
+
|
|
252
|
+
case "yesterday,past":
|
|
253
|
+
return add(date, {days: -1}).getTime();
|
|
254
|
+
|
|
255
|
+
case "7_days_past,past":
|
|
256
|
+
return add(date, {days: 0}).getTime();
|
|
257
|
+
|
|
258
|
+
case "10_days_past,past":
|
|
259
|
+
return add(date, {days: 0}).getTime();
|
|
260
|
+
|
|
261
|
+
case "14_days_past,past":
|
|
262
|
+
return add(date, {days: 0}).getTime();
|
|
263
|
+
|
|
264
|
+
case "30_days_past,past":
|
|
265
|
+
return add(date, {days: 0}).getTime();
|
|
266
|
+
|
|
267
|
+
case "year_future,future,calendar":
|
|
268
|
+
return add(new Date(date.getFullYear() + 1, 0, 0), {years: 1}).getTime();
|
|
269
|
+
|
|
270
|
+
case "year_past,past,calendar":
|
|
271
|
+
return add(new Date(date.getFullYear(), 0, 0), {years: 0}).getTime();
|
|
272
|
+
|
|
273
|
+
case "week_current,current":
|
|
274
|
+
return getMonday(new Date()).getTime();
|
|
275
|
+
|
|
276
|
+
case "month_current,current":
|
|
277
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getTime();
|
|
278
|
+
|
|
279
|
+
case "quarter_current,current":
|
|
280
|
+
return new Date(year, (currentQuarter + 1) * 3, 0).getTime();
|
|
281
|
+
|
|
282
|
+
case "year_current,current":
|
|
283
|
+
return add(new Date(date.getFullYear() + 1, 0, 0), {years: 0}).getTime();
|
|
284
|
+
|
|
285
|
+
case "week_next,future":
|
|
286
|
+
return getNextWeek(new Date()).getTime();
|
|
287
|
+
|
|
288
|
+
case "month_next,future":
|
|
289
|
+
return new Date(date.getFullYear(), date.getMonth() + 2, 0).getTime();
|
|
290
|
+
|
|
291
|
+
case "quarter_next,future":
|
|
292
|
+
return new Date(year, (currentQuarter + 1) * 3 +3, 0).getTime();
|
|
293
|
+
|
|
294
|
+
case "year_next,future":
|
|
295
|
+
return add(date, {years: 1}).getTime();
|
|
296
|
+
|
|
297
|
+
case "week_past,past":
|
|
298
|
+
return getPastWeek(new Date()).getTime();
|
|
299
|
+
|
|
300
|
+
case "month_past,past":
|
|
301
|
+
return new Date(date.getFullYear(), date.getMonth(), 0, 0).getTime();
|
|
302
|
+
|
|
303
|
+
case "quarter_past,past":
|
|
304
|
+
return new Date(year, (currentQuarter + 1) * 3 -3, 0).getTime();
|
|
305
|
+
|
|
306
|
+
case "year_past,past":
|
|
307
|
+
return add(date, {days: 0}).getTime();
|
|
308
|
+
|
|
309
|
+
case "now":
|
|
310
|
+
default:
|
|
311
|
+
return date.getTime();
|
|
90
312
|
}
|
|
91
313
|
}
|
|
92
314
|
|
|
@@ -118,5 +340,5 @@ export function checkRecurringDate(date, option) {
|
|
|
118
340
|
default:
|
|
119
341
|
return true;
|
|
120
342
|
}
|
|
121
|
-
|
|
343
|
+
|
|
122
344
|
}
|
|
@@ -117,13 +117,16 @@ export function compiler(scheme, item, util, variables, appId) {
|
|
|
117
117
|
let result = scheme.function(item, appId, util.gudhub, ...scheme.args);
|
|
118
118
|
return result;
|
|
119
119
|
} else {
|
|
120
|
-
const func = new Function('item, appId, gudhub', 'return (async ' + scheme.function + ')(item, appId,
|
|
120
|
+
const func = new Function('item, appId, gudhub', 'return (async ' + scheme.function + ')(item, appId, gudhub)');
|
|
121
121
|
let result = await func(item, appId, util.gudhub);
|
|
122
122
|
return result;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
case "field_value":
|
|
126
126
|
default:
|
|
127
|
+
if(!scheme.field_id && scheme.name_space) {
|
|
128
|
+
scheme.field_id = await util.gudhub.getFieldIdByNameSpace(appId, scheme.name_space);
|
|
129
|
+
}
|
|
127
130
|
if (Boolean(Number(scheme.interpretation))) {
|
|
128
131
|
let interpretatedValue = await util.gudhub.getInterpretationById(Number(appId), Number(item.item_id), Number(scheme.field_id), 'value');
|
|
129
132
|
return interpretatedValue;
|
|
@@ -20,13 +20,14 @@ describe("JSON CONSTRUCTOR", function () {
|
|
|
20
20
|
gudhub.ghconstructor.initJsdomWindow(window);
|
|
21
21
|
|
|
22
22
|
it("JSON FROM ONE APP : Here we construct simple json from one App", async function () {
|
|
23
|
-
this.timeout(
|
|
23
|
+
this.timeout(5000);
|
|
24
24
|
//-- checking if json was generated properly
|
|
25
25
|
let json = await gudhub.jsonConstructor(fishtank_scheme);
|
|
26
26
|
json.fishtank[0].should.have.property("name", "Big Fish Tank");
|
|
27
27
|
json.fishtank[0].should.have.property("state", "Normal ");
|
|
28
28
|
});
|
|
29
29
|
it("CHECK INTERPRETATION VALUE FOR FILES: output: we should get url's", async function () {
|
|
30
|
+
this.timeout(5000);
|
|
30
31
|
//-- checking interpretation mode
|
|
31
32
|
let json = await gudhub.jsonConstructor(fishtank_scheme);
|
|
32
33
|
json.fishtank[0].should.have.property("image","https://gudhub.com/userdata/16259/809199.jpg,https://gudhub.com/userdata/16259/811768.png");
|
|
@@ -34,6 +35,7 @@ describe("JSON CONSTRUCTOR", function () {
|
|
|
34
35
|
json.fishtank[0].should.have.property("notes","https://gudhub.com/userdata/16259/811770.html?timestamp=0");
|
|
35
36
|
});
|
|
36
37
|
it("GET FILTERED ITEMS LENGTH WITH CURRENT ITEM FILTER", async function () {
|
|
38
|
+
this.timeout(5000);
|
|
37
39
|
let json = await gudhub.jsonConstructor(currentItemScheme);
|
|
38
40
|
let firstLength = json.scheme[0].array.length;
|
|
39
41
|
let secondLength = json.scheme[1].array.length;
|
|
@@ -42,6 +44,11 @@ describe("JSON CONSTRUCTOR", function () {
|
|
|
42
44
|
secondLength.should.equal(4);
|
|
43
45
|
|
|
44
46
|
});
|
|
47
|
+
it("WORK WITH NAMESPACE INSTEAD OF FIELD ID", async function () {
|
|
48
|
+
this.timeout(5000);
|
|
49
|
+
let json = await gudhub.jsonConstructor(schemeWithNamespace);
|
|
50
|
+
json.scheme[0].name.should.equal("Big Fish Tank");
|
|
51
|
+
});
|
|
45
52
|
});
|
|
46
53
|
|
|
47
54
|
var fishtank_scheme = {
|
|
@@ -146,3 +153,20 @@ let currentItemScheme = {
|
|
|
146
153
|
app_id: "16259",
|
|
147
154
|
filter: [],
|
|
148
155
|
};
|
|
156
|
+
|
|
157
|
+
let schemeWithNamespace = {
|
|
158
|
+
type: "array",
|
|
159
|
+
id: 1,
|
|
160
|
+
childs: [
|
|
161
|
+
{
|
|
162
|
+
type: "property",
|
|
163
|
+
id: 2,
|
|
164
|
+
property_name: "name",
|
|
165
|
+
property_type: "field_value",
|
|
166
|
+
name_space: "name"
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
property_name: "scheme",
|
|
170
|
+
app_id: "16259",
|
|
171
|
+
filter: []
|
|
172
|
+
}
|
package/GUDHUB/config.js
CHANGED
|
@@ -3,7 +3,7 @@ export const server_url = "https://gudhub.com/GudHub_Test";
|
|
|
3
3
|
//export const server_url = "https://integration.gudhub.com/GudHub_Test";
|
|
4
4
|
//export const server_url = "http://localhost:9000";
|
|
5
5
|
export const wss_url = "wss://gudhub.com/GudHub/ws/app/";
|
|
6
|
-
export const async_modules_path = 'build/latest/
|
|
6
|
+
export const async_modules_path = 'build/latest/async_modules_node/';
|
|
7
7
|
export const automation_modules_path = 'build/latest/automation_modules/'
|
|
8
8
|
export const file_server_url = 'https://gudhub.com'
|
|
9
9
|
|
package/GUDHUB/gudhub.js
CHANGED
|
@@ -314,6 +314,10 @@ export class GudHub {
|
|
|
314
314
|
return this.fieldProcessor.getField(app_id, field_id);
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
+
getFieldIdByNameSpace(app_id, name_space) {
|
|
318
|
+
return this.fieldProcessor.getFieldIdByNameSpace(app_id, name_space);
|
|
319
|
+
}
|
|
320
|
+
|
|
317
321
|
getFieldModels(app_id) {
|
|
318
322
|
return this.fieldProcessor.getFieldModels(app_id);
|
|
319
323
|
}
|