@gudhub/core 1.0.37 → 1.0.41
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.js +9 -8
- package/GUDHUB/Processors/ItemProcessor/ItemProcessor.js +2 -2
- package/GUDHUB/Utils/Utils.js +2 -2
- package/GUDHUB/Utils/compare_items_lists_worker/compare_items_lists.worker.js +63 -38
- package/GUDHUB/Utils/interpretation/interpretation.js +1 -1
- package/GUDHUB/Utils/interpretation/interpretation.test.js +11 -0
- package/GUDHUB/Utils/merge_chunks/merge_chunks.js +1 -0
- package/GUDHUB/Utils/nested_list/nested_list.js +21 -3
- package/GUDHUB/Utils/nested_list/nested_list.test.js +79 -1
- package/GUDHUB/gudhub.js +2 -2
- package/package.json +1 -1
- package/umd/library.min.js +20 -44
- package/umd/library.min.js.map +1 -1
|
@@ -205,7 +205,7 @@ export class AppProcessor {
|
|
|
205
205
|
return this.deletingAppFromStorage(app_id);
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
async getApp(app_id) {
|
|
208
|
+
async getApp(app_id, trash = false) {
|
|
209
209
|
if (!app_id) return null;
|
|
210
210
|
|
|
211
211
|
let app = this.getAppFromStorage(app_id);
|
|
@@ -242,7 +242,7 @@ export class AppProcessor {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
return app;
|
|
245
|
+
return trash ? app : {...app, items_list: app.items_list.filter(item => !item.trash)};
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
async updateApp(app) {
|
|
@@ -372,17 +372,18 @@ export class AppProcessor {
|
|
|
372
372
|
if (IS_WEB && this.activateSW) {
|
|
373
373
|
navigator.serviceWorker.addEventListener("message", async (event) => {
|
|
374
374
|
if (event.data.type === "refresh app") {
|
|
375
|
-
const app = this.
|
|
376
|
-
if (app
|
|
375
|
+
const app = await this.getApp(event.data.payload.app_id);
|
|
376
|
+
if (app) {
|
|
377
377
|
this.util.compareAppsItemsLists(
|
|
378
|
-
event.data.payload.items_list,
|
|
379
378
|
app.items_list,
|
|
380
|
-
(
|
|
381
|
-
|
|
379
|
+
event.data.payload.items_list.filter(item => !item.trash),
|
|
380
|
+
({ diff_fields_items, diff_fields_items_Ids, diff_items, newItems, deletedItems }) => {
|
|
381
|
+
if (diff_items.length || newItems.length || deletedItems.length) {
|
|
382
|
+
|
|
382
383
|
this.pipeService.emit(
|
|
383
384
|
"gh_items_update",
|
|
384
385
|
{ app_id: event.data.payload.app_id },
|
|
385
|
-
event.data.payload.items_list
|
|
386
|
+
event.data.payload.items_list.filter(item => !item.trash),
|
|
386
387
|
);
|
|
387
388
|
diff_items.forEach((item) =>
|
|
388
389
|
this.pipeService.emit(
|
|
@@ -122,9 +122,9 @@ export class ItemProcessor {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
async getItems(app_id, trash = false) {
|
|
125
|
-
const app = await this.appProcessor.getApp(app_id)
|
|
125
|
+
const app = await this.appProcessor.getApp(app_id, trash);
|
|
126
126
|
if(!app) return null;
|
|
127
|
-
return
|
|
127
|
+
return app.items_list;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
async addNewItems(app_id, itemsList) {
|
package/GUDHUB/Utils/Utils.js
CHANGED
|
@@ -127,8 +127,8 @@ export class Utils {
|
|
|
127
127
|
return mergeObjects(target, source, optionsArgument);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
makeNestedList(arr, id, parent_id, children_property) {
|
|
131
|
-
return makeNestedList(arr, id, parent_id, children_property);
|
|
130
|
+
makeNestedList(arr, id, parent_id, children_property, priority_property) {
|
|
131
|
+
return makeNestedList(arr, id, parent_id, children_property, priority_property);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
mergeChunks(chunks) {
|
|
@@ -1,46 +1,71 @@
|
|
|
1
1
|
export function compare_items_lists_Worker() {
|
|
2
|
-
return `function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
return `function createList(items) {
|
|
3
|
+
return items.reduce(
|
|
4
|
+
(acc, item) => {
|
|
5
|
+
acc.list[item.item_id] = item;
|
|
6
|
+
acc.ids.push(item.item_id);
|
|
7
|
+
return acc;
|
|
8
|
+
},
|
|
9
|
+
{ ids: [], list: {} }
|
|
9
10
|
);
|
|
11
|
+
};
|
|
12
|
+
function compareItemsLists(oldItems, newItems) {
|
|
13
|
+
const { ids: oldIds, list: oldList } = createList(oldItems);
|
|
14
|
+
const { ids: newIds, list: newList } = createList(newItems);
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
const deletedItemsIds = oldIds.filter((id) => !newIds.includes(id));
|
|
17
|
+
const recentItemsIds = oldIds.filter((id) => !deletedItemsIds.includes(id));
|
|
18
|
+
const newItemsIds = newIds.filter((id) => !oldIds.includes(id));
|
|
19
|
+
|
|
20
|
+
const diff_fields_items = {};
|
|
21
|
+
const diff_fields_items_Ids = [];
|
|
22
|
+
|
|
23
|
+
recentItemsIds.forEach((id) => {
|
|
24
|
+
const newItem = newList[id];
|
|
25
|
+
const oldItem = oldList[id];
|
|
26
|
+
|
|
27
|
+
oldItem.fields.forEach((field1) => {
|
|
28
|
+
const sameField = newItem.fields.find(
|
|
29
|
+
(field2) => Number(field2.field_id) === Number(field1.field_id)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (!sameField) {
|
|
33
|
+
if (!diff_fields_items[newItem.item_id]) {
|
|
34
|
+
diff_fields_items[newItem.item_id] = [];
|
|
35
|
+
diff_fields_items_Ids.push(newItem.item_id);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return diff_fields_items[newItem.item_id].push(field1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (field1.field_value != sameField.field_value) {
|
|
42
|
+
if (!diff_fields_items[newItem.item_id]) {
|
|
43
|
+
diff_fields_items[newItem.item_id] = [];
|
|
44
|
+
diff_fields_items_Ids.push(newItem.item_id);
|
|
45
|
+
}
|
|
46
|
+
return diff_fields_items[newItem.item_id].push(field1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
39
49
|
});
|
|
40
|
-
});
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
return {
|
|
52
|
+
newItems: newItemsIds.reduce((acc, id) => {
|
|
53
|
+
acc.push(newList[id]);
|
|
54
|
+
return acc;
|
|
55
|
+
}, []),
|
|
56
|
+
deletedItems: deletedItemsIds.reduce((acc, id) => {
|
|
57
|
+
acc.push(oldList[id]);
|
|
58
|
+
return acc;
|
|
59
|
+
}, []),
|
|
60
|
+
diff_fields_items_Ids,
|
|
61
|
+
diff_fields_items,
|
|
62
|
+
diff_items: diff_fields_items_Ids.reduce((acc, id) => {
|
|
63
|
+
acc.push(oldList[id]);
|
|
64
|
+
return acc;
|
|
65
|
+
}, []),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
44
69
|
self.addEventListener("message", (event) => {
|
|
45
70
|
const { items_list1, items_list2 } = event.data;
|
|
46
71
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import should from "should";
|
|
2
|
+
import {GudHub} from '../../gudhub.js';
|
|
3
|
+
|
|
4
|
+
describe("CHECK INTERPRETATION", function () {
|
|
5
|
+
const gudhub = new GudHub();
|
|
6
|
+
|
|
7
|
+
it("Check radio_button interpretation", async function () {
|
|
8
|
+
let interpretationValue = await gudhub.getInterpretedValue(16259,1064673,270607);
|
|
9
|
+
interpretationValue.should.equal("Normal");
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -5,6 +5,7 @@ export function mergeChunks(chunks) {
|
|
|
5
5
|
chunk.items_list.forEach((item) => {
|
|
6
6
|
const dstItem = result[item.item_id];
|
|
7
7
|
if (dstItem) {
|
|
8
|
+
dstItem.trash = item.trash;
|
|
8
9
|
return item.fields.forEach((srcField) => {
|
|
9
10
|
let isFieldNonExist = true;
|
|
10
11
|
dstItem.fields = dstItem.fields.map((dstField) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export function makeNestedList(arr, id, parent_id, children_property) {
|
|
1
|
+
export function makeNestedList(arr, id, parent_id, children_property, priority_property) {
|
|
2
2
|
let array = JSON.parse(JSON.stringify(arr));
|
|
3
3
|
let children = Boolean(children_property) ? children_property : 'children';
|
|
4
|
+
let priority = Boolean(priority_property) ? priority_property : false;
|
|
4
5
|
let i;
|
|
5
6
|
for (i = 0; i < array.length; i++) {
|
|
6
7
|
if (array[i][parent_id] && array[i][parent_id] !== 0) {
|
|
@@ -11,7 +12,7 @@ export function makeNestedList(arr, id, parent_id, children_property) {
|
|
|
11
12
|
}
|
|
12
13
|
parent[children].push(array[i]);
|
|
13
14
|
array.splice(i, 1);
|
|
14
|
-
i--;
|
|
15
|
+
i == 0 ? i = 0 : i--;
|
|
15
16
|
} else if (parent[children]) {
|
|
16
17
|
findIdsOfChildren(parent);
|
|
17
18
|
}
|
|
@@ -27,12 +28,29 @@ export function makeNestedList(arr, id, parent_id, children_property) {
|
|
|
27
28
|
}
|
|
28
29
|
child[children].push(array[i]);
|
|
29
30
|
array.splice(i, 1);
|
|
30
|
-
i--;
|
|
31
|
+
i == 0 ? i = 0 : i--;
|
|
31
32
|
} else if (child[children]) {
|
|
32
33
|
findIdsOfChildren(child);
|
|
33
34
|
}
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
function sortChildrensByPriority(unsorted_array) {
|
|
39
|
+
unsorted_array.forEach(item => {
|
|
40
|
+
if(item[children]) {
|
|
41
|
+
item[children].sort((a, b) => a[priority] - b[priority]);
|
|
42
|
+
item[children].forEach(child => {
|
|
43
|
+
if(child[children]) {
|
|
44
|
+
sortChildrensByPriority(child[children]);
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if(priority) {
|
|
52
|
+
sortChildrensByPriority(array);
|
|
53
|
+
}
|
|
54
|
+
|
|
37
55
|
return array;
|
|
38
56
|
}
|
|
@@ -19,6 +19,11 @@ describe("NESTED LIST", function () {
|
|
|
19
19
|
nestedList[0].custom_children[0].should.have.property('custom_children');
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
+
it('Should sort nested list childrens by priority', function () {
|
|
23
|
+
let nestedList = gudhub.makeNestedList(complicatedInput, 'id', 'parent_id', 'custom_children_array_name', 'priority');
|
|
24
|
+
nestedList[0].custom_children_array_name[1].title.should.equal('Child 1');
|
|
25
|
+
})
|
|
26
|
+
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
let input = [
|
|
@@ -67,4 +72,77 @@ let input = [
|
|
|
67
72
|
id: 9,
|
|
68
73
|
parent_id: 8
|
|
69
74
|
},
|
|
70
|
-
];
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
let complicatedInput = [
|
|
78
|
+
{
|
|
79
|
+
id: "26553.2884361",
|
|
80
|
+
parent_id: "26553.2904452",
|
|
81
|
+
title: "Second parent",
|
|
82
|
+
priority: 3
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: "26553.2904452",
|
|
86
|
+
parent_id: "",
|
|
87
|
+
title: "Parent"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: "26553.2904533",
|
|
91
|
+
parent_id: "26553.2904452",
|
|
92
|
+
title: "Child 2",
|
|
93
|
+
priority: 5
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "26553.2904534",
|
|
97
|
+
parent_id: "26553.2904452",
|
|
98
|
+
title: "Child 3",
|
|
99
|
+
priority: 4
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "26553.2904535",
|
|
103
|
+
parent_id: "26553.2884361",
|
|
104
|
+
title: "Child of child 1"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "26553.2904536",
|
|
108
|
+
parent_id: "26553.2884361",
|
|
109
|
+
title: "Child of child 2"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "26553.2904538",
|
|
113
|
+
parent_id: "26553.2884361",
|
|
114
|
+
title: "Third parent"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "26553.2904539",
|
|
118
|
+
parent_id: "26553.2904538",
|
|
119
|
+
title: "Child of child of child"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: "26553.2904540",
|
|
123
|
+
parent_id: "",
|
|
124
|
+
title: "Another parent"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: "26553.2906081",
|
|
128
|
+
parent_id: "26553.2904452",
|
|
129
|
+
title: "Child 1",
|
|
130
|
+
priority: 2
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: "26553.2914316",
|
|
134
|
+
parent_id: "26553.2904540",
|
|
135
|
+
title: "Child of another parent"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "26553.2914491",
|
|
139
|
+
parent_id: "26553.2904452",
|
|
140
|
+
title: "Child of first parent",
|
|
141
|
+
priority: 1
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: "26553.2914500",
|
|
145
|
+
parent_id: "26553.2884361",
|
|
146
|
+
title: "Child of second parent"
|
|
147
|
+
}
|
|
148
|
+
]
|
package/GUDHUB/gudhub.js
CHANGED
|
@@ -216,8 +216,8 @@ export class GudHub {
|
|
|
216
216
|
return this.util.mergeObjects(sourceObject, destinationObject);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
makeNestedList(arr, id, parent_id, children_property) {
|
|
220
|
-
return this.util.makeNestedList(arr, id, parent_id, children_property);
|
|
219
|
+
makeNestedList(arr, id, parent_id, children_property, priority_property) {
|
|
220
|
+
return this.util.makeNestedList(arr, id, parent_id, children_property, priority_property);
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
jsonConstructor(scheme, items, variables){
|