@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
|
@@ -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
|
}
|
|
@@ -25566,10 +25572,12 @@
|
|
|
25566
25572
|
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
25567
25573
|
return [2 /*return*/, 0]; // SKip
|
|
25568
25574
|
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
25569
|
-
if (!this._enabled)
|
|
25570
|
-
return [2 /*return*/, 0];
|
|
25571
|
-
if (this.loading ||
|
|
25572
|
-
|
|
25575
|
+
if (!this._enabled || isEmptyArray(rows))
|
|
25576
|
+
return [2 /*return*/, 0]; // Skip is disabled, or no rows to delete
|
|
25577
|
+
if (this.loading && (!opts || opts.skipIfLoading !== true)) {
|
|
25578
|
+
console.warn('[app-table] Skip deleteRows() because table is busy (loading). Use opts.skipLoading = false to force deletion');
|
|
25579
|
+
return [2 /*return*/, 0]; // Skip if loading
|
|
25580
|
+
}
|
|
25573
25581
|
// Make sure to keep newly created row
|
|
25574
25582
|
if (((_a = this.editedRow) === null || _a === void 0 ? void 0 : _a.id) === -1 && this.editedRow.editing && !rows.includes(this.editedRow)) {
|
|
25575
25583
|
confirmed = this.confirmEditCreate();
|
|
@@ -25581,21 +25589,33 @@
|
|
|
25581
25589
|
canDelete = _e.sent();
|
|
25582
25590
|
if (!canDelete)
|
|
25583
25591
|
return [2 /*return*/, 0]; // Cannot delete
|
|
25592
|
+
// Reverse row order (on a copy)
|
|
25593
|
+
// This is a workaround, need because row.delete() has async execution
|
|
25594
|
+
// and index cache is updated with a delay
|
|
25595
|
+
rows = rows.slice()
|
|
25596
|
+
.sort(function (a, b) { return a.id > b.id ? -1 : 1; });
|
|
25584
25597
|
if (!this.saveBeforeDelete) return [3 /*break*/, 3];
|
|
25585
|
-
//
|
|
25586
|
-
rows = rows.
|
|
25598
|
+
// Exclude invalid rows (because of save() will fail, when exists some invalid rows)
|
|
25599
|
+
rows = rows.filter(function (row) {
|
|
25587
25600
|
if (row.validator && !row.validator.valid) {
|
|
25588
|
-
var deleted = row.id === -1;
|
|
25589
|
-
row.cancelOrDelete();
|
|
25590
25601
|
// When deleted (= newly created row) : decrement counter
|
|
25591
|
-
if (
|
|
25602
|
+
if (row.id === -1 || !row.editing) {
|
|
25603
|
+
row.delete();
|
|
25592
25604
|
_this.visibleRowCount--;
|
|
25593
25605
|
_this.totalRowCount--;
|
|
25594
|
-
return
|
|
25606
|
+
return false; // Remove this row to the list, because already deleted
|
|
25607
|
+
}
|
|
25608
|
+
// Mark row as pristine, to avoid row to be saved even if still invalid
|
|
25609
|
+
else {
|
|
25610
|
+
// Will cancel only (delete will always go into the previous 'if')
|
|
25611
|
+
row.cancelOrDelete();
|
|
25612
|
+
// Mark row as pristine (if possible)
|
|
25613
|
+
_this.checkIfRowPristine(row, { emitEvent: false, onlySelf: true /*avoid propagation to table*/ });
|
|
25614
|
+
// Continue: the row will be deleted after the save
|
|
25595
25615
|
}
|
|
25596
25616
|
}
|
|
25597
|
-
return
|
|
25598
|
-
}
|
|
25617
|
+
return true;
|
|
25618
|
+
});
|
|
25599
25619
|
if (!isNotEmptyArray(rows)) return [3 /*break*/, 3];
|
|
25600
25620
|
return [4 /*yield*/, this.saveBeforeAction('delete')];
|
|
25601
25621
|
case 2:
|
|
@@ -25611,11 +25631,6 @@
|
|
|
25611
25631
|
if (!deleteCount) return [3 /*break*/, 5];
|
|
25612
25632
|
if (this.debug)
|
|
25613
25633
|
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
25634
|
return [4 /*yield*/, this._dataSource.deleteAll(rows)];
|
|
25620
25635
|
case 4:
|
|
25621
25636
|
_e.sent();
|
|
@@ -25816,6 +25831,7 @@
|
|
|
25816
25831
|
}); });
|
|
25817
25832
|
};
|
|
25818
25833
|
AppTable.prototype.escapeEditingRow = function (event, row) {
|
|
25834
|
+
var _this = this;
|
|
25819
25835
|
row = row || this.editedRow;
|
|
25820
25836
|
if (!row || !row.editing)
|
|
25821
25837
|
return;
|
|
@@ -25826,21 +25842,31 @@
|
|
|
25826
25842
|
event.preventDefault();
|
|
25827
25843
|
event.stopPropagation();
|
|
25828
25844
|
}
|
|
25829
|
-
// If new row
|
|
25830
|
-
if (row.id === -1
|
|
25831
|
-
|
|
25845
|
+
// If new row (no id)
|
|
25846
|
+
if (row.id === -1) {
|
|
25847
|
+
if (row.validator) {
|
|
25848
|
+
// If pending: Wait end of validation, then loop
|
|
25849
|
+
if (row.validator.pending) {
|
|
25850
|
+
AppFormUtils.waitWhilePending(row.validator).then(function () { return _this.escapeEditingRow(event, row); });
|
|
25851
|
+
return;
|
|
25852
|
+
}
|
|
25853
|
+
// Row is invalid: delete the row
|
|
25854
|
+
if (row.validator.invalid) {
|
|
25855
|
+
this.deleteNewRow(event, row);
|
|
25856
|
+
return;
|
|
25857
|
+
}
|
|
25858
|
+
}
|
|
25832
25859
|
}
|
|
25833
|
-
// If exists
|
|
25860
|
+
// If the row exists (has an id)
|
|
25834
25861
|
else {
|
|
25835
|
-
// cancel (if confirmation)
|
|
25862
|
+
// need to call cancel function (if confirmation will be call before before)
|
|
25836
25863
|
if (this.confirmBeforeCancel) {
|
|
25837
25864
|
this.cancelExistingRow(event, row, { keepEditing: false });
|
|
25838
|
-
|
|
25839
|
-
// Or validate, if no confirmation
|
|
25840
|
-
else {
|
|
25841
|
-
this.confirmEditCreate(event, row);
|
|
25865
|
+
return;
|
|
25842
25866
|
}
|
|
25843
25867
|
}
|
|
25868
|
+
// By default, try to confirm the row
|
|
25869
|
+
this.confirmEditCreate(event, row);
|
|
25844
25870
|
};
|
|
25845
25871
|
AppTable.prototype.translateControlPath = function (path) {
|
|
25846
25872
|
// Can be override by subclasses, to resolve all field name
|
|
@@ -26337,6 +26363,8 @@
|
|
|
26337
26363
|
}
|
|
26338
26364
|
};
|
|
26339
26365
|
AppTable.prototype.deleteNewRow = function (event, row) {
|
|
26366
|
+
if (row.id !== -1)
|
|
26367
|
+
throw new Error('Row must have id = -1');
|
|
26340
26368
|
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
|
26341
26369
|
this.selection.clear();
|
|
26342
26370
|
this.editedRow = undefined; // unselect row
|
|
@@ -26346,9 +26374,21 @@
|
|
|
26346
26374
|
this.totalRowCount--;
|
|
26347
26375
|
this.visibleRowCount--;
|
|
26348
26376
|
};
|
|
26377
|
+
AppTable.prototype.deleteExistingRow = function (event, row, opts) {
|
|
26378
|
+
// Make sure row will be cancelled, and NOT deleted
|
|
26379
|
+
if (row.id === -1)
|
|
26380
|
+
throw new Error('Row must have an id');
|
|
26381
|
+
if (event === null || event === void 0 ? void 0 : event.defaultPrevented)
|
|
26382
|
+
return 0; // SKip
|
|
26383
|
+
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
26384
|
+
this.deleteRow(null, row, opts);
|
|
26385
|
+
};
|
|
26349
26386
|
AppTable.prototype.cancelExistingRow = function (event, row, opts) {
|
|
26350
26387
|
var _this = this;
|
|
26351
|
-
var _a
|
|
26388
|
+
var _a;
|
|
26389
|
+
// Make sure row will be cancelled, and NOT deleted
|
|
26390
|
+
if (row.id === -1 || !row.editing)
|
|
26391
|
+
throw new Error('Row cannot be canceling, but only deleting');
|
|
26352
26392
|
var confirmed = (!opts || opts.interactive !== false);
|
|
26353
26393
|
// Ask user confirmation, if cancel
|
|
26354
26394
|
if (!confirmed && ((_a = row.validator) === null || _a === void 0 ? void 0 : _a.dirty) && (this.confirmBeforeCancel || this.onBeforeCancelRows.observers.length > 0)) {
|
|
@@ -26366,17 +26406,32 @@
|
|
|
26366
26406
|
this._dataSource.cancelOrDelete(row);
|
|
26367
26407
|
this.onCancelOrDeleteRow.next(row);
|
|
26368
26408
|
// 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
|
-
}
|
|
26409
|
+
this.checkIfRowPristine(row);
|
|
26375
26410
|
// Restore editing state
|
|
26376
26411
|
if (keepEditing) {
|
|
26377
26412
|
this.editRow(undefined, row);
|
|
26378
26413
|
}
|
|
26379
26414
|
};
|
|
26415
|
+
AppTable.prototype.checkIfRowPristine = function (row, opts) {
|
|
26416
|
+
var _a, _b;
|
|
26417
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
26418
|
+
var markRowAsPristine;
|
|
26419
|
+
return __generator(this, function (_e) {
|
|
26420
|
+
switch (_e.label) {
|
|
26421
|
+
case 0:
|
|
26422
|
+
markRowAsPristine = ((_a = this.dataSource) === null || _a === void 0 ? void 0 : _a.options.keepOriginalDataAfterConfirm) === true;
|
|
26423
|
+
if (!markRowAsPristine) return [3 /*break*/, 2];
|
|
26424
|
+
(_b = row.validator) === null || _b === void 0 ? void 0 : _b.markAsPristine();
|
|
26425
|
+
if (!(!opts || opts.onlySelf !== true)) return [3 /*break*/, 2];
|
|
26426
|
+
return [4 /*yield*/, this.checkIfPristine(opts)];
|
|
26427
|
+
case 1:
|
|
26428
|
+
_e.sent();
|
|
26429
|
+
_e.label = 2;
|
|
26430
|
+
case 2: return [2 /*return*/];
|
|
26431
|
+
}
|
|
26432
|
+
});
|
|
26433
|
+
});
|
|
26434
|
+
};
|
|
26380
26435
|
AppTable.prototype.checkIfPristine = function (opts) {
|
|
26381
26436
|
return __awaiter(this, void 0, void 0, function () {
|
|
26382
26437
|
var rows, pristine;
|
|
@@ -27443,7 +27498,7 @@
|
|
|
27443
27498
|
this._listenChangesSubscription = this.listenChanges(this.data.id, { interval: this._listenIntervalInSeconds })
|
|
27444
27499
|
.pipe(operators.filter(isNotNil))
|
|
27445
27500
|
.subscribe(function (data) {
|
|
27446
|
-
if (data.updateDate && data.updateDate.isAfter(_this.data.updateDate)) {
|
|
27501
|
+
if (momentImported.isMoment(data.updateDate) && data.updateDate.isAfter(_this.data.updateDate)) {
|
|
27447
27502
|
if (!_this.dirty) {
|
|
27448
27503
|
if (_this.debug)
|
|
27449
27504
|
console.debug("[data-editor] Changes detected on server, at {" + data.updateDate + "}: reloading page...");
|