@onehat/data 1.18.9 → 1.18.11
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
|
}
|
|
@@ -775,7 +787,13 @@ class AjaxRepository extends Repository {
|
|
|
775
787
|
const
|
|
776
788
|
method = this.methods.delete,
|
|
777
789
|
url = this.api.delete,
|
|
778
|
-
data = {
|
|
790
|
+
data = {
|
|
791
|
+
id: entity.id,
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
if (this.isTree && this.moveSubtreeUp) {
|
|
795
|
+
data.moveSubtreeUp = this.moveSubtreeUp;
|
|
796
|
+
}
|
|
779
797
|
|
|
780
798
|
return this._send(method, url, data)
|
|
781
799
|
.then(result => {
|
|
@@ -800,6 +818,10 @@ class AjaxRepository extends Repository {
|
|
|
800
818
|
const id = entity.id;
|
|
801
819
|
this.entities = _.filter(this.entities, (entity) => entity.id !== id);
|
|
802
820
|
entity.destroy();
|
|
821
|
+
|
|
822
|
+
if (this.isTree) {
|
|
823
|
+
this.assembleTreeNodes();
|
|
824
|
+
}
|
|
803
825
|
});
|
|
804
826
|
}
|
|
805
827
|
|
|
@@ -856,6 +878,10 @@ class AjaxRepository extends Repository {
|
|
|
856
878
|
}
|
|
857
879
|
return !deleteIt;
|
|
858
880
|
});
|
|
881
|
+
|
|
882
|
+
if (this.isTree) {
|
|
883
|
+
this.assembleTreeNodes();
|
|
884
|
+
}
|
|
859
885
|
});
|
|
860
886
|
}
|
|
861
887
|
|
|
@@ -874,6 +900,10 @@ class AjaxRepository extends Repository {
|
|
|
874
900
|
return !match;
|
|
875
901
|
});
|
|
876
902
|
|
|
903
|
+
if (this.isTree) {
|
|
904
|
+
this.assembleTreeNodes();
|
|
905
|
+
}
|
|
906
|
+
|
|
877
907
|
return true;
|
|
878
908
|
}
|
|
879
909
|
|
|
@@ -977,7 +1007,10 @@ class AjaxRepository extends Repository {
|
|
|
977
1007
|
|
|
978
1008
|
// Do we need to reload?
|
|
979
1009
|
if (!this.eventsPaused) {
|
|
980
|
-
if (this.
|
|
1010
|
+
if (this.isTree) {
|
|
1011
|
+
this.assembleTreeNodes();
|
|
1012
|
+
this.emit('changeData', this.entities);
|
|
1013
|
+
} else if (this.isRemotePhantomMode && (this._operations.add || this._operations.deletePhantom)) {
|
|
981
1014
|
// 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
1015
|
if (this._operations.deletePhantom) {
|
|
983
1016
|
// 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) {
|
|
@@ -204,6 +204,11 @@ export default class Repository extends EventEmitter {
|
|
|
204
204
|
*/
|
|
205
205
|
this.isTree = schema.model.isTree || false;
|
|
206
206
|
|
|
207
|
+
/**
|
|
208
|
+
* @member {boolean} moveSubtreeUp - Whether to move the subtree up on the next delete operation (trees only)
|
|
209
|
+
*/
|
|
210
|
+
this.moveSubtreeUp = false;
|
|
211
|
+
|
|
207
212
|
/**
|
|
208
213
|
* @member {boolean} isLoaded - State: whether or not entities have been loaded at least once
|
|
209
214
|
*/
|
|
@@ -282,7 +287,7 @@ export default class Repository extends EventEmitter {
|
|
|
282
287
|
|
|
283
288
|
// Assign event handlers
|
|
284
289
|
this.on('entity_change', async (entity) => { // Entity changed its value
|
|
285
|
-
if (this.isAutoSave) {
|
|
290
|
+
if (this.isAutoSave && !this.isRemotePhantomMode) {
|
|
286
291
|
return await this.save(entity);
|
|
287
292
|
}
|
|
288
293
|
});
|
|
@@ -999,7 +1004,17 @@ export default class Repository extends EventEmitter {
|
|
|
999
1004
|
entity = Repository._createEntity(this.schema, data, this, isPersisted, isDelayedSave, this.isRemotePhantomMode);
|
|
1000
1005
|
}
|
|
1001
1006
|
this._relayEntityEvents(entity);
|
|
1002
|
-
this.
|
|
1007
|
+
if (this.isTree && data.parentId) {
|
|
1008
|
+
// Trees need new node to be added as first child of parent
|
|
1009
|
+
const ix = this.getIxById(data.parentId) +1;
|
|
1010
|
+
this.entities = [
|
|
1011
|
+
...this.entities.slice(0, ix),
|
|
1012
|
+
entity,
|
|
1013
|
+
...this.entities.slice(ix)
|
|
1014
|
+
];
|
|
1015
|
+
} else {
|
|
1016
|
+
this.entities.unshift(entity); // Add to *beginning* of entities array, so the phantom record will appear at the beginning of the current page
|
|
1017
|
+
}
|
|
1003
1018
|
|
|
1004
1019
|
// Create id if needed
|
|
1005
1020
|
if (!this.isRemotePhantomMode && entity.isPhantom) {
|
|
@@ -1781,9 +1796,10 @@ export default class Repository extends EventEmitter {
|
|
|
1781
1796
|
* Marks entities for deletion from storage medium.
|
|
1782
1797
|
* Actual deletion takes place in save(), unless isPhantom
|
|
1783
1798
|
* @param {object|array} entities - one or more entities to delete
|
|
1799
|
+
* @param {bool} moveSubtreeUp - whether or not to move the subtree up (if this is a tree)
|
|
1784
1800
|
* @fires delete
|
|
1785
1801
|
*/
|
|
1786
|
-
delete = async (entities) => {
|
|
1802
|
+
delete = async (entities, moveSubtreeUp = false) => {
|
|
1787
1803
|
if (this.isDestroyed) {
|
|
1788
1804
|
this.throwError('this.delete is no longer valid. Repository has been destroyed.');
|
|
1789
1805
|
return;
|
|
@@ -1809,6 +1825,10 @@ export default class Repository extends EventEmitter {
|
|
|
1809
1825
|
}
|
|
1810
1826
|
});
|
|
1811
1827
|
|
|
1828
|
+
if (this.isTree) {
|
|
1829
|
+
this.moveSubtreeUp = moveSubtreeUp;
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1812
1832
|
this.emit('delete', entities);
|
|
1813
1833
|
|
|
1814
1834
|
if (this.isAutoSave) {
|
|
@@ -1958,6 +1978,7 @@ export default class Repository extends EventEmitter {
|
|
|
1958
1978
|
return entities;
|
|
1959
1979
|
}
|
|
1960
1980
|
|
|
1981
|
+
|
|
1961
1982
|
/**
|
|
1962
1983
|
* Populates the TreeNodes with .parent and .children references
|
|
1963
1984
|
*/
|
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 {
|