@onehat/data 1.18.9 → 1.18.10
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/Entity/Entity.js
CHANGED
|
@@ -377,7 +377,7 @@ class Entity extends EventEmitter {
|
|
|
377
377
|
* Assumes (and sets) isTempId === false.
|
|
378
378
|
* @param {array} originalData - Raw data to load into entity.
|
|
379
379
|
*/
|
|
380
|
-
loadOriginalData = (originalData
|
|
380
|
+
loadOriginalData = (originalData) => {
|
|
381
381
|
if (this.isDestroyed) {
|
|
382
382
|
throw Error('this.loadOriginalData is no longer valid. Entity has been destroyed.');
|
|
383
383
|
}
|
|
@@ -386,10 +386,6 @@ class Entity extends EventEmitter {
|
|
|
386
386
|
this._originalData = originalData || {};
|
|
387
387
|
this.reset();
|
|
388
388
|
this.getIdProperty().isTempId = false;
|
|
389
|
-
|
|
390
|
-
if (this.isTree && this.repository && assembleTreeNodes) {
|
|
391
|
-
this.repository.assembleTreeNodes(); // rebuilds them all
|
|
392
|
-
}
|
|
393
389
|
}
|
|
394
390
|
|
|
395
391
|
/**
|
|
@@ -1606,6 +1602,10 @@ class Entity extends EventEmitter {
|
|
|
1606
1602
|
throw Error('this.getHasChildren is no longer valid. TreeNode has been destroyed.');
|
|
1607
1603
|
}
|
|
1608
1604
|
|
|
1605
|
+
if (!_.isEmpty(this.children)) {
|
|
1606
|
+
return true; // In case the hasChildrenProperty is stale. i.e. That property came from server, and we now have children here
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
1609
|
return this.getHasChildrenProperty().getSubmitValue();
|
|
1610
1610
|
}
|
|
1611
1611
|
|
|
@@ -1670,11 +1670,11 @@ class Entity extends EventEmitter {
|
|
|
1670
1670
|
if (this.isDestroyed) {
|
|
1671
1671
|
throw Error('this.loadChildren is no longer valid. TreeNode has been destroyed.');
|
|
1672
1672
|
}
|
|
1673
|
-
if (!this.repository?.
|
|
1674
|
-
throw Error('repository.
|
|
1673
|
+
if (!this.repository?.loadChildNodes) {
|
|
1674
|
+
throw Error('repository.loadChildNodes is not defined.');
|
|
1675
1675
|
}
|
|
1676
1676
|
|
|
1677
|
-
const children = await this.repository.
|
|
1677
|
+
const children = await this.repository.loadChildNodes(this, depth);
|
|
1678
1678
|
this.areChildrenLoaded = true;
|
|
1679
1679
|
return children;
|
|
1680
1680
|
}
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -385,6 +385,9 @@ class AjaxRepository extends Repository {
|
|
|
385
385
|
* @fires beforeLoad,changeData,load,error
|
|
386
386
|
*/
|
|
387
387
|
load = async (params, callback = null) => {
|
|
388
|
+
if (this.isTree && this.getRootNodes) {
|
|
389
|
+
return this.getRootNodes();
|
|
390
|
+
}
|
|
388
391
|
if (this.isDestroyed) {
|
|
389
392
|
this.throwError('this.load is no longer valid. Repository has been destroyed.');
|
|
390
393
|
return;
|
|
@@ -431,10 +434,6 @@ class AjaxRepository extends Repository {
|
|
|
431
434
|
this._relayEntityEvents(entity);
|
|
432
435
|
return entity;
|
|
433
436
|
});
|
|
434
|
-
|
|
435
|
-
if (this.isTree) {
|
|
436
|
-
this.assembleTreeNodes();
|
|
437
|
-
}
|
|
438
437
|
|
|
439
438
|
// Set the total records that pass filter
|
|
440
439
|
this.total = total;
|
|
@@ -442,6 +441,9 @@ class AjaxRepository extends Repository {
|
|
|
442
441
|
|
|
443
442
|
this.markLoaded();
|
|
444
443
|
|
|
444
|
+
if (this.isTree) {
|
|
445
|
+
this.assembleTreeNodes();
|
|
446
|
+
}
|
|
445
447
|
this.emit('changeData', this.entities);
|
|
446
448
|
this.emit('load', this);
|
|
447
449
|
|
|
@@ -584,6 +586,10 @@ class AjaxRepository extends Repository {
|
|
|
584
586
|
if (entity.isRemotePhantomMode) {
|
|
585
587
|
entity.isRemotePhantom = true;
|
|
586
588
|
}
|
|
589
|
+
|
|
590
|
+
if (this.isTree) {
|
|
591
|
+
this.assembleTreeNodes();
|
|
592
|
+
}
|
|
587
593
|
});
|
|
588
594
|
}
|
|
589
595
|
|
|
@@ -637,11 +643,12 @@ class AjaxRepository extends Repository {
|
|
|
637
643
|
// Reload each entity with new data
|
|
638
644
|
// TODO: Check this
|
|
639
645
|
_.each(entities, (entity, ix) => {
|
|
640
|
-
entity.loadOriginalData(root[ix]
|
|
646
|
+
entity.loadOriginalData(root[ix]);
|
|
641
647
|
if (entity.isRemotePhantomMode) {
|
|
642
648
|
entity.isRemotePhantom = true;
|
|
643
649
|
}
|
|
644
650
|
});
|
|
651
|
+
|
|
645
652
|
if (this.isTree) {
|
|
646
653
|
this.assembleTreeNodes();
|
|
647
654
|
}
|
|
@@ -690,6 +697,10 @@ class AjaxRepository extends Repository {
|
|
|
690
697
|
if (entity.isRemotePhantomMode && entity.isRemotePhantom) {
|
|
691
698
|
entity.isRemotePhantom = false;
|
|
692
699
|
}
|
|
700
|
+
|
|
701
|
+
if (this.isTree) {
|
|
702
|
+
this.assembleTreeNodes();
|
|
703
|
+
}
|
|
693
704
|
});
|
|
694
705
|
}
|
|
695
706
|
|
|
@@ -743,11 +754,12 @@ class AjaxRepository extends Repository {
|
|
|
743
754
|
// Reload each entity with new data
|
|
744
755
|
// TODO: Check this
|
|
745
756
|
_.each(entities, (entity, ix) => {
|
|
746
|
-
entity.loadOriginalData(root[ix]
|
|
757
|
+
entity.loadOriginalData(root[ix]);
|
|
747
758
|
if (entity.isRemotePhantomMode && entity.isRemotePhantom) {
|
|
748
759
|
entity.isRemotePhantom = false;
|
|
749
760
|
}
|
|
750
761
|
});
|
|
762
|
+
|
|
751
763
|
if (this.isTree) {
|
|
752
764
|
this.assembleTreeNodes();
|
|
753
765
|
}
|
|
@@ -800,6 +812,10 @@ class AjaxRepository extends Repository {
|
|
|
800
812
|
const id = entity.id;
|
|
801
813
|
this.entities = _.filter(this.entities, (entity) => entity.id !== id);
|
|
802
814
|
entity.destroy();
|
|
815
|
+
|
|
816
|
+
if (this.isTree) {
|
|
817
|
+
this.assembleTreeNodes();
|
|
818
|
+
}
|
|
803
819
|
});
|
|
804
820
|
}
|
|
805
821
|
|
|
@@ -856,6 +872,10 @@ class AjaxRepository extends Repository {
|
|
|
856
872
|
}
|
|
857
873
|
return !deleteIt;
|
|
858
874
|
});
|
|
875
|
+
|
|
876
|
+
if (this.isTree) {
|
|
877
|
+
this.assembleTreeNodes();
|
|
878
|
+
}
|
|
859
879
|
});
|
|
860
880
|
}
|
|
861
881
|
|
|
@@ -874,6 +894,10 @@ class AjaxRepository extends Repository {
|
|
|
874
894
|
return !match;
|
|
875
895
|
});
|
|
876
896
|
|
|
897
|
+
if (this.isTree) {
|
|
898
|
+
this.assembleTreeNodes();
|
|
899
|
+
}
|
|
900
|
+
|
|
877
901
|
return true;
|
|
878
902
|
}
|
|
879
903
|
|
|
@@ -977,7 +1001,10 @@ class AjaxRepository extends Repository {
|
|
|
977
1001
|
|
|
978
1002
|
// Do we need to reload?
|
|
979
1003
|
if (!this.eventsPaused) {
|
|
980
|
-
if (this.
|
|
1004
|
+
if (this.isTree) {
|
|
1005
|
+
this.assembleTreeNodes();
|
|
1006
|
+
this.emit('changeData', this.entities);
|
|
1007
|
+
} else if (this.isRemotePhantomMode && (this._operations.add || this._operations.deletePhantom)) {
|
|
981
1008
|
// Do nothing, as we don't want to immediately reload on add for a remote phantom mode record. It won't appear, and it will cause all kinds of trouble!
|
|
982
1009
|
if (this._operations.deletePhantom) {
|
|
983
1010
|
// sweep existing deleted records and remove them
|
|
@@ -434,9 +434,9 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
434
434
|
// /_/ /_/ \___/\___/____/
|
|
435
435
|
|
|
436
436
|
/**
|
|
437
|
-
*
|
|
437
|
+
* Loads the root nodes of this tree.
|
|
438
438
|
*/
|
|
439
|
-
|
|
439
|
+
loadRootNodes = (depth) => {
|
|
440
440
|
this.ensureTree();
|
|
441
441
|
if (this.isDestroyed) {
|
|
442
442
|
this.throwError('this.setRootNode is no longer valid. Repository has been destroyed.');
|
|
@@ -507,12 +507,12 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
/**
|
|
510
|
-
* Loads the children of the supplied treeNode
|
|
510
|
+
* Loads (or reloads) the children of the supplied treeNode
|
|
511
511
|
*/
|
|
512
|
-
|
|
512
|
+
loadChildNodes = (treeNode, depth = 1) => {
|
|
513
513
|
this.ensureTree();
|
|
514
514
|
if (this.isDestroyed) {
|
|
515
|
-
this.throwError('this.
|
|
515
|
+
this.throwError('this.loadChildNodes is no longer valid. Repository has been destroyed.');
|
|
516
516
|
return;
|
|
517
517
|
}
|
|
518
518
|
if (!this.isOnline) {
|
|
@@ -537,7 +537,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
537
537
|
return this._send('POST', this.name + '/getNodes', data)
|
|
538
538
|
.then((result) => {
|
|
539
539
|
if (this.debugMode) {
|
|
540
|
-
console.log('Response for
|
|
540
|
+
console.log('Response for loadChildNodes', result);
|
|
541
541
|
}
|
|
542
542
|
|
|
543
543
|
if (this.isDestroyed) {
|
|
@@ -282,7 +282,7 @@ export default class Repository extends EventEmitter {
|
|
|
282
282
|
|
|
283
283
|
// Assign event handlers
|
|
284
284
|
this.on('entity_change', async (entity) => { // Entity changed its value
|
|
285
|
-
if (this.isAutoSave) {
|
|
285
|
+
if (this.isAutoSave && !this.isRemotePhantomMode) {
|
|
286
286
|
return await this.save(entity);
|
|
287
287
|
}
|
|
288
288
|
});
|
|
@@ -999,7 +999,17 @@ export default class Repository extends EventEmitter {
|
|
|
999
999
|
entity = Repository._createEntity(this.schema, data, this, isPersisted, isDelayedSave, this.isRemotePhantomMode);
|
|
1000
1000
|
}
|
|
1001
1001
|
this._relayEntityEvents(entity);
|
|
1002
|
-
this.
|
|
1002
|
+
if (this.isTree && data.parentId) {
|
|
1003
|
+
// Trees need new node to be added as first child of parent
|
|
1004
|
+
const ix = this.getIxById(data.parentId) +1;
|
|
1005
|
+
this.entities = [
|
|
1006
|
+
...this.entities.slice(0, ix),
|
|
1007
|
+
entity,
|
|
1008
|
+
...this.entities.slice(ix)
|
|
1009
|
+
];
|
|
1010
|
+
} else {
|
|
1011
|
+
this.entities.unshift(entity); // Add to *beginning* of entities array, so the phantom record will appear at the beginning of the current page
|
|
1012
|
+
}
|
|
1003
1013
|
|
|
1004
1014
|
// Create id if needed
|
|
1005
1015
|
if (!this.isRemotePhantomMode && entity.isPhantom) {
|
|
@@ -1958,6 +1968,7 @@ export default class Repository extends EventEmitter {
|
|
|
1958
1968
|
return entities;
|
|
1959
1969
|
}
|
|
1960
1970
|
|
|
1971
|
+
|
|
1961
1972
|
/**
|
|
1962
1973
|
* Populates the TreeNodes with .parent and .children references
|
|
1963
1974
|
*/
|
package/src/Util/Parsers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
2
|
import momentAlt from 'relative-time-parser'; // Notice this version of moment is imported from 'relative-time-parser', and may be out of sync with our general 'moment' package
|
|
3
3
|
import accounting from 'accounting-js';
|
|
4
|
-
import * as chrono from 'chrono-node'; // Doesn't yet work in React Native ("SyntaxError: Invalid RegExp: Quantifier has nothing to repeat, js engine: hermes") Github ticket: https://github.com/facebook/hermes/blob/main/doc/RegExp.md
|
|
4
|
+
// import * as chrono from 'chrono-node'; // Doesn't yet work in React Native ("SyntaxError: Invalid RegExp: Quantifier has nothing to repeat, js engine: hermes") Github ticket: https://github.com/facebook/hermes/blob/main/doc/RegExp.md
|
|
5
5
|
import _ from 'lodash';
|
|
6
6
|
|
|
7
7
|
class Parsers {
|