@ecodev/natural 38.1.0 → 41.1.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.
@@ -2941,7 +2941,7 @@ function unwrapNavigable(item) {
2941
2941
  * Components inheriting from this class can be used as standalone with input attributes.
2942
2942
  *
2943
2943
  * Usage :
2944
- * <natural-my-listing [forcedVariables]="{filter:...}" [initialColumns]="['col1']" [persistSearch]="false">
2944
+ * <natural-my-listing [forcedVariables]="{filter:...}" [selectedColumns]="['col1']" [persistSearch]="false">
2945
2945
  */
2946
2946
  // @dynamic
2947
2947
  class NaturalAbstractList extends NaturalAbstractPanel {
@@ -2956,7 +2956,7 @@ class NaturalAbstractList extends NaturalAbstractPanel {
2956
2956
  /**
2957
2957
  * Columns list after interaction with <natural-columns-picker>
2958
2958
  */
2959
- this._selectedColumns = [];
2959
+ this.columnsForTable = [];
2960
2960
  /**
2961
2961
  * The default column selection that automatically happened after <natural-columns-picker> initialization
2962
2962
  */
@@ -3199,7 +3199,7 @@ class NaturalAbstractList extends NaturalAbstractPanel {
3199
3199
  * Uses data provided by router such as:
3200
3200
  *
3201
3201
  * - `route.data.forcedVariables`
3202
- * - `route.data.initialColumns`
3202
+ * - `route.data.selectedColumns`
3203
3203
  */
3204
3204
  initFromRoute() {
3205
3205
  // Variables
@@ -3207,8 +3207,8 @@ class NaturalAbstractList extends NaturalAbstractPanel {
3207
3207
  this.applyForcedVariables(this.route.snapshot.data.forcedVariables);
3208
3208
  }
3209
3209
  // Columns
3210
- if (this.route.snapshot.data.initialColumns) {
3211
- this.initialColumns = this.route.snapshot.data.initialColumns;
3210
+ if (this.route.snapshot.data.selectedColumns) {
3211
+ this.selectedColumns = this.route.snapshot.data.selectedColumns;
3212
3212
  }
3213
3213
  }
3214
3214
  getDataObservable() {
@@ -3234,6 +3234,11 @@ class NaturalAbstractList extends NaturalAbstractPanel {
3234
3234
  if (sorting) {
3235
3235
  this.variablesManager.set('sorting', { sorting });
3236
3236
  }
3237
+ // Columns
3238
+ const persistedColumns = this.persistenceService.get('col', this.route, storageKey);
3239
+ if (typeof persistedColumns === 'string') {
3240
+ this.selectedColumns = persistedColumns.split(',');
3241
+ }
3237
3242
  // Natural search : ns
3238
3243
  this.naturalSearchSelections = fromUrl(this.persistenceService.get('ns', this.route, storageKey));
3239
3244
  this.translateSearchAndRefreshList(this.naturalSearchSelections, true);
@@ -3289,23 +3294,14 @@ class NaturalAbstractList extends NaturalAbstractPanel {
3289
3294
  this.variablesManager.set('sorting', { sorting: variables.sorting });
3290
3295
  }
3291
3296
  }
3292
- get selectedColumns() {
3293
- return this._selectedColumns;
3294
- }
3295
- set selectedColumns(columns) {
3296
- this._selectedColumns = columns;
3297
+ selectColumns(columns) {
3298
+ this.columnsForTable = columns;
3297
3299
  if (!this.persistSearch || this.isPanel) {
3298
3300
  return;
3299
3301
  }
3300
3302
  // The first selection we receive is the default one made by <natural-columns-picker>
3301
3303
  if (!this.defaultSelectedColumns) {
3302
3304
  this.defaultSelectedColumns = columns;
3303
- // Now that we know the defaults, we can try to reload from persistence
3304
- const storageKey = this.getStorageKey();
3305
- const persistedColumns = this.persistenceService.get('col', this.route, storageKey);
3306
- if (typeof persistedColumns === 'string') {
3307
- this.selectedColumns = persistedColumns.split(',');
3308
- }
3309
3305
  }
3310
3306
  else {
3311
3307
  // Persist only if wanted columns are different from default selection
@@ -3323,7 +3319,7 @@ NaturalAbstractList.ctorParameters = () => [
3323
3319
  ];
3324
3320
  NaturalAbstractList.propDecorators = {
3325
3321
  persistSearch: [{ type: Input }],
3326
- initialColumns: [{ type: Input }],
3322
+ selectedColumns: [{ type: Input }],
3327
3323
  forcedVariables: [{ type: Input }]
3328
3324
  };
3329
3325
 
@@ -4342,19 +4338,37 @@ class NaturalColumnsPickerComponent {
4342
4338
  constructor(changeDetectorRef) {
4343
4339
  this.changeDetectorRef = changeDetectorRef;
4344
4340
  /**
4345
- * Emit a list of column keys whenever the selection changes
4341
+ * Emit a list of valid and selected column keys whenever the selection changes
4346
4342
  */
4347
4343
  this.selectionChange = new EventEmitter();
4348
- this.defaultSelectionChange = new EventEmitter();
4344
+ /**
4345
+ * Available columns are defined by options in the template
4346
+ */
4349
4347
  this.availableColumns = null;
4348
+ /**
4349
+ * Displayed options in the dropdown menu
4350
+ */
4350
4351
  this.displayedColumns = [];
4351
4352
  this.ngUnsubscribe = new Subject();
4352
4353
  }
4353
- set selection(columns) {
4354
+ /**
4355
+ * Set the columns that are wanted but might be unavailable.
4356
+ *
4357
+ * If a column is unavailable it will be ignored silently. To know what columns were actually applied
4358
+ * you should use `selectionChange`.
4359
+ *
4360
+ * It is often set once on component initialization, but it can also be set again later in the lifespan of the component.
4361
+ */
4362
+ set selections(columns) {
4354
4363
  var _a;
4364
+ this._selections = columns;
4365
+ if (!columns || !this.availableColumns) {
4366
+ return;
4367
+ }
4355
4368
  (_a = this.availableColumns) === null || _a === void 0 ? void 0 : _a.forEach(col => {
4356
4369
  col.checked = columns.includes(col.key);
4357
4370
  });
4371
+ this.updateColumns();
4358
4372
  }
4359
4373
  ngAfterViewInit() {
4360
4374
  cancellableTimeout(this.ngUnsubscribe).subscribe(() => {
@@ -4366,8 +4380,10 @@ class NaturalColumnsPickerComponent {
4366
4380
  initColumns() {
4367
4381
  var _a, _b, _c;
4368
4382
  (_a = this.availableColumns) === null || _a === void 0 ? void 0 : _a.forEach(col => {
4369
- col.checked = this.initialSelection ? this.initialSelection.includes(col.key) : col.checked;
4383
+ var _a;
4384
+ col.checked = ((_a = this._selections) === null || _a === void 0 ? void 0 : _a.length) ? this._selections.includes(col.key) : col.checked;
4370
4385
  });
4386
+ // Show options only for columns that are not hidden
4371
4387
  this.displayedColumns = (_c = (_b = this.availableColumns) === null || _b === void 0 ? void 0 : _b.filter(col => !col.hidden)) !== null && _c !== void 0 ? _c : [];
4372
4388
  }
4373
4389
  updateColumns() {
@@ -4391,10 +4407,8 @@ NaturalColumnsPickerComponent.ctorParameters = () => [
4391
4407
  { type: ChangeDetectorRef }
4392
4408
  ];
4393
4409
  NaturalColumnsPickerComponent.propDecorators = {
4394
- selection: [{ type: Input }],
4410
+ selections: [{ type: Input }],
4395
4411
  selectionChange: [{ type: Output }],
4396
- defaultSelectionChange: [{ type: Output }],
4397
- initialSelection: [{ type: Input }],
4398
4412
  availableColumns: [{ type: ContentChildren, args: [NaturalColumnsPickerColumnDirective,] }]
4399
4413
  };
4400
4414
 
@@ -6517,7 +6531,7 @@ class NaturalHierarchicSelectorDialogComponent {
6517
6531
  }
6518
6532
  NaturalHierarchicSelectorDialogComponent.decorators = [
6519
6533
  { type: Component, args: [{
6520
- template: "<h2 i18n mat-dialog-title>S\u00E9lection</h2>\n\n<mat-dialog-content>\n <natural-hierarchic-selector\n (selectionChange)=\"config.hierarchicSelection = $event\"\n [selected]=\"config.hierarchicSelection ?? {}\"\n [config]=\"config.hierarchicConfig\"\n [filters]=\"config.hierarchicFilters\"\n [multiple]=\"config.multiple ?? false\"\n [allowUnselect]=\"config.allowUnselect ?? true\"\n [searchFacets]=\"config.searchFacets ?? []\"\n [searchSelections]=\"config.searchSelections ?? []\"\n (searchSelectionChange)=\"searchSelectionsOutput = $event\"\n ></natural-hierarchic-selector>\n</mat-dialog-content>\n\n<mat-dialog-actions>\n <button [mat-dialog-close] i18n mat-button>Annuler</button>\n <button (click)=\"close(config.hierarchicSelection)\" color=\"primary\" mat-raised-button\n ><span i18n>Valider</span>\n </button>\n</mat-dialog-actions>\n",
6534
+ template: "<h2 i18n mat-dialog-title>S\u00E9lection</h2>\n\n<mat-dialog-content>\n <natural-hierarchic-selector\n (selectionChange)=\"config.hierarchicSelection = $event\"\n [selected]=\"config.hierarchicSelection ?? {}\"\n [config]=\"config.hierarchicConfig\"\n [filters]=\"config.hierarchicFilters\"\n [multiple]=\"config.multiple ?? false\"\n [allowUnselect]=\"config.allowUnselect ?? true\"\n [searchFacets]=\"config.searchFacets ?? []\"\n [searchSelections]=\"config.searchSelections ?? []\"\n (searchSelectionChange)=\"searchSelectionsOutput = $event\"\n ></natural-hierarchic-selector>\n</mat-dialog-content>\n\n<mat-dialog-actions>\n <button [mat-dialog-close] mat-button i18n>Annuler</button>\n <button (click)=\"close(config.hierarchicSelection)\" color=\"primary\" mat-raised-button\n ><span i18n>Valider</span>\n </button>\n</mat-dialog-actions>\n",
6521
6535
  styles: [":host mat-dialog-actions{display:flex;flex-direction:row;justify-content:flex-end}\n"]
6522
6536
  },] }
6523
6537
  ];
@@ -7948,6 +7962,13 @@ class NaturalAbstractFile extends NaturalAbstractController {
7948
7962
  * no effect.
7949
7963
  */
7950
7964
  this.selectable = false;
7965
+ /**
7966
+ * If true, the file selection will be broadcast through `NaturalFileService.filesChanged`.
7967
+ *
7968
+ * It is useful to set this to false if there is two upload on a page with different purpose
7969
+ * and the second upload should not be confused with the first one.
7970
+ */
7971
+ this.broadcast = true;
7951
7972
  /**
7952
7973
  * The single valid file that has been selected.
7953
7974
  *
@@ -8028,7 +8049,9 @@ class NaturalAbstractFile extends NaturalAbstractController {
8028
8049
  }
8029
8050
  if (selection.valid.length || selection.invalid.length) {
8030
8051
  this.filesChange.emit(selection);
8031
- this.naturalFileService.filesChanged.next(selection);
8052
+ if (this.broadcast) {
8053
+ this.naturalFileService.filesChanged.next(selection);
8054
+ }
8032
8055
  }
8033
8056
  this.getFileElement().value = '';
8034
8057
  }
@@ -8105,6 +8128,7 @@ NaturalAbstractFile.propDecorators = {
8105
8128
  maxSize: [{ type: Input }],
8106
8129
  fileSelectionDisabled: [{ type: Input }],
8107
8130
  selectable: [{ type: Input }],
8131
+ broadcast: [{ type: Input }],
8108
8132
  fileChange: [{ type: Output }],
8109
8133
  filesChange: [{ type: Output }],
8110
8134
  onChange: [{ type: HostListener, args: ['change', ['$event'],] }]
@@ -8186,7 +8210,9 @@ class NaturalFileDropDirective extends NaturalAbstractFile {
8186
8210
  this.closeDrags();
8187
8211
  }
8188
8212
  hasObservers() {
8189
- return this.fileChange.observed || this.filesChange.observed || this.naturalFileService.filesChanged.observed;
8213
+ return (this.fileChange.observed ||
8214
+ this.filesChange.observed ||
8215
+ (this.broadcast && this.naturalFileService.filesChanged.observed));
8190
8216
  }
8191
8217
  }
8192
8218
  NaturalFileDropDirective.decorators = [