@onehat/data 1.21.20 → 1.22.1
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 +1 -1
- package/src/Entity/Entity.js +21 -9
- package/src/Repository/Ajax.js +15 -11
- package/src/Repository/OneBuild.js +22 -414
- package/src/Repository/Repository.js +6 -89
- package/src/Repository/Tree.js +445 -0
- package/src/Repository/index.js +2 -0
- package/src/Schema/Schema.js +0 -5
- package/src/Repository/OneBuild2.js +0 -953
package/package.json
CHANGED
package/src/Entity/Entity.js
CHANGED
|
@@ -113,7 +113,7 @@ class Entity extends EventEmitter {
|
|
|
113
113
|
/**
|
|
114
114
|
* @member {boolean} isTree - Whether this Entity is a TreeNode
|
|
115
115
|
*/
|
|
116
|
-
this.isTree = schema.
|
|
116
|
+
this.isTree = schema.repository.type === 'tree' || false;
|
|
117
117
|
|
|
118
118
|
if (this.isTree && !schema.model.parentIdProperty) {
|
|
119
119
|
throw new Error('parentIdProperty cannot be empty for a TreeNode');
|
|
@@ -1625,16 +1625,16 @@ class Entity extends EventEmitter {
|
|
|
1625
1625
|
/**
|
|
1626
1626
|
* Loads the children of this TreeNode from repository.
|
|
1627
1627
|
*/
|
|
1628
|
-
loadChildren = async (depth) => {
|
|
1628
|
+
loadChildren = async (depth = 1) => {
|
|
1629
1629
|
this.ensureTree();
|
|
1630
1630
|
if (this.isDestroyed) {
|
|
1631
1631
|
throw Error('this.loadChildren is no longer valid. TreeNode has been destroyed.');
|
|
1632
1632
|
}
|
|
1633
|
-
if (!this.repository?.
|
|
1634
|
-
throw Error('repository.
|
|
1633
|
+
if (!this.repository?.loadNode) {
|
|
1634
|
+
throw Error('repository.loadNode is not defined.');
|
|
1635
1635
|
}
|
|
1636
1636
|
|
|
1637
|
-
const children = await this.repository.
|
|
1637
|
+
const children = await this.repository.loadNode(this, depth);
|
|
1638
1638
|
this.areChildrenLoaded = true;
|
|
1639
1639
|
return children;
|
|
1640
1640
|
}
|
|
@@ -1642,8 +1642,8 @@ class Entity extends EventEmitter {
|
|
|
1642
1642
|
/**
|
|
1643
1643
|
* Alias for loadChildren
|
|
1644
1644
|
*/
|
|
1645
|
-
reloadChildren = () => { // alias
|
|
1646
|
-
return this.loadChildren();
|
|
1645
|
+
reloadChildren = (depth = 1) => { // alias
|
|
1646
|
+
return this.loadChildren(depth);
|
|
1647
1647
|
}
|
|
1648
1648
|
|
|
1649
1649
|
/**
|
|
@@ -1768,6 +1768,18 @@ class Entity extends EventEmitter {
|
|
|
1768
1768
|
return parentIds.reverse().join('/');
|
|
1769
1769
|
}
|
|
1770
1770
|
|
|
1771
|
+
/**
|
|
1772
|
+
* Gets the model that this entity uses
|
|
1773
|
+
* @return {string} model
|
|
1774
|
+
*/
|
|
1775
|
+
getModel = () => {
|
|
1776
|
+
if (this.isTree && this.nodeType) {
|
|
1777
|
+
// Trees can have entities of different models
|
|
1778
|
+
return this.nodeType;
|
|
1779
|
+
}
|
|
1780
|
+
return this.repository.getModel();
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1771
1783
|
/**
|
|
1772
1784
|
* Moves this TreeNode to another parentId.
|
|
1773
1785
|
*/
|
|
@@ -1777,7 +1789,7 @@ class Entity extends EventEmitter {
|
|
|
1777
1789
|
throw Error('this.moveTreeNode is no longer valid. TreeNode has been destroyed.');
|
|
1778
1790
|
}
|
|
1779
1791
|
if (!this.repository?.moveTreeNode) {
|
|
1780
|
-
throw Error('repository.moveTreeNode is not defined.');
|
|
1792
|
+
throw Error('repository.moveTreeNode is not defined.');
|
|
1781
1793
|
}
|
|
1782
1794
|
|
|
1783
1795
|
return this.repository.moveTreeNode(this, newParentId);
|
|
@@ -1789,7 +1801,7 @@ class Entity extends EventEmitter {
|
|
|
1789
1801
|
*/
|
|
1790
1802
|
ensureTree = () => {
|
|
1791
1803
|
if (!this.isTree) {
|
|
1792
|
-
|
|
1804
|
+
throw Error('This Entity is not a tree!');
|
|
1793
1805
|
return false;
|
|
1794
1806
|
}
|
|
1795
1807
|
return true;
|
package/src/Repository/Ajax.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @module Repository */
|
|
2
2
|
|
|
3
|
-
import Repository from './Repository.js';
|
|
3
|
+
import Repository from './Repository.js'; // so we can use static methods
|
|
4
4
|
import ReaderTypes from '../Reader/index.js';
|
|
5
5
|
import WriterTypes from '../Writer/index.js';
|
|
6
6
|
import axios from 'axios';
|
|
@@ -429,10 +429,12 @@ class AjaxRepository extends Repository {
|
|
|
429
429
|
this.setParams(params);
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
const
|
|
433
|
-
|
|
432
|
+
const
|
|
433
|
+
repository = this,
|
|
434
|
+
url = this.getModel() + '/' + this.api.get,
|
|
435
|
+
data = _.merge({}, this._baseParams, this._params);
|
|
434
436
|
|
|
435
|
-
return this._send(this.methods.get,
|
|
437
|
+
return this._send(this.methods.get, url, data)
|
|
436
438
|
.then(result => {
|
|
437
439
|
if (this.debugMode) {
|
|
438
440
|
console.log('Response for ' + this.name, result);
|
|
@@ -519,8 +521,10 @@ class AjaxRepository extends Repository {
|
|
|
519
521
|
if (this.debugMode) {
|
|
520
522
|
console.log('reloadEntity ' + entity.id, params);
|
|
521
523
|
}
|
|
524
|
+
|
|
525
|
+
const url = entity.getModel() + '/' + this.api.get;
|
|
522
526
|
|
|
523
|
-
return this._send(this.methods.get,
|
|
527
|
+
return this._send(this.methods.get, url, params)
|
|
524
528
|
.then(result => {
|
|
525
529
|
if (this.debugMode) {
|
|
526
530
|
console.log('reloadEntity response ' + entity.id, result);
|
|
@@ -604,7 +608,7 @@ class AjaxRepository extends Repository {
|
|
|
604
608
|
|
|
605
609
|
const
|
|
606
610
|
method = this.methods.add,
|
|
607
|
-
url = this.api.add,
|
|
611
|
+
url = entity.getModel() + '/' + this.api.add,
|
|
608
612
|
data = entity.getSubmitValues();
|
|
609
613
|
|
|
610
614
|
return this._send(method, url, data)
|
|
@@ -658,7 +662,7 @@ class AjaxRepository extends Repository {
|
|
|
658
662
|
|
|
659
663
|
const
|
|
660
664
|
method = this.methods.add,
|
|
661
|
-
url = this.api.batchAdd,
|
|
665
|
+
url = this.getModel() + '/' + this.api.batchAdd,
|
|
662
666
|
data = {
|
|
663
667
|
entities: _.map(entities, entity => {
|
|
664
668
|
const values = entity.submitValues;
|
|
@@ -723,7 +727,7 @@ class AjaxRepository extends Repository {
|
|
|
723
727
|
|
|
724
728
|
const
|
|
725
729
|
method = this.methods.edit,
|
|
726
|
-
url = this.api.edit,
|
|
730
|
+
url = entity.getModel() + '/' + this.api.edit,
|
|
727
731
|
data = entity.getSubmitValues();
|
|
728
732
|
|
|
729
733
|
return this._send(method, url, data)
|
|
@@ -777,7 +781,7 @@ class AjaxRepository extends Repository {
|
|
|
777
781
|
|
|
778
782
|
const
|
|
779
783
|
method = this.methods.edit,
|
|
780
|
-
url = this.api.batchEdit,
|
|
784
|
+
url = this.getModel() + '/' + this.api.batchEdit,
|
|
781
785
|
data = {
|
|
782
786
|
entities: _.map(entities, entity => {
|
|
783
787
|
const values = entity.submitValues;
|
|
@@ -846,7 +850,7 @@ class AjaxRepository extends Repository {
|
|
|
846
850
|
|
|
847
851
|
const
|
|
848
852
|
method = this.methods.delete,
|
|
849
|
-
url = this.api.delete,
|
|
853
|
+
url = entity.getModel() + '/' + this.api.delete,
|
|
850
854
|
data = {
|
|
851
855
|
id: entity.id,
|
|
852
856
|
};
|
|
@@ -906,7 +910,7 @@ class AjaxRepository extends Repository {
|
|
|
906
910
|
|
|
907
911
|
const
|
|
908
912
|
method = this.methods.delete,
|
|
909
|
-
url = this.api.batchDelete,
|
|
913
|
+
url = this.getModel() + '/' + this.api.batchDelete,
|
|
910
914
|
ids = _.map(entities, (entity) => {
|
|
911
915
|
entity.isSaving = true;
|
|
912
916
|
return entity.id;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** @module Repository */
|
|
2
2
|
|
|
3
|
-
import Repository from './Repository.js';
|
|
4
3
|
import AjaxRepository from './Ajax.js';
|
|
5
4
|
import qs from 'qs';
|
|
6
5
|
import _ from 'lodash';
|
|
@@ -11,9 +10,11 @@ const nonConditionFilters = [
|
|
|
11
10
|
'fields',
|
|
12
11
|
'distinct',
|
|
13
12
|
'leftJoinWith',
|
|
13
|
+
'innerJoin',
|
|
14
14
|
'join',
|
|
15
15
|
'where',
|
|
16
16
|
'matching',
|
|
17
|
+
'groupBy',
|
|
17
18
|
'contain',
|
|
18
19
|
'order',
|
|
19
20
|
'limit',
|
|
@@ -30,21 +31,22 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
30
31
|
constructor(config = {}) {
|
|
31
32
|
super(...arguments);
|
|
32
33
|
|
|
33
|
-
const model = this._getModel();
|
|
34
34
|
const defaults = {
|
|
35
35
|
|
|
36
36
|
isAutoLoad: false,
|
|
37
37
|
isAutoSave: false,
|
|
38
38
|
|
|
39
39
|
api: {
|
|
40
|
-
get:
|
|
41
|
-
add:
|
|
42
|
-
edit:
|
|
43
|
-
delete:
|
|
44
|
-
batchAdd:
|
|
45
|
-
batchEdit:
|
|
46
|
-
batchDelete:
|
|
47
|
-
|
|
40
|
+
get: 'get',
|
|
41
|
+
add: 'add',
|
|
42
|
+
edit: 'edit',
|
|
43
|
+
delete: 'delete',
|
|
44
|
+
batchAdd: 'batchAdd',
|
|
45
|
+
batchEdit: 'batchEdit',
|
|
46
|
+
batchDelete: 'batchDelete',
|
|
47
|
+
reorder: 'reorder',
|
|
48
|
+
duplicate: 'duplicate',
|
|
49
|
+
getLastModifiedDate: 'getLastModifiedDate',
|
|
48
50
|
},
|
|
49
51
|
|
|
50
52
|
methods: {
|
|
@@ -83,7 +85,6 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
83
85
|
|
|
84
86
|
this.registerEvents([
|
|
85
87
|
'logout',
|
|
86
|
-
'loadRootNodes',
|
|
87
88
|
]);
|
|
88
89
|
|
|
89
90
|
await super.initialize();
|
|
@@ -149,13 +150,6 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
149
150
|
});
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
_getModel() {
|
|
153
|
-
if (!this.isUnique) {
|
|
154
|
-
return this.name;
|
|
155
|
-
}
|
|
156
|
-
return this.name.match(/^([^-]*)-(.*)/)[1]; // converts 'ModelName-22f9915c-79f5-4e86-a25b-9446c7b85b63' to 'ModelName'
|
|
157
|
-
}
|
|
158
|
-
|
|
159
153
|
/**
|
|
160
154
|
* Helper for reloadEntity.
|
|
161
155
|
* @private
|
|
@@ -304,7 +298,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
304
298
|
}
|
|
305
299
|
|
|
306
300
|
const data = {
|
|
307
|
-
url: this.
|
|
301
|
+
url: this.getModel() + '/' + this.api.reorder,
|
|
308
302
|
data: qs.stringify({
|
|
309
303
|
ids,
|
|
310
304
|
dropPosition,
|
|
@@ -341,9 +335,9 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
341
335
|
this.markLoading();
|
|
342
336
|
|
|
343
337
|
const
|
|
344
|
-
|
|
338
|
+
url = entity.getModel() + '/' + this.api.duplicate,
|
|
345
339
|
id = entity.id,
|
|
346
|
-
result = await this._send('POST',
|
|
340
|
+
result = await this._send('POST', url, { id });
|
|
347
341
|
|
|
348
342
|
if (!result) {
|
|
349
343
|
this.markLoading(false);
|
|
@@ -412,13 +406,15 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
412
406
|
const params = {};
|
|
413
407
|
params['conditions[' + idPropertyName + ']'] = id;
|
|
414
408
|
|
|
415
|
-
const
|
|
409
|
+
const
|
|
410
|
+
url = this.getModel() + '/' + this.api.get,
|
|
411
|
+
data = _.merge(params, this._baseParams);
|
|
416
412
|
|
|
417
413
|
if (this.debugMode) {
|
|
418
414
|
console.log('getSingleEntityFromServer', data);
|
|
419
415
|
}
|
|
420
416
|
|
|
421
|
-
return this._send(this.methods.get,
|
|
417
|
+
return this._send(this.methods.get, url, data)
|
|
422
418
|
.then(result => {
|
|
423
419
|
if (this.debugMode) {
|
|
424
420
|
console.log('Response for getSingleEntityFromServer for ' + this.name, result);
|
|
@@ -468,7 +464,9 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
468
464
|
console.log('getLastModifiedDate');
|
|
469
465
|
}
|
|
470
466
|
|
|
471
|
-
|
|
467
|
+
const url = this.getModel() + '/' + this.api.getLastModifiedDate;
|
|
468
|
+
|
|
469
|
+
return this._send(this.methods.get, url, this._baseParams)
|
|
472
470
|
.then(result => {
|
|
473
471
|
if (this.debugMode) {
|
|
474
472
|
console.log('Response for getLastModifiedDate for ' + this.name, result);
|
|
@@ -618,396 +616,6 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
618
616
|
});
|
|
619
617
|
}
|
|
620
618
|
|
|
621
|
-
|
|
622
|
-
// ______
|
|
623
|
-
// /_ __/_______ ___ _____
|
|
624
|
-
// / / / ___/ _ \/ _ \/ ___/
|
|
625
|
-
// / / / / / __/ __(__ )
|
|
626
|
-
// /_/ /_/ \___/\___/____/
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Loads the root nodes of this tree.
|
|
630
|
-
*/
|
|
631
|
-
loadRootNodes(depth) {
|
|
632
|
-
this.ensureTree();
|
|
633
|
-
if (this.isDestroyed) {
|
|
634
|
-
this.throwError('this.setRootNode is no longer valid. Repository has been destroyed.');
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
if (!this.isOnline) {
|
|
638
|
-
this.throwError('Offline');
|
|
639
|
-
return;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
this.emit('beforeLoad'); // TODO: canceling beforeLoad will cancel the load operation
|
|
643
|
-
this.markLoading();
|
|
644
|
-
|
|
645
|
-
const data = _.merge({ depth }, this._baseParams, this._params);
|
|
646
|
-
|
|
647
|
-
if (this.debugMode) {
|
|
648
|
-
console.log('loadRootNodes', data);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
652
|
-
.then((result) => {
|
|
653
|
-
if (this.debugMode) {
|
|
654
|
-
console.log('Response for loadRootNodes', result);
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
if (this.isDestroyed) {
|
|
658
|
-
// If this repository gets destroyed before it has a chance
|
|
659
|
-
// to process the Ajax request, just ignore the response.
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
const {
|
|
664
|
-
root,
|
|
665
|
-
success,
|
|
666
|
-
total,
|
|
667
|
-
message
|
|
668
|
-
} = this._processServerResponse(result);
|
|
669
|
-
|
|
670
|
-
if (!success) {
|
|
671
|
-
this.throwError(message);
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
this._destroyEntities();
|
|
676
|
-
|
|
677
|
-
// Set the current entities
|
|
678
|
-
const oThis = this;
|
|
679
|
-
this.entities = _.map(root, (data) => {
|
|
680
|
-
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
681
|
-
oThis._relayEntityEvents(entity);
|
|
682
|
-
return entity;
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
this.assembleTreeNodes();
|
|
686
|
-
|
|
687
|
-
// Set the total records that pass filter
|
|
688
|
-
this.total = total;
|
|
689
|
-
this._setPaginationVars();
|
|
690
|
-
|
|
691
|
-
this.areRootNodesLoaded = true;
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
// Don't emit events for root nodes...
|
|
695
|
-
this.rehash();
|
|
696
|
-
this.emit('loadRootNodes', this);
|
|
697
|
-
// this.emit('changeData', this.entities);
|
|
698
|
-
|
|
699
|
-
return this.getBy((entity) => {
|
|
700
|
-
return entity.isRoot;
|
|
701
|
-
});
|
|
702
|
-
})
|
|
703
|
-
.finally(() => {
|
|
704
|
-
this.markLoading(false);
|
|
705
|
-
});
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Loads (or reloads) the supplied treeNode
|
|
710
|
-
*/
|
|
711
|
-
loadNode(treeNode, depth = 1) {
|
|
712
|
-
this.ensureTree();
|
|
713
|
-
if (this.isDestroyed) {
|
|
714
|
-
this.throwError('this.loadNode is no longer valid. Repository has been destroyed.');
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
|
-
if (!this.isOnline) {
|
|
718
|
-
this.throwError('Offline');
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// If children already exist, remove them from the repository
|
|
723
|
-
// This way, we can reload just a portion of the tree
|
|
724
|
-
if (!_.isEmpty(treeNode.children)) {
|
|
725
|
-
const children = treeNode.children;
|
|
726
|
-
treeNode.children = [];
|
|
727
|
-
|
|
728
|
-
const oThis = this;
|
|
729
|
-
_.each(children, (child) => {
|
|
730
|
-
oThis.removeEntity(child);
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
this.markLoading();
|
|
735
|
-
|
|
736
|
-
const data = _.merge({ depth, nodeId: treeNode.id, }, this._baseParams, this._params);
|
|
737
|
-
|
|
738
|
-
if (this.debugMode) {
|
|
739
|
-
console.log('loadNode', data);
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
743
|
-
.then((result) => {
|
|
744
|
-
if (this.debugMode) {
|
|
745
|
-
console.log('Response for loadNode', result);
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
if (this.isDestroyed) {
|
|
749
|
-
// If this repository gets destroyed before it has a chance
|
|
750
|
-
// to process the Ajax request, just ignore the response.
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
const {
|
|
755
|
-
root,
|
|
756
|
-
success,
|
|
757
|
-
total,
|
|
758
|
-
message
|
|
759
|
-
} = this._processServerResponse(result);
|
|
760
|
-
|
|
761
|
-
if (!success) {
|
|
762
|
-
this.throwError(message);
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
// Set the current entities
|
|
767
|
-
const oThis = this;
|
|
768
|
-
const children = _.map(root, (data) => {
|
|
769
|
-
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
770
|
-
oThis._relayEntityEvents(entity);
|
|
771
|
-
return entity;
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
this.entities = this.entities.concat(children);
|
|
775
|
-
|
|
776
|
-
this.assembleTreeNodes();
|
|
777
|
-
|
|
778
|
-
this._setPaginationVars();
|
|
779
|
-
|
|
780
|
-
this.rehash();
|
|
781
|
-
// this.emit('changeData', this.entities);
|
|
782
|
-
this.emit('load', this);
|
|
783
|
-
|
|
784
|
-
return children;
|
|
785
|
-
})
|
|
786
|
-
.finally(() => {
|
|
787
|
-
this.markLoading(false);
|
|
788
|
-
});
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
/**
|
|
792
|
-
* Loads (or reloads) the children of the supplied treeNode
|
|
793
|
-
*/
|
|
794
|
-
loadChildNodes(treeNode, depth = 1) {
|
|
795
|
-
this.ensureTree();
|
|
796
|
-
if (this.isDestroyed) {
|
|
797
|
-
this.throwError('this.loadChildNodes is no longer valid. Repository has been destroyed.');
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
if (!this.isOnline) {
|
|
801
|
-
this.throwError('Offline');
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
// If children already exist, remove them from the repository
|
|
806
|
-
// This way, we can reload just a portion of the tree
|
|
807
|
-
if (!_.isEmpty(treeNode.children)) {
|
|
808
|
-
_.each(treeNode.children, (child) => {
|
|
809
|
-
treeNode.repository.removeTreeNode(child);
|
|
810
|
-
});
|
|
811
|
-
treeNode.children = [];
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
this.markLoading();
|
|
815
|
-
|
|
816
|
-
const data = _.merge({ depth, parentId: treeNode.id, }, this._baseParams, this._params);
|
|
817
|
-
|
|
818
|
-
if (this.debugMode) {
|
|
819
|
-
console.log('loadChildNodes', data);
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
823
|
-
.then((result) => {
|
|
824
|
-
if (this.debugMode) {
|
|
825
|
-
console.log('Response for loadChildNodes', result);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
if (this.isDestroyed) {
|
|
829
|
-
// If this repository gets destroyed before it has a chance
|
|
830
|
-
// to process the Ajax request, just ignore the response.
|
|
831
|
-
return;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
const {
|
|
835
|
-
root,
|
|
836
|
-
success,
|
|
837
|
-
total,
|
|
838
|
-
message
|
|
839
|
-
} = this._processServerResponse(result);
|
|
840
|
-
|
|
841
|
-
if (!success) {
|
|
842
|
-
this.throwError(message);
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// Set the current entities
|
|
847
|
-
const oThis = this;
|
|
848
|
-
const children = _.map(root, (data) => {
|
|
849
|
-
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
850
|
-
oThis._relayEntityEvents(entity);
|
|
851
|
-
return entity;
|
|
852
|
-
});
|
|
853
|
-
|
|
854
|
-
this.entities = this.entities.concat(children);
|
|
855
|
-
|
|
856
|
-
this.assembleTreeNodes();
|
|
857
|
-
|
|
858
|
-
this._setPaginationVars();
|
|
859
|
-
|
|
860
|
-
this.rehash();
|
|
861
|
-
// this.emit('changeData', this.entities);
|
|
862
|
-
this.emit('load', this);
|
|
863
|
-
|
|
864
|
-
return children;
|
|
865
|
-
})
|
|
866
|
-
.finally(() => {
|
|
867
|
-
this.markLoading(false);
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
/**
|
|
872
|
-
* Override the AjaxRepository to we can reload a treeNode if needed
|
|
873
|
-
*/
|
|
874
|
-
reloadEntity(entity, callback = null) {
|
|
875
|
-
if (!entity.isTree) {
|
|
876
|
-
return super.reloadEntity(entity, callback);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
return this.loadNode(entity, 1);
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
/**
|
|
883
|
-
* Searches all nodes for the supplied text.
|
|
884
|
-
* This basically takes the search query and returns whatever the server sends
|
|
885
|
-
*/
|
|
886
|
-
searchNodes(q) {
|
|
887
|
-
this.ensureTree();
|
|
888
|
-
if (this.isDestroyed) {
|
|
889
|
-
this.throwError('this.searchNodes is no longer valid. Repository has been destroyed.');
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
if (!this.isOnline) {
|
|
893
|
-
this.throwError('Offline');
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
const data = _.merge({ q, }, this._baseParams, this._params);
|
|
898
|
-
|
|
899
|
-
if (this.debugMode) {
|
|
900
|
-
console.log('searchNodes', data);
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
return this._send('POST', this._getModel() + '/searchNodes', data)
|
|
904
|
-
.then((result) => {
|
|
905
|
-
if (this.debugMode) {
|
|
906
|
-
console.log('Response for searchNodes', result);
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
if (this.isDestroyed) {
|
|
910
|
-
// If this repository gets destroyed before it has a chance
|
|
911
|
-
// to process the Ajax request, just ignore the response.
|
|
912
|
-
return;
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
const {
|
|
916
|
-
root,
|
|
917
|
-
success,
|
|
918
|
-
total,
|
|
919
|
-
message
|
|
920
|
-
} = this._processServerResponse(result);
|
|
921
|
-
|
|
922
|
-
if (!success) {
|
|
923
|
-
this.throwError(message);
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
return root;
|
|
928
|
-
})
|
|
929
|
-
.finally(() => {
|
|
930
|
-
this.markLoading(false);
|
|
931
|
-
});
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
/**
|
|
935
|
-
* Alias for loadChildren
|
|
936
|
-
*/
|
|
937
|
-
reloadChildren(treeNode, depth) {
|
|
938
|
-
return this.loadChildren(treeNode, depth);
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
/**
|
|
942
|
-
* Moves the supplied treeNode to a new position on the tree
|
|
943
|
-
* @returns id of common ancestor node
|
|
944
|
-
*/
|
|
945
|
-
moveTreeNode(treeNode, newParentId) {
|
|
946
|
-
this.ensureTree();
|
|
947
|
-
if (this.isDestroyed) {
|
|
948
|
-
this.throwError('this.moveTreeNode is no longer valid. Repository has been destroyed.');
|
|
949
|
-
return;
|
|
950
|
-
}
|
|
951
|
-
if (!this.isOnline) {
|
|
952
|
-
this.throwError('Offline');
|
|
953
|
-
return;
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
const oldParentId = treeNode.parent?.id;
|
|
957
|
-
|
|
958
|
-
const data = _.merge({ nodeId: treeNode.id, parentId: newParentId, }, this._baseParams, this._params);
|
|
959
|
-
|
|
960
|
-
if (this.debugMode) {
|
|
961
|
-
console.log('moveTreeNode', data);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
return this._send('POST', this._getModel() + '/moveNode', data)
|
|
965
|
-
.then((result) => {
|
|
966
|
-
if (this.debugMode) {
|
|
967
|
-
console.log('Response for searchNodes', result);
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
if (this.isDestroyed) {
|
|
971
|
-
// If this repository gets destroyed before it has a chance
|
|
972
|
-
// to process the Ajax request, just ignore the response.
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
const {
|
|
977
|
-
root: {
|
|
978
|
-
commonAncestorId,
|
|
979
|
-
oldParent,
|
|
980
|
-
newParent,
|
|
981
|
-
node,
|
|
982
|
-
},
|
|
983
|
-
success,
|
|
984
|
-
total,
|
|
985
|
-
message
|
|
986
|
-
} = this._processServerResponse(result);
|
|
987
|
-
|
|
988
|
-
if (!success) {
|
|
989
|
-
this.throwError(message);
|
|
990
|
-
return;
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
// move it from oldParent.children to newParent.children
|
|
994
|
-
const
|
|
995
|
-
oldParentRecord = this.getById(oldParentId),
|
|
996
|
-
newParentRecord = this.getById(newParentId);
|
|
997
|
-
|
|
998
|
-
oldParentRecord?.loadOriginalData(oldParent);
|
|
999
|
-
newParentRecord.loadOriginalData(newParent);
|
|
1000
|
-
treeNode.loadOriginalData(node);
|
|
1001
|
-
|
|
1002
|
-
this.assembleTreeNodes();
|
|
1003
|
-
|
|
1004
|
-
return commonAncestorId;
|
|
1005
|
-
})
|
|
1006
|
-
.finally(() => {
|
|
1007
|
-
this.markLoading(false);
|
|
1008
|
-
});
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
619
|
}
|
|
1012
620
|
|
|
1013
621
|
|