@sumaris-net/ngx-components 1.21.1 → 1.21.4

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.
@@ -17447,13 +17447,13 @@ class AppForm {
17447
17447
  * @deprecated
17448
17448
  */
17449
17449
  set _loading(value) {
17450
- this._$loading.next(value);
17450
+ this.loadingSubject.next(value);
17451
17451
  }
17452
17452
  /**
17453
17453
  * @deprecated
17454
17454
  */
17455
17455
  get _loading() {
17456
- return this._$loading.value;
17456
+ return this.loadingSubject.value;
17457
17457
  }
17458
17458
  /**
17459
17459
  * @deprecated
@@ -22635,9 +22635,15 @@ class AppTable {
22635
22635
  set error(error) {
22636
22636
  this.setError(error);
22637
22637
  }
22638
+ /**
22639
+ * @deprecated
22640
+ */
22638
22641
  get loading$() {
22639
22642
  return this.loadingSubject.asObservable();
22640
22643
  }
22644
+ /**
22645
+ * @deprecated
22646
+ */
22641
22647
  get saving$() {
22642
22648
  return this.savingSubject.asObservable();
22643
22649
  }
@@ -22760,17 +22766,15 @@ class AppTable {
22760
22766
  if (this.savingSubject.value !== true) {
22761
22767
  this.focusColumn = undefined; // unselect focus column
22762
22768
  this.savingSubject.next(true);
22763
- if (!opts || opts.emitEvent !== false) {
22769
+ if (!opts || opts.emitEvent !== false)
22764
22770
  this.markForCheck();
22765
- }
22766
22771
  }
22767
22772
  }
22768
22773
  markAsSaved(opts) {
22769
22774
  if (this.savingSubject.value !== false) {
22770
22775
  this.savingSubject.next(false);
22771
- if (!opts || opts.emitEvent !== false) {
22776
+ if (!opts || opts.emitEvent !== false)
22772
22777
  this.markForCheck();
22773
- }
22774
22778
  }
22775
22779
  }
22776
22780
  markAsLoading(opts) {
@@ -24189,7 +24193,7 @@ class AppEditor {
24189
24193
  * @deprecated
24190
24194
  */
24191
24195
  set _loading(value) {
24192
- this.readySubject.next(value);
24196
+ this.loadingSubject.next(value);
24193
24197
  }
24194
24198
  /**
24195
24199
  * @deprecated
@@ -24576,11 +24580,13 @@ class AppEditor {
24576
24580
  setError(value, opts) {
24577
24581
  if (this.errorSubject.value !== value) {
24578
24582
  this.errorSubject.next(value);
24579
- if (!opts || opts.emitEvent !== false) {
24583
+ if (!opts || opts.emitEvent !== false)
24580
24584
  this.markForCheck();
24581
- }
24582
24585
  }
24583
24586
  }
24587
+ resetError(opts) {
24588
+ this.setError(undefined, opts);
24589
+ }
24584
24590
  markForCheck() {
24585
24591
  // Should be override by subclasses, if change detection is Push
24586
24592
  }
@@ -24645,6 +24651,8 @@ class AppTabEditor extends AppEditor {
24645
24651
  ngOnDestroy() {
24646
24652
  super.ngOnDestroy();
24647
24653
  this.selectedTabIndexChange.complete();
24654
+ this.loadingSubject.unsubscribe();
24655
+ this.errorSubject.unsubscribe();
24648
24656
  }
24649
24657
  setSelectedTabIndex(value, opts) {
24650
24658
  // Fix value
@@ -24740,6 +24748,16 @@ class AppTabEditor extends AppEditor {
24740
24748
  yield _super.unload.call(this, opts);
24741
24749
  });
24742
24750
  }
24751
+ saveDirtyTables() {
24752
+ return __awaiter(this, void 0, void 0, function* () {
24753
+ // Save all dirty tables
24754
+ const results = yield Promise.all((this.tables || [])
24755
+ .filter(c => c.dirty)
24756
+ .map(c => c.save()));
24757
+ const saved = results.findIndex(result => result !== true) === -1;
24758
+ return saved;
24759
+ });
24760
+ }
24743
24761
  }
24744
24762
  AppTabEditor.decorators = [
24745
24763
  { type: Directive }
@@ -24768,7 +24786,7 @@ class AppEntityEditor extends AppTabEditor {
24768
24786
  super(injector.get(ActivatedRoute), injector.get(Router), injector.get(AlertController), injector.get(TranslateService), options);
24769
24787
  this.dataType = dataType;
24770
24788
  this.dataService = dataService;
24771
- this.saving = false;
24789
+ this.savingSubject = new BehaviorSubject(false);
24772
24790
  this.$title = new Subject();
24773
24791
  this.onUpdateView = new EventEmitter();
24774
24792
  this.environement = injector.get(ENVIRONMENT);
@@ -24811,21 +24829,24 @@ class AppEntityEditor extends AppTabEditor {
24811
24829
  return isNil((_a = this.data) === null || _a === void 0 ? void 0 : _a.id);
24812
24830
  }
24813
24831
  get loading() {
24814
- return this._loading;
24832
+ return this.loadingSubject.value;
24833
+ }
24834
+ get saving() {
24835
+ return this.savingSubject.value;
24815
24836
  }
24816
24837
  get service() {
24817
24838
  return this.dataService;
24818
24839
  }
24819
24840
  markAsSaving(opts) {
24820
- if (!this.saving) {
24821
- this.saving = true;
24841
+ if (this.savingSubject.value !== true) {
24842
+ this.savingSubject.next(true);
24822
24843
  if (!opts || opts.emitEvent !== false)
24823
24844
  this.markForCheck();
24824
24845
  }
24825
24846
  }
24826
24847
  markAsSaved(opts) {
24827
- if (this.saving) {
24828
- this.saving = false;
24848
+ if (this.savingSubject.value !== false) {
24849
+ this.savingSubject.next(false);
24829
24850
  if (!opts || opts.emitEvent !== false)
24830
24851
  this.markForCheck();
24831
24852
  }
@@ -24854,11 +24875,12 @@ class AppEntityEditor extends AppTabEditor {
24854
24875
  this.$title.unsubscribe();
24855
24876
  this.onUpdateView.complete();
24856
24877
  this.onUpdateView.unsubscribe();
24878
+ this.savingSubject.unsubscribe();
24857
24879
  }
24858
24880
  waitIdle(opts) {
24859
24881
  // Wait end of saving
24860
24882
  if (this.saving)
24861
- return waitFor(() => this.saving !== true);
24883
+ return waitForFalse(this.savingSubject);
24862
24884
  return super.waitIdle(opts);
24863
24885
  }
24864
24886
  /**
@@ -25103,9 +25125,10 @@ class AppEntityEditor extends AppTabEditor {
25103
25125
  yield this.waitWhilePending();
25104
25126
  // If invalid
25105
25127
  if (this.invalid) {
25106
- this.markAllAsTouched();
25107
25128
  this.logFormErrors();
25108
25129
  this.openFirstInvalidTab();
25130
+ this.scrollToTop();
25131
+ this.markAllAsTouched();
25109
25132
  this.submitted = true;
25110
25133
  return false;
25111
25134
  }
@@ -25116,6 +25139,10 @@ class AppEntityEditor extends AppTabEditor {
25116
25139
  try {
25117
25140
  // Compute next tab index (if enable)
25118
25141
  const nextTabIndex = this._autoOpenNextTab && isNil(this.previousDataId) && this.computeNextTabIndex();
25142
+ // Save all dirty tables
25143
+ const saved = yield this.saveDirtyTables();
25144
+ if (!saved)
25145
+ return false;
25119
25146
  // Get data
25120
25147
  const data = yield this.getValue();
25121
25148
  this.disable();
@@ -25229,7 +25256,7 @@ class AppEntityEditor extends AppTabEditor {
25229
25256
  this.registerForms();
25230
25257
  this._dirty = false;
25231
25258
  this.data = null;
25232
- this.saving = false;
25259
+ this.savingSubject.next(false);
25233
25260
  });
25234
25261
  }
25235
25262
  goBack(event) {
@@ -25249,19 +25276,15 @@ class AppEntityEditor extends AppTabEditor {
25249
25276
  });
25250
25277
  }
25251
25278
  resetError(opts) {
25252
- if (isNotNilOrBlank(this.error)) {
25253
- this.error = null;
25254
- if (!opts || opts.emitEvent !== false)
25255
- this.markForCheck();
25256
- }
25279
+ super.resetError(opts);
25257
25280
  }
25258
25281
  setError(err, opts) {
25259
25282
  if (!err) {
25260
- this.error = undefined;
25283
+ super.setError(undefined, opts);
25261
25284
  }
25262
25285
  else if (typeof err === 'string') {
25263
25286
  console.error('[entity-editor] Error: ' + (err || ''));
25264
- this.error = err;
25287
+ super.setError(err, opts);
25265
25288
  }
25266
25289
  else {
25267
25290
  console.error('[entity-editor] Error: ' + err.message || '', err);
@@ -25276,10 +25299,8 @@ class AppEntityEditor extends AppTabEditor {
25276
25299
  userMessage += detailMessage.length < 70 ? detailMessage : detailMessage.substring(0, 67) + '...';
25277
25300
  userMessage += '</small>';
25278
25301
  }
25279
- this.error = userMessage;
25302
+ super.setError(userMessage, opts);
25280
25303
  }
25281
- if (!opts || opts.emitEvent !== false)
25282
- this.markForCheck();
25283
25304
  }
25284
25305
  /* -- protected methods -- */
25285
25306
  /**
@@ -25439,7 +25460,7 @@ class AppEntityEditorModal extends AppTabEditor {
25439
25460
  constructor(injector, dataType, options) {
25440
25461
  super(null, injector.get(Router), injector.get(AlertController), injector.get(TranslateService), options);
25441
25462
  this.dataType = dataType;
25442
- this.saving = false;
25463
+ this.savingSubject = new BehaviorSubject(false);
25443
25464
  this.$title = new Subject();
25444
25465
  this.i18nSuffix = null;
25445
25466
  this.environement = injector.get(ENVIRONMENT);
@@ -25475,16 +25496,19 @@ class AppEntityEditorModal extends AppTabEditor {
25475
25496
  get isOnFieldMode() {
25476
25497
  return this.settings.isOnFieldMode(this._usageMode);
25477
25498
  }
25499
+ get saving() {
25500
+ return this.savingSubject.value;
25501
+ }
25478
25502
  markAsSaving(opts) {
25479
- if (!this.saving) {
25480
- this.saving = true;
25503
+ if (this.savingSubject.value !== true) {
25504
+ this.savingSubject.next(true);
25481
25505
  if (!opts || opts.emitEvent !== false)
25482
25506
  this.markForCheck();
25483
25507
  }
25484
25508
  }
25485
25509
  markAsSaved(opts) {
25486
- if (this.saving) {
25487
- this.saving = false;
25510
+ if (this.savingSubject.value !== false) {
25511
+ this.savingSubject.next(false);
25488
25512
  if (!opts || opts.emitEvent !== false)
25489
25513
  this.markForCheck();
25490
25514
  }
@@ -25528,11 +25552,12 @@ class AppEntityEditorModal extends AppTabEditor {
25528
25552
  super.ngOnDestroy();
25529
25553
  this.$title.complete();
25530
25554
  this.$title.unsubscribe();
25555
+ this.savingSubject.unsubscribe();
25531
25556
  }
25532
25557
  waitIdle(opts) {
25533
25558
  // Wait end of saving
25534
25559
  if (this.saving)
25535
- return waitFor(() => this.saving !== true);
25560
+ return waitForFalse(this.savingSubject);
25536
25561
  return super.waitIdle(opts);
25537
25562
  }
25538
25563
  load() {
@@ -25638,9 +25663,9 @@ class AppEntityEditorModal extends AppTabEditor {
25638
25663
  if (this.invalid) {
25639
25664
  this.logFormErrors();
25640
25665
  this.setError('COMMON.FORM.HAS_ERROR');
25641
- this.markAllAsTouched();
25642
25666
  this.openFirstInvalidTab();
25643
25667
  this.scrollToTop();
25668
+ this.markAllAsTouched();
25644
25669
  this.submitted = true;
25645
25670
  return false;
25646
25671
  }
@@ -25744,11 +25769,11 @@ class AppEntityEditorModal extends AppTabEditor {
25744
25769
  }
25745
25770
  setError(err, opts) {
25746
25771
  if (!err) {
25747
- this.error = undefined;
25772
+ super.setError(undefined, opts);
25748
25773
  }
25749
25774
  else if (typeof err === 'string') {
25750
25775
  console.error('[entity-editor] Error: ' + (err || ''));
25751
- this.error = err;
25776
+ super.setError(err, opts);
25752
25777
  }
25753
25778
  else {
25754
25779
  console.error('[entity-editor] Error: ' + err.message || '', err);
@@ -25763,22 +25788,10 @@ class AppEntityEditorModal extends AppTabEditor {
25763
25788
  userMessage += detailMessage.length < 70 ? detailMessage : detailMessage.substring(0, 67) + '...';
25764
25789
  userMessage += '</small>';
25765
25790
  }
25766
- this.error = userMessage;
25791
+ super.setError(userMessage, opts);
25767
25792
  }
25768
- if (!opts || opts.emitEvent !== false)
25769
- this.markForCheck();
25770
25793
  }
25771
25794
  /* -- protected methods -- */
25772
- saveDirtyTables() {
25773
- return __awaiter(this, void 0, void 0, function* () {
25774
- // Save all dirty tables
25775
- const results = yield Promise.all((this.tables || [])
25776
- .filter(c => c.dirty)
25777
- .map(c => c.save()));
25778
- const saved = results.findIndex(result => result !== true) === -1;
25779
- return saved;
25780
- });
25781
- }
25782
25795
  waitWhilePending(opts) {
25783
25796
  return AppFormUtils.waitWhilePending(this, opts);
25784
25797
  }