@onehat/data 1.21.0 → 1.21.2
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
|
@@ -1787,7 +1787,7 @@ class Entity extends EventEmitter {
|
|
|
1787
1787
|
* Helper to make sure this Repository is a tree
|
|
1788
1788
|
* @private
|
|
1789
1789
|
*/
|
|
1790
|
-
ensureTree =
|
|
1790
|
+
ensureTree = () => {
|
|
1791
1791
|
if (!this.isTree) {
|
|
1792
1792
|
this.throwError('This Entity is not a tree!');
|
|
1793
1793
|
return false;
|
|
@@ -30,19 +30,20 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
30
30
|
constructor(config = {}) {
|
|
31
31
|
super(...arguments);
|
|
32
32
|
|
|
33
|
+
const model = this._getModel();
|
|
33
34
|
const defaults = {
|
|
34
35
|
|
|
35
36
|
isAutoLoad: false,
|
|
36
37
|
isAutoSave: false,
|
|
37
38
|
|
|
38
39
|
api: {
|
|
39
|
-
get:
|
|
40
|
-
add:
|
|
41
|
-
edit:
|
|
42
|
-
delete:
|
|
43
|
-
batchAdd:
|
|
44
|
-
batchEdit:
|
|
45
|
-
batchDelete:
|
|
40
|
+
get: model + '/get',
|
|
41
|
+
add: model + '/add',
|
|
42
|
+
edit: model + '/edit',
|
|
43
|
+
delete: model + '/delete',
|
|
44
|
+
batchAdd: model + '/batchAdd',
|
|
45
|
+
batchEdit: model + '/batchEdit',
|
|
46
|
+
batchDelete: model + '/batchDelete',
|
|
46
47
|
},
|
|
47
48
|
|
|
48
49
|
methods: {
|
|
@@ -81,6 +82,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
81
82
|
|
|
82
83
|
this.registerEvents([
|
|
83
84
|
'logout',
|
|
85
|
+
'loadRootNodes',
|
|
84
86
|
]);
|
|
85
87
|
|
|
86
88
|
await super.initialize();
|
|
@@ -146,6 +148,13 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
146
148
|
});
|
|
147
149
|
}
|
|
148
150
|
|
|
151
|
+
_getModel() {
|
|
152
|
+
if (!this.isUnique) {
|
|
153
|
+
return this.name;
|
|
154
|
+
}
|
|
155
|
+
return this.name.match(/^([^-]*)-(.*)/)[1]; // converts 'ModelName-22f9915c-79f5-4e86-a25b-9446c7b85b63' to 'ModelName'
|
|
156
|
+
}
|
|
157
|
+
|
|
149
158
|
/**
|
|
150
159
|
* Helper for reloadEntity.
|
|
151
160
|
* @private
|
|
@@ -285,7 +294,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
285
294
|
}
|
|
286
295
|
|
|
287
296
|
const data = {
|
|
288
|
-
url: this.
|
|
297
|
+
url: this._getModel() + '/reorder',
|
|
289
298
|
data: qs.stringify({
|
|
290
299
|
ids,
|
|
291
300
|
dropPosition,
|
|
@@ -581,7 +590,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
581
590
|
console.log('loadRootNodes', data);
|
|
582
591
|
}
|
|
583
592
|
|
|
584
|
-
return this._send('POST', this.
|
|
593
|
+
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
585
594
|
.then((result) => {
|
|
586
595
|
if (this.debugMode) {
|
|
587
596
|
console.log('Response for loadRootNodes', result);
|
|
@@ -626,7 +635,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
626
635
|
|
|
627
636
|
// Don't emit events for root nodes...
|
|
628
637
|
this.rehash();
|
|
629
|
-
this.emit('
|
|
638
|
+
this.emit('loadRootNodes', this);
|
|
630
639
|
// this.emit('changeData', this.entities);
|
|
631
640
|
|
|
632
641
|
return this.getBy((entity) => {
|
|
@@ -672,7 +681,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
672
681
|
console.log('loadNode', data);
|
|
673
682
|
}
|
|
674
683
|
|
|
675
|
-
return this._send('POST', this.
|
|
684
|
+
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
676
685
|
.then((result) => {
|
|
677
686
|
if (this.debugMode) {
|
|
678
687
|
console.log('Response for loadNode', result);
|
|
@@ -755,7 +764,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
755
764
|
console.log('loadChildNodes', data);
|
|
756
765
|
}
|
|
757
766
|
|
|
758
|
-
return this._send('POST', this.
|
|
767
|
+
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
759
768
|
.then((result) => {
|
|
760
769
|
if (this.debugMode) {
|
|
761
770
|
console.log('Response for loadChildNodes', result);
|
|
@@ -836,7 +845,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
836
845
|
console.log('searchNodes', data);
|
|
837
846
|
}
|
|
838
847
|
|
|
839
|
-
return this._send('POST', this.
|
|
848
|
+
return this._send('POST', this._getModel() + '/searchNodes', data)
|
|
840
849
|
.then((result) => {
|
|
841
850
|
if (this.debugMode) {
|
|
842
851
|
console.log('Response for searchNodes', result);
|
|
@@ -897,7 +906,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
897
906
|
console.log('moveTreeNode', data);
|
|
898
907
|
}
|
|
899
908
|
|
|
900
|
-
return this._send('POST', this.
|
|
909
|
+
return this._send('POST', this._getModel() + '/moveNode', data)
|
|
901
910
|
.then((result) => {
|
|
902
911
|
if (this.debugMode) {
|
|
903
912
|
console.log('Response for searchNodes', result);
|
|
@@ -1353,6 +1353,9 @@ export default class Repository extends EventEmitter {
|
|
|
1353
1353
|
this.throwError('this.getById is no longer valid. Repository has been destroyed.');
|
|
1354
1354
|
return;
|
|
1355
1355
|
}
|
|
1356
|
+
if (_.isNil(id)) {
|
|
1357
|
+
return null;
|
|
1358
|
+
}
|
|
1356
1359
|
return this.getFirstBy(entity => entity.id === id);
|
|
1357
1360
|
}
|
|
1358
1361
|
|
|
@@ -1366,12 +1369,15 @@ export default class Repository extends EventEmitter {
|
|
|
1366
1369
|
this.throwError('this.getIxById is no longer valid. Repository has been destroyed.');
|
|
1367
1370
|
return;
|
|
1368
1371
|
}
|
|
1372
|
+
if (_.isNil(id)) {
|
|
1373
|
+
return null;
|
|
1374
|
+
}
|
|
1369
1375
|
|
|
1370
1376
|
const ix = this.entities.findIndex((entity) => entity.id === id);
|
|
1371
1377
|
if (ix >= 0) {
|
|
1372
1378
|
return ix;
|
|
1373
1379
|
}
|
|
1374
|
-
return
|
|
1380
|
+
return null;
|
|
1375
1381
|
}
|
|
1376
1382
|
|
|
1377
1383
|
/**
|