@onehat/data 1.19.24 → 1.19.25
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.
|
@@ -1114,6 +1114,38 @@ describe('Repository Base', function() {
|
|
|
1114
1114
|
const str = this.repository.toString();
|
|
1115
1115
|
expect(str).to.be.eq('NullRepository {bar} - foo');
|
|
1116
1116
|
});
|
|
1117
|
+
|
|
1118
|
+
it('_insertBefore', function() {
|
|
1119
|
+
|
|
1120
|
+
const
|
|
1121
|
+
repository = this.repository,
|
|
1122
|
+
one = { id: 'one' },
|
|
1123
|
+
two = { id: 'two' },
|
|
1124
|
+
three = { id: 'three' };
|
|
1125
|
+
|
|
1126
|
+
// insert into empty array
|
|
1127
|
+
repository.entities = [];
|
|
1128
|
+
repository._insertBefore(one);
|
|
1129
|
+
expect(repository.entities.length).to.be.eq(1);
|
|
1130
|
+
expect(repository.entities[0]).to.be.eq(one);
|
|
1131
|
+
|
|
1132
|
+
// insert into array with one
|
|
1133
|
+
repository.entities = [two];
|
|
1134
|
+
repository._insertBefore(one, two);
|
|
1135
|
+
expect(repository.entities.length).to.be.eq(2);
|
|
1136
|
+
expect(repository.entities[0]).to.be.eq(one);
|
|
1137
|
+
expect(repository.entities[1]).to.be.eq(two);
|
|
1138
|
+
|
|
1139
|
+
// insert into middle of array
|
|
1140
|
+
repository.entities = [one, three];
|
|
1141
|
+
repository._insertBefore(two, three);
|
|
1142
|
+
expect(repository.entities.length).to.be.eq(3);
|
|
1143
|
+
expect(repository.entities[0]).to.be.eq(one);
|
|
1144
|
+
expect(repository.entities[1]).to.be.eq(two);
|
|
1145
|
+
expect(repository.entities[2]).to.be.eq(three);
|
|
1146
|
+
|
|
1147
|
+
repository.entities = []; // because the entities aren't real entities and we don't want a destory error
|
|
1148
|
+
});
|
|
1117
1149
|
});
|
|
1118
1150
|
|
|
1119
1151
|
describe('tree', function() {
|
package/package.json
CHANGED
package/src/Repository/Memory.js
CHANGED
|
@@ -590,6 +590,11 @@ class MemoryRepository extends Repository {
|
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
592
|
|
|
593
|
+
|
|
594
|
+
_insertBefore = (newEntity, entity = null) => {
|
|
595
|
+
throw Error('Not yet implemented');
|
|
596
|
+
}
|
|
597
|
+
|
|
593
598
|
/**
|
|
594
599
|
* Gets the total number of Entities in the storage medium,
|
|
595
600
|
* before any sorting or filtering is applied.
|
|
@@ -307,6 +307,45 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
307
307
|
});
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
remoteDuplicate = async (entity) => {
|
|
311
|
+
|
|
312
|
+
this.markLoading();
|
|
313
|
+
|
|
314
|
+
const
|
|
315
|
+
Model = this.getSchema().name,
|
|
316
|
+
id = entity.id,
|
|
317
|
+
result = await this._send('POST', Model + '/duplicate', { id });
|
|
318
|
+
|
|
319
|
+
if (!result) {
|
|
320
|
+
this.markLoading(false);
|
|
321
|
+
this.throwError('error duplicating on server');
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const {
|
|
326
|
+
root,
|
|
327
|
+
success,
|
|
328
|
+
total,
|
|
329
|
+
message
|
|
330
|
+
} = this._processServerResponse(result);
|
|
331
|
+
|
|
332
|
+
if (!success) {
|
|
333
|
+
this.markLoading(false);
|
|
334
|
+
throw Error(message);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Click duplicateId. The new row appears directly above the one that was duplicated
|
|
338
|
+
// The new duplicate is selected
|
|
339
|
+
// The display field should read "{old name} (duplicate)"
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
const duplicateEntity = await this.createStandaloneEntity(root, true, true);
|
|
343
|
+
this._insertBefore(duplicateEntity, entity);
|
|
344
|
+
|
|
345
|
+
this.markLoading(false);
|
|
346
|
+
return duplicateEntity;
|
|
347
|
+
}
|
|
348
|
+
|
|
310
349
|
getSingleEntityFromServer = async (id) => {
|
|
311
350
|
if (this.isDestroyed) {
|
|
312
351
|
this.throwError('this.getSingleEntityFromServer is no longer valid. Repository has been destroyed.');
|
|
@@ -321,6 +360,8 @@ class OneBuildRepository extends AjaxRepository {
|
|
|
321
360
|
return null;
|
|
322
361
|
}
|
|
323
362
|
|
|
363
|
+
this.markLoading();
|
|
364
|
+
|
|
324
365
|
const idPropertyName = this.getSchema().model.idProperty;
|
|
325
366
|
const params = {};
|
|
326
367
|
params['conditions[' + idPropertyName + ']'] = id;
|
|
@@ -1160,6 +1160,34 @@ export default class Repository extends EventEmitter {
|
|
|
1160
1160
|
this.entities = [];
|
|
1161
1161
|
}
|
|
1162
1162
|
|
|
1163
|
+
/**
|
|
1164
|
+
* Inserts the newEntity directly before entity on the current page.
|
|
1165
|
+
*/
|
|
1166
|
+
_insertBefore = (newEntity, entity = null) => {
|
|
1167
|
+
|
|
1168
|
+
const
|
|
1169
|
+
currentEntities = this.getEntities(),
|
|
1170
|
+
foundIx = _.findIndex(currentEntities, ent => ent === entity),
|
|
1171
|
+
existingEntityIx = foundIx === -1 ? 0 : foundIx;
|
|
1172
|
+
|
|
1173
|
+
let firstHalf = [],
|
|
1174
|
+
secondHalf = [];
|
|
1175
|
+
|
|
1176
|
+
if (!currentEntities.length || existingEntityIx === 0) {
|
|
1177
|
+
firstHalf.push(newEntity);
|
|
1178
|
+
secondHalf = currentEntities;
|
|
1179
|
+
} else {
|
|
1180
|
+
firstHalf = _.slice(currentEntities, 0, existingEntityIx);
|
|
1181
|
+
firstHalf.push(newEntity);
|
|
1182
|
+
secondHalf = _.slice(currentEntities, existingEntityIx);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
this.entities = [
|
|
1186
|
+
...firstHalf,
|
|
1187
|
+
...secondHalf,
|
|
1188
|
+
];
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1163
1191
|
/**
|
|
1164
1192
|
* Deletes all locally cached entities in repository,
|
|
1165
1193
|
* usually, the current "page".
|
|
@@ -1169,6 +1197,13 @@ export default class Repository extends EventEmitter {
|
|
|
1169
1197
|
this._destroyEntities();
|
|
1170
1198
|
}
|
|
1171
1199
|
|
|
1200
|
+
|
|
1201
|
+
// _ __ __
|
|
1202
|
+
// | | / /___ _/ /_ _____ _____
|
|
1203
|
+
// | | / / __ `/ / / / / _ \/ ___/
|
|
1204
|
+
// | |/ / /_/ / / /_/ / __(__ )
|
|
1205
|
+
// |___/\__,_/_/\__,_/\___/____/
|
|
1206
|
+
|
|
1172
1207
|
/**
|
|
1173
1208
|
* Gets an array of "submit" values objects for the entities
|
|
1174
1209
|
* @return {array} map -
|