@sumaris-net/ngx-components 1.21.0 → 1.21.3

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
@@ -17666,6 +17666,8 @@ class AppForm {
17666
17666
  * @param opts
17667
17667
  */
17668
17668
  ready(opts) {
17669
+ if (this.readySubject.value)
17670
+ return Promise.resolve();
17669
17671
  return waitForTrue(this.readySubject, opts);
17670
17672
  }
17671
17673
  /**
@@ -17673,6 +17675,8 @@ class AppForm {
17673
17675
  * @param opts
17674
17676
  */
17675
17677
  waitIdle(opts) {
17678
+ if (!this.loadingSubject.value)
17679
+ return Promise.resolve();
17676
17680
  return waitForFalse(this.loadingSubject, opts);
17677
17681
  }
17678
17682
  updateValueAndValidity(opts) {
@@ -22631,9 +22635,15 @@ class AppTable {
22631
22635
  set error(error) {
22632
22636
  this.setError(error);
22633
22637
  }
22638
+ /**
22639
+ * @deprecated
22640
+ */
22634
22641
  get loading$() {
22635
22642
  return this.loadingSubject.asObservable();
22636
22643
  }
22644
+ /**
22645
+ * @deprecated
22646
+ */
22637
22647
  get saving$() {
22638
22648
  return this.savingSubject.asObservable();
22639
22649
  }
@@ -22756,17 +22766,15 @@ class AppTable {
22756
22766
  if (this.savingSubject.value !== true) {
22757
22767
  this.focusColumn = undefined; // unselect focus column
22758
22768
  this.savingSubject.next(true);
22759
- if (!opts || opts.emitEvent !== false) {
22769
+ if (!opts || opts.emitEvent !== false)
22760
22770
  this.markForCheck();
22761
- }
22762
22771
  }
22763
22772
  }
22764
22773
  markAsSaved(opts) {
22765
22774
  if (this.savingSubject.value !== false) {
22766
22775
  this.savingSubject.next(false);
22767
- if (!opts || opts.emitEvent !== false) {
22776
+ if (!opts || opts.emitEvent !== false)
22768
22777
  this.markForCheck();
22769
- }
22770
22778
  }
22771
22779
  }
22772
22780
  markAsLoading(opts) {
@@ -24173,8 +24181,9 @@ class AppEditor {
24173
24181
  this._subscription = new Subscription();
24174
24182
  this._enabled = false;
24175
24183
  this._dirty = false;
24176
- this._$ready = new BehaviorSubject(false);
24177
- this._$loading = new BehaviorSubject(true);
24184
+ this.readySubject = new BehaviorSubject(false);
24185
+ this.loadingSubject = new BehaviorSubject(true);
24186
+ this.errorSubject = new BehaviorSubject(undefined);
24178
24187
  this.debug = false;
24179
24188
  this.submitted = false;
24180
24189
  this.toolbar = null;
@@ -24184,13 +24193,31 @@ class AppEditor {
24184
24193
  * @deprecated
24185
24194
  */
24186
24195
  set _loading(value) {
24187
- this._$loading.next(value);
24196
+ this.loadingSubject.next(value);
24188
24197
  }
24189
24198
  /**
24190
24199
  * @deprecated
24191
24200
  */
24192
24201
  get _loading() {
24193
- return this._$loading.value;
24202
+ return this.loadingSubject.value;
24203
+ }
24204
+ /**
24205
+ * @deprecated
24206
+ */
24207
+ get _$ready() {
24208
+ return this.readySubject;
24209
+ }
24210
+ /**
24211
+ * @deprecated
24212
+ */
24213
+ get _$loading() {
24214
+ return this.loadingSubject;
24215
+ }
24216
+ get error() {
24217
+ return this.errorSubject.value;
24218
+ }
24219
+ set error(error) {
24220
+ this.setError(error);
24194
24221
  }
24195
24222
  get tables() {
24196
24223
  return this._children && this._children.filter(c => c instanceof AppTable);
@@ -24219,7 +24246,7 @@ class AppEditor {
24219
24246
  }
24220
24247
  get loading() {
24221
24248
  var _a;
24222
- return this._$loading.value || (((_a = this._children) === null || _a === void 0 ? void 0 : _a.findIndex(c => c.enabled && c.loading)) !== -1) || false;
24249
+ return this.loadingSubject.value || (((_a = this._children) === null || _a === void 0 ? void 0 : _a.findIndex(c => c.enabled && c.loading)) !== -1) || false;
24223
24250
  }
24224
24251
  get enabled() {
24225
24252
  return this._enabled;
@@ -24243,10 +24270,9 @@ class AppEditor {
24243
24270
  }
24244
24271
  ngOnDestroy() {
24245
24272
  this._subscription.unsubscribe();
24246
- this._$ready.complete();
24247
- this._$ready.unsubscribe();
24248
- this._$loading.complete();
24249
- this._$loading.unsubscribe();
24273
+ this.readySubject.unsubscribe();
24274
+ this.loadingSubject.unsubscribe();
24275
+ this.errorSubject.unsubscribe();
24250
24276
  }
24251
24277
  addChildForm(form) {
24252
24278
  if (!form)
@@ -24315,16 +24341,16 @@ class AppEditor {
24315
24341
  this.markForCheck();
24316
24342
  }
24317
24343
  markAsLoading(opts) {
24318
- if (!this._loading) {
24319
- this._loading = true;
24344
+ if (!this.loadingSubject.value) {
24345
+ this.loadingSubject.next(true);
24320
24346
  if (!opts || opts.emitEvent !== false)
24321
24347
  this.markForCheck();
24322
24348
  }
24323
24349
  }
24324
24350
  markAsLoaded(opts) {
24325
24351
  var _a;
24326
- if (this._loading) {
24327
- this._loading = false;
24352
+ if (this.loadingSubject.value) {
24353
+ this.loadingSubject.next(false);
24328
24354
  if (!opts || opts.onlySelf !== true) {
24329
24355
  // Emit to children forms
24330
24356
  // Tables should be changed by parent
@@ -24338,17 +24364,17 @@ class AppEditor {
24338
24364
  markAsReady(opts) {
24339
24365
  var _a;
24340
24366
  (_a = this._children) === null || _a === void 0 ? void 0 : _a.forEach(c => c.markAsReady(opts));
24341
- this._$ready.next(true);
24367
+ this.readySubject.next(true);
24342
24368
  }
24343
24369
  ready(opts) {
24344
- return __awaiter(this, void 0, void 0, function* () {
24345
- if (this._$ready.value)
24346
- return;
24347
- return waitForTrue(this._$ready, opts);
24348
- });
24370
+ if (this.readySubject.value)
24371
+ return Promise.resolve();
24372
+ return waitForTrue(this.readySubject, opts);
24349
24373
  }
24350
24374
  waitIdle(opts) {
24351
- return AppFormUtils.waitIdle(this, opts);
24375
+ if (!this.loadingSubject.value)
24376
+ return Promise.resolve();
24377
+ return waitForFalse(this.loadingSubject, opts);
24352
24378
  }
24353
24379
  cancel(event) {
24354
24380
  return __awaiter(this, void 0, void 0, function* () {
@@ -24551,6 +24577,16 @@ class AppEditor {
24551
24577
  console.warn(`${prefix} Unknown children sub-form: `, c);
24552
24578
  }
24553
24579
  }
24580
+ setError(value, opts) {
24581
+ if (this.errorSubject.value !== value) {
24582
+ this.errorSubject.next(value);
24583
+ if (!opts || opts.emitEvent !== false)
24584
+ this.markForCheck();
24585
+ }
24586
+ }
24587
+ resetError(opts) {
24588
+ this.setError(undefined, opts);
24589
+ }
24554
24590
  markForCheck() {
24555
24591
  // Should be override by subclasses, if change detection is Push
24556
24592
  }
@@ -24615,6 +24651,8 @@ class AppTabEditor extends AppEditor {
24615
24651
  ngOnDestroy() {
24616
24652
  super.ngOnDestroy();
24617
24653
  this.selectedTabIndexChange.complete();
24654
+ this.loadingSubject.unsubscribe();
24655
+ this.errorSubject.unsubscribe();
24618
24656
  }
24619
24657
  setSelectedTabIndex(value, opts) {
24620
24658
  // Fix value
@@ -24710,6 +24748,16 @@ class AppTabEditor extends AppEditor {
24710
24748
  yield _super.unload.call(this, opts);
24711
24749
  });
24712
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
+ }
24713
24761
  }
24714
24762
  AppTabEditor.decorators = [
24715
24763
  { type: Directive }
@@ -24738,7 +24786,7 @@ class AppEntityEditor extends AppTabEditor {
24738
24786
  super(injector.get(ActivatedRoute), injector.get(Router), injector.get(AlertController), injector.get(TranslateService), options);
24739
24787
  this.dataType = dataType;
24740
24788
  this.dataService = dataService;
24741
- this.saving = false;
24789
+ this.savingSubject = new BehaviorSubject(false);
24742
24790
  this.$title = new Subject();
24743
24791
  this.onUpdateView = new EventEmitter();
24744
24792
  this.environement = injector.get(ENVIRONMENT);
@@ -24781,21 +24829,24 @@ class AppEntityEditor extends AppTabEditor {
24781
24829
  return isNil((_a = this.data) === null || _a === void 0 ? void 0 : _a.id);
24782
24830
  }
24783
24831
  get loading() {
24784
- return this._loading;
24832
+ return this.loadingSubject.value;
24833
+ }
24834
+ get saving() {
24835
+ return this.savingSubject.value;
24785
24836
  }
24786
24837
  get service() {
24787
24838
  return this.dataService;
24788
24839
  }
24789
24840
  markAsSaving(opts) {
24790
- if (!this.saving) {
24791
- this.saving = true;
24841
+ if (this.savingSubject.value !== true) {
24842
+ this.savingSubject.next(true);
24792
24843
  if (!opts || opts.emitEvent !== false)
24793
24844
  this.markForCheck();
24794
24845
  }
24795
24846
  }
24796
24847
  markAsSaved(opts) {
24797
- if (this.saving) {
24798
- this.saving = false;
24848
+ if (this.savingSubject.value !== false) {
24849
+ this.savingSubject.next(false);
24799
24850
  if (!opts || opts.emitEvent !== false)
24800
24851
  this.markForCheck();
24801
24852
  }
@@ -24824,11 +24875,12 @@ class AppEntityEditor extends AppTabEditor {
24824
24875
  this.$title.unsubscribe();
24825
24876
  this.onUpdateView.complete();
24826
24877
  this.onUpdateView.unsubscribe();
24878
+ this.savingSubject.unsubscribe();
24827
24879
  }
24828
24880
  waitIdle(opts) {
24829
24881
  // Wait end of saving
24830
24882
  if (this.saving)
24831
- return waitFor(() => this.saving !== true);
24883
+ return waitForFalse(this.savingSubject);
24832
24884
  return super.waitIdle(opts);
24833
24885
  }
24834
24886
  /**
@@ -25073,9 +25125,10 @@ class AppEntityEditor extends AppTabEditor {
25073
25125
  yield this.waitWhilePending();
25074
25126
  // If invalid
25075
25127
  if (this.invalid) {
25076
- this.markAllAsTouched();
25077
25128
  this.logFormErrors();
25078
25129
  this.openFirstInvalidTab();
25130
+ this.scrollToTop();
25131
+ this.markAllAsTouched();
25079
25132
  this.submitted = true;
25080
25133
  return false;
25081
25134
  }
@@ -25086,6 +25139,10 @@ class AppEntityEditor extends AppTabEditor {
25086
25139
  try {
25087
25140
  // Compute next tab index (if enable)
25088
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;
25089
25146
  // Get data
25090
25147
  const data = yield this.getValue();
25091
25148
  this.disable();
@@ -25199,7 +25256,7 @@ class AppEntityEditor extends AppTabEditor {
25199
25256
  this.registerForms();
25200
25257
  this._dirty = false;
25201
25258
  this.data = null;
25202
- this.saving = false;
25259
+ this.savingSubject.next(false);
25203
25260
  });
25204
25261
  }
25205
25262
  goBack(event) {
@@ -25219,19 +25276,15 @@ class AppEntityEditor extends AppTabEditor {
25219
25276
  });
25220
25277
  }
25221
25278
  resetError(opts) {
25222
- if (isNotNilOrBlank(this.error)) {
25223
- this.error = null;
25224
- if (!opts || opts.emitEvent !== false)
25225
- this.markForCheck();
25226
- }
25279
+ super.resetError(opts);
25227
25280
  }
25228
25281
  setError(err, opts) {
25229
25282
  if (!err) {
25230
- this.error = undefined;
25283
+ super.setError(undefined, opts);
25231
25284
  }
25232
25285
  else if (typeof err === 'string') {
25233
25286
  console.error('[entity-editor] Error: ' + (err || ''));
25234
- this.error = err;
25287
+ super.setError(err, opts);
25235
25288
  }
25236
25289
  else {
25237
25290
  console.error('[entity-editor] Error: ' + err.message || '', err);
@@ -25246,10 +25299,8 @@ class AppEntityEditor extends AppTabEditor {
25246
25299
  userMessage += detailMessage.length < 70 ? detailMessage : detailMessage.substring(0, 67) + '...';
25247
25300
  userMessage += '</small>';
25248
25301
  }
25249
- this.error = userMessage;
25302
+ super.setError(userMessage, opts);
25250
25303
  }
25251
- if (!opts || opts.emitEvent !== false)
25252
- this.markForCheck();
25253
25304
  }
25254
25305
  /* -- protected methods -- */
25255
25306
  /**
@@ -25409,7 +25460,7 @@ class AppEntityEditorModal extends AppTabEditor {
25409
25460
  constructor(injector, dataType, options) {
25410
25461
  super(null, injector.get(Router), injector.get(AlertController), injector.get(TranslateService), options);
25411
25462
  this.dataType = dataType;
25412
- this.saving = false;
25463
+ this.savingSubject = new BehaviorSubject(false);
25413
25464
  this.$title = new Subject();
25414
25465
  this.i18nSuffix = null;
25415
25466
  this.environement = injector.get(ENVIRONMENT);
@@ -25445,16 +25496,19 @@ class AppEntityEditorModal extends AppTabEditor {
25445
25496
  get isOnFieldMode() {
25446
25497
  return this.settings.isOnFieldMode(this._usageMode);
25447
25498
  }
25499
+ get saving() {
25500
+ return this.savingSubject.value;
25501
+ }
25448
25502
  markAsSaving(opts) {
25449
- if (!this.saving) {
25450
- this.saving = true;
25503
+ if (this.savingSubject.value !== true) {
25504
+ this.savingSubject.next(true);
25451
25505
  if (!opts || opts.emitEvent !== false)
25452
25506
  this.markForCheck();
25453
25507
  }
25454
25508
  }
25455
25509
  markAsSaved(opts) {
25456
- if (this.saving) {
25457
- this.saving = false;
25510
+ if (this.savingSubject.value !== false) {
25511
+ this.savingSubject.next(false);
25458
25512
  if (!opts || opts.emitEvent !== false)
25459
25513
  this.markForCheck();
25460
25514
  }
@@ -25498,11 +25552,12 @@ class AppEntityEditorModal extends AppTabEditor {
25498
25552
  super.ngOnDestroy();
25499
25553
  this.$title.complete();
25500
25554
  this.$title.unsubscribe();
25555
+ this.savingSubject.unsubscribe();
25501
25556
  }
25502
25557
  waitIdle(opts) {
25503
25558
  // Wait end of saving
25504
25559
  if (this.saving)
25505
- return waitFor(() => this.saving !== true);
25560
+ return waitForFalse(this.savingSubject);
25506
25561
  return super.waitIdle(opts);
25507
25562
  }
25508
25563
  load() {
@@ -25608,9 +25663,9 @@ class AppEntityEditorModal extends AppTabEditor {
25608
25663
  if (this.invalid) {
25609
25664
  this.logFormErrors();
25610
25665
  this.setError('COMMON.FORM.HAS_ERROR');
25611
- this.markAllAsTouched();
25612
25666
  this.openFirstInvalidTab();
25613
25667
  this.scrollToTop();
25668
+ this.markAllAsTouched();
25614
25669
  this.submitted = true;
25615
25670
  return false;
25616
25671
  }
@@ -25739,16 +25794,6 @@ class AppEntityEditorModal extends AppTabEditor {
25739
25794
  this.markForCheck();
25740
25795
  }
25741
25796
  /* -- protected methods -- */
25742
- saveDirtyTables() {
25743
- return __awaiter(this, void 0, void 0, function* () {
25744
- // Save all dirty tables
25745
- const results = yield Promise.all((this.tables || [])
25746
- .filter(c => c.dirty)
25747
- .map(c => c.save()));
25748
- const saved = results.findIndex(result => result !== true) === -1;
25749
- return saved;
25750
- });
25751
- }
25752
25797
  waitWhilePending(opts) {
25753
25798
  return AppFormUtils.waitWhilePending(this, opts);
25754
25799
  }