@onehat/data 1.20.9 → 1.21.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/cypress/downloads/downloads.html +0 -0
- package/cypress/e2e/Entity.cy.js +2 -2
- package/cypress/e2e/Property/Base64.cy.js +37 -3
- package/cypress/e2e/Property/Boolean.cy.js +30 -0
- package/cypress/e2e/Property/Currency.cy.js +41 -0
- package/cypress/e2e/Property/Date.cy.js +33 -0
- package/cypress/e2e/Property/DateTime.cy.js +33 -0
- package/cypress/e2e/Property/Float.cy.js +31 -0
- package/cypress/e2e/Property/Integer.cy.js +31 -0
- package/cypress/e2e/Property/Json.cy.js +29 -0
- package/cypress/e2e/Property/PercentInt.cy.js +32 -0
- package/cypress/e2e/Property/Property.cy.js +29 -0
- package/cypress/e2e/Property/Time.cy.js +33 -0
- package/cypress/e2e/Repository/Repository.cy.js +23 -16
- package/cypress/e2e/Schema.cy.js +2 -2
- package/package.json +1 -1
- package/src/Integration/Browser/Repository/Cookie.js +4 -4
- package/src/Integration/Browser/Repository/IndexedDB.js +4 -4
- package/src/Integration/Browser/Repository/LocalStorage.js +4 -4
- package/src/Integration/Browser/Repository/SecureLocalStorage.js +2 -2
- package/src/Integration/Browser/Repository/SecureSessionStorage.js +2 -2
- package/src/Integration/Browser/Repository/SessionStorage.js +4 -4
- package/src/Integration/ReactNative/Repository/AsyncStorage.js +8 -8
- package/src/Integration/ReactNative/Repository/SecureStore.js +4 -4
- package/src/Property/Base64.js +21 -11
- package/src/Property/Boolean.js +20 -12
- package/src/Property/Currency.js +30 -21
- package/src/Property/Date.js +23 -14
- package/src/Property/DateTime.js +18 -9
- package/src/Property/File.js +0 -4
- package/src/Property/Float.js +19 -10
- package/src/Property/Integer.js +19 -10
- package/src/Property/Json.js +22 -13
- package/src/Property/Percent.js +2 -2
- package/src/Property/PercentInt.js +16 -7
- package/src/Property/Property.js +150 -140
- package/src/Property/String.js +2 -7
- package/src/Property/Time.js +17 -8
- package/src/Property/Uuid.js +3 -8
- package/src/Property/index.js +2 -0
- package/src/Repository/Ajax.js +33 -28
- package/src/Repository/LocalFromRemote/Command.js +5 -5
- package/src/Repository/LocalFromRemote/CommandRepository.js +1 -1
- package/src/Repository/LocalFromRemote/LocalFromRemote.js +18 -17
- package/src/Repository/Memory.js +22 -21
- package/src/Repository/Null.js +5 -5
- package/src/Repository/Offline.js +17 -16
- package/src/Repository/OneBuild.js +57 -42
- package/src/Repository/OneBuild2.js +16 -10
- package/src/Repository/Repository.js +105 -102
- package/src/Schema/Schema.js +9 -6
|
@@ -41,7 +41,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
41
41
|
* Deletes all data in storage medium.
|
|
42
42
|
* @private
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
async _deleteFromStorage() {
|
|
45
45
|
try {
|
|
46
46
|
const ids = await this._getIndex(),
|
|
47
47
|
total = ids.length,
|
|
@@ -80,7 +80,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
80
80
|
* @return {array} data - Array of rawData objects
|
|
81
81
|
* @private
|
|
82
82
|
*/
|
|
83
|
-
|
|
83
|
+
async _loadFromStorage() {
|
|
84
84
|
try {
|
|
85
85
|
|
|
86
86
|
this._index = await this._getIndex();
|
|
@@ -122,7 +122,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
122
122
|
* @return {array} data - Array of rawData objects
|
|
123
123
|
* @private
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
async _saveToStorage(entities) {
|
|
126
126
|
try {
|
|
127
127
|
let i, entity,
|
|
128
128
|
total = entities.length,
|
|
@@ -197,7 +197,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
197
197
|
* @param {string} id - The id to add.
|
|
198
198
|
* @private
|
|
199
199
|
*/
|
|
200
|
-
|
|
200
|
+
async _addToIndex(id) {
|
|
201
201
|
let index = await this._getIndex();
|
|
202
202
|
index.push(id);
|
|
203
203
|
index = _.uniq(index);
|
|
@@ -266,7 +266,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
266
266
|
* @param {string} id - The id to delete.
|
|
267
267
|
* @private
|
|
268
268
|
*/
|
|
269
|
-
|
|
269
|
+
async _deleteFromIndex(id) {
|
|
270
270
|
let index = await this._getIndex();
|
|
271
271
|
_.pull(index, id);
|
|
272
272
|
await this._setIndex(index);
|
|
@@ -289,7 +289,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
289
289
|
* @fires save
|
|
290
290
|
* @private
|
|
291
291
|
*/
|
|
292
|
-
|
|
292
|
+
async _finalizeSave(results) {
|
|
293
293
|
return Promise.all(results)
|
|
294
294
|
.then(() => {
|
|
295
295
|
this.isSaving = false;
|
|
@@ -309,7 +309,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
309
309
|
* @return {array} index - Array of ids.
|
|
310
310
|
* @private
|
|
311
311
|
*/
|
|
312
|
-
|
|
312
|
+
async _getIndex() {
|
|
313
313
|
// return await this._storageGetValue('index');
|
|
314
314
|
let result = await this._storageGetValue('index');
|
|
315
315
|
if (!result) {
|
|
@@ -325,7 +325,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
325
325
|
* @return {array} index - Array of keys.
|
|
326
326
|
* @private
|
|
327
327
|
*/
|
|
328
|
-
|
|
328
|
+
async _getKeys() {
|
|
329
329
|
if (!this._getAllKeys) {
|
|
330
330
|
this.throwError('Storage medium does not support _getAllKeys');
|
|
331
331
|
return;
|
|
@@ -342,7 +342,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
342
342
|
* @param {array} index - Array of ids.
|
|
343
343
|
* @private
|
|
344
344
|
*/
|
|
345
|
-
|
|
345
|
+
async _setIndex(index) {
|
|
346
346
|
if (!_.isEqual(this._index, index)) {
|
|
347
347
|
this._index = index;
|
|
348
348
|
return await this._storageSetValue('index', index);
|
|
@@ -358,7 +358,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
358
358
|
* @private
|
|
359
359
|
* @abstract
|
|
360
360
|
*/
|
|
361
|
-
|
|
361
|
+
async _storageGetValue(name) {
|
|
362
362
|
this.throwError('this._storageGetValue must be implemented by OfflineRepository subclass.');
|
|
363
363
|
return;
|
|
364
364
|
}
|
|
@@ -370,7 +370,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
370
370
|
* @private
|
|
371
371
|
* @abstract
|
|
372
372
|
*/
|
|
373
|
-
|
|
373
|
+
async _storageSetValue(name, value) {
|
|
374
374
|
this.throwError('this._storageSetValue must be implemented by OfflineRepository subclass.');
|
|
375
375
|
return;
|
|
376
376
|
}
|
|
@@ -381,7 +381,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
381
381
|
* @private
|
|
382
382
|
* @abstract
|
|
383
383
|
*/
|
|
384
|
-
|
|
384
|
+
async _storageDeleteValue(name) {
|
|
385
385
|
this.throwError('this._storageDeleteValue must be implemented by OfflineRepository subclass.');
|
|
386
386
|
return;
|
|
387
387
|
}
|
|
@@ -394,7 +394,8 @@ class OfflineRepository extends MemoryRepository {
|
|
|
394
394
|
*/
|
|
395
395
|
_namespace(name) {
|
|
396
396
|
if (_.isArray(name)) {
|
|
397
|
-
|
|
397
|
+
const oThis = this;
|
|
398
|
+
return _.map(name, (key) => oThis.schema.name + '-' + key);
|
|
398
399
|
}
|
|
399
400
|
return this.schema.name + '-' + name;
|
|
400
401
|
}
|
|
@@ -404,7 +405,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
404
405
|
* (when this is the "local" side of at LocalFromRemoteRepository)
|
|
405
406
|
* @return {moment} lastSync
|
|
406
407
|
*/
|
|
407
|
-
|
|
408
|
+
async getLastSync() {
|
|
408
409
|
const dateStr = await this._storageGetValue(LAST_SYNC);
|
|
409
410
|
if (!_.isNil(dateStr)) {
|
|
410
411
|
const date = moment(dateStr);
|
|
@@ -420,7 +421,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
420
421
|
* Used when this is the "local" side of a LocalFromRemoteRepository
|
|
421
422
|
* @param {date} lastSync
|
|
422
423
|
*/
|
|
423
|
-
|
|
424
|
+
async setLastSync(date) {
|
|
424
425
|
await this._storageSetValue(LAST_SYNC, date);
|
|
425
426
|
}
|
|
426
427
|
|
|
@@ -429,7 +430,7 @@ class OfflineRepository extends MemoryRepository {
|
|
|
429
430
|
* Clears the date when this Repository was last synced with remote.
|
|
430
431
|
* Used when this is the "local" side of a LocalFromRemoteRepository
|
|
431
432
|
*/
|
|
432
|
-
|
|
433
|
+
async clearLastSync() {
|
|
433
434
|
await this._storageDeleteValue(LAST_SYNC);
|
|
434
435
|
}
|
|
435
436
|
|
|
@@ -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();
|
|
@@ -93,7 +95,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
93
95
|
* Fires off axios request to server
|
|
94
96
|
* @private
|
|
95
97
|
*/
|
|
96
|
-
_send
|
|
98
|
+
_send(method, url, data) {
|
|
97
99
|
|
|
98
100
|
if (!url) {
|
|
99
101
|
this.throwError('No url submitted');
|
|
@@ -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
|
|
@@ -161,7 +170,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
161
170
|
* OneBuild uses a single, multi-dimentional param for filtering.
|
|
162
171
|
* Refreshes entities.
|
|
163
172
|
*/
|
|
164
|
-
_onChangeFilters
|
|
173
|
+
_onChangeFilters() {
|
|
165
174
|
// Clear existing "conditions" params
|
|
166
175
|
if (!_.isEmpty(this._params)) {
|
|
167
176
|
this._params = _.omitBy(this._params, (value, key) => {
|
|
@@ -169,11 +178,12 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
169
178
|
});
|
|
170
179
|
}
|
|
171
180
|
|
|
181
|
+
const oThis = this;
|
|
172
182
|
_.each(this.filters, (filter, ix) => {
|
|
173
183
|
if (_.includes(nonConditionFilters, filter.name)) {
|
|
174
|
-
|
|
184
|
+
oThis.setParam(filter.name, filter.value);
|
|
175
185
|
} else {
|
|
176
|
-
|
|
186
|
+
oThis.setParam('conditions[' + filter.name + ']', filter.value);
|
|
177
187
|
}
|
|
178
188
|
});
|
|
179
189
|
|
|
@@ -191,7 +201,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
191
201
|
* OneBuild uses a single order param, rather than separate name & direction params.
|
|
192
202
|
* Refreshes entities.
|
|
193
203
|
*/
|
|
194
|
-
_onChangeSorters
|
|
204
|
+
_onChangeSorters() {
|
|
195
205
|
let sorterStrings = [];
|
|
196
206
|
_.each(this.sorters, (sorter) => {
|
|
197
207
|
sorterStrings.push(sorter.name + ' ' + sorter.direction);
|
|
@@ -225,7 +235,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
225
235
|
* @fires error
|
|
226
236
|
* @private
|
|
227
237
|
*/
|
|
228
|
-
_processServerResponse
|
|
238
|
+
_processServerResponse(result) {
|
|
229
239
|
|
|
230
240
|
if (result === false) { // e.g. 401 error
|
|
231
241
|
return {
|
|
@@ -267,7 +277,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
267
277
|
* @param {string} dropPosition - position in which it was dropped; could be 'before' or 'after'
|
|
268
278
|
* @return {Promise}
|
|
269
279
|
*/
|
|
270
|
-
reorder
|
|
280
|
+
reorder(dragRecordOrIds, dropRecord, dropPosition) {
|
|
271
281
|
|
|
272
282
|
if (!this.isOnline) {
|
|
273
283
|
this.throwError('Offline');
|
|
@@ -284,7 +294,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
284
294
|
}
|
|
285
295
|
|
|
286
296
|
const data = {
|
|
287
|
-
url: this.
|
|
297
|
+
url: this._getModel() + '/reorder',
|
|
288
298
|
data: qs.stringify({
|
|
289
299
|
ids,
|
|
290
300
|
dropPosition,
|
|
@@ -316,7 +326,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
316
326
|
});
|
|
317
327
|
}
|
|
318
328
|
|
|
319
|
-
|
|
329
|
+
async remoteDuplicate(entity) {
|
|
320
330
|
|
|
321
331
|
this.markLoading();
|
|
322
332
|
|
|
@@ -358,7 +368,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
358
368
|
return duplicateEntity;
|
|
359
369
|
}
|
|
360
370
|
|
|
361
|
-
|
|
371
|
+
async loadOneAdditionalEntity(id) {
|
|
362
372
|
const entity = await this.getSingleEntityFromServer(id);
|
|
363
373
|
if (!entity) {
|
|
364
374
|
this.throwError('entity not found');
|
|
@@ -372,7 +382,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
372
382
|
this.emit('changeData', this.entities);
|
|
373
383
|
}
|
|
374
384
|
|
|
375
|
-
|
|
385
|
+
async getSingleEntityFromServer(id) {
|
|
376
386
|
if (this.isDestroyed) {
|
|
377
387
|
this.throwError('this.getSingleEntityFromServer is no longer valid. Repository has been destroyed.');
|
|
378
388
|
return;
|
|
@@ -438,7 +448,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
438
448
|
* - password,
|
|
439
449
|
* @return {Promise}
|
|
440
450
|
*/
|
|
441
|
-
login
|
|
451
|
+
login(creds) {
|
|
442
452
|
|
|
443
453
|
if (!this.isOnline) {
|
|
444
454
|
this.throwError('Offline');
|
|
@@ -477,7 +487,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
477
487
|
* Logout from OneBuild API
|
|
478
488
|
* @return {Promise}
|
|
479
489
|
*/
|
|
480
|
-
logout
|
|
490
|
+
logout() {
|
|
481
491
|
|
|
482
492
|
if (!this.isOnline) {
|
|
483
493
|
this.throwError('Offline');
|
|
@@ -513,7 +523,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
513
523
|
});
|
|
514
524
|
}
|
|
515
525
|
|
|
516
|
-
forgotPassword
|
|
526
|
+
forgotPassword(email = null, username = null) {
|
|
517
527
|
|
|
518
528
|
if (!this.isOnline) {
|
|
519
529
|
this.throwError('Offline');
|
|
@@ -560,7 +570,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
560
570
|
/**
|
|
561
571
|
* Loads the root nodes of this tree.
|
|
562
572
|
*/
|
|
563
|
-
loadRootNodes
|
|
573
|
+
loadRootNodes(depth) {
|
|
564
574
|
this.ensureTree();
|
|
565
575
|
if (this.isDestroyed) {
|
|
566
576
|
this.throwError('this.setRootNode is no longer valid. Repository has been destroyed.');
|
|
@@ -580,7 +590,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
580
590
|
console.log('loadRootNodes', data);
|
|
581
591
|
}
|
|
582
592
|
|
|
583
|
-
return this._send('POST', this.
|
|
593
|
+
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
584
594
|
.then((result) => {
|
|
585
595
|
if (this.debugMode) {
|
|
586
596
|
console.log('Response for loadRootNodes', result);
|
|
@@ -607,9 +617,10 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
607
617
|
this._destroyEntities();
|
|
608
618
|
|
|
609
619
|
// Set the current entities
|
|
620
|
+
const oThis = this;
|
|
610
621
|
this.entities = _.map(root, (data) => {
|
|
611
|
-
const entity = Repository._createEntity(
|
|
612
|
-
|
|
622
|
+
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
623
|
+
oThis._relayEntityEvents(entity);
|
|
613
624
|
return entity;
|
|
614
625
|
});
|
|
615
626
|
|
|
@@ -624,7 +635,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
624
635
|
|
|
625
636
|
// Don't emit events for root nodes...
|
|
626
637
|
this.rehash();
|
|
627
|
-
this.emit('
|
|
638
|
+
this.emit('loadRootNodes', this);
|
|
628
639
|
// this.emit('changeData', this.entities);
|
|
629
640
|
|
|
630
641
|
return this.getBy((entity) => {
|
|
@@ -639,7 +650,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
639
650
|
/**
|
|
640
651
|
* Loads (or reloads) the supplied treeNode
|
|
641
652
|
*/
|
|
642
|
-
loadNode
|
|
653
|
+
loadNode(treeNode, depth = 1) {
|
|
643
654
|
this.ensureTree();
|
|
644
655
|
if (this.isDestroyed) {
|
|
645
656
|
this.throwError('this.loadNode is no longer valid. Repository has been destroyed.');
|
|
@@ -656,8 +667,9 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
656
667
|
const children = treeNode.children;
|
|
657
668
|
treeNode.children = [];
|
|
658
669
|
|
|
670
|
+
const oThis = this;
|
|
659
671
|
_.each(children, (child) => {
|
|
660
|
-
|
|
672
|
+
oThis.removeEntity(child);
|
|
661
673
|
});
|
|
662
674
|
}
|
|
663
675
|
|
|
@@ -669,7 +681,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
669
681
|
console.log('loadNode', data);
|
|
670
682
|
}
|
|
671
683
|
|
|
672
|
-
return this._send('POST', this.
|
|
684
|
+
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
673
685
|
.then((result) => {
|
|
674
686
|
if (this.debugMode) {
|
|
675
687
|
console.log('Response for loadNode', result);
|
|
@@ -694,9 +706,10 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
694
706
|
}
|
|
695
707
|
|
|
696
708
|
// Set the current entities
|
|
709
|
+
const oThis = this;
|
|
697
710
|
const children = _.map(root, (data) => {
|
|
698
|
-
const entity = Repository._createEntity(
|
|
699
|
-
|
|
711
|
+
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
712
|
+
oThis._relayEntityEvents(entity);
|
|
700
713
|
return entity;
|
|
701
714
|
});
|
|
702
715
|
|
|
@@ -720,7 +733,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
720
733
|
/**
|
|
721
734
|
* Loads (or reloads) the children of the supplied treeNode
|
|
722
735
|
*/
|
|
723
|
-
loadChildNodes
|
|
736
|
+
loadChildNodes(treeNode, depth = 1) {
|
|
724
737
|
this.ensureTree();
|
|
725
738
|
if (this.isDestroyed) {
|
|
726
739
|
this.throwError('this.loadChildNodes is no longer valid. Repository has been destroyed.');
|
|
@@ -737,8 +750,9 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
737
750
|
const children = treeNode.children;
|
|
738
751
|
treeNode.children = [];
|
|
739
752
|
|
|
753
|
+
const oThis = this;
|
|
740
754
|
_.each(children, (child) => {
|
|
741
|
-
|
|
755
|
+
oThis.removeEntity(child);
|
|
742
756
|
});
|
|
743
757
|
}
|
|
744
758
|
|
|
@@ -750,7 +764,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
750
764
|
console.log('loadChildNodes', data);
|
|
751
765
|
}
|
|
752
766
|
|
|
753
|
-
return this._send('POST', this.
|
|
767
|
+
return this._send('POST', this._getModel() + '/getNodes', data)
|
|
754
768
|
.then((result) => {
|
|
755
769
|
if (this.debugMode) {
|
|
756
770
|
console.log('Response for loadChildNodes', result);
|
|
@@ -775,9 +789,10 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
775
789
|
}
|
|
776
790
|
|
|
777
791
|
// Set the current entities
|
|
792
|
+
const oThis = this;
|
|
778
793
|
const children = _.map(root, (data) => {
|
|
779
|
-
const entity = Repository._createEntity(
|
|
780
|
-
|
|
794
|
+
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
795
|
+
oThis._relayEntityEvents(entity);
|
|
781
796
|
return entity;
|
|
782
797
|
});
|
|
783
798
|
|
|
@@ -801,7 +816,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
801
816
|
/**
|
|
802
817
|
* Override the AjaxRepository to we can reload a treeNode if needed
|
|
803
818
|
*/
|
|
804
|
-
reloadEntity
|
|
819
|
+
reloadEntity(entity, callback = null) {
|
|
805
820
|
if (!entity.isTree) {
|
|
806
821
|
return super.reloadEntity(entity, callback);
|
|
807
822
|
}
|
|
@@ -813,7 +828,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
813
828
|
* Searches all nodes for the supplied text.
|
|
814
829
|
* This basically takes the search query and returns whatever the server sends
|
|
815
830
|
*/
|
|
816
|
-
searchNodes
|
|
831
|
+
searchNodes(q) {
|
|
817
832
|
this.ensureTree();
|
|
818
833
|
if (this.isDestroyed) {
|
|
819
834
|
this.throwError('this.searchNodes is no longer valid. Repository has been destroyed.');
|
|
@@ -830,7 +845,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
830
845
|
console.log('searchNodes', data);
|
|
831
846
|
}
|
|
832
847
|
|
|
833
|
-
return this._send('POST', this.
|
|
848
|
+
return this._send('POST', this._getModel() + '/searchNodes', data)
|
|
834
849
|
.then((result) => {
|
|
835
850
|
if (this.debugMode) {
|
|
836
851
|
console.log('Response for searchNodes', result);
|
|
@@ -864,7 +879,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
864
879
|
/**
|
|
865
880
|
* Alias for loadChildren
|
|
866
881
|
*/
|
|
867
|
-
reloadChildren
|
|
882
|
+
reloadChildren(treeNode, depth) {
|
|
868
883
|
return this.loadChildren(treeNode, depth);
|
|
869
884
|
}
|
|
870
885
|
|
|
@@ -872,7 +887,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
872
887
|
* Moves the supplied treeNode to a new position on the tree
|
|
873
888
|
* @returns id of common ancestor node
|
|
874
889
|
*/
|
|
875
|
-
moveTreeNode
|
|
890
|
+
moveTreeNode(treeNode, newParentId) {
|
|
876
891
|
this.ensureTree();
|
|
877
892
|
if (this.isDestroyed) {
|
|
878
893
|
this.throwError('this.moveTreeNode is no longer valid. Repository has been destroyed.');
|
|
@@ -891,7 +906,7 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
891
906
|
console.log('moveTreeNode', data);
|
|
892
907
|
}
|
|
893
908
|
|
|
894
|
-
return this._send('POST', this.
|
|
909
|
+
return this._send('POST', this._getModel() + '/moveNode', data)
|
|
895
910
|
.then((result) => {
|
|
896
911
|
if (this.debugMode) {
|
|
897
912
|
console.log('Response for searchNodes', result);
|
|
@@ -169,11 +169,12 @@ class OneBuild2Repository extends AjaxRepository {
|
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
const oThis = this;
|
|
172
173
|
_.each(this.filters, (filter, ix) => {
|
|
173
174
|
if (_.includes(nonConditionFilters, filter.name)) {
|
|
174
|
-
|
|
175
|
+
oThis.setParam(filter.name, filter.value);
|
|
175
176
|
} else {
|
|
176
|
-
|
|
177
|
+
oThis.setParam('conditions[' + filter.name + ']', filter.value);
|
|
177
178
|
}
|
|
178
179
|
});
|
|
179
180
|
|
|
@@ -607,9 +608,10 @@ class OneBuild2Repository extends AjaxRepository {
|
|
|
607
608
|
this._destroyEntities();
|
|
608
609
|
|
|
609
610
|
// Set the current entities
|
|
611
|
+
const oThis = this;
|
|
610
612
|
this.entities = _.map(root, (data) => {
|
|
611
|
-
const entity = Repository._createEntity(
|
|
612
|
-
|
|
613
|
+
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
614
|
+
oThis._relayEntityEvents(entity);
|
|
613
615
|
return entity;
|
|
614
616
|
});
|
|
615
617
|
|
|
@@ -656,8 +658,9 @@ class OneBuild2Repository extends AjaxRepository {
|
|
|
656
658
|
const children = treeNode.children;
|
|
657
659
|
treeNode.children = [];
|
|
658
660
|
|
|
661
|
+
const oThis = this;
|
|
659
662
|
_.each(children, (child) => {
|
|
660
|
-
|
|
663
|
+
oThis.removeEntity(child);
|
|
661
664
|
});
|
|
662
665
|
}
|
|
663
666
|
|
|
@@ -694,9 +697,10 @@ class OneBuild2Repository extends AjaxRepository {
|
|
|
694
697
|
}
|
|
695
698
|
|
|
696
699
|
// Set the current entities
|
|
700
|
+
const oThis = this;
|
|
697
701
|
const children = _.map(root, (data) => {
|
|
698
|
-
const entity = Repository._createEntity(
|
|
699
|
-
|
|
702
|
+
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
703
|
+
oThis._relayEntityEvents(entity);
|
|
700
704
|
return entity;
|
|
701
705
|
});
|
|
702
706
|
|
|
@@ -737,8 +741,9 @@ class OneBuild2Repository extends AjaxRepository {
|
|
|
737
741
|
const children = treeNode.children;
|
|
738
742
|
treeNode.children = [];
|
|
739
743
|
|
|
744
|
+
const oThis = this;
|
|
740
745
|
_.each(children, (child) => {
|
|
741
|
-
|
|
746
|
+
oThis.removeEntity(child);
|
|
742
747
|
});
|
|
743
748
|
}
|
|
744
749
|
|
|
@@ -775,9 +780,10 @@ class OneBuild2Repository extends AjaxRepository {
|
|
|
775
780
|
}
|
|
776
781
|
|
|
777
782
|
// Set the current entities
|
|
783
|
+
const oThis = this;
|
|
778
784
|
const children = _.map(root, (data) => {
|
|
779
|
-
const entity = Repository._createEntity(
|
|
780
|
-
|
|
785
|
+
const entity = Repository._createEntity(oThis.schema, data, this, true);
|
|
786
|
+
oThis._relayEntityEvents(entity);
|
|
781
787
|
return entity;
|
|
782
788
|
});
|
|
783
789
|
|