@sumaris-net/ngx-components 1.12.2 → 1.12.5
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 +89 -34
- 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/form/entity-editor.class.js +3 -2
- package/esm2015/src/app/core/table/table.class.js +82 -34
- package/fesm2015/sumaris-net.ngx-components.js +82 -34
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/core/table/table.class.d.ts +3 -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
|
}
|
|
@@ -22083,10 +22089,12 @@ class AppTable {
|
|
|
22083
22089
|
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
22084
22090
|
return 0; // SKip
|
|
22085
22091
|
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
22086
|
-
if (!this._enabled)
|
|
22087
|
-
return 0;
|
|
22088
|
-
if (this.loading ||
|
|
22089
|
-
|
|
22092
|
+
if (!this._enabled || isEmptyArray(rows))
|
|
22093
|
+
return 0; // Skip is disabled, or no rows to delete
|
|
22094
|
+
if (this.loading && (!opts || opts.skipIfLoading !== true)) {
|
|
22095
|
+
console.warn('[app-table] Skip deleteRows() because table is busy (loading). Use opts.skipLoading = false to force deletion');
|
|
22096
|
+
return 0; // Skip if loading
|
|
22097
|
+
}
|
|
22090
22098
|
// Make sure to keep newly created row
|
|
22091
22099
|
if (((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.id) === -1 && this.editedRow.editing && !rows.includes(this.editedRow)) {
|
|
22092
22100
|
const confirmed = this.confirmEditCreate();
|
|
@@ -22097,22 +22105,34 @@ class AppTable {
|
|
|
22097
22105
|
const canDelete = yield this.canDeleteRows(rows, opts);
|
|
22098
22106
|
if (!canDelete)
|
|
22099
22107
|
return 0; // Cannot delete
|
|
22108
|
+
// Reverse row order (on a copy)
|
|
22109
|
+
// This is a workaround, need because row.delete() has async execution
|
|
22110
|
+
// and index cache is updated with a delay
|
|
22111
|
+
rows = rows.slice()
|
|
22112
|
+
.sort((a, b) => a.id > b.id ? -1 : 1);
|
|
22100
22113
|
// If data need to be saved first
|
|
22101
22114
|
if (this.saveBeforeDelete) {
|
|
22102
|
-
//
|
|
22103
|
-
rows = rows.
|
|
22115
|
+
// Exclude invalid rows (because of save() will fail, when exists some invalid rows)
|
|
22116
|
+
rows = rows.filter(row => {
|
|
22104
22117
|
if (row.validator && !row.validator.valid) {
|
|
22105
|
-
const deleted = row.id === -1;
|
|
22106
|
-
row.cancelOrDelete();
|
|
22107
22118
|
// When deleted (= newly created row) : decrement counter
|
|
22108
|
-
if (
|
|
22119
|
+
if (row.id === -1 || !row.editing) {
|
|
22120
|
+
row.delete();
|
|
22109
22121
|
this.visibleRowCount--;
|
|
22110
22122
|
this.totalRowCount--;
|
|
22111
|
-
return
|
|
22123
|
+
return false; // Remove this row to the list, because already deleted
|
|
22124
|
+
}
|
|
22125
|
+
// Mark row as pristine, to avoid row to be saved even if still invalid
|
|
22126
|
+
else {
|
|
22127
|
+
// Will cancel only (delete will always go into the previous 'if')
|
|
22128
|
+
row.cancelOrDelete();
|
|
22129
|
+
// Mark row as pristine (if possible)
|
|
22130
|
+
this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
|
|
22131
|
+
// Continue: the row will be deleted after the save
|
|
22112
22132
|
}
|
|
22113
22133
|
}
|
|
22114
|
-
return
|
|
22115
|
-
}
|
|
22134
|
+
return true;
|
|
22135
|
+
});
|
|
22116
22136
|
// Apply save, only if there is still some rows to delete
|
|
22117
22137
|
// WARN: If no more rows (e.g. because all has been cancelled) then continue anyway to clear editedRow and selection (issue IMAGINE-669)
|
|
22118
22138
|
if (isNotEmptyArray(rows)) {
|
|
@@ -22131,11 +22151,6 @@ class AppTable {
|
|
|
22131
22151
|
if (deleteCount) {
|
|
22132
22152
|
if (this.debug)
|
|
22133
22153
|
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
22154
|
yield this._dataSource.deleteAll(rows);
|
|
22140
22155
|
}
|
|
22141
22156
|
// DO not update manually, because watchALl().subscribe() will update this count
|
|
@@ -22282,21 +22297,31 @@ class AppTable {
|
|
|
22282
22297
|
event.preventDefault();
|
|
22283
22298
|
event.stopPropagation();
|
|
22284
22299
|
}
|
|
22285
|
-
// If new row
|
|
22286
|
-
if (row.id === -1
|
|
22287
|
-
|
|
22300
|
+
// If new row (no id)
|
|
22301
|
+
if (row.id === -1) {
|
|
22302
|
+
if (row.validator) {
|
|
22303
|
+
// If pending: Wait end of validation, then loop
|
|
22304
|
+
if (row.validator.pending) {
|
|
22305
|
+
AppFormUtils.waitWhilePending(row.validator).then(() => this.escapeEditingRow(event, row));
|
|
22306
|
+
return;
|
|
22307
|
+
}
|
|
22308
|
+
// Row is invalid: delete the row
|
|
22309
|
+
if (row.validator.invalid) {
|
|
22310
|
+
this.deleteNewRow(event, row);
|
|
22311
|
+
return;
|
|
22312
|
+
}
|
|
22313
|
+
}
|
|
22288
22314
|
}
|
|
22289
|
-
// If exists
|
|
22315
|
+
// If the row exists (has an id)
|
|
22290
22316
|
else {
|
|
22291
|
-
// cancel (if confirmation)
|
|
22317
|
+
// need to call cancel function (if confirmation will be call before before)
|
|
22292
22318
|
if (this.confirmBeforeCancel) {
|
|
22293
22319
|
this.cancelExistingRow(event, row, { keepEditing: false });
|
|
22294
|
-
|
|
22295
|
-
// Or validate, if no confirmation
|
|
22296
|
-
else {
|
|
22297
|
-
this.confirmEditCreate(event, row);
|
|
22320
|
+
return;
|
|
22298
22321
|
}
|
|
22299
22322
|
}
|
|
22323
|
+
// By default, try to confirm the row
|
|
22324
|
+
this.confirmEditCreate(event, row);
|
|
22300
22325
|
}
|
|
22301
22326
|
translateControlPath(path) {
|
|
22302
22327
|
// Can be override by subclasses, to resolve all field name
|
|
@@ -22720,6 +22745,8 @@ class AppTable {
|
|
|
22720
22745
|
}
|
|
22721
22746
|
}
|
|
22722
22747
|
deleteNewRow(event, row) {
|
|
22748
|
+
if (row.id !== -1)
|
|
22749
|
+
throw new Error('Row must have id = -1');
|
|
22723
22750
|
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
|
22724
22751
|
this.selection.clear();
|
|
22725
22752
|
this.editedRow = undefined; // unselect row
|
|
@@ -22729,8 +22756,20 @@ class AppTable {
|
|
|
22729
22756
|
this.totalRowCount--;
|
|
22730
22757
|
this.visibleRowCount--;
|
|
22731
22758
|
}
|
|
22759
|
+
deleteExistingRow(event, row, opts) {
|
|
22760
|
+
// Make sure row will be cancelled, and NOT deleted
|
|
22761
|
+
if (row.id === -1)
|
|
22762
|
+
throw new Error('Row must have an id');
|
|
22763
|
+
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
22764
|
+
return 0; // SKip
|
|
22765
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
22766
|
+
this.deleteRow(null, row, opts);
|
|
22767
|
+
}
|
|
22732
22768
|
cancelExistingRow(event, row, opts) {
|
|
22733
|
-
var _a
|
|
22769
|
+
var _a;
|
|
22770
|
+
// Make sure row will be cancelled, and NOT deleted
|
|
22771
|
+
if (row.id === -1 || !row.editing)
|
|
22772
|
+
throw new Error('Row cannot be canceling, but only deleting');
|
|
22734
22773
|
const confirmed = (!opts || opts.interactive !== false);
|
|
22735
22774
|
// Ask user confirmation, if cancel
|
|
22736
22775
|
if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
|
|
@@ -22748,17 +22787,26 @@ class AppTable {
|
|
|
22748
22787
|
this._dataSource.cancelOrDelete(row);
|
|
22749
22788
|
this.onCancelOrDeleteRow.next(row);
|
|
22750
22789
|
// 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
|
-
}
|
|
22790
|
+
this.checkIfRowPristine(row);
|
|
22757
22791
|
// Restore editing state
|
|
22758
22792
|
if (keepEditing) {
|
|
22759
22793
|
this.editRow(undefined, row);
|
|
22760
22794
|
}
|
|
22761
22795
|
}
|
|
22796
|
+
checkIfRowPristine(row, opts) {
|
|
22797
|
+
var _a, _b;
|
|
22798
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22799
|
+
// Mark row as pristine
|
|
22800
|
+
const markRowAsPristine = ((_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.options.keepOriginalDataAfterConfirm) === true;
|
|
22801
|
+
if (markRowAsPristine) {
|
|
22802
|
+
(_b = row.validator) === null || _b === void 0 ? void 0 : _b.markAsPristine();
|
|
22803
|
+
// Check if table is now pristine
|
|
22804
|
+
if (!opts || opts.onlySelf !== true) {
|
|
22805
|
+
yield this.checkIfPristine(opts);
|
|
22806
|
+
}
|
|
22807
|
+
}
|
|
22808
|
+
});
|
|
22809
|
+
}
|
|
22762
22810
|
checkIfPristine(opts) {
|
|
22763
22811
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22764
22812
|
if (!this.dirty)
|
|
@@ -23639,7 +23687,7 @@ class AppEntityEditor extends AppTabEditor {
|
|
|
23639
23687
|
this._listenChangesSubscription = this.listenChanges(this.data.id, { interval: this._listenIntervalInSeconds })
|
|
23640
23688
|
.pipe(filter(isNotNil))
|
|
23641
23689
|
.subscribe((data) => {
|
|
23642
|
-
if (data.updateDate && data.updateDate.isAfter(this.data.updateDate)) {
|
|
23690
|
+
if (isMoment(data.updateDate) && data.updateDate.isAfter(this.data.updateDate)) {
|
|
23643
23691
|
if (!this.dirty) {
|
|
23644
23692
|
if (this.debug)
|
|
23645
23693
|
console.debug(`[data-editor] Changes detected on server, at {${data.updateDate}}: reloading page...`);
|