@sumaris-net/ngx-components 2.2.1-rc8 → 2.2.1

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.
@@ -4175,7 +4175,7 @@ function disableControls(form, paths, opts) {
4175
4175
  });
4176
4176
  }
4177
4177
  function addValueInArray(arrayControl, createControl, equals, isEmpty, value, options) {
4178
- options = options || { emitEvent: true };
4178
+ const disabled = arrayControl.disabled;
4179
4179
  let hasChanged = false;
4180
4180
  let index = -1;
4181
4181
  // Search if value already exists
@@ -4195,11 +4195,17 @@ function addValueInArray(arrayControl, createControl, equals, isEmpty, value, op
4195
4195
  }
4196
4196
  else {
4197
4197
  const control = createControl(value);
4198
- arrayControl.push(control);
4198
+ // Apply parent disabled state, before to push it into the array
4199
+ // This is need to avoid parent form to be enabled
4200
+ if (disabled && control.enabled)
4201
+ control.disable({ emitEvent: false });
4202
+ else if (!disabled && control.disabled)
4203
+ control.enable({ emitEvent: false });
4204
+ arrayControl.push(control, options);
4199
4205
  hasChanged = true;
4200
4206
  }
4201
4207
  if (hasChanged) {
4202
- if (isNil(options.emitEvent) || options.emitEvent) {
4208
+ if (!options || options.emitEvent !== false) {
4203
4209
  // Mark array control dirty
4204
4210
  if (!isEmpty(value)) {
4205
4211
  arrayControl.markAsDirty();
@@ -4611,11 +4617,15 @@ class AppFormArray extends UntypedFormArray {
4611
4617
  this.createControl = createControl;
4612
4618
  this.equals = equals;
4613
4619
  this.isEmpty = isEmpty;
4614
- this.options = options;
4615
- this.setAllowEmptyArray(toBoolean(options && options.allowEmptyArray, false));
4620
+ this.options = {
4621
+ allowEmptyArray: true,
4622
+ allowReuseControls: true,
4623
+ ...options
4624
+ };
4625
+ this.setAllowEmptyArray(this.options.allowEmptyArray);
4616
4626
  }
4617
4627
  get allowEmptyArray() {
4618
- return this._allowEmptyArray;
4628
+ return this.options.allowEmptyArray;
4619
4629
  }
4620
4630
  set allowEmptyArray(value) {
4621
4631
  this.setAllowEmptyArray(value);
@@ -4626,16 +4636,29 @@ class AppFormArray extends UntypedFormArray {
4626
4636
  * @param options
4627
4637
  */
4628
4638
  setValue(values, options) {
4629
- if (this.options?.resizeStrategy === 'recreate') {
4630
- initArrayControlsFromValues(this, this.createControl, values, options);
4639
+ if (this.options.allowReuseControls === false) {
4640
+ const disabled = this.disabled;
4641
+ // Clean all
4642
+ this.resize(0, { emitEvent: options?.emitEvent });
4643
+ // Recreate each control, with a default value
4644
+ (values || []).forEach(value => {
4645
+ const control = this.createControl(value);
4646
+ // Apply parent disabled state, before to push it into the array
4647
+ // This is need to avoid parent form to be enabled, after calling AppFormArray.patchValue() (e.g. in table's row validator)
4648
+ if (disabled && control.enabled)
4649
+ control.disable({ emitEvent: false });
4650
+ else if (!disabled && control.disabled)
4651
+ control.enable({ emitEvent: false });
4652
+ this.push(control, options);
4653
+ });
4631
4654
  }
4632
4655
  else {
4633
- this.resize(values?.length || 0);
4656
+ this.resize(values?.length || 0, { emitEvent: false });
4634
4657
  super.setValue(values, options);
4635
4658
  }
4636
4659
  }
4637
4660
  patchValue(values, options) {
4638
- if (this.options?.resizeStrategy === 'recreate') {
4661
+ if (this.options.allowReuseControls === false) {
4639
4662
  const disabled = this.disabled;
4640
4663
  // Clean all
4641
4664
  this.resize(0, { emitEvent: options?.emitEvent });
@@ -4695,14 +4718,13 @@ class AppFormArray extends UntypedFormArray {
4695
4718
  /**
4696
4719
  * @param value
4697
4720
  * @param options
4698
- * @deprecated Use push() instead
4699
4721
  */
4700
4722
  add(value, options) {
4701
4723
  addValueInArray(this, this.createControl, this.equals, this.isEmpty, value, options);
4702
4724
  }
4703
4725
  removeAt(index, options) {
4704
4726
  // Do not remove if last criterion
4705
- if (!this._allowEmptyArray && this.length === 1) {
4727
+ if (this.options.allowEmptyArray === false && this.length === 1) {
4706
4728
  this.clearAt(index, options);
4707
4729
  }
4708
4730
  else {
@@ -4736,11 +4758,11 @@ class AppFormArray extends UntypedFormArray {
4736
4758
  }
4737
4759
  /* -- internal -- */
4738
4760
  setAllowEmptyArray(value) {
4739
- if (this._allowEmptyArray === value)
4761
+ if (this.options.allowEmptyArray === value)
4740
4762
  return; // Skip if same
4741
- this._allowEmptyArray = value;
4763
+ this.options.allowEmptyArray = value;
4742
4764
  // Set required (or reste) min length validator
4743
- if (this._allowEmptyArray) {
4765
+ if (this.options.allowEmptyArray) {
4744
4766
  this.setValidators(this.options.validators || null);
4745
4767
  }
4746
4768
  else {
@@ -8727,10 +8749,10 @@ class MatChipsField {
8727
8749
  return this.formControl.value || [];
8728
8750
  }
8729
8751
  get disabled() {
8730
- return this.readonly || this.formControl.disabled;
8752
+ return this.readonly || this.formControl?.disabled || false;
8731
8753
  }
8732
8754
  get enabled() {
8733
- return !this.readonly && this.formControl.enabled;
8755
+ return !this.readonly && this.formControl?.enabled || false;
8734
8756
  }
8735
8757
  get loading() {
8736
8758
  return isNil(this.$filteredItems.value);
@@ -8775,7 +8797,7 @@ class MatChipsField {
8775
8797
  this.displayColumnNames = this.displayAttributes.map((attr, index) => this.displayColumnNames && this.displayColumnNames[index] ||
8776
8798
  (this.i18nPrefix + changeCaseToUnderscore(attr).toUpperCase()));
8777
8799
  this.mobile = toBoolean(this.mobile, false);
8778
- this.equals = this.equals || ((o1, o2) => o1 && o2 && o1.id === o2.id);
8800
+ this.equals = this.equals || MatAutocompleteFieldUtils.defaultEquals;
8779
8801
  const classList = this.classList?.split(' ');
8780
8802
  this.panelWidth = this.panelWidth || (classList && ((classList.includes('min-width-medium') && '300px')
8781
8803
  || (classList.includes('min-width-large') && '400px')
@@ -24577,10 +24599,11 @@ class BaseEntityService extends BaseGraphqlService {
24577
24599
  watch(id, opts) {
24578
24600
  if (this._debug)
24579
24601
  console.debug(this._logPrefix + `Watching ${this._logTypeName} {${id}}...`);
24602
+ const variables = opts?.variables || { id };
24580
24603
  const query = opts && opts.query || this.queries.load;
24581
24604
  return this.graphql.watchQuery({
24582
24605
  query,
24583
- variables: { id },
24606
+ variables,
24584
24607
  fetchPolicy: opts && opts.fetchPolicy || undefined,
24585
24608
  error: { code: ErrorCodes.LOAD_DATA_ERROR, message: 'REFERENTIAL.ERROR.LOAD_DATA_ERROR' }
24586
24609
  })
@@ -24591,10 +24614,11 @@ class BaseEntityService extends BaseGraphqlService {
24591
24614
  async load(id, opts) {
24592
24615
  if (this._debug)
24593
24616
  console.debug(this._logPrefix + `Loading ${this._logTypeName} {${id}}...`);
24594
- const query = opts && opts.query || this.queries.load;
24617
+ const variables = opts?.variables || { id };
24618
+ const query = opts?.query || this.queries.load;
24595
24619
  const { data } = await this.graphql.query({
24596
24620
  query,
24597
- variables: { id },
24621
+ variables,
24598
24622
  fetchPolicy: opts && opts.fetchPolicy || undefined,
24599
24623
  error: { code: ErrorCodes.LOAD_DATA_ERROR, message: 'REFERENTIAL.ERROR.LOAD_DATA_ERROR' }
24600
24624
  });
@@ -24606,6 +24630,7 @@ class BaseEntityService extends BaseGraphqlService {
24606
24630
  watchAll(offset, size, sortBy, sortDirection, filter, opts) {
24607
24631
  filter = this.asFilter(filter);
24608
24632
  const variables = {
24633
+ ...(opts?.variables || {}),
24609
24634
  offset: offset || 0,
24610
24635
  size: size || 100,
24611
24636
  sortBy: sortBy || this.defaultSortBy,
@@ -24620,12 +24645,13 @@ class BaseEntityService extends BaseGraphqlService {
24620
24645
  // Or get loadAll or loadAllWithTotal query
24621
24646
  || (withTotal ? this.queries.loadAllWithTotal : this.queries.loadAll);
24622
24647
  return this.mutableWatchQuery({
24623
- queryName: withTotal ? 'LoadAllWithTotal' : 'LoadAll',
24624
24648
  query,
24649
+ variables,
24650
+ // Force cached mutable query
24651
+ queryName: withTotal ? 'LoadAllWithTotal' : 'LoadAll',
24625
24652
  arrayFieldName: 'data',
24626
24653
  totalFieldName: withTotal ? 'total' : undefined,
24627
24654
  insertFilterFn: filter && filter.asFilterFn(),
24628
- variables,
24629
24655
  error: { code: ErrorCodes.LOAD_DATA_ERROR, message: 'REFERENTIAL.ERROR.LOAD_DATA_ERROR' },
24630
24656
  fetchPolicy: opts && opts.fetchPolicy || undefined
24631
24657
  })
@@ -24645,6 +24671,7 @@ class BaseEntityService extends BaseGraphqlService {
24645
24671
  const debug = this._debug && (!opts || opts.debug !== false);
24646
24672
  filter = this.asFilter(filter);
24647
24673
  const variables = {
24674
+ ...(opts?.variables || {}),
24648
24675
  offset: offset || 0,
24649
24676
  size: size || 100,
24650
24677
  sortBy: sortBy || 'id',
@@ -24655,7 +24682,8 @@ class BaseEntityService extends BaseGraphqlService {
24655
24682
  if (debug)
24656
24683
  console.debug(this._logPrefix + `Loading ${this._logTypeName}...`, variables);
24657
24684
  const withTotal = (!opts || opts.withTotal !== false) && this.queries.loadAllWithTotal && true;
24658
- const query = (opts && opts.query) // use given query
24685
+ // use given query
24686
+ const query = opts?.query
24659
24687
  // Or get loadAll or loadAllWithTotal query
24660
24688
  || (withTotal ? this.queries.loadAllWithTotal : this.queries.loadAll);
24661
24689
  const { data, total } = await this.graphql.query({
@@ -24684,7 +24712,7 @@ class BaseEntityService extends BaseGraphqlService {
24684
24712
  }
24685
24713
  async countAll(filter, opts) {
24686
24714
  // If no countAll query
24687
- if (!this.queries.countAll) {
24715
+ if (!this.queries.countAll && !opts?.query) {
24688
24716
  // Fail if no loadAll (cannot count)
24689
24717
  if (!this.queries.loadAllWithTotal)
24690
24718
  throw new Error('Not implemented');
@@ -24692,11 +24720,14 @@ class BaseEntityService extends BaseGraphqlService {
24692
24720
  return (await this.loadAll(0, 1, null, null, filter, { withTotal: true }))?.total || 0;
24693
24721
  }
24694
24722
  filter = this.asFilter(filter);
24723
+ const variables = {
24724
+ ...(opts?.variables || {}),
24725
+ filter: filter && filter.asPodObject()
24726
+ };
24727
+ const query = opts?.query || this.queries.countAll;
24695
24728
  const res = await this.graphql.query({
24696
- query: this.queries.countAll,
24697
- variables: {
24698
- filter: filter && filter.asPodObject()
24699
- },
24729
+ query,
24730
+ variables,
24700
24731
  error: { code: ErrorCodes.LOAD_DATA_ERROR, message: 'ERROR.COUNT_DATA_ERROR' },
24701
24732
  fetchPolicy: opts && opts.fetchPolicy || 'network-only'
24702
24733
  });
@@ -28778,7 +28809,7 @@ class AbstractUserEventService extends BaseGraphqlService {
28778
28809
  }
28779
28810
  async ngOnStart() {
28780
28811
  // Update component when refresh is need (=login events)
28781
- this._subscriptions.add(merge(this.accountService.onLogin, this.accountService.onLogout, of() // Starts with - first attempt if account is ready
28812
+ this._subscriptions.add(merge(this.accountService.onLogin, this.accountService.onLogout, timer(1000) // Starts with - first attempt if account is ready
28782
28813
  )
28783
28814
  .pipe(
28784
28815
  // Wait account service ready (can be restarted)
@@ -29131,6 +29162,9 @@ class AbstractUserEventService extends BaseGraphqlService {
29131
29162
  this.startListenCountChanges();
29132
29163
  }
29133
29164
  onLogout() {
29165
+ // Reset counter
29166
+ this._countSubject.next(0);
29167
+ // Stop listening
29134
29168
  this.stopListenCountChanges();
29135
29169
  }
29136
29170
  startListenCountChanges() {