@sumaris-net/ngx-components 1.23.23 → 1.23.25

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.
@@ -18317,17 +18317,21 @@ class InMemoryEntitiesService extends StartableObservableService {
18317
18317
  this.stop();
18318
18318
  }
18319
18319
  setValue(data) {
18320
- if (this.dataSubject.value !== data) {
18321
- // If service already started, then update data
18322
- if (this.started) {
18320
+ // If service already started
18321
+ if (this.started) {
18322
+ // Update the data, if changed
18323
+ if (this.dataSubject.value !== data) {
18323
18324
  this._hiddenData = [];
18324
18325
  this.dataSubject.next(data);
18325
- this.markAsPristine();
18326
- }
18327
- // if service not started yet, then start it, using given data
18328
- else {
18329
- this.start(data);
18330
18326
  }
18327
+ // Reset dirty and saving state
18328
+ // (Fix ObsBio issue on samples table : still dirty after setting the same value again)
18329
+ this.markAsSaved();
18330
+ this.markAsPristine();
18331
+ }
18332
+ // If service not started yet, then start it, using given data
18333
+ else {
18334
+ this.start(data);
18331
18335
  }
18332
18336
  }
18333
18337
  loadAll(offset, size, sortBy, sortDirection, filter, opts) {
@@ -18520,6 +18524,16 @@ class InMemoryEntitiesService extends StartableObservableService {
18520
18524
  yield this.waitWhileSaving(opts);
18521
18525
  });
18522
18526
  }
18527
+ markAsDirty() {
18528
+ if (!this.dirtySubject.value) {
18529
+ this.dirtySubject.next(true);
18530
+ }
18531
+ }
18532
+ markAsPristine() {
18533
+ if (this.dirtySubject.value) {
18534
+ this.dirtySubject.next(false);
18535
+ }
18536
+ }
18523
18537
  /* -- protected methods -- */
18524
18538
  filter(data, _filter, hiddenData) {
18525
18539
  // if filter is DataFilter instance, use its test function
@@ -18561,16 +18575,6 @@ class InMemoryEntitiesService extends StartableObservableService {
18561
18575
  this.savingSubject.next(false);
18562
18576
  }
18563
18577
  }
18564
- markAsDirty() {
18565
- if (!this.dirtySubject.value) {
18566
- this.dirtySubject.next(true);
18567
- }
18568
- }
18569
- markAsPristine() {
18570
- if (this.dirtySubject.value) {
18571
- this.dirtySubject.next(false);
18572
- }
18573
- }
18574
18578
  }
18575
18579
  InMemoryEntitiesService.decorators = [
18576
18580
  { type: Directive }
@@ -24550,11 +24554,12 @@ class AppEditor {
24550
24554
  this.translate = translate;
24551
24555
  this._subscription = new Subscription();
24552
24556
  this._enabled = false;
24553
- this._dirty = false;
24554
24557
  this.destroySubject = new Subject();
24555
24558
  this.readySubject = new BehaviorSubject(false);
24559
+ this.dirtySubject = new BehaviorSubject(false);
24556
24560
  this.loadingSubject = new BehaviorSubject(true);
24557
24561
  this.errorSubject = new BehaviorSubject(undefined);
24562
+ this.savingSubject = new BehaviorSubject(false);
24558
24563
  this.debug = false;
24559
24564
  this.submitted = false;
24560
24565
  this.toolbar = null;
@@ -24590,6 +24595,10 @@ class AppEditor {
24590
24595
  set error(error) {
24591
24596
  this.setError(error);
24592
24597
  }
24598
+ get saving() {
24599
+ var _a;
24600
+ return this.savingSubject.value || ((_a = this.editors) === null || _a === void 0 ? void 0 : _a.some(e => e.saving));
24601
+ }
24593
24602
  get tables() {
24594
24603
  return this._children && this._children.filter(c => c instanceof AppTable);
24595
24604
  }
@@ -24600,7 +24609,7 @@ class AppEditor {
24600
24609
  return this._children && this._children.filter(c => c instanceof AppEditor);
24601
24610
  }
24602
24611
  get dirty() {
24603
- return this._dirty || (this._children && this._children.findIndex(c => c.enabled && c.dirty) !== -1) || false;
24612
+ return this.dirtySubject.value || (this._children && this._children.findIndex(c => c.enabled && c.dirty) !== -1) || false;
24604
24613
  }
24605
24614
  /**
24606
24615
  * Is valid (tables and forms)
@@ -24628,7 +24637,7 @@ class AppEditor {
24628
24637
  return this._children;
24629
24638
  }
24630
24639
  get empty() {
24631
- return this._enabled;
24640
+ return !this._enabled;
24632
24641
  }
24633
24642
  ngOnInit() {
24634
24643
  if (this.formButtonsBar) {
@@ -24688,7 +24697,9 @@ class AppEditor {
24688
24697
  var _a;
24689
24698
  this.error = null;
24690
24699
  this.submitted = false;
24691
- this._dirty = false;
24700
+ if (this.dirtySubject.value !== false) {
24701
+ this.dirtySubject.next(false);
24702
+ }
24692
24703
  (_a = this._children) === null || _a === void 0 ? void 0 : _a.forEach(c => c.markAsPristine(opts));
24693
24704
  if (!this.loading && (!opts || opts.emitEvent !== false))
24694
24705
  this.markForCheck();
@@ -24716,9 +24727,11 @@ class AppEditor {
24716
24727
  this.markForCheck();
24717
24728
  }
24718
24729
  markAsDirty(opts) {
24719
- this._dirty = true;
24720
- if (!this.loading && (!opts || opts.emitEvent !== false))
24721
- this.markForCheck();
24730
+ if (!this.dirtySubject.value) {
24731
+ this.dirtySubject.next(true);
24732
+ if (!this.loading && (!opts || opts.emitEvent !== false))
24733
+ this.markForCheck();
24734
+ }
24722
24735
  }
24723
24736
  markAsLoading(opts) {
24724
24737
  if (!this.loadingSubject.value) {
@@ -24757,6 +24770,20 @@ class AppEditor {
24757
24770
  return Promise.resolve();
24758
24771
  return waitForFalse(this.loadingSubject, opts);
24759
24772
  }
24773
+ markAsSaving(opts) {
24774
+ if (this.savingSubject.value !== true) {
24775
+ this.savingSubject.next(true);
24776
+ if (!opts || opts.emitEvent !== false)
24777
+ this.markForCheck();
24778
+ }
24779
+ }
24780
+ markAsSaved(opts) {
24781
+ if (this.savingSubject.value !== false) {
24782
+ this.savingSubject.next(false);
24783
+ if (!opts || opts.emitEvent !== false)
24784
+ this.markForCheck();
24785
+ }
24786
+ }
24760
24787
  cancel(event) {
24761
24788
  return __awaiter(this, void 0, void 0, function* () {
24762
24789
  if (this.isNewData) {
@@ -24775,7 +24802,7 @@ class AppEditor {
24775
24802
  unload(opts) {
24776
24803
  var _a;
24777
24804
  return __awaiter(this, void 0, void 0, function* () {
24778
- console.debug('[tab-page] Unloading data...');
24805
+ console.debug('[editor] Unloading data...');
24779
24806
  this.markAsLoading();
24780
24807
  (_a = this._children) === null || _a === void 0 ? void 0 : _a.forEach(f => {
24781
24808
  if (f instanceof AppForm) {
@@ -24784,7 +24811,12 @@ class AppEditor {
24784
24811
  else if (f instanceof AppTable) {
24785
24812
  f.dataSource.disconnect();
24786
24813
  }
24814
+ else if (f instanceof AppEditor) {
24815
+ f.unload(opts);
24816
+ }
24787
24817
  });
24818
+ this.markAsPristine(opts);
24819
+ this.markAsSaved(opts);
24788
24820
  });
24789
24821
  }
24790
24822
  reloadWithConfirmation(confirm) {
@@ -24836,11 +24868,11 @@ class AppEditor {
24836
24868
  }
24837
24869
  });
24838
24870
  }
24839
- logFormErrors() {
24871
+ logFormErrors(prefix) {
24840
24872
  var _a;
24841
24873
  if (this.debug)
24842
- console.debug('[app-tab-editor] Page not valid. Checking where (forms, tables)...');
24843
- (_a = this._children) === null || _a === void 0 ? void 0 : _a.forEach(c => this.logChildrenFormErrors(c));
24874
+ console.debug('[editor] Editor not valid. Checking where (forms, tables)...');
24875
+ (_a = this._children) === null || _a === void 0 ? void 0 : _a.forEach(c => this.logChildrenErrors(c, prefix));
24844
24876
  }
24845
24877
  /* -- protected methods -- */
24846
24878
  scrollToTop(duration) {
@@ -24919,7 +24951,7 @@ class AppEditor {
24919
24951
  yield Toasts.show(this.toastController, this.translate, opts);
24920
24952
  });
24921
24953
  }
24922
- logChildrenFormErrors(c, prefix, path) {
24954
+ logChildrenErrors(c, prefix, path) {
24923
24955
  prefix = prefix || '[app-tab-editor] ';
24924
24956
  // If editor
24925
24957
  if (c instanceof AppEditor) {
@@ -24932,7 +24964,7 @@ class AppEditor {
24932
24964
  // If form provider: get delegate
24933
24965
  else if (c instanceof AppFormProvider) {
24934
24966
  if (!c.empty && !c.valid) {
24935
- c.waitDelegate({ timeout: 1000 }).then(delegate => this.logChildrenFormErrors(delegate, prefix, 'provider'));
24967
+ c.waitDelegate({ timeout: 1000 }).then(delegate => this.logChildrenErrors(delegate, prefix, 'provider'));
24936
24968
  }
24937
24969
  }
24938
24970
  // If table
@@ -24942,20 +24974,34 @@ class AppEditor {
24942
24974
  AppFormUtils.logFormErrors(c.editedRow.validator, prefix, path);
24943
24975
  }
24944
24976
  }
24945
- // If IAppForm
24977
+ // If form
24946
24978
  else if (c instanceof AppForm) {
24947
24979
  if (!c.empty && !c.valid) {
24948
24980
  if (c.pending) {
24949
24981
  const path = c.constructor.name.toLowerCase();
24950
24982
  console.warn(`${prefix} -> ${path}: waiting while pending...`);
24951
24983
  AppFormUtils.waitWhilePending(c, { timeout: 1000 })
24952
- .then(() => this.logChildrenFormErrors(c.form, prefix, path));
24984
+ .then(() => this.logChildrenErrors(c.form, prefix, path));
24953
24985
  }
24954
24986
  else {
24955
24987
  AppFormUtils.logFormErrors(c.form, prefix);
24956
24988
  }
24957
24989
  }
24958
24990
  }
24991
+ // If editor
24992
+ else if (c instanceof AppEditor) {
24993
+ if (!c.empty && !c.valid) {
24994
+ if (c.pending) {
24995
+ const path = c.constructor.name.toLowerCase();
24996
+ console.warn(`${prefix} -> ${path}: waiting while pending...`);
24997
+ AppFormUtils.waitWhilePending(c, { timeout: 1000 })
24998
+ .then(() => c.logFormErrors(prefix));
24999
+ }
25000
+ else {
25001
+ c.logFormErrors(prefix);
25002
+ }
25003
+ }
25004
+ }
24959
25005
  else {
24960
25006
  console.warn(`${prefix} Unknown children sub-form: `, c);
24961
25007
  }
@@ -25171,7 +25217,6 @@ class AppEntityEditor extends AppTabEditor {
25171
25217
  super(injector.get(ActivatedRoute), injector.get(Router), injector.get(AlertController), injector.get(TranslateService), options);
25172
25218
  this.dataType = dataType;
25173
25219
  this.dataService = dataService;
25174
- this.savingSubject = new BehaviorSubject(false);
25175
25220
  this.$title = new Subject();
25176
25221
  this.onUpdateView = new EventEmitter();
25177
25222
  this.environment = injector.get(ENVIRONMENT);
@@ -25213,29 +25258,9 @@ class AppEntityEditor extends AppTabEditor {
25213
25258
  var _a;
25214
25259
  return isNil((_a = this.data) === null || _a === void 0 ? void 0 : _a.id);
25215
25260
  }
25216
- get loading() {
25217
- return this.loadingSubject.value;
25218
- }
25219
- get saving() {
25220
- return this.savingSubject.value;
25221
- }
25222
25261
  get service() {
25223
25262
  return this.dataService;
25224
25263
  }
25225
- markAsSaving(opts) {
25226
- if (this.savingSubject.value !== true) {
25227
- this.savingSubject.next(true);
25228
- if (!opts || opts.emitEvent !== false)
25229
- this.markForCheck();
25230
- }
25231
- }
25232
- markAsSaved(opts) {
25233
- if (this.savingSubject.value !== false) {
25234
- this.savingSubject.next(false);
25235
- if (!opts || opts.emitEvent !== false)
25236
- this.markForCheck();
25237
- }
25238
- }
25239
25264
  ngOnInit() {
25240
25265
  super.ngOnInit();
25241
25266
  // Defaults
@@ -25390,9 +25415,7 @@ class AppEntityEditor extends AppTabEditor {
25390
25415
  this.data = data;
25391
25416
  this.previousDataId = data.id || null;
25392
25417
  yield this.ready();
25393
- const promiseOrVoid = this.setValue(data);
25394
- if (promiseOrVoid)
25395
- yield promiseOrVoid;
25418
+ yield this.setValue(data);
25396
25419
  if (!opts || opts.emitEvent !== false) {
25397
25420
  this.markAsPristine();
25398
25421
  this.markAsUntouched();
@@ -25635,14 +25658,17 @@ class AppEntityEditor extends AppTabEditor {
25635
25658
  yield this.load((_a = this.data) === null || _a === void 0 ? void 0 : _a.id);
25636
25659
  });
25637
25660
  }
25638
- unload() {
25661
+ unload(opts) {
25662
+ const _super = Object.create(null, {
25663
+ unload: { get: () => super.unload }
25664
+ });
25639
25665
  return __awaiter(this, void 0, void 0, function* () {
25666
+ yield _super.unload.call(this, opts);
25640
25667
  this.stopListenRemoteChanges();
25641
25668
  this.form.reset();
25642
25669
  this.registerForms();
25643
- this._dirty = false;
25644
25670
  this.data = null;
25645
- this.savingSubject.next(false);
25671
+ // TODO: find a way to remove current page from the navigation history
25646
25672
  });
25647
25673
  }
25648
25674
  goBack(event) {