@onehat/data 1.18.4 → 1.18.7
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/package.json
CHANGED
package/src/Property/Json.js
CHANGED
|
@@ -115,3 +115,9 @@ export default class JsonProperty extends Property {
|
|
|
115
115
|
|
|
116
116
|
JsonProperty.className = 'Json';
|
|
117
117
|
JsonProperty.type = 'json';
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
// For the sake of OneBuild, create an alias of Json, that's Tag
|
|
121
|
+
class TagProperty extends JsonProperty {}
|
|
122
|
+
TagProperty.className = 'Tag';
|
|
123
|
+
TagProperty.type = 'tag';
|
package/src/Property/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import DateTimeProperty from './DateTime.js';
|
|
|
8
8
|
import FileProperty from './File.js';
|
|
9
9
|
import FloatProperty from './Float.js';
|
|
10
10
|
import IntegerProperty from './Integer.js';
|
|
11
|
-
import JsonProperty from './Json.js';
|
|
11
|
+
import JsonProperty, { TagProperty } from './Json.js';
|
|
12
12
|
import PercentProperty from './Percent.js';
|
|
13
13
|
import PercentIntProperty from './PercentInt.js';
|
|
14
14
|
import StringProperty from './String.js';
|
|
@@ -28,6 +28,7 @@ const PropertyTypes = {
|
|
|
28
28
|
[PercentProperty.type]: PercentProperty,
|
|
29
29
|
[PercentIntProperty.type]: PercentIntProperty,
|
|
30
30
|
[StringProperty.type]: StringProperty,
|
|
31
|
+
[TagProperty.type]: TagProperty,
|
|
31
32
|
[TimeProperty.type]: TimeProperty,
|
|
32
33
|
[UuidProperty.type]: UuidProperty,
|
|
33
34
|
};
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -450,7 +450,7 @@ class AjaxRepository extends Repository {
|
|
|
450
450
|
}
|
|
451
451
|
})
|
|
452
452
|
.finally(() => {
|
|
453
|
-
this.
|
|
453
|
+
this.markLoading(false);
|
|
454
454
|
});
|
|
455
455
|
}
|
|
456
456
|
|
|
@@ -511,7 +511,7 @@ class AjaxRepository extends Repository {
|
|
|
511
511
|
}
|
|
512
512
|
})
|
|
513
513
|
.finally(() => {
|
|
514
|
-
this.
|
|
514
|
+
this.markLoading(false);
|
|
515
515
|
});
|
|
516
516
|
|
|
517
517
|
}
|
|
@@ -894,12 +894,17 @@ class AjaxRepository extends Repository {
|
|
|
894
894
|
return;
|
|
895
895
|
}
|
|
896
896
|
|
|
897
|
+
const headers = _.merge({
|
|
898
|
+
'Content-Type': 'application/json',
|
|
899
|
+
'Accept': 'application/json',
|
|
900
|
+
}, this.headers);
|
|
901
|
+
|
|
897
902
|
const options = {
|
|
898
903
|
url,
|
|
899
904
|
method,
|
|
900
905
|
baseURL: this.api.baseURL,
|
|
901
906
|
transformResponse: null,
|
|
902
|
-
headers
|
|
907
|
+
headers,
|
|
903
908
|
params: method === 'GET' ? data : null,
|
|
904
909
|
data: method !== 'GET' ? qs.stringify(data) : null,
|
|
905
910
|
timeout: this.timeout,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @module Repository */
|
|
2
2
|
|
|
3
|
+
import Repository from './Repository.js';
|
|
3
4
|
import AjaxRepository from './Ajax.js';
|
|
4
5
|
import qs from 'qs';
|
|
5
6
|
import _ from 'lodash';
|
|
@@ -45,7 +46,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
45
46
|
},
|
|
46
47
|
|
|
47
48
|
methods: {
|
|
48
|
-
get: 'POST',
|
|
49
|
+
// get: 'POST',
|
|
49
50
|
},
|
|
50
51
|
|
|
51
52
|
rootProperty: 'data',
|
|
@@ -104,12 +105,17 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
104
105
|
return;
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
const headers = _.merge({
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
Accept: 'application/json',
|
|
111
|
+
}, this.headers);
|
|
112
|
+
|
|
107
113
|
const options = {
|
|
108
114
|
url,
|
|
109
115
|
method,
|
|
110
116
|
baseURL: this.api.baseURL,
|
|
111
117
|
transformResponse: null,
|
|
112
|
-
headers
|
|
118
|
+
headers,
|
|
113
119
|
params: method === 'GET' ? data : null,
|
|
114
120
|
data: method !== 'GET' ? qs.stringify(data) : null,
|
|
115
121
|
timeout: this.timeout,
|
|
@@ -220,7 +226,8 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
220
226
|
};
|
|
221
227
|
}
|
|
222
228
|
|
|
223
|
-
const
|
|
229
|
+
const
|
|
230
|
+
response = _.isPlainObject(result.data) ? result.data : this.reader.read(result.data),
|
|
224
231
|
root = response[this.rootProperty],
|
|
225
232
|
success = response[this.successProperty],
|
|
226
233
|
total = response[this.totalProperty],
|
|
@@ -347,11 +354,16 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
347
354
|
console.log('logout');
|
|
348
355
|
}
|
|
349
356
|
|
|
357
|
+
const headers = _.merge({
|
|
358
|
+
'Content-Type': 'application/json',
|
|
359
|
+
Accept: 'application/json',
|
|
360
|
+
}, this.headers);
|
|
361
|
+
|
|
350
362
|
return this.axios({
|
|
351
363
|
url: 'Users/apiLogout',
|
|
352
364
|
method: 'POST',
|
|
353
365
|
baseURL: this.api.baseURL,
|
|
354
|
-
headers
|
|
366
|
+
headers,
|
|
355
367
|
timeout: this.timeout,
|
|
356
368
|
})
|
|
357
369
|
.then((result) => {
|
|
@@ -424,13 +436,9 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
424
436
|
this.throwError('Offline');
|
|
425
437
|
return;
|
|
426
438
|
}
|
|
439
|
+
this.emit('beforeLoad'); // TODO: canceling beforeLoad will cancel the load operation
|
|
440
|
+
this.markLoading();
|
|
427
441
|
|
|
428
|
-
// Clear all entities, if any exist
|
|
429
|
-
_.each(this.entities, (entity) => {
|
|
430
|
-
entity.destroy();
|
|
431
|
-
});
|
|
432
|
-
this.entities = [];
|
|
433
|
-
|
|
434
442
|
|
|
435
443
|
const data = {
|
|
436
444
|
url: this.name + '/getRootNodes',
|
|
@@ -450,19 +458,50 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
450
458
|
return this.axios(data)
|
|
451
459
|
.then((result) => {
|
|
452
460
|
if (this.debugMode) {
|
|
453
|
-
console.log('getRootNodes
|
|
461
|
+
console.log('Response for getRootNodes', result);
|
|
454
462
|
}
|
|
455
463
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
464
|
+
if (this.isDestroyed) {
|
|
465
|
+
// If this repository gets destroyed before it has a chance
|
|
466
|
+
// to process the Ajax request, just ignore the response.
|
|
459
467
|
return;
|
|
460
468
|
}
|
|
461
469
|
|
|
462
|
-
|
|
470
|
+
const {
|
|
471
|
+
root,
|
|
472
|
+
success,
|
|
473
|
+
total,
|
|
474
|
+
message
|
|
475
|
+
} = this._processServerResponse(result);
|
|
463
476
|
|
|
477
|
+
this._destroyEntities();
|
|
464
478
|
|
|
479
|
+
// Set the current entities
|
|
480
|
+
this.entities = _.map(root, (data) => {
|
|
481
|
+
const entity = Repository._createEntity(this.schema, data, this, true);
|
|
482
|
+
this._relayEntityEvents(entity);
|
|
483
|
+
return entity;
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
this.assembleTreeNodes();
|
|
487
|
+
|
|
488
|
+
// Set the total records that pass filter
|
|
489
|
+
this.total = total;
|
|
490
|
+
this._setPaginationVars();
|
|
491
|
+
|
|
492
|
+
this.areRootNodesLoaded = true;
|
|
493
|
+
|
|
494
|
+
this.markLoaded();
|
|
465
495
|
|
|
496
|
+
this.emit('changeData', this.entities);
|
|
497
|
+
this.emit('load', this);
|
|
498
|
+
|
|
499
|
+
return this.getBy((entity) => {
|
|
500
|
+
return entity.isRoot;
|
|
501
|
+
});
|
|
502
|
+
})
|
|
503
|
+
.finally(() => {
|
|
504
|
+
this.markLoading(false);
|
|
466
505
|
});
|
|
467
506
|
}
|
|
468
507
|
|
|
@@ -219,6 +219,11 @@ export default class Repository extends EventEmitter {
|
|
|
219
219
|
*/
|
|
220
220
|
this.lastLoaded = null;
|
|
221
221
|
|
|
222
|
+
/**
|
|
223
|
+
* @member {boolean} areRootNodesLoaded - State: whether or not root nodes have been loaded at least once
|
|
224
|
+
*/
|
|
225
|
+
this.areRootNodesLoaded = false;
|
|
226
|
+
|
|
222
227
|
/**
|
|
223
228
|
* @member {boolean} isSaving - State: whether or not entities are currently being saved
|
|
224
229
|
*/
|
|
@@ -355,15 +360,15 @@ export default class Repository extends EventEmitter {
|
|
|
355
360
|
/**
|
|
356
361
|
* Marks this repository as loading
|
|
357
362
|
*/
|
|
358
|
-
markLoading = () => {
|
|
359
|
-
this.isLoading =
|
|
363
|
+
markLoading = (bool = true) => {
|
|
364
|
+
this.isLoading = bool;
|
|
360
365
|
}
|
|
361
366
|
|
|
362
367
|
/**
|
|
363
368
|
* Marks this repository as loaded
|
|
364
369
|
*/
|
|
365
370
|
markLoaded = () => {
|
|
366
|
-
this.
|
|
371
|
+
this.markLoading(false);
|
|
367
372
|
this.isLoaded = true;
|
|
368
373
|
this.lastLoaded = moment(new Date()).format('YYYY-MM-DD HH:mm:ss.SSSS');
|
|
369
374
|
}
|