@gudhub/core 1.1.26 → 1.1.27

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.
@@ -89,8 +89,13 @@ export class FieldProcessor {
89
89
 
90
90
  async getField(app_id, field_id) {
91
91
  const app = await this.appProcessor.getApp(app_id);
92
- if(!app) return null
93
- return app.field_list.find((field) => field.field_id == field_id);
92
+ if(!app) return null;
93
+ for(let i = 0; i < app.field_list.length; i++) {
94
+ if(app.field_list[i].field_id == field_id) {
95
+ return app.field_list[i];
96
+ }
97
+ }
98
+ return null;
94
99
  }
95
100
 
96
101
  //!!!!! Shou Be Renamed to getFields() !!!!!!!
@@ -4,7 +4,7 @@ import createClassInstance from './createClassInstance.js';
4
4
  export class GHConstructor {
5
5
  constructor(gudhub) {
6
6
  this.gudhub = gudhub;
7
- this.cache = [];
7
+ this.cache = {};
8
8
  this.modulesQueue = {};
9
9
  this.angularInjector;
10
10
  this.nodeWindow;
@@ -16,34 +16,29 @@ export class GHConstructor {
16
16
  // If yes, return module from cache.
17
17
 
18
18
  async getInstance(module_id) {
19
- return new Promise(async (resolve) => {
20
- if (this.modulesQueue[module_id]) {
21
- return this.modulesQueue[module_id].then(() => {
22
- resolve(this.getCached(module_id));
23
- });
24
- } else if (!this.cache.find(module => module.type === module_id)) {
25
- this.modulesQueue[module_id] = this.createInstance(module_id);
26
- this.modulesQueue[module_id].then(() => {
27
- resolve(this.getCached(module_id));
28
- });
29
- } else {
30
- resolve(this.getCached(module_id));
31
- }
32
- });
19
+ if(this.getCached(module_id)) {
20
+ return this.getCached(module_id);
21
+ } else if (this.modulesQueue[module_id]) {
22
+ await this.modulesQueue[module_id];
23
+ } else {
24
+ this.modulesQueue[module_id] = this.createInstance(module_id);
25
+ await this.modulesQueue[module_id];
26
+ }
27
+ return this.getCached(module_id);
33
28
  }
34
29
 
35
30
  /*************** PUT TO CACHE ***************/
36
31
  // Just pushing module to cache.
37
32
 
38
- pupToCache(module) {
39
- this.cache.push(module);
33
+ pupToCache(module_id, module) {
34
+ this.cache[module_id] = module;
40
35
  }
41
36
 
42
37
  /*************** GET CACHED ***************/
43
38
  // Find module in cache and return it.
44
39
 
45
40
  getCached(module_id) {
46
- return this.cache.find(module => module.type === module_id);
41
+ return this.cache[module_id];
47
42
  }
48
43
 
49
44
  /*************** INIT ANGULAR INJECTOR ***************/
@@ -83,7 +78,7 @@ export class GHConstructor {
83
78
  }
84
79
 
85
80
  if(result) {
86
- this.pupToCache(result);
81
+ this.pupToCache(module_id, result);
87
82
  }
88
83
 
89
84
  return result;
@@ -72,22 +72,25 @@ export class Interpritate {
72
72
 
73
73
  /********************* GET INTERPRETATION BY ID *********************/
74
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
- if(fieldModel == null) {
80
- resolve('');
81
- }
82
- this.gudhub.ghconstructor.getInstance(fieldModel.data_type).then(async (instance) => {
83
- let interpretatedValue = await instance.getInterpretation(fieldValue, interpretationId, fieldModel.data_type, fieldModel, itemId, appId);
84
- if(interpretatedValue.html == '<span>no interpretation</span>') {
85
- resolve(fieldValue);
86
- } else {
87
- resolve(interpretatedValue.html);
88
- }
89
- });
90
- });
75
+ // We add ability to pass value as argument, to reduce number of operations in this case (getFieldValue)
76
+ // This helps if you call method many times, for example in calculator sum and you already have field value
77
+ // By default, value is null, to not break old code working with this method
78
+
79
+ // For field same as above for value
80
+ async getInterpretationById(appId, itemId, fieldId, interpretationId, value = null, field = null) {
81
+ let fieldValue = value == null ? await this.gudhub.getFieldValue(appId, itemId, fieldId) : value;
82
+ let fieldModel = field == null ? await this.gudhub.getField(appId, fieldId) : field;
83
+ if(fieldModel == null) {
84
+ resolve('');
85
+ }
86
+
87
+ const instance = await this.gudhub.ghconstructor.getInstance(fieldModel.data_type);
88
+ const interpretatedValue = await instance.getInterpretation(fieldValue, interpretationId, fieldModel.data_type, fieldModel, itemId, appId);
89
+ if(interpretatedValue.html == '<span>no interpretation</span>') {
90
+ return fieldValue;
91
+ } else {
92
+ return interpretatedValue.html;
93
+ }
91
94
  }
92
95
 
93
96
  }
@@ -61,7 +61,11 @@ export class Storage {
61
61
 
62
62
 
63
63
  getApp(app_id) {
64
- return this.apps_list.find((app) => app.app_id == app_id);
64
+ for(let i = 0; i < this.apps_list.length; i++) {
65
+ if(this.apps_list[i].app_id == app_id) {
66
+ return this.apps_list[i];
67
+ }
68
+ }
65
69
  }
66
70
 
67
71
  unsetApps() {
package/GUDHUB/gudhub.js CHANGED
@@ -166,8 +166,8 @@ export class GudHub {
166
166
 
167
167
  /******************* GET INTERPRETATION BY ID *******************/
168
168
 
169
- getInterpretationById(appId, itemId, fieldId, interpretationId) {
170
- return this.interpritate.getInterpretationById(appId, itemId, fieldId, interpretationId);
169
+ getInterpretationById(appId, itemId, fieldId, interpretationId, value, field) {
170
+ return this.interpritate.getInterpretationById(appId, itemId, fieldId, interpretationId, value, field);
171
171
  }
172
172
 
173
173
  //============ FILTER ==========//
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {