@gudhub/core 1.0.37
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/Auth/Auth.js +137 -0
- package/GUDHUB/Auth/Auth.test.js +15 -0
- package/GUDHUB/Managers/ChunksManager/ChunksManager.js +80 -0
- package/GUDHUB/Managers/ChunksManager/ChunksManager.test.js +46 -0
- package/GUDHUB/Managers/DocumentManager/DocumentManager.js +48 -0
- package/GUDHUB/Managers/FileManager/FileManager.js +208 -0
- package/GUDHUB/Managers/FileManager/file_manager.test.js +17 -0
- package/GUDHUB/Managers/managers.js +5 -0
- package/GUDHUB/PipeService/PipeService.js +167 -0
- package/GUDHUB/PipeService/PipeService.test.js +64 -0
- package/GUDHUB/PipeService/utils.js +32 -0
- package/GUDHUB/Processors/AppProcessor/AppProcessor.js +433 -0
- package/GUDHUB/Processors/AppProcessor/AppProcessor.test.js +38 -0
- package/GUDHUB/Processors/AppProcessor/AppProcessorMocks.js +83 -0
- package/GUDHUB/Processors/FieldProcessor/FieldProcessor.js +139 -0
- package/GUDHUB/Processors/FieldProcessor/FieldProcessor.test.js +16 -0
- package/GUDHUB/Processors/FieldProcessor/Untitled-1.json +17 -0
- package/GUDHUB/Processors/FieldProcessor/field_processor.md +85 -0
- package/GUDHUB/Processors/ItemProcessor/ItemProcessor.js +247 -0
- package/GUDHUB/Processors/ItemProcessor/item_processor.md +50 -0
- package/GUDHUB/Processors/processors.js +5 -0
- package/GUDHUB/Storage/Storage.js +115 -0
- package/GUDHUB/Storage/Storage.test.js +112 -0
- package/GUDHUB/Utils/Utils.js +153 -0
- package/GUDHUB/Utils/compare_items_lists_worker/compare_items_lists.worker.js +50 -0
- package/GUDHUB/Utils/filter/filter.js +308 -0
- package/GUDHUB/Utils/filter/filter.test.js +94 -0
- package/GUDHUB/Utils/filter/filterPreparation.js +103 -0
- package/GUDHUB/Utils/filter/group.js +41 -0
- package/GUDHUB/Utils/filter/utils.js +119 -0
- package/GUDHUB/Utils/get_date/get_date.js +90 -0
- package/GUDHUB/Utils/get_date/get_date.test.js +53 -0
- package/GUDHUB/Utils/interpretation/interpretation.js +100 -0
- package/GUDHUB/Utils/json_constructor/json_constructor.js +130 -0
- package/GUDHUB/Utils/json_constructor/json_constructor.test.js +70 -0
- package/GUDHUB/Utils/json_to_items/json_to_items.js +161 -0
- package/GUDHUB/Utils/json_to_items/json_to_items.test.js +85 -0
- package/GUDHUB/Utils/merge_chunks/merge_chunks.js +30 -0
- package/GUDHUB/Utils/merge_compare_items/merge_compare_items.js +316 -0
- package/GUDHUB/Utils/merge_compare_items/merge_compare_items.test.js +632 -0
- package/GUDHUB/Utils/merge_objects/merge_objects.js +120 -0
- package/GUDHUB/Utils/merge_objects/merge_objects.test.js +137 -0
- package/GUDHUB/Utils/nested_list/nested_list.js +38 -0
- package/GUDHUB/Utils/nested_list/nested_list.test.js +70 -0
- package/GUDHUB/Utils/populate_items/populate_items.js +66 -0
- package/GUDHUB/WebSocket/WebSocket.js +136 -0
- package/GUDHUB/config.js +8 -0
- package/GUDHUB/consts.js +1 -0
- package/GUDHUB/gudhub-https-service.js +193 -0
- package/GUDHUB/gudhub.js +477 -0
- package/GUDHUB/gudhub.test.js +218 -0
- package/GUDHUB/utils.js +25 -0
- package/Readme.md +537 -0
- package/fake_server/fake_java_server.js +112 -0
- package/fake_server/fake_server_data/app_132.js +3037 -0
- package/fake_server/fake_server_data/app_16259.js +1152 -0
- package/fake_server/fake_server_data/app_214.js +2057 -0
- package/fake_server/fake_server_data/app_8263.js +4167 -0
- package/fake_server/fake_server_data/chunks_mocks/bcacjbgqorherqmtykrj_8263.js +44561 -0
- package/fake_server/fake_server_data/chunks_mocks/bcjyuoqaewybudfyhir_8263.js +44197 -0
- package/fake_server/fake_server_data/chunks_mocks/tpajkpolmzklodcba_8263.js +44977 -0
- package/fake_server/fake_server_data/fake_server_data.js +111 -0
- package/index.js +3 -0
- package/indexUMD.js +5 -0
- package/package.json +45 -0
- package/umd/library.min.js +186 -0
- package/umd/library.min.js.map +1 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/*============================================================================*/
|
|
2
|
+
/*======================== PIPE MODULE ===============================*/
|
|
3
|
+
/*============================================================================*/
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
| ======================== PIPE EVENTS TYPES =================================
|
|
7
|
+
|
|
|
8
|
+
|
|
|
9
|
+
| ---------------------------- APP EVENTS -----------------------------------
|
|
10
|
+
| 'gh_app' - send event when element initialised
|
|
11
|
+
| 'gh_app_info_get' - Return app_name, app_id, app_icon
|
|
12
|
+
| 'gh_app_get' -
|
|
13
|
+
| 'gh_app_update' -
|
|
14
|
+
| 'gh_apps_list_get' -
|
|
15
|
+
| 'gh_delete_app' -
|
|
16
|
+
| 'gh_apps_list_update' -
|
|
17
|
+
|
|
|
18
|
+
| ---------------------------- VIEW EVENTS -----------------------------------
|
|
19
|
+
| 'gh_app_views_update' -
|
|
20
|
+
| 'gh_app_views_get' -
|
|
21
|
+
| 'gh_app_view_get' -
|
|
22
|
+
| -------------------------- ITEM EVENTS ------------------------------------
|
|
23
|
+
|
|
|
24
|
+
| 'gh_items_get' - get items_list
|
|
25
|
+
| 'gh_items_chunks_get' - get items splitted to chunks with specified chunk size
|
|
26
|
+
| 'gh_items_update' - update items_list
|
|
27
|
+
|
|
|
28
|
+
| 'gh_item_update' - item's any field value update
|
|
29
|
+
| 'gh_item_get' - item fields value get
|
|
30
|
+
|
|
|
31
|
+
| -------------------------- FIELD EVENTS -----------------------------------
|
|
32
|
+
|
|
|
33
|
+
| 'gh_model_get' - get field model in field_list.
|
|
34
|
+
| 'gh_model_update' - update field model in field_list
|
|
35
|
+
| 'gh_model_delete' - delete field model from field_list and from items
|
|
36
|
+
|
|
|
37
|
+
|
|
|
38
|
+
|
|
|
39
|
+
| 'gh_models_edit' - use in 'edit_template','edit_field' and 'edit_interpretation'
|
|
40
|
+
| actions
|
|
41
|
+
| 'gh_models_get' - get field_model list.
|
|
42
|
+
|
|
|
43
|
+
|
|
|
44
|
+
|
|
|
45
|
+
| 'gh_value_update' - update field value in item
|
|
46
|
+
| 'gh_value_get' - get field value
|
|
47
|
+
| 'gh_interpreted_value_get' - get field interpretation
|
|
48
|
+
| 'gh_value_set' - setter of field value
|
|
49
|
+
|
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
import { checkParams, createId } from "./utils.js";
|
|
53
|
+
|
|
54
|
+
export class PipeService {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.subscribers = {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//============================== ON PIPE ====================================//
|
|
60
|
+
/*----------------------------------------------------------------------------
|
|
61
|
+
| Params:
|
|
62
|
+
| 'type' - String (require). type of event ('gh_field_update', ........)
|
|
63
|
+
| from event list or maybe 'gh_field_update gh_field_value_update'
|
|
64
|
+
| 'destination' - Object (require).
|
|
65
|
+
| {
|
|
66
|
+
| app_id: '',
|
|
67
|
+
| item_id: ''
|
|
68
|
+
| field_id: ''
|
|
69
|
+
| }
|
|
70
|
+
| 'fn' - Function (require). callback function
|
|
71
|
+
| 'scope' - Scope
|
|
72
|
+
|------------------------------------------------------------------------------*/
|
|
73
|
+
|
|
74
|
+
on(types, destination, fn) {
|
|
75
|
+
if (checkParams(types, destination, fn)) {
|
|
76
|
+
types
|
|
77
|
+
.split(" ")
|
|
78
|
+
.map((type) => {
|
|
79
|
+
return type + ":" + createId(destination);
|
|
80
|
+
})
|
|
81
|
+
.forEach((typeWithId) => {
|
|
82
|
+
if (!this.subscribers[typeWithId]) {
|
|
83
|
+
this.subscribers[typeWithId] = new Set();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.subscribers[typeWithId].add(fn);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//============================== EMIT PIPE ====================================//
|
|
93
|
+
/*------------------------------------------------------------------------------
|
|
94
|
+
| Params:
|
|
95
|
+
| 'type' - String (require). type of event ('gh_field_update', ........)
|
|
96
|
+
| from eventlist
|
|
97
|
+
| 'destination' - Object (require).
|
|
98
|
+
| {
|
|
99
|
+
| app_id: '',
|
|
100
|
+
| item_id: ''
|
|
101
|
+
| field_id: ''
|
|
102
|
+
| }
|
|
103
|
+
| 'value' - Any (require). Emiter value to subscribers
|
|
104
|
+
|-------------------------------------------------------------------------------*/
|
|
105
|
+
|
|
106
|
+
emit(types, destination, address, params) {
|
|
107
|
+
types.split(" ").forEach((type) => {
|
|
108
|
+
const listenerName = type + ":" + createId(destination);
|
|
109
|
+
|
|
110
|
+
if (this.subscribers[listenerName]) {
|
|
111
|
+
this.subscribers[listenerName].forEach(function (fn) {
|
|
112
|
+
fn(null, address, params);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//============================== ON ROOT PIPE ====================================//
|
|
120
|
+
/*---------------------------------------------------------------------------------
|
|
121
|
+
| Params:
|
|
122
|
+
| 'type' - String (require). type of event ('gh_field_update', ........)
|
|
123
|
+
| from event list or maybe 'gh_field_update gh_field_value_update'
|
|
124
|
+
| 'destination' - Object (require).
|
|
125
|
+
| {
|
|
126
|
+
| app_id: '',
|
|
127
|
+
| item_id: ''
|
|
128
|
+
| field_id: ''
|
|
129
|
+
| }
|
|
130
|
+
| 'fn' - Function (require). callback function
|
|
131
|
+
|---------------------------------------------------------------------------------*/
|
|
132
|
+
|
|
133
|
+
onRoot(type, destination, fn) {
|
|
134
|
+
return this.on(type, destination, fn);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//=========================== DELETE LISTENER =================================//
|
|
138
|
+
/*-------------------------------------------------------------------------------
|
|
139
|
+
| Params:
|
|
140
|
+
| 'type' - String (require). type of event ('gh_field_update', ........)
|
|
141
|
+
| from eventlist
|
|
142
|
+
| 'destination' - Object (require).
|
|
143
|
+
| {
|
|
144
|
+
| app_id: '',
|
|
145
|
+
| item_id: ''
|
|
146
|
+
| field_id: ''
|
|
147
|
+
| }
|
|
148
|
+
|--------------------------------------------------------------------------------*/
|
|
149
|
+
|
|
150
|
+
destroy(types, destination, func) {
|
|
151
|
+
types.split(" ").forEach((type) => {
|
|
152
|
+
const listenerName = type + ":" + createId(destination);
|
|
153
|
+
|
|
154
|
+
//if we pass a function then we remove just function in subscriber property
|
|
155
|
+
if (this.subscribers[listenerName] && func) {
|
|
156
|
+
this.subscribers[listenerName].delete(func);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//if we are not passing a function then we remove a subscriber property
|
|
160
|
+
if (this.subscribers[listenerName] && !func) {
|
|
161
|
+
delete this.subscribers[listenerName]
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import should from "should";
|
|
2
|
+
import { data } from "../../fake_server/fake_server_data/fake_server_data.js";
|
|
3
|
+
import {GudHub} from './../gudhub.js';
|
|
4
|
+
|
|
5
|
+
describe("PipeService", () => {
|
|
6
|
+
var auth_key = 'Z/lxMHLenEaQTvPjW5U6c3jBDwWFYZrh2F9Kxa3fbt8drvabS2u2lXQ2zI+SRmic';
|
|
7
|
+
const gudhub = new GudHub(auth_key);
|
|
8
|
+
|
|
9
|
+
it("add new subscriber", () => {
|
|
10
|
+
gudhub.on("gh_items_get", { app_id: 121 }, () => {});
|
|
11
|
+
gudhub.pipeService.subscribers.should.have.property("gh_items_get:121");
|
|
12
|
+
gudhub.pipeService.subscribers["gh_items_get:121"].size.should.equal(1);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("add new subscriber and emit it", () => {
|
|
16
|
+
gudhub.on("gh_app_get", {}, (event, request) => {
|
|
17
|
+
const app = data[request.app_id];
|
|
18
|
+
gudhub.pipeService.emit("gh_app_get", request, app);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
gudhub
|
|
22
|
+
.on("gh_app_get", { app_id: 214 }, (event, app) => {
|
|
23
|
+
app.app_name.should.have.equal("Aqua-Test");
|
|
24
|
+
})
|
|
25
|
+
.emit("gh_app_get", {}, { app_id: 214 });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("add new subscriber on App and delete it", () => {
|
|
29
|
+
function getApp() {}
|
|
30
|
+
|
|
31
|
+
gudhub.on("gh_app_get", { app_id: 200 }, getApp);
|
|
32
|
+
gudhub.pipeService.subscribers["gh_app_get:200"].size.should.have.equal(1);
|
|
33
|
+
gudhub.destroy("gh_app_get", { app_id: 200 }, getApp);
|
|
34
|
+
gudhub.pipeService.subscribers["gh_app_get:200"].size.should.have.equal(0);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("add new subscriber on GH-Element value update and delete it", () => {
|
|
38
|
+
function modelUpdate() {}
|
|
39
|
+
var model_address = {
|
|
40
|
+
app_id: 11,
|
|
41
|
+
field_id: 222
|
|
42
|
+
};
|
|
43
|
+
gudhub.on("gh_model_update", model_address, modelUpdate);
|
|
44
|
+
gudhub.pipeService.subscribers["gh_model_update:11.222"].size.should.have.equal(1);
|
|
45
|
+
gudhub.destroy("gh_model_update", model_address, modelUpdate);
|
|
46
|
+
gudhub.pipeService.subscribers["gh_model_update:11.222"].size.should.have.equal(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
it("add several subscriber on one GH-Element and delete all of them at one function call", () => {
|
|
51
|
+
function modelUpdate() {};
|
|
52
|
+
function modelGet() {};
|
|
53
|
+
var model_address = {
|
|
54
|
+
app_id: 22,
|
|
55
|
+
field_id: 333
|
|
56
|
+
};
|
|
57
|
+
gudhub.on("gh_model_update", model_address, modelUpdate);
|
|
58
|
+
gudhub.on("gh_model_update", model_address, modelGet);
|
|
59
|
+
gudhub.pipeService.subscribers["gh_model_update:22.333"].size.should.have.equal(2);
|
|
60
|
+
gudhub.destroy("gh_model_update", model_address);
|
|
61
|
+
gudhub.pipeService.subscribers.should.not.have.property("gh_model_update:22.333");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
export function createId(obj) {
|
|
3
|
+
let stringId = "";
|
|
4
|
+
for (let key in obj) {
|
|
5
|
+
if (obj.hasOwnProperty(key) && obj[key]) {
|
|
6
|
+
stringId += "." + obj[key];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return stringId ? stringId.substring(1) : "any";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function checkParams(type, destination, fn) {
|
|
13
|
+
if (type == undefined || typeof type !== "string") {
|
|
14
|
+
console.log(
|
|
15
|
+
"Listener type is \"undefined\" or not have actual 'type' for subscribe"
|
|
16
|
+
);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (destination == undefined || typeof destination !== "object") {
|
|
21
|
+
console.log(
|
|
22
|
+
"Listener destination is \"undefined\" or not have actual 'type' for subscribe"
|
|
23
|
+
);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof fn !== "function") {
|
|
28
|
+
console.log("Listener is not a function for subscribe!");
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { IS_WEB } from "../../consts.js";
|
|
2
|
+
|
|
3
|
+
export class AppProcessor {
|
|
4
|
+
constructor(
|
|
5
|
+
storage,
|
|
6
|
+
pipeService,
|
|
7
|
+
req,
|
|
8
|
+
websocket,
|
|
9
|
+
chunksManager,
|
|
10
|
+
util,
|
|
11
|
+
activateSW
|
|
12
|
+
) {
|
|
13
|
+
this.storage = storage;
|
|
14
|
+
this.pipeService = pipeService;
|
|
15
|
+
this.req = req;
|
|
16
|
+
this.ws = websocket;
|
|
17
|
+
this.applistReceived = false;
|
|
18
|
+
this.activateSW = activateSW; // we use this flag to check if applist was received. The problem is that if you receive an app it also goes to app_list as a result you have the app_list with one app.
|
|
19
|
+
this.chunksManager = chunksManager;
|
|
20
|
+
this.util = util;
|
|
21
|
+
this.appListeners();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async createNewAppApi(app) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await this.req.post({
|
|
27
|
+
url: "/api/app/create",
|
|
28
|
+
form: { app: JSON.stringify(app) },
|
|
29
|
+
});
|
|
30
|
+
response.from_apps_list = true;
|
|
31
|
+
return response;
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.log(err);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async updateAppApi(app) {
|
|
39
|
+
try {
|
|
40
|
+
const response = await this.req.post({
|
|
41
|
+
url: "/api/app/update",
|
|
42
|
+
form: { app: JSON.stringify(app) },
|
|
43
|
+
});
|
|
44
|
+
return response;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.log(err);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async deleteAppApi(app_id) {
|
|
52
|
+
try {
|
|
53
|
+
const response = await this.req.post({
|
|
54
|
+
url: "/api/app/delete",
|
|
55
|
+
form: { app_id },
|
|
56
|
+
});
|
|
57
|
+
return response;
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.log(err);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async getAppListApi() {
|
|
65
|
+
try {
|
|
66
|
+
const response = await this.req.get({
|
|
67
|
+
url: "/api/applist/get",
|
|
68
|
+
});
|
|
69
|
+
return response.apps_list.map((app) => {
|
|
70
|
+
app.from_apps_list = true;
|
|
71
|
+
return app;
|
|
72
|
+
});
|
|
73
|
+
} catch (err) {
|
|
74
|
+
console.log(err);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async getAppApi(app_id) {
|
|
80
|
+
try {
|
|
81
|
+
const response = await this.req.get({
|
|
82
|
+
url: "/api/app/get",
|
|
83
|
+
params: {
|
|
84
|
+
app_id: app_id,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return response;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
console.log(err);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getAppListFromStorage() {
|
|
95
|
+
return this.storage.getAppsList();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getAppFromStorage(app_id) {
|
|
99
|
+
const app = this.storage.getApp(app_id);
|
|
100
|
+
return app && app.field_list.length ? app : null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
addNewAppToStorage(app) {
|
|
104
|
+
return this.storage.getAppsList().push(app);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
saveAppInStorage(app) {
|
|
108
|
+
const storageApp = this.storage.getApp(app.app_id);
|
|
109
|
+
if (storageApp) {
|
|
110
|
+
app.from_apps_list = storageApp.from_apps_list;
|
|
111
|
+
app.permission = storageApp.permission;
|
|
112
|
+
this.storage.updateApp(app);
|
|
113
|
+
} else {
|
|
114
|
+
app.from_apps_list = false;
|
|
115
|
+
this.addNewAppToStorage(app);
|
|
116
|
+
}
|
|
117
|
+
return this.getAppFromStorage(app.app_id);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
updatingAppInStorage(app) {
|
|
121
|
+
const storageApp = this.getAppFromStorage(app.app_id);
|
|
122
|
+
app.items_list = storageApp.items_list;
|
|
123
|
+
app.file_list = storageApp.file_list;
|
|
124
|
+
app.from_apps_list = storageApp.from_apps_list;
|
|
125
|
+
this.storage.updateApp(app);
|
|
126
|
+
//-- Sending updates for Views Updates
|
|
127
|
+
this.pipeService.emit(
|
|
128
|
+
"gh_app_views_update",
|
|
129
|
+
{ app_id: app.app_id },
|
|
130
|
+
app.views_list
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
//-- Sending updates for updating Fields
|
|
134
|
+
app.field_list.forEach((fieldModel) => {
|
|
135
|
+
this.pipeService.emit(
|
|
136
|
+
"gh_model_update",
|
|
137
|
+
{ app_id: app.app_id, field_id: fieldModel.field_id },
|
|
138
|
+
fieldModel
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
deletingAppFromStorage(app_id) {
|
|
144
|
+
let appList = this.storage.getAppsList();
|
|
145
|
+
appList.forEach((app, key) => {
|
|
146
|
+
if (app.app_id == app_id) appList.splice(key);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
return appList;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//-- here we check if app already in storage then we dont update it.
|
|
153
|
+
//-- the thing is that is posible that we receive app before receiveng an applist
|
|
154
|
+
updateAppsListInStorage(appsList = []) {
|
|
155
|
+
for (const app of appsList) {
|
|
156
|
+
const storageApp = this.storage.getApp(app.app_id);
|
|
157
|
+
if (storageApp) {
|
|
158
|
+
storageApp.from_apps_list = app.from_apps_list;
|
|
159
|
+
storageApp.permission = app.permission;
|
|
160
|
+
} else this.addNewAppToStorage(app);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async refreshApps(apps_id = []) {
|
|
165
|
+
for (const app_id of apps_id) {
|
|
166
|
+
if (app_id != undefined && this.storage.getApp(app_id)) {
|
|
167
|
+
try {
|
|
168
|
+
const app = await this.getAppApi(app_id);
|
|
169
|
+
if (app) {
|
|
170
|
+
this.storage.updateApp(app);
|
|
171
|
+
}
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.log(err);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
console.log("Apps refreshed: ", JSON.stringify(apps_id));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async getAppsList() {
|
|
181
|
+
let app_list = this.getAppListFromStorage();
|
|
182
|
+
if (!this.applistReceived) {
|
|
183
|
+
let received_app_list = await this.getAppListApi();
|
|
184
|
+
if (!received_app_list) return null;
|
|
185
|
+
|
|
186
|
+
// for oprimization purpose: in case when there was severals calls at same moment of the getAppLists one call will overwrite app_list of another call with the same app_list,
|
|
187
|
+
this.updateAppsListInStorage(received_app_list);
|
|
188
|
+
this.applistReceived = true;
|
|
189
|
+
app_list = received_app_list;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return app_list;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
//********** GET APP INFO ************/
|
|
196
|
+
//-- it returs App with Empty fields_list, items_list, file_list, views_list
|
|
197
|
+
//-- Such simmple data needed to render App Icons, and do some simple updates in App like updating App name icon permisions etc when full app data is not needed
|
|
198
|
+
async getAppInfo(app_id) {
|
|
199
|
+
const app_list = await this.getAppsList();
|
|
200
|
+
return app_list ? app_list.find((app) => app.app_id == app_id) : null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async deleteApp(app_id) {
|
|
204
|
+
await this.deleteAppApi(app_id);
|
|
205
|
+
return this.deletingAppFromStorage(app_id);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async getApp(app_id) {
|
|
209
|
+
if (!app_id) return null;
|
|
210
|
+
|
|
211
|
+
let app = this.getAppFromStorage(app_id);
|
|
212
|
+
if (!app) {
|
|
213
|
+
let receivedApp = await this.getAppApi(app_id);
|
|
214
|
+
if (!receivedApp) return null;
|
|
215
|
+
|
|
216
|
+
//!!! temporary check !!!! if app has chanks property then we start getting it
|
|
217
|
+
if (receivedApp.chunks && receivedApp.chunks.length) {
|
|
218
|
+
this.chunksManager
|
|
219
|
+
.getChunks(app_id, receivedApp.chunks)
|
|
220
|
+
.then((chunks) => {
|
|
221
|
+
receivedApp.items_list = this.util.mergeChunks([
|
|
222
|
+
...chunks,
|
|
223
|
+
receivedApp,
|
|
224
|
+
]);
|
|
225
|
+
this.saveAppInStorage(receivedApp);
|
|
226
|
+
this.pipeService.emit(
|
|
227
|
+
"gh_items_update",
|
|
228
|
+
{ app_id },
|
|
229
|
+
receivedApp.items_list
|
|
230
|
+
);
|
|
231
|
+
});
|
|
232
|
+
app = receivedApp
|
|
233
|
+
this.saveAppInStorage(receivedApp);
|
|
234
|
+
} else {
|
|
235
|
+
app = this.getAppFromStorage(app_id);
|
|
236
|
+
// for oprimization purpose: we check if app was already received in case when there was severals calls at same moment of the getApp one call will overwrite the App from another call with the same App,
|
|
237
|
+
if (!app) {
|
|
238
|
+
app = receivedApp;
|
|
239
|
+
this.saveAppInStorage(receivedApp); //!!! will be saved over several times for each app request
|
|
240
|
+
this.ws.addSubscription(app_id);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return app;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async updateApp(app) {
|
|
249
|
+
if (!app.view_list || !app.view_list.length) {
|
|
250
|
+
const storageApp = await this.getApp(app.app_id);
|
|
251
|
+
app.view_list = storageApp.view_list;
|
|
252
|
+
}
|
|
253
|
+
const updatedApp = await this.updateAppApi(app);
|
|
254
|
+
this.updatingAppInStorage(updatedApp);
|
|
255
|
+
return updatedApp;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async updateAppInfo(appInfo = {}) {
|
|
259
|
+
const app = this.getAppFromStorage(appInfo.app_id);
|
|
260
|
+
return this.updateApp({ ...app, ...appInfo });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async createNewApp(app) {
|
|
264
|
+
const newApp = await this.createNewAppApi(app);
|
|
265
|
+
this.addNewAppToStorage(newApp);
|
|
266
|
+
return newApp;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
clearAppProcessor() {
|
|
270
|
+
this.getAppListPromises = null;
|
|
271
|
+
this.getAppPromises = {};
|
|
272
|
+
this.applistReceived = false;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
appListeners() {
|
|
276
|
+
this.pipeService.onRoot("gh_app_get", {}, async (event, data) => {
|
|
277
|
+
if (data && data.app_id) {
|
|
278
|
+
const app = await this.getApp(data.app_id);
|
|
279
|
+
this.pipeService.emit("gh_app_get", data, app);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
this.pipeService.onRoot("gh_apps_list_get", {}, async (event, data) => {
|
|
284
|
+
const appList = await this.getAppsList();
|
|
285
|
+
this.pipeService.emit("gh_apps_list_get", data, appList);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
this.pipeService.onRoot("gh_delete_app", {}, async (event, data) => {
|
|
289
|
+
const appList = await this.deleteApp(data.app_id);
|
|
290
|
+
this.pipeService.emit(
|
|
291
|
+
"gh_apps_list_update",
|
|
292
|
+
{ recipient: "all" },
|
|
293
|
+
appList
|
|
294
|
+
);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
this.pipeService.onRoot("gh_app_update", {}, async (event, data) => {
|
|
298
|
+
data.app.items_list = [];
|
|
299
|
+
data.app.file_list = [];
|
|
300
|
+
|
|
301
|
+
const newApp = await this.updateApp(data.app);
|
|
302
|
+
|
|
303
|
+
this.pipeService.emit(
|
|
304
|
+
"gh_app_views_update",
|
|
305
|
+
{ app_id: newApp.app_id },
|
|
306
|
+
newApp.views_list
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const appsList = await this.getAppsList();
|
|
310
|
+
this.pipeService.emit(
|
|
311
|
+
"gh_apps_list_update",
|
|
312
|
+
{ recipient: "all" },
|
|
313
|
+
appsList
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
newApp.field_list.forEach((fieldModel) => {
|
|
317
|
+
this.pipeService.emit(
|
|
318
|
+
"gh_model_update",
|
|
319
|
+
{
|
|
320
|
+
app_id: newApp.app_id,
|
|
321
|
+
field_id: fieldModel.field_id,
|
|
322
|
+
},
|
|
323
|
+
fieldModel
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
this.pipeService.onRoot("gh_app_view_get", {}, async (event, data) => {
|
|
329
|
+
if (data && data.app_id) {
|
|
330
|
+
const app = await this.getApp(data.app_id);
|
|
331
|
+
app.views_list.forEach((view, key) => {
|
|
332
|
+
if (view.view_id == data.view_id) {
|
|
333
|
+
this.pipeService.emit("gh_app_view_get", data, app.views_list[key]);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
this.pipeService.onRoot("gh_app_views_get", {}, async (event, data) => {
|
|
340
|
+
if (data && data.app_id) {
|
|
341
|
+
const app = await this.getApp(data.app_id);
|
|
342
|
+
this.pipeService.emit("gh_app_views_get", data, app.views_list);
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// Return app_name, app_id, app_icon
|
|
347
|
+
this.pipeService.onRoot("gh_app_info_get", {}, async (event, data) => {
|
|
348
|
+
const appInfo = await this.getAppInfo(data.app_id);
|
|
349
|
+
if (appInfo) this.pipeService.emit("gh_app_info_get", data, appInfo);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
this.pipeService.onRoot("gh_app_info_update", {}, async (event, data) => {
|
|
353
|
+
if (data && data.app) {
|
|
354
|
+
const appInfo = await this.updateAppInfo(data.app);
|
|
355
|
+
this.pipeService.emit(
|
|
356
|
+
"gh_app_info_update",
|
|
357
|
+
{ app_id: data.app.app_id },
|
|
358
|
+
appInfo
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
this.pipeService.onRoot("gh_app_create", {}, async (event, data) => {
|
|
364
|
+
await this.createNewApp(data.app);
|
|
365
|
+
const appsList = await this.getAppsList();
|
|
366
|
+
this.pipeService.emit(
|
|
367
|
+
"gh_apps_list_update",
|
|
368
|
+
{ recipient: "all" },
|
|
369
|
+
appsList
|
|
370
|
+
);
|
|
371
|
+
});
|
|
372
|
+
if (IS_WEB && this.activateSW) {
|
|
373
|
+
navigator.serviceWorker.addEventListener("message", async (event) => {
|
|
374
|
+
if (event.data.type === "refresh app") {
|
|
375
|
+
const app = this.getAppFromStorage(event.data.payload.app_id);
|
|
376
|
+
if (app && app.items_list.length) {
|
|
377
|
+
this.util.compareAppsItemsLists(
|
|
378
|
+
event.data.payload.items_list,
|
|
379
|
+
app.items_list,
|
|
380
|
+
({ diff_fields_items, diff_fields_items_Ids, diff_items }) => {
|
|
381
|
+
if (diff_items.length) {
|
|
382
|
+
this.pipeService.emit(
|
|
383
|
+
"gh_items_update",
|
|
384
|
+
{ app_id: event.data.payload.app_id },
|
|
385
|
+
event.data.payload.items_list
|
|
386
|
+
);
|
|
387
|
+
diff_items.forEach((item) =>
|
|
388
|
+
this.pipeService.emit(
|
|
389
|
+
"gh_item_update",
|
|
390
|
+
{ app_id: event.data.payload.app_id, item_id: item.item_id },
|
|
391
|
+
item
|
|
392
|
+
)
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
diff_fields_items_Ids.forEach((item_id) => {
|
|
396
|
+
const item = diff_fields_items[item_id];
|
|
397
|
+
if (!item) return;
|
|
398
|
+
item.forEach((field) => {
|
|
399
|
+
this.pipeService.emit(
|
|
400
|
+
"gh_value_update",
|
|
401
|
+
{
|
|
402
|
+
app_id: event.data.payload.app_id,
|
|
403
|
+
item_id,
|
|
404
|
+
field_id: field.field_id,
|
|
405
|
+
},
|
|
406
|
+
field.field_value
|
|
407
|
+
);
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
event.data.payload.items_list = this.util.mergeChunks([app, event.data.payload])
|
|
414
|
+
this.saveAppInStorage(event.data.payload);
|
|
415
|
+
}
|
|
416
|
+
// if (event.data.type === "refresh appList") {
|
|
417
|
+
// this.storage.unsetApps();
|
|
418
|
+
// this.updateAppsListInStorage(
|
|
419
|
+
// event.data.payload.apps_list.map((app) => {
|
|
420
|
+
// app.from_apps_list = true;
|
|
421
|
+
// return app;
|
|
422
|
+
// })
|
|
423
|
+
// );
|
|
424
|
+
// this.pipeService.emit(
|
|
425
|
+
// "gh_apps_list_update",
|
|
426
|
+
// { recipient: "all" },
|
|
427
|
+
// event.data.payload.apps_list
|
|
428
|
+
// );
|
|
429
|
+
// }
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|