@gudhub/core 1.1.13 → 1.1.16

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.
@@ -51,10 +51,15 @@ export class ItemProcessor {
51
51
  }
52
52
 
53
53
  addItemsToStorage(app_id, items) {
54
+ // !!!!! Need to fix this
54
55
  const app = this.storage.getApp(app_id);
55
56
  if (app) {
56
57
  items.forEach((item) => {
57
58
  app.items_list.push(item);
59
+ app.items_object[item.item_id] = {};
60
+ for(let field = 0; field < item.fields.length; field++) {
61
+ app.items_object[item.item_id][item.fields[field].field_id] = item.fields[field];
62
+ }
58
63
  this.pipeService.emit("gh_item_update", { app_id }, [item]);
59
64
  });
60
65
  this.pipeService.emit("gh_items_update", { app_id }, app.items_list);
@@ -88,6 +93,8 @@ export class ItemProcessor {
88
93
  //-- Checking if value of existing fields were updated, because we are not sending updates if value didn't changed
89
94
  if (fundedField.field_value != field.field_value) {
90
95
  fundedField.field_value = field.field_value;
96
+ app.items_object[fundedItem.item_id][fundedField.field_id] = fundedField;
97
+
91
98
  this.pipeService.emit(
92
99
  "gh_value_update",
93
100
  addressToEmit,
@@ -113,9 +120,13 @@ export class ItemProcessor {
113
120
  deleteItemsFromStorage(app_id, itemsForDelete = []) {
114
121
  const app = this.storage.getApp(app_id);
115
122
  if (app) {
116
- app.items_list = app.items_list.filter(
117
- (item) => !itemsForDelete.includes(item.item_id)
118
- );
123
+ app.items_list = app.items_list.filter(item => {
124
+ if(itemsForDelete.find(findedItem => item.item_id == findedItem.item_id)) {
125
+ delete app.items_object[item.item_id];
126
+ return false;
127
+ }
128
+ return true;
129
+ });
119
130
  this.pipeService.emit("gh_items_update", { app_id }, app.items_list);
120
131
  this.storage.updateApp(app);
121
132
  }
@@ -148,8 +159,8 @@ export class ItemProcessor {
148
159
  }
149
160
 
150
161
  async deleteItems(app_id, itemsIds) {
151
- return this.deleteItemsApi(itemsIds).then(() =>
152
- this.deleteItemsFromStorage(app_id, itemsIds)
162
+ return this.deleteItemsApi(itemsIds).then((items) =>
163
+ this.deleteItemsFromStorage(app_id, items)
153
164
  );
154
165
  }
155
166
 
@@ -0,0 +1,76 @@
1
+ import should from "should";
2
+ import { GudHub } from './../gudhub.js';
3
+
4
+ describe("ITEM PROCESSOR", async function () {
5
+ const auth_key = 'Z/lxMHLenEaQTvPjW5U6c3jBDwWFYZrh2F9Kxa3fbt8drvabS2u2lXQ2zI+SRmic';
6
+ const gudhub = new GudHub(auth_key);
7
+
8
+
9
+ it("GET ITEM / should return an item", async () => {
10
+ let item = await gudhub.getItem(16259, 1064673);
11
+ item.item_id.should.equal(1064673)
12
+ let itemType = typeof item;
13
+ itemType.should.equal('object');
14
+ });
15
+
16
+ it("ADD ITEM AND GET IT / should return new item twice", async () => {
17
+ let items = await gudhub.addNewItems(16259, newItems);
18
+
19
+ let isItemsArray = Array.isArray(items);
20
+
21
+ isItemsArray.should.equal(true);
22
+ items[0].fields[0].field_value.should.equal('Big Fish Tank');
23
+
24
+ let item = await gudhub.getItem(16259, items[0].item_id);
25
+
26
+ item.fields[0].field_value.should.equal('Big Fish Tank');
27
+ });
28
+
29
+ it("ADD NEW ITEM AND GET ITS VALUE / should return new item's value", async () => {
30
+ let items = await gudhub.addNewItems(16259, newItems);
31
+ let item_id = items[0].item_id;
32
+
33
+ let value = await gudhub.getFieldValue(16259, item_id, 254056);
34
+
35
+ value.should.equal('Big Fish Tank');
36
+ });
37
+
38
+ it("ADD NEW ITEM, UPDATE ITS VALUE AND GET IT / should return updated value of new item", async () => {
39
+ let items = await gudhub.addNewItems(16259, newItems);
40
+ let item_id = items[0].item_id;
41
+
42
+ await gudhub.setFieldValue(16259, item_id, 254056, 'Updated value');
43
+
44
+ let value = await gudhub.getFieldValue(16259, item_id, 254056);
45
+
46
+ value.should.equal('Updated value');
47
+ });
48
+
49
+ it("ADD NEW ITEM, THEN DELETE IT / should return null", async () => {
50
+ let items = await gudhub.addNewItems(16259, newItems);
51
+ let item_id = items[0].item_id;
52
+
53
+ await gudhub.deleteItems(16259, [item_id]);
54
+
55
+ let value = await gudhub.getFieldValue(16259, item_id, 254056);
56
+
57
+ let isValueNull = value === null ? true : false;
58
+
59
+ isValueNull.should.equal(true);
60
+ });
61
+
62
+ });
63
+
64
+ const newItems = [
65
+ {
66
+ item_id: 0,
67
+ fields: [
68
+ {
69
+ field_id: 254056,
70
+ element_id: 254056,
71
+ field_value: "Big Fish Tank",
72
+ data_id: 5994845
73
+ }
74
+ ]
75
+ },
76
+ ]
@@ -62,16 +62,16 @@ describe("PipeService", () => {
62
62
  });
63
63
 
64
64
 
65
- it("Emitting event and then adding new subscriber", () => {
66
- let incomeData = null;
65
+ // it("Emitting event and then adding new subscriber", () => {
66
+ // let incomeData = null;
67
67
 
68
- gudhub
69
- .emit("test", { app_id: 4, item_id: 3, field_id: 2 }, {"message" : "this is the data"})
70
- .on("test", { app_id: 4, item_id: 3, field_id: 2 }, (event, data) => {
71
- incomeData = data.message;
72
- });
73
- incomeData.should.equal("this is the data");
74
- });
68
+ // gudhub
69
+ // .emit("test", { app_id: 4, item_id: 3, field_id: 2 }, {"message" : "this is the data"})
70
+ // .on("test", { app_id: 4, item_id: 3, field_id: 2 }, (event, data) => {
71
+ // incomeData = data.message;
72
+ // });
73
+ // incomeData.should.equal("this is the data");
74
+ // });
75
75
 
76
76
 
77
77
  });
@@ -87,8 +87,9 @@ export default function generateModulesList(async_modules_path, file_server_url)
87
87
  },
88
88
  {
89
89
  name: "calendar",
90
- url: file_server_url + '/' + async_modules_path + "calendar_data.js",
91
- type: 'angular'
90
+ js: 'https://gudhub.com/modules/FullCalendar-Gh-Element/dist/main.js',
91
+ css: 'https://gudhub.com/modules/FullCalendar-Gh-Element/dist/style.css',
92
+ type: "class"
92
93
  },
93
94
  {
94
95
  name: "data_ref",
@@ -23,7 +23,7 @@ export default class AppsTemplateService {
23
23
  })
24
24
  }).then(success => {
25
25
  self.createItems(success, maxNumberOfInsstalledItems, (status) => {
26
- if(typeof status === 'string') {
26
+ if (typeof status === 'string') {
27
27
  currentStep += 1;
28
28
  progressCallback.call(this, {
29
29
  percent: currentStep * stepPercents,
@@ -51,67 +51,67 @@ export default class AppsTemplateService {
51
51
 
52
52
  create_apps.forEach(app => {
53
53
  promises.push(new Promise(app_resolve => {
54
- self.gudhub.getApp(self._searchOldAppId(app.app_id, self.appsConnectingMap.apps)).then(result_app => {
55
- callback ? callback.call(this, `GET APP: ${result_app.app_name} (Items steps)`) : null;
56
- let source_app = JSON.parse(JSON.stringify(result_app));
57
- let items = source_app.items_list.map(item => {
58
- return {
59
- index_number: item.index_number,
60
- item_id: 0,
61
- fields: []
62
- }
63
- }).filter((item, index) => index <= MAX_NUMBER_OF_INSTALLED_ITEMS);
54
+ self.gudhub.getApp(self._searchOldAppId(app.app_id, self.appsConnectingMap.apps)).then(result_app => {
55
+ callback ? callback.call(this, `GET APP: ${result_app.app_name} (Items steps)`) : null;
56
+ let source_app = JSON.parse(JSON.stringify(result_app));
57
+ let items = source_app.items_list.map(item => {
58
+ return {
59
+ index_number: item.index_number,
60
+ item_id: 0,
61
+ fields: []
62
+ }
63
+ }).filter((item, index) => index <= MAX_NUMBER_OF_INSTALLED_ITEMS);
64
64
 
65
- self.gudhub.addNewItems(app.app_id, items).then(items => {
66
- callback ? callback.call(this, `ADD NEW ITEMS: ${result_app.app_name} (Items steps)`) : null;
65
+ self.gudhub.addNewItems(app.app_id, items).then(items => {
66
+ callback ? callback.call(this, `ADD NEW ITEMS: ${result_app.app_name} (Items steps)`) : null;
67
67
 
68
- if(items.length === 0) {
69
- callback ? callback.call(this, `NO ITEMS TO REPLACE VALUE: ${result_app.app_name} (Items steps)`) : null;
70
- app_resolve();
71
- }
68
+ if (items.length === 0) {
69
+ callback ? callback.call(this, `NO ITEMS TO REPLACE VALUE: ${result_app.app_name} (Items steps)`) : null;
70
+ app_resolve();
71
+ }
72
72
 
73
- app.items_list = items;
74
- self._updateMap(app.items_list, source_app.items_list);
75
- self._addFieldValue(source_app.items_list, app.items_list, self.appsConnectingMap);
76
-
77
- createsItems.push(app);
78
-
79
- if (self.appsConnectingMap.apps.length === createsItems.length) {
80
- createsItems.forEach(app => {
81
- app.items_list.forEach(item => {
82
- item.fields.forEach(field_item => {
83
- self.appsConnectingMap.fields.forEach(field_map => {
84
- if (field_item.field_id === field_map.old_field_id) {
85
- field_item.field_id = field_map.new_field_id;
86
- field_item.element_id = field_map.new_field_id;
87
- }
73
+ app.items_list = items;
74
+ self._updateMap(app.items_list, source_app.items_list);
75
+ self._addFieldValue(source_app.items_list, app.items_list, self.appsConnectingMap);
76
+
77
+ createsItems.push(app);
78
+
79
+ if (self.appsConnectingMap.apps.length === createsItems.length) {
80
+ createsItems.forEach(app => {
81
+ app.items_list.forEach(item => {
82
+ item.fields.forEach(field_item => {
83
+ self.appsConnectingMap.fields.forEach(field_map => {
84
+ if (field_item.field_id === field_map.old_field_id) {
85
+ field_item.field_id = field_map.new_field_id;
86
+ field_item.element_id = field_map.new_field_id;
87
+ }
88
+ })
88
89
  })
89
90
  })
90
- })
91
- });
92
-
93
- self.deleteField(createsItems);
94
-
95
- self.replaceValue(createsItems, self.appsConnectingMap).then(() => {
96
- callback ? callback.call(this, `REPLACE VALUE: ${result_app.app_name} (Items steps)`) : null;
97
- createsItems.forEach(created_app => {
98
- let newItems = created_app.items_list.map(item => {
99
- item.fields.forEach(field => {
100
- delete field.data_id;
91
+ });
92
+
93
+ self.deleteField(createsItems);
94
+
95
+ self.replaceValue(createsItems, self.appsConnectingMap).then(() => {
96
+ callback ? callback.call(this, `REPLACE VALUE: ${result_app.app_name} (Items steps)`) : null;
97
+ createsItems.forEach(created_app => {
98
+ let newItems = created_app.items_list.map(item => {
99
+ item.fields.forEach(field => {
100
+ delete field.data_id;
101
+ });
102
+ return item;
101
103
  });
102
- return item;
103
- });
104
104
 
105
- self.gudhub.updateItems(created_app.app_id, newItems).then(() => {
106
- app_resolve();
105
+ self.gudhub.updateItems(created_app.app_id, newItems).then(() => {
106
+ app_resolve();
107
+ })
107
108
  })
108
- })
109
- });
110
- }
109
+ });
110
+ }
111
+ });
111
112
  });
112
- });
113
- }));
114
- });
113
+ }));
114
+ });
115
115
 
116
116
  Promise.all(promises).then(() => {
117
117
  let apps = create_apps.map(app => {
@@ -144,24 +144,32 @@ export default class AppsTemplateService {
144
144
  self._replaceValueItemRef(app, field_of_list, map);
145
145
  }
146
146
 
147
- allPromises.push(self.gudhub.ghconstructor.getInstance(field_of_list.data_type).then(data => {
148
- if (data.getTemplate().constructor == 'file') {
149
- return self.gudhub.util.fileInstallerHelper(app.app_id, app.items_list, field_of_list.field_id).then(result => {
150
- return result;
151
- });
152
- } else if (data.getTemplate().constructor == 'document') {
153
- self.documentInstallerHelper(app.app_id, app.items_list, field_of_list.field_id).then(result => {
154
- return data;
147
+ allPromises.push(new Promise(resolve => {
148
+ self.gudhub.ghconstructor.getInstance(field_of_list.data_type).then(data => {
149
+ if(typeof data === 'undefined') {
150
+ console.log('ERROR WHILE GETTING INSTANCE OF ', field_of_list.data_type);
151
+ resolve({
152
+ type: field_of_list.data_type
153
+ });
154
+ return;
155
+ }
156
+ if (data.getTemplate().constructor == 'file') {
157
+ return self.gudhub.util.fileInstallerHelper(app.app_id, app.items_list, field_of_list.field_id).then(result => {
158
+ resolve(result);
159
+ });
160
+ } else if (data.getTemplate().constructor == 'document') {
161
+ self.documentInstallerHelper(app.app_id, app.items_list, field_of_list.field_id).then(result => {
162
+ resolve(data);
163
+ })
164
+ } else {
165
+ resolve(data);
166
+ }
155
167
  })
156
- } else {
157
- return data;
158
- }
159
168
  }))
160
-
161
169
  })
162
170
  });
163
171
 
164
- if(allPromises.length > 0) {
172
+ if (allPromises.length > 0) {
165
173
 
166
174
  Promise.all(allPromises).then(result => {
167
175
  resolve(result);
@@ -136,7 +136,7 @@ export function compiler(scheme, item, util, variables) {
136
136
 
137
137
  async function getFilteredItems(filtersList, element_app_id, app_id, item_id, itemsList) {
138
138
  const modified_filters_list = await util.gudhub.prefilter(
139
- filtersList,
139
+ JSON.parse(JSON.stringify(filtersList)),
140
140
  element_app_id,
141
141
  app_id,
142
142
  item_id,
@@ -1,14 +1,29 @@
1
1
  import should from "should";
2
2
  import { GudHub } from "./../../gudhub.js";
3
+ import { JSDOM } from 'jsdom';
3
4
 
4
5
  describe("JSON CONSTRUCTOR", function () {
5
- const gudhub = new GudHub();
6
+ const gudhub = new GudHub('Z/lxMHLenEaQTvPjW5U6c3jBDwWFYZrh2F9Kxa3fbt8drvabS2u2lXQ2zI+SRmic', {
7
+ server_url: 'https://gudhub.com/GudHub_Test',
8
+ async_modules_path: 'build/async_modules_node/',
9
+ file_server_url: 'http://localhost:8080'
10
+ });
11
+
12
+ const jsdom = new JSDOM('', {
13
+ url: 'http://localhost:1234',
14
+ runScripts: 'dangerously'
15
+ });
16
+
17
+ const { window } = jsdom;
18
+
19
+ gudhub.ghconstructor.initJsdomWindow(window);
6
20
 
7
21
  it("JSON FROM ONE APP : Here we construct simple json from one App", async function () {
22
+ this.timeout(4000);
8
23
  //-- checking if json was generated properly
9
24
  let json = await gudhub.jsonConstructor(fishtank_scheme);
10
25
  json.fishtank[0].should.have.property("name", "Big Fish Tank");
11
- json.fishtank[0].should.have.property("state", "Normal");
26
+ json.fishtank[0].should.have.property("state", "Normal ");
12
27
  });
13
28
  it("CHECK INTERPRETATION VALUE FOR FILES: output: we should get url's", async function () {
14
29
  //-- checking interpretation mode
@@ -17,6 +32,15 @@ describe("JSON CONSTRUCTOR", function () {
17
32
  json.fishtank[0].should.have.property("url","https://google.com,https://test.com");
18
33
  json.fishtank[0].should.have.property("notes","https://gudhub.com/userdata/16259/811770.html?timestamp=0");
19
34
  });
35
+ it("GET FILTERED ITEMS LENGTH WITH CURRENT ITEM FILTER", async function () {
36
+ let json = await gudhub.jsonConstructor(currentItemScheme);
37
+ let firstLength = json.scheme[0].array.length;
38
+ let secondLength = json.scheme[1].array.length;
39
+
40
+ firstLength.should.equal(8);
41
+ secondLength.should.equal(4);
42
+
43
+ });
20
44
  });
21
45
 
22
46
  var fishtank_scheme = {
@@ -68,3 +92,56 @@ var fishtank_scheme = {
68
92
  app_id: "16259",
69
93
  filter: [],
70
94
  };
95
+
96
+ let currentItemScheme = {
97
+ type: "array",
98
+ id: 1,
99
+ childs: [
100
+ {
101
+ type: "property",
102
+ id: 3,
103
+ property_name: "value",
104
+ property_type: "field_value",
105
+ field_id: "254056",
106
+ interpretation: 1,
107
+ },
108
+ {
109
+ type: "property",
110
+ id: 4,
111
+ property_name: "image",
112
+ property_type: "field_value",
113
+ field_id: "551380",
114
+ interpretation: 1,
115
+ },
116
+ {
117
+ type: "array",
118
+ id: 2,
119
+ childs: [
120
+ {
121
+ type: "property",
122
+ id: 5,
123
+ property_name: "date",
124
+ property_type: "field_value",
125
+ field_id: "1455",
126
+ interpretation: 1,
127
+ },
128
+ ],
129
+ property_name: "array",
130
+ app_id: "214",
131
+ filter: [
132
+ {
133
+ field_id: 254058,
134
+ data_type: "item_ref",
135
+ valuesArray: [],
136
+ search_type: "equal_or",
137
+ selected_search_option_variable: "Variable",
138
+ input_type: "variable",
139
+ input_value: "current_item",
140
+ },
141
+ ],
142
+ },
143
+ ],
144
+ property_name: "scheme",
145
+ app_id: "16259",
146
+ filter: [],
147
+ };
package/GUDHUB/config.js CHANGED
@@ -1,8 +1,10 @@
1
- //export const server_url = "https://gudhub.com/GudHub";
1
+ export const server_url = "https://gudhub.com/GudHub";
2
2
  //export const server_url = "https://gudhub.com/GudHub_Temp";
3
3
  //export const server_url = "https://integration.gudhub.com/GudHub_Test";
4
- export const server_url = "http://localhost:9000";
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/async_modules_node/';
7
+ export const file_server_url = 'http://localhost:8080';
6
8
 
7
9
  // FOR TESTS
8
10
  export const port = 9000;
package/GUDHUB/gudhub.js CHANGED
@@ -2,7 +2,7 @@ import { GudHubHttpsService } from "./gudhub-https-service.js";
2
2
  import { PipeService } from "./PipeService/PipeService.js";
3
3
  import { Storage } from "./Storage/Storage.js";
4
4
  import { WebSocketApi } from "./WebSocket/WebSocket.js";
5
- import { wss_url, server_url } from "./config.js";
5
+ import { wss_url, server_url, async_modules_path, file_server_url } from "./config.js";
6
6
  import { Utils } from "./Utils/Utils.js";
7
7
  import { Auth } from "./Auth/Auth.js";
8
8
  import { GHConstructor } from "./GHConstructor/ghconstructor.js";
@@ -25,8 +25,8 @@ export class GudHub {
25
25
  initWebsocket: false,
26
26
  activateSW: false,
27
27
  swLink: "",
28
- async_modules_path: '',
29
- file_server_url: ''
28
+ async_modules_path,
29
+ file_server_url
30
30
  }
31
31
  ) {
32
32
  this.ghconstructor = new GHConstructor(this);