@ecodev/natural 38.1.0 → 40.0.0

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.
@@ -3372,7 +3372,7 @@
3372
3372
  * Components inheriting from this class can be used as standalone with input attributes.
3373
3373
  *
3374
3374
  * Usage :
3375
- * <natural-my-listing [forcedVariables]="{filter:...}" [initialColumns]="['col1']" [persistSearch]="false">
3375
+ * <natural-my-listing [forcedVariables]="{filter:...}" [selectedColumns]="['col1']" [persistSearch]="false">
3376
3376
  */
3377
3377
  // @dynamic
3378
3378
  var NaturalAbstractList = /** @class */ (function (_super) {
@@ -3388,7 +3388,7 @@
3388
3388
  /**
3389
3389
  * Columns list after interaction with <natural-columns-picker>
3390
3390
  */
3391
- _this._selectedColumns = [];
3391
+ _this.columnsForTable = [];
3392
3392
  /**
3393
3393
  * The default column selection that automatically happened after <natural-columns-picker> initialization
3394
3394
  */
@@ -3639,7 +3639,7 @@
3639
3639
  * Uses data provided by router such as:
3640
3640
  *
3641
3641
  * - `route.data.forcedVariables`
3642
- * - `route.data.initialColumns`
3642
+ * - `route.data.selectedColumns`
3643
3643
  */
3644
3644
  NaturalAbstractList.prototype.initFromRoute = function () {
3645
3645
  // Variables
@@ -3647,8 +3647,8 @@
3647
3647
  this.applyForcedVariables(this.route.snapshot.data.forcedVariables);
3648
3648
  }
3649
3649
  // Columns
3650
- if (this.route.snapshot.data.initialColumns) {
3651
- this.initialColumns = this.route.snapshot.data.initialColumns;
3650
+ if (this.route.snapshot.data.selectedColumns) {
3651
+ this.selectedColumns = this.route.snapshot.data.selectedColumns;
3652
3652
  }
3653
3653
  };
3654
3654
  NaturalAbstractList.prototype.getDataObservable = function () {
@@ -3674,6 +3674,11 @@
3674
3674
  if (sorting) {
3675
3675
  this.variablesManager.set('sorting', { sorting: sorting });
3676
3676
  }
3677
+ // Columns
3678
+ var persistedColumns = this.persistenceService.get('col', this.route, storageKey);
3679
+ if (typeof persistedColumns === 'string') {
3680
+ this.selectedColumns = persistedColumns.split(',');
3681
+ }
3677
3682
  // Natural search : ns
3678
3683
  this.naturalSearchSelections = fromUrl(this.persistenceService.get('ns', this.route, storageKey));
3679
3684
  this.translateSearchAndRefreshList(this.naturalSearchSelections, true);
@@ -3731,34 +3736,21 @@
3731
3736
  this.variablesManager.set('sorting', { sorting: variables.sorting });
3732
3737
  }
3733
3738
  };
3734
- Object.defineProperty(NaturalAbstractList.prototype, "selectedColumns", {
3735
- get: function () {
3736
- return this._selectedColumns;
3737
- },
3738
- set: function (columns) {
3739
- this._selectedColumns = columns;
3740
- if (!this.persistSearch || this.isPanel) {
3741
- return;
3742
- }
3743
- // The first selection we receive is the default one made by <natural-columns-picker>
3744
- if (!this.defaultSelectedColumns) {
3745
- this.defaultSelectedColumns = columns;
3746
- // Now that we know the defaults, we can try to reload from persistence
3747
- var storageKey = this.getStorageKey();
3748
- var persistedColumns = this.persistenceService.get('col', this.route, storageKey);
3749
- if (typeof persistedColumns === 'string') {
3750
- this.selectedColumns = persistedColumns.split(',');
3751
- }
3752
- }
3753
- else {
3754
- // Persist only if wanted columns are different from default selection
3755
- var value = lodashEs.isEqual(this.defaultSelectedColumns, columns) ? null : columns.join(',');
3756
- this.persistenceService.persist('col', value, this.route, this.getStorageKey());
3757
- }
3758
- },
3759
- enumerable: false,
3760
- configurable: true
3761
- });
3739
+ NaturalAbstractList.prototype.selectColumns = function (columns) {
3740
+ this.columnsForTable = columns;
3741
+ if (!this.persistSearch || this.isPanel) {
3742
+ return;
3743
+ }
3744
+ // The first selection we receive is the default one made by <natural-columns-picker>
3745
+ if (!this.defaultSelectedColumns) {
3746
+ this.defaultSelectedColumns = columns;
3747
+ }
3748
+ else {
3749
+ // Persist only if wanted columns are different from default selection
3750
+ var value = lodashEs.isEqual(this.defaultSelectedColumns, columns) ? null : columns.join(',');
3751
+ this.persistenceService.persist('col', value, this.route, this.getStorageKey());
3752
+ }
3753
+ };
3762
3754
  return NaturalAbstractList;
3763
3755
  }(NaturalAbstractPanel));
3764
3756
  NaturalAbstractList.decorators = [
@@ -3770,7 +3762,7 @@
3770
3762
  ]; };
3771
3763
  NaturalAbstractList.propDecorators = {
3772
3764
  persistSearch: [{ type: i0.Input }],
3773
- initialColumns: [{ type: i0.Input }],
3765
+ selectedColumns: [{ type: i0.Input }],
3774
3766
  forcedVariables: [{ type: i0.Input }]
3775
3767
  };
3776
3768
  var templateObject_1$6, templateObject_2$1, templateObject_3$1, templateObject_4$1;
@@ -4870,20 +4862,38 @@
4870
4862
  function NaturalColumnsPickerComponent(changeDetectorRef) {
4871
4863
  this.changeDetectorRef = changeDetectorRef;
4872
4864
  /**
4873
- * Emit a list of column keys whenever the selection changes
4865
+ * Emit a list of valid and selected column keys whenever the selection changes
4874
4866
  */
4875
4867
  this.selectionChange = new i0.EventEmitter();
4876
- this.defaultSelectionChange = new i0.EventEmitter();
4868
+ /**
4869
+ * Available columns are defined by options in the template
4870
+ */
4877
4871
  this.availableColumns = null;
4872
+ /**
4873
+ * Displayed options in the dropdown menu
4874
+ */
4878
4875
  this.displayedColumns = [];
4879
4876
  this.ngUnsubscribe = new rxjs.Subject();
4880
4877
  }
4881
- Object.defineProperty(NaturalColumnsPickerComponent.prototype, "selection", {
4878
+ Object.defineProperty(NaturalColumnsPickerComponent.prototype, "selections", {
4879
+ /**
4880
+ * Set the columns that are wanted but might be unavailable.
4881
+ *
4882
+ * If a column is unavailable it will be ignored silently. To know what columns were actually applied
4883
+ * you should use `selectionChange`.
4884
+ *
4885
+ * It is often set once on component initialization, but it can also be set again later in the lifespan of the component.
4886
+ */
4882
4887
  set: function (columns) {
4883
4888
  var _a;
4889
+ this._selections = columns;
4890
+ if (!columns || !this.availableColumns) {
4891
+ return;
4892
+ }
4884
4893
  (_a = this.availableColumns) === null || _a === void 0 ? void 0 : _a.forEach(function (col) {
4885
4894
  col.checked = columns.includes(col.key);
4886
4895
  });
4896
+ this.updateColumns();
4887
4897
  },
4888
4898
  enumerable: false,
4889
4899
  configurable: true
@@ -4900,8 +4910,10 @@
4900
4910
  var _this = this;
4901
4911
  var _a, _b, _c;
4902
4912
  (_a = this.availableColumns) === null || _a === void 0 ? void 0 : _a.forEach(function (col) {
4903
- col.checked = _this.initialSelection ? _this.initialSelection.includes(col.key) : col.checked;
4913
+ var _a;
4914
+ col.checked = ((_a = _this._selections) === null || _a === void 0 ? void 0 : _a.length) ? _this._selections.includes(col.key) : col.checked;
4904
4915
  });
4916
+ // Show options only for columns that are not hidden
4905
4917
  this.displayedColumns = (_c = (_b = this.availableColumns) === null || _b === void 0 ? void 0 : _b.filter(function (col) { return !col.hidden; })) !== null && _c !== void 0 ? _c : [];
4906
4918
  };
4907
4919
  NaturalColumnsPickerComponent.prototype.updateColumns = function () {
@@ -4926,10 +4938,8 @@
4926
4938
  { type: i0.ChangeDetectorRef }
4927
4939
  ]; };
4928
4940
  NaturalColumnsPickerComponent.propDecorators = {
4929
- selection: [{ type: i0.Input }],
4941
+ selections: [{ type: i0.Input }],
4930
4942
  selectionChange: [{ type: i0.Output }],
4931
- defaultSelectionChange: [{ type: i0.Output }],
4932
- initialSelection: [{ type: i0.Input }],
4933
4943
  availableColumns: [{ type: i0.ContentChildren, args: [NaturalColumnsPickerColumnDirective,] }]
4934
4944
  };
4935
4945