@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
|
@@ -21924,9 +21924,15 @@ class AppTable {
|
|
|
21924
21924
|
return false;
|
|
21925
21925
|
}
|
|
21926
21926
|
cancelOrDelete(event, row, opts) {
|
|
21927
|
+
// Delete new row
|
|
21927
21928
|
if (row.id === -1) {
|
|
21928
21929
|
this.deleteNewRow(event, row);
|
|
21929
21930
|
}
|
|
21931
|
+
// Delete existing (bu not editing) row
|
|
21932
|
+
else if (!row.editing) {
|
|
21933
|
+
this.deleteExistingRow(event, row, opts);
|
|
21934
|
+
}
|
|
21935
|
+
// Cancel existing (and editing) row
|
|
21930
21936
|
else {
|
|
21931
21937
|
this.cancelExistingRow(event, row, opts);
|
|
21932
21938
|
}
|
|
@@ -22061,6 +22067,7 @@ class AppTable {
|
|
|
22061
22067
|
* @param event
|
|
22062
22068
|
* @param row
|
|
22063
22069
|
* @param opts Use interactive=false to avoid user interaction (e.g. user confirmation)
|
|
22070
|
+
* Use skipIfLoading=false to force deletion even if table is busy
|
|
22064
22071
|
*/
|
|
22065
22072
|
deleteRow(event, row, opts) {
|
|
22066
22073
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -22073,6 +22080,7 @@ class AppTable {
|
|
|
22073
22080
|
* @param event
|
|
22074
22081
|
* @param rows
|
|
22075
22082
|
* @param opts Use interactive=false to avoid user interaction (e.g. user confirmation)
|
|
22083
|
+
* Use skipIfLoading=false to force deletion even if table is busy
|
|
22076
22084
|
*/
|
|
22077
22085
|
deleteRows(event, rows, opts) {
|
|
22078
22086
|
var _a;
|
|
@@ -22083,10 +22091,12 @@ class AppTable {
|
|
|
22083
22091
|
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
22084
22092
|
return 0; // SKip
|
|
22085
22093
|
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
22086
|
-
if (!this._enabled)
|
|
22087
|
-
return 0;
|
|
22088
|
-
if (this.loading ||
|
|
22089
|
-
|
|
22094
|
+
if (!this._enabled || isEmptyArray(rows))
|
|
22095
|
+
return 0; // Skip is disabled, or no rows to delete
|
|
22096
|
+
if (this.loading && (!opts || opts.skipIfLoading !== true)) {
|
|
22097
|
+
console.warn('[app-table] Skip deleteRows() because table is busy (loading). Use opts.skipLoading = false to force deletion');
|
|
22098
|
+
return 0; // Skip if loading
|
|
22099
|
+
}
|
|
22090
22100
|
// Make sure to keep newly created row
|
|
22091
22101
|
if (((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.id) === -1 && this.editedRow.editing && !rows.includes(this.editedRow)) {
|
|
22092
22102
|
const confirmed = this.confirmEditCreate();
|
|
@@ -22097,22 +22107,34 @@ class AppTable {
|
|
|
22097
22107
|
const canDelete = yield this.canDeleteRows(rows, opts);
|
|
22098
22108
|
if (!canDelete)
|
|
22099
22109
|
return 0; // Cannot delete
|
|
22110
|
+
// Reverse row order (on a copy)
|
|
22111
|
+
// This is a workaround, need because row.delete() has async execution
|
|
22112
|
+
// and index cache is updated with a delay
|
|
22113
|
+
rows = rows.slice()
|
|
22114
|
+
.sort((a, b) => a.id > b.id ? -1 : 1);
|
|
22100
22115
|
// If data need to be saved first
|
|
22101
22116
|
if (this.saveBeforeDelete) {
|
|
22102
|
-
//
|
|
22103
|
-
rows = rows.
|
|
22117
|
+
// Exclude invalid rows (because of save() will fail, when exists some invalid rows)
|
|
22118
|
+
rows = rows.filter(row => {
|
|
22104
22119
|
if (row.validator && !row.validator.valid) {
|
|
22105
|
-
const deleted = row.id === -1;
|
|
22106
|
-
row.cancelOrDelete();
|
|
22107
22120
|
// When deleted (= newly created row) : decrement counter
|
|
22108
|
-
if (
|
|
22121
|
+
if (row.id === -1 || !row.editing) {
|
|
22122
|
+
row.delete();
|
|
22109
22123
|
this.visibleRowCount--;
|
|
22110
22124
|
this.totalRowCount--;
|
|
22111
|
-
return
|
|
22125
|
+
return false; // Remove this row to the list, because already deleted
|
|
22126
|
+
}
|
|
22127
|
+
// Mark row as pristine, to avoid row to be saved even if still invalid
|
|
22128
|
+
else {
|
|
22129
|
+
// Will cancel only (delete will always go into the previous 'if')
|
|
22130
|
+
row.cancelOrDelete();
|
|
22131
|
+
// Mark row as pristine (if possible)
|
|
22132
|
+
this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
|
|
22133
|
+
// Continue: the row will be deleted after the save
|
|
22112
22134
|
}
|
|
22113
22135
|
}
|
|
22114
|
-
return
|
|
22115
|
-
}
|
|
22136
|
+
return true;
|
|
22137
|
+
});
|
|
22116
22138
|
// Apply save, only if there is still some rows to delete
|
|
22117
22139
|
// WARN: If no more rows (e.g. because all has been cancelled) then continue anyway to clear editedRow and selection (issue IMAGINE-669)
|
|
22118
22140
|
if (isNotEmptyArray(rows)) {
|
|
@@ -22131,11 +22153,6 @@ class AppTable {
|
|
|
22131
22153
|
if (deleteCount) {
|
|
22132
22154
|
if (this.debug)
|
|
22133
22155
|
console.debug('[table] Delete selected rows...');
|
|
22134
|
-
// Reverse row order (on a copy)
|
|
22135
|
-
// This is a workaround, need because row.delete() has async execution
|
|
22136
|
-
// and index cache is updated with a delay
|
|
22137
|
-
rows = rows.slice()
|
|
22138
|
-
.sort((a, b) => a.id > b.id ? -1 : 1);
|
|
22139
22156
|
yield this._dataSource.deleteAll(rows);
|
|
22140
22157
|
}
|
|
22141
22158
|
// DO not update manually, because watchALl().subscribe() will update this count
|
|
@@ -22282,21 +22299,31 @@ class AppTable {
|
|
|
22282
22299
|
event.preventDefault();
|
|
22283
22300
|
event.stopPropagation();
|
|
22284
22301
|
}
|
|
22285
|
-
// If new row
|
|
22286
|
-
if (row.id === -1
|
|
22287
|
-
|
|
22302
|
+
// If new row (no id)
|
|
22303
|
+
if (row.id === -1) {
|
|
22304
|
+
if (row.validator) {
|
|
22305
|
+
// If pending: Wait end of validation, then loop
|
|
22306
|
+
if (row.validator.pending) {
|
|
22307
|
+
AppFormUtils.waitWhilePending(row.validator).then(() => this.escapeEditingRow(event, row));
|
|
22308
|
+
return;
|
|
22309
|
+
}
|
|
22310
|
+
// Row is invalid: delete the row
|
|
22311
|
+
if (row.validator.invalid) {
|
|
22312
|
+
this.deleteNewRow(event, row);
|
|
22313
|
+
return;
|
|
22314
|
+
}
|
|
22315
|
+
}
|
|
22288
22316
|
}
|
|
22289
|
-
// If exists
|
|
22317
|
+
// If the row exists (has an id)
|
|
22290
22318
|
else {
|
|
22291
|
-
// cancel (if confirmation)
|
|
22319
|
+
// need to call cancel function (if confirmation will be call before before)
|
|
22292
22320
|
if (this.confirmBeforeCancel) {
|
|
22293
22321
|
this.cancelExistingRow(event, row, { keepEditing: false });
|
|
22294
|
-
|
|
22295
|
-
// Or validate, if no confirmation
|
|
22296
|
-
else {
|
|
22297
|
-
this.confirmEditCreate(event, row);
|
|
22322
|
+
return;
|
|
22298
22323
|
}
|
|
22299
22324
|
}
|
|
22325
|
+
// By default, try to confirm the row
|
|
22326
|
+
this.confirmEditCreate(event, row);
|
|
22300
22327
|
}
|
|
22301
22328
|
translateControlPath(path) {
|
|
22302
22329
|
// Can be override by subclasses, to resolve all field name
|
|
@@ -22720,6 +22747,8 @@ class AppTable {
|
|
|
22720
22747
|
}
|
|
22721
22748
|
}
|
|
22722
22749
|
deleteNewRow(event, row) {
|
|
22750
|
+
if (row.id !== -1)
|
|
22751
|
+
throw new Error('Row must have id = -1');
|
|
22723
22752
|
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
|
22724
22753
|
this.selection.clear();
|
|
22725
22754
|
this.editedRow = undefined; // unselect row
|
|
@@ -22729,8 +22758,20 @@ class AppTable {
|
|
|
22729
22758
|
this.totalRowCount--;
|
|
22730
22759
|
this.visibleRowCount--;
|
|
22731
22760
|
}
|
|
22761
|
+
deleteExistingRow(event, row, opts) {
|
|
22762
|
+
// Make sure row will be cancelled, and NOT deleted
|
|
22763
|
+
if (row.id === -1)
|
|
22764
|
+
throw new Error('Row must have an id');
|
|
22765
|
+
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
22766
|
+
return 0; // SKip
|
|
22767
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
22768
|
+
this.deleteRow(null, row, opts);
|
|
22769
|
+
}
|
|
22732
22770
|
cancelExistingRow(event, row, opts) {
|
|
22733
|
-
var _a
|
|
22771
|
+
var _a;
|
|
22772
|
+
// Make sure row will be cancelled, and NOT deleted
|
|
22773
|
+
if (row.id === -1 || !row.editing)
|
|
22774
|
+
throw new Error('Row cannot be canceling, but only deleting');
|
|
22734
22775
|
const confirmed = (!opts || opts.interactive !== false);
|
|
22735
22776
|
// Ask user confirmation, if cancel
|
|
22736
22777
|
if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
|
|
@@ -22748,17 +22789,26 @@ class AppTable {
|
|
|
22748
22789
|
this._dataSource.cancelOrDelete(row);
|
|
22749
22790
|
this.onCancelOrDeleteRow.next(row);
|
|
22750
22791
|
// Mark row as pristine
|
|
22751
|
-
|
|
22752
|
-
if (markRowAsPristine) {
|
|
22753
|
-
(_c = row.validator) === null || _c === void 0 ? void 0 : _c.markAsPristine();
|
|
22754
|
-
// Check if table is now pristine
|
|
22755
|
-
this.checkIfPristine();
|
|
22756
|
-
}
|
|
22792
|
+
this.checkIfRowPristine(row);
|
|
22757
22793
|
// Restore editing state
|
|
22758
22794
|
if (keepEditing) {
|
|
22759
22795
|
this.editRow(undefined, row);
|
|
22760
22796
|
}
|
|
22761
22797
|
}
|
|
22798
|
+
checkIfRowPristine(row, opts) {
|
|
22799
|
+
var _a, _b;
|
|
22800
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22801
|
+
// Mark row as pristine
|
|
22802
|
+
const markRowAsPristine = ((_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.options.keepOriginalDataAfterConfirm) === true;
|
|
22803
|
+
if (markRowAsPristine) {
|
|
22804
|
+
(_b = row.validator) === null || _b === void 0 ? void 0 : _b.markAsPristine();
|
|
22805
|
+
// Check if table is now pristine
|
|
22806
|
+
if (!opts || opts.onlySelf !== true) {
|
|
22807
|
+
yield this.checkIfPristine(opts);
|
|
22808
|
+
}
|
|
22809
|
+
}
|
|
22810
|
+
});
|
|
22811
|
+
}
|
|
22762
22812
|
checkIfPristine(opts) {
|
|
22763
22813
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22764
22814
|
if (!this.dirty)
|