@sumaris-net/ngx-components 1.12.3 → 1.12.6
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/bundles/sumaris-net.ngx-components.umd.js +90 -33
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +2 -2
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/doc/changelog.md +4 -0
- package/esm2015/src/app/core/table/table.class.js +84 -34
- package/fesm2015/sumaris-net.ngx-components.js +83 -33
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/core/table/table.class.d.ts +6 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -25365,9 +25365,15 @@
|
|
|
25365
25365
|
return false;
|
|
25366
25366
|
};
|
|
25367
25367
|
AppTable.prototype.cancelOrDelete = function (event, row, opts) {
|
|
25368
|
+
// Delete new row
|
|
25368
25369
|
if (row.id === -1) {
|
|
25369
25370
|
this.deleteNewRow(event, row);
|
|
25370
25371
|
}
|
|
25372
|
+
// Delete existing (bu not editing) row
|
|
25373
|
+
else if (!row.editing) {
|
|
25374
|
+
this.deleteExistingRow(event, row, opts);
|
|
25375
|
+
}
|
|
25376
|
+
// Cancel existing (and editing) row
|
|
25371
25377
|
else {
|
|
25372
25378
|
this.cancelExistingRow(event, row, opts);
|
|
25373
25379
|
}
|
|
@@ -25532,6 +25538,7 @@
|
|
|
25532
25538
|
* @param event
|
|
25533
25539
|
* @param row
|
|
25534
25540
|
* @param opts Use interactive=false to avoid user interaction (e.g. user confirmation)
|
|
25541
|
+
* Use skipIfLoading=false to force deletion even if table is busy
|
|
25535
25542
|
*/
|
|
25536
25543
|
AppTable.prototype.deleteRow = function (event, row, opts) {
|
|
25537
25544
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -25551,6 +25558,7 @@
|
|
|
25551
25558
|
* @param event
|
|
25552
25559
|
* @param rows
|
|
25553
25560
|
* @param opts Use interactive=false to avoid user interaction (e.g. user confirmation)
|
|
25561
|
+
* Use skipIfLoading=false to force deletion even if table is busy
|
|
25554
25562
|
*/
|
|
25555
25563
|
AppTable.prototype.deleteRows = function (event, rows, opts) {
|
|
25556
25564
|
var _a;
|
|
@@ -25566,10 +25574,12 @@
|
|
|
25566
25574
|
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
25567
25575
|
return [2 /*return*/, 0]; // SKip
|
|
25568
25576
|
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
25569
|
-
if (!this._enabled)
|
|
25570
|
-
return [2 /*return*/, 0];
|
|
25571
|
-
if (this.loading ||
|
|
25572
|
-
|
|
25577
|
+
if (!this._enabled || isEmptyArray(rows))
|
|
25578
|
+
return [2 /*return*/, 0]; // Skip is disabled, or no rows to delete
|
|
25579
|
+
if (this.loading && (!opts || opts.skipIfLoading !== true)) {
|
|
25580
|
+
console.warn('[app-table] Skip deleteRows() because table is busy (loading). Use opts.skipLoading = false to force deletion');
|
|
25581
|
+
return [2 /*return*/, 0]; // Skip if loading
|
|
25582
|
+
}
|
|
25573
25583
|
// Make sure to keep newly created row
|
|
25574
25584
|
if (((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.id) === -1 && this.editedRow.editing && !rows.includes(this.editedRow)) {
|
|
25575
25585
|
confirmed = this.confirmEditCreate();
|
|
@@ -25581,21 +25591,33 @@
|
|
|
25581
25591
|
canDelete = _e.sent();
|
|
25582
25592
|
if (!canDelete)
|
|
25583
25593
|
return [2 /*return*/, 0]; // Cannot delete
|
|
25594
|
+
// Reverse row order (on a copy)
|
|
25595
|
+
// This is a workaround, need because row.delete() has async execution
|
|
25596
|
+
// and index cache is updated with a delay
|
|
25597
|
+
rows = rows.slice()
|
|
25598
|
+
.sort(function (a, b) { return a.id > b.id ? -1 : 1; });
|
|
25584
25599
|
if (!this.saveBeforeDelete) return [3 /*break*/, 3];
|
|
25585
|
-
//
|
|
25586
|
-
rows = rows.
|
|
25600
|
+
// Exclude invalid rows (because of save() will fail, when exists some invalid rows)
|
|
25601
|
+
rows = rows.filter(function (row) {
|
|
25587
25602
|
if (row.validator && !row.validator.valid) {
|
|
25588
|
-
var deleted = row.id === -1;
|
|
25589
|
-
row.cancelOrDelete();
|
|
25590
25603
|
// When deleted (= newly created row) : decrement counter
|
|
25591
|
-
if (
|
|
25604
|
+
if (row.id === -1 || !row.editing) {
|
|
25605
|
+
row.delete();
|
|
25592
25606
|
_this.visibleRowCount--;
|
|
25593
25607
|
_this.totalRowCount--;
|
|
25594
|
-
return
|
|
25608
|
+
return false; // Remove this row to the list, because already deleted
|
|
25609
|
+
}
|
|
25610
|
+
// Mark row as pristine, to avoid row to be saved even if still invalid
|
|
25611
|
+
else {
|
|
25612
|
+
// Will cancel only (delete will always go into the previous 'if')
|
|
25613
|
+
row.cancelOrDelete();
|
|
25614
|
+
// Mark row as pristine (if possible)
|
|
25615
|
+
_this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
|
|
25616
|
+
// Continue: the row will be deleted after the save
|
|
25595
25617
|
}
|
|
25596
25618
|
}
|
|
25597
|
-
return
|
|
25598
|
-
}
|
|
25619
|
+
return true;
|
|
25620
|
+
});
|
|
25599
25621
|
if (!isNotEmptyArray(rows)) return [3 /*break*/, 3];
|
|
25600
25622
|
return [4 /*yield*/, this.saveBeforeAction('delete')];
|
|
25601
25623
|
case 2:
|
|
@@ -25611,11 +25633,6 @@
|
|
|
25611
25633
|
if (!deleteCount) return [3 /*break*/, 5];
|
|
25612
25634
|
if (this.debug)
|
|
25613
25635
|
console.debug('[table] Delete selected rows...');
|
|
25614
|
-
// Reverse row order (on a copy)
|
|
25615
|
-
// This is a workaround, need because row.delete() has async execution
|
|
25616
|
-
// and index cache is updated with a delay
|
|
25617
|
-
rows = rows.slice()
|
|
25618
|
-
.sort(function (a, b) { return a.id > b.id ? -1 : 1; });
|
|
25619
25636
|
return [4 /*yield*/, this._dataSource.deleteAll(rows)];
|
|
25620
25637
|
case 4:
|
|
25621
25638
|
_e.sent();
|
|
@@ -25816,6 +25833,7 @@
|
|
|
25816
25833
|
}); });
|
|
25817
25834
|
};
|
|
25818
25835
|
AppTable.prototype.escapeEditingRow = function (event, row) {
|
|
25836
|
+
var _this = this;
|
|
25819
25837
|
row = row || this.editedRow;
|
|
25820
25838
|
if (!row || !row.editing)
|
|
25821
25839
|
return;
|
|
@@ -25826,21 +25844,31 @@
|
|
|
25826
25844
|
event.preventDefault();
|
|
25827
25845
|
event.stopPropagation();
|
|
25828
25846
|
}
|
|
25829
|
-
// If new row
|
|
25830
|
-
if (row.id === -1
|
|
25831
|
-
|
|
25847
|
+
// If new row (no id)
|
|
25848
|
+
if (row.id === -1) {
|
|
25849
|
+
if (row.validator) {
|
|
25850
|
+
// If pending: Wait end of validation, then loop
|
|
25851
|
+
if (row.validator.pending) {
|
|
25852
|
+
AppFormUtils.waitWhilePending(row.validator).then(function () { return _this.escapeEditingRow(event, row); });
|
|
25853
|
+
return;
|
|
25854
|
+
}
|
|
25855
|
+
// Row is invalid: delete the row
|
|
25856
|
+
if (row.validator.invalid) {
|
|
25857
|
+
this.deleteNewRow(event, row);
|
|
25858
|
+
return;
|
|
25859
|
+
}
|
|
25860
|
+
}
|
|
25832
25861
|
}
|
|
25833
|
-
// If exists
|
|
25862
|
+
// If the row exists (has an id)
|
|
25834
25863
|
else {
|
|
25835
|
-
// cancel (if confirmation)
|
|
25864
|
+
// need to call cancel function (if confirmation will be call before before)
|
|
25836
25865
|
if (this.confirmBeforeCancel) {
|
|
25837
25866
|
this.cancelExistingRow(event, row, { keepEditing: false });
|
|
25838
|
-
|
|
25839
|
-
// Or validate, if no confirmation
|
|
25840
|
-
else {
|
|
25841
|
-
this.confirmEditCreate(event, row);
|
|
25867
|
+
return;
|
|
25842
25868
|
}
|
|
25843
25869
|
}
|
|
25870
|
+
// By default, try to confirm the row
|
|
25871
|
+
this.confirmEditCreate(event, row);
|
|
25844
25872
|
};
|
|
25845
25873
|
AppTable.prototype.translateControlPath = function (path) {
|
|
25846
25874
|
// Can be override by subclasses, to resolve all field name
|
|
@@ -26337,6 +26365,8 @@
|
|
|
26337
26365
|
}
|
|
26338
26366
|
};
|
|
26339
26367
|
AppTable.prototype.deleteNewRow = function (event, row) {
|
|
26368
|
+
if (row.id !== -1)
|
|
26369
|
+
throw new Error('Row must have id = -1');
|
|
26340
26370
|
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
|
26341
26371
|
this.selection.clear();
|
|
26342
26372
|
this.editedRow = undefined; // unselect row
|
|
@@ -26346,9 +26376,21 @@
|
|
|
26346
26376
|
this.totalRowCount--;
|
|
26347
26377
|
this.visibleRowCount--;
|
|
26348
26378
|
};
|
|
26379
|
+
AppTable.prototype.deleteExistingRow = function (event, row, opts) {
|
|
26380
|
+
// Make sure row will be cancelled, and NOT deleted
|
|
26381
|
+
if (row.id === -1)
|
|
26382
|
+
throw new Error('Row must have an id');
|
|
26383
|
+
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
26384
|
+
return 0; // SKip
|
|
26385
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
26386
|
+
this.deleteRow(null, row, opts);
|
|
26387
|
+
};
|
|
26349
26388
|
AppTable.prototype.cancelExistingRow = function (event, row, opts) {
|
|
26350
26389
|
var _this = this;
|
|
26351
|
-
var _a
|
|
26390
|
+
var _a;
|
|
26391
|
+
// Make sure row will be cancelled, and NOT deleted
|
|
26392
|
+
if (row.id === -1 || !row.editing)
|
|
26393
|
+
throw new Error('Row cannot be canceling, but only deleting');
|
|
26352
26394
|
var confirmed = (!opts || opts.interactive !== false);
|
|
26353
26395
|
// Ask user confirmation, if cancel
|
|
26354
26396
|
if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
|
|
@@ -26366,17 +26408,32 @@
|
|
|
26366
26408
|
this._dataSource.cancelOrDelete(row);
|
|
26367
26409
|
this.onCancelOrDeleteRow.next(row);
|
|
26368
26410
|
// Mark row as pristine
|
|
26369
|
-
|
|
26370
|
-
if (markRowAsPristine) {
|
|
26371
|
-
(_c = row.validator) === null || _c === void 0 ? void 0 : _c.markAsPristine();
|
|
26372
|
-
// Check if table is now pristine
|
|
26373
|
-
this.checkIfPristine();
|
|
26374
|
-
}
|
|
26411
|
+
this.checkIfRowPristine(row);
|
|
26375
26412
|
// Restore editing state
|
|
26376
26413
|
if (keepEditing) {
|
|
26377
26414
|
this.editRow(undefined, row);
|
|
26378
26415
|
}
|
|
26379
26416
|
};
|
|
26417
|
+
AppTable.prototype.checkIfRowPristine = function (row, opts) {
|
|
26418
|
+
var _a, _b;
|
|
26419
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
26420
|
+
var markRowAsPristine;
|
|
26421
|
+
return __generator(this, function (_e) {
|
|
26422
|
+
switch (_e.label) {
|
|
26423
|
+
case 0:
|
|
26424
|
+
markRowAsPristine = ((_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.options.keepOriginalDataAfterConfirm) === true;
|
|
26425
|
+
if (!markRowAsPristine) return [3 /*break*/, 2];
|
|
26426
|
+
(_b = row.validator) === null || _b === void 0 ? void 0 : _b.markAsPristine();
|
|
26427
|
+
if (!(!opts || opts.onlySelf !== true)) return [3 /*break*/, 2];
|
|
26428
|
+
return [4 /*yield*/, this.checkIfPristine(opts)];
|
|
26429
|
+
case 1:
|
|
26430
|
+
_e.sent();
|
|
26431
|
+
_e.label = 2;
|
|
26432
|
+
case 2: return [2 /*return*/];
|
|
26433
|
+
}
|
|
26434
|
+
});
|
|
26435
|
+
});
|
|
26436
|
+
};
|
|
26380
26437
|
AppTable.prototype.checkIfPristine = function (opts) {
|
|
26381
26438
|
return __awaiter(this, void 0, void 0, function () {
|
|
26382
26439
|
var rows, pristine;
|