@esfaenza/es-table 19.2.21 → 19.2.23

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.
@@ -9,7 +9,7 @@ import * as i1 from '@angular/forms';
9
9
  import { FormsModule } from '@angular/forms';
10
10
  import * as i5$1 from 'primeng/select';
11
11
  import { SelectModule } from 'primeng/select';
12
- import { Subject, forkJoin, fromEvent, takeUntil } from 'rxjs';
12
+ import { ReplaySubject, Subject, forkJoin, fromEvent, takeUntil } from 'rxjs';
13
13
  import * as i13 from '@angular/cdk/drag-drop';
14
14
  import { moveItemInArray, DragDropModule } from '@angular/cdk/drag-drop';
15
15
  import * as i2$1 from '@esfaenza/preferences';
@@ -474,7 +474,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImpo
474
474
 
475
475
  class ThTdProvider {
476
476
  constructor() {
477
- this.LoadedSignal = new Subject();
477
+ this.LoadedSignal = new ReplaySubject();
478
478
  }
479
479
  setLoaded() {
480
480
  requestAnimationFrame(() => {
@@ -4357,15 +4357,15 @@ class EsTableComponent {
4357
4357
  if (usesThsAndTdsDirectives || hasNoContentProjection) {
4358
4358
  if (this.UseCustomCells() == null)
4359
4359
  this.UseCustomCells.set(true);
4360
- if (this.HiddenColumns() == null && this.UseCustomCells)
4360
+ if (this.HiddenColumns() == null && this.UseCustomCells())
4361
4361
  this.HiddenColumns.set(true);
4362
- if (this.ColumnsOrdering() == null && this.UseCustomCells)
4362
+ if (this.ColumnsOrdering() == null && this.UseCustomCells())
4363
4363
  this.ColumnsOrdering.set(true);
4364
- if (this.OrderByColumn() == null && this.UseCustomCells)
4364
+ if (this.OrderByColumn() == null && this.UseCustomCells())
4365
4365
  this.OrderByColumn.set(true);
4366
- if (this.SelectAll() == null && this.Selection)
4366
+ if (this.SelectAll() == null && this.Selection())
4367
4367
  this.SelectAll.set(true);
4368
- if (this.ShiftClick() == null && this.Selection)
4368
+ if (this.ShiftClick() == null && this.Selection())
4369
4369
  this.ShiftClick.set(true);
4370
4370
  this.DirectivesBased.set(true);
4371
4371
  }
@@ -4404,6 +4404,11 @@ class EsTableComponent {
4404
4404
  /** @ignore */
4405
4405
  async writeValue(obj, throttle = true) {
4406
4406
  this.View = obj ? obj : null;
4407
+ // Qui il concetto è "devo aspettare che l'afterViewInit venga eseguito prima di eseguire questo"
4408
+ // E dato che entrambi aspettano sui provider li faccio così
4409
+ let thsTdsProviders = [...(this.EsThTdProvider ? [this.EsThTdProvider] : []), ...(this.ThTdProvider || [])];
4410
+ if (thsTdsProviders?.length > 0)
4411
+ await forkJoin(thsTdsProviders.map(t => t.LoadedSignal)).toPromise();
4407
4412
  if (this.EsTableHandledSearch() && throttle) {
4408
4413
  if (this.callTimeout)
4409
4414
  clearTimeout(this.callTimeout);
@@ -4426,13 +4431,14 @@ class EsTableComponent {
4426
4431
  else if (this.SearchView() && typeof this.SearchView().itemsperpageoverride != 'undefined' && !(this.SearchView() instanceof AppSearch))
4427
4432
  this.SearchView().__proto__ = new AppSearch();
4428
4433
  // -------------------------------------------------------------------------------------------------------------------------
4434
+ let isp = this.ItemSourceProperty();
4429
4435
  if (this.View && this.View instanceof AppSearch) {
4430
4436
  // Se cambia l'oggetto intero significa che ho rimandato la ricerca
4431
4437
  this.setMode('view');
4432
4438
  let firstItemGroupOrNoGrouping = (this.View.requestedgroups?.length || 0) == 0;
4433
4439
  // Queste sono item source custom. Le valorizzo al default se non esistono
4434
- if (this.ItemSourceProperty() && !this.View[this.ItemSourceProperty()])
4435
- this.View[this.ItemSourceProperty()] = [];
4440
+ if (isp && !this.View[isp])
4441
+ this.View[isp] = [];
4436
4442
  // Se vengo da una ricerca interna mantengo lo stato di selezione precedente (quindi su cambio pagina, cambio ipp, ecc...)
4437
4443
  // se invece l'utente ha fatto una ricerca lui (quindi cambiando filtri), secco le info di selezione
4438
4444
  if (!this.View.selection || (!this.View.internalsearchrequest && firstItemGroupOrNoGrouping) || !this.UseSelectionCache())
@@ -4491,7 +4497,7 @@ class EsTableComponent {
4491
4497
  }
4492
4498
  }
4493
4499
  if (firstItemGroupOrNoGrouping)
4494
- this.arrayPulsanti.set(this.utilities_H.getPagesArray(6, this.View.page, this.View.pages || 1, (this.ItemSourceProperty() ? this.View[this.ItemSourceProperty()] : this.View.items).length, this.View.itemsperpageoverride));
4500
+ this.arrayPulsanti.set(this.utilities_H.getPagesArray(6, this.View.page, this.View.pages || 1, (isp ? this.View[isp] : this.View.items).length, this.View.itemsperpageoverride));
4495
4501
  }
4496
4502
  else if (this.View && (this.View.length != null && this.View.length != undefined)) {
4497
4503
  this.setMode('array');
@@ -4541,12 +4547,14 @@ class EsTableComponent {
4541
4547
  }
4542
4548
  this.finalizeContext();
4543
4549
  this.postBoundSourceCalculation();
4544
- if (this.View && !this.View.selfsearch && this.EsTableHandledSearch() && !this.View.firstsearch) {
4550
+ if (!this.EsTableHandledSearch() || !this.View)
4551
+ return;
4552
+ if (!this.View.selfsearch && !this.View.firstsearch) {
4545
4553
  this.View.selfsearch = true;
4546
4554
  this.changed(true);
4547
4555
  this.onSearchRequest.emit(false);
4548
4556
  }
4549
- else if (this.View && this.View.selfsearch && this.EsTableHandledSearch()) {
4557
+ else if (this.View.selfsearch) {
4550
4558
  this.View.selfsearch = false;
4551
4559
  this.changed();
4552
4560
  }
@@ -4585,22 +4593,23 @@ class EsTableComponent {
4585
4593
  this.PagerOptions.ShowButtons = !this.HidePagingButtons();
4586
4594
  this.PagerOptions.ShowPaging = !this.HidePaging();
4587
4595
  this.PagerOptions.UsesView = true;
4588
- if (this.arrayMode() && this.UseArrayModePaging() && !this.SearchView()) {
4596
+ let sv = this.SearchView();
4597
+ if (this.arrayMode() && this.UseArrayModePaging() && !sv) {
4589
4598
  this.PagerOptions.PagerCount = this.View.length || 0;
4590
4599
  this.PagerOptions.ShowButtons = this.PagerOptions.ShowButtons && this.View.length > 10;
4591
4600
  this.PagerOptions.View = this.View;
4592
4601
  this.PagerOptions.UsesView = false;
4593
4602
  this.PagerOptions.ShowPagingOptions = this.PagerOptions.ShowButtons;
4594
4603
  }
4595
- else if (this.arrayMode() && (!this.UseArrayModePaging() || this.SearchView())) {
4596
- if (this.SearchView()) {
4597
- this.PagerOptions.View = this.SearchView();
4598
- this.PagerOptions.PagerCount = this.SearchView().objectcount || 0;
4604
+ else if (this.arrayMode() && (!this.UseArrayModePaging() || sv)) {
4605
+ if (sv) {
4606
+ this.PagerOptions.View = sv;
4607
+ this.PagerOptions.PagerCount = sv.objectcount || 0;
4599
4608
  }
4600
4609
  else
4601
4610
  this.PagerOptions.PagerCount = this.View.length || 0;
4602
- this.PagerOptions.ShowButtons = this.PagerOptions.ShowButtons && (this.View.length > 10 || (this.SearchView()?.objectcount || 0) > 10);
4603
- this.PagerOptions.ShowCount = this.PagerOptions.ShowCount || (this.View && this.View.length) || (this.SearchView() && this.SearchView().objectcount && this.SearchView().objectcount != -1);
4611
+ this.PagerOptions.ShowButtons = this.PagerOptions.ShowButtons && (this.View.length > 10 || (sv?.objectcount || 0) > 10);
4612
+ this.PagerOptions.ShowCount = this.PagerOptions.ShowCount || (this.View && this.View.length) || (sv && sv.objectcount && sv.objectcount != -1);
4604
4613
  this.PagerOptions.ShowPaging = this.PagerOptions.ShowPaging && (this.PagerOptions.ShowButtons || this.PagerOptions.ShowCount);
4605
4614
  this.PagerOptions.ShowPagingOptions = this.PagerOptions.ShowButtons;
4606
4615
  }
@@ -4629,9 +4638,11 @@ class EsTableComponent {
4629
4638
  /** Per poter distinguere le chiamate a questo metodo: Dopo il setTimeout se uso gli EsTd/EsTh vecchi, senza il setTimeout se uso le nuove direttive */
4630
4639
  async internalPostBoundSource() {
4631
4640
  let View = this.View;
4632
- let thsTdsProviders = [...(this.EsThTdProvider ? [this.EsThTdProvider] : []), ...this.ThTdProvider];
4633
- if (thsTdsProviders?.length > 0)
4634
- await forkJoin(thsTdsProviders.map(t => t.LoadedSignal)).toPromise();
4641
+ let viewMode = this.viewMode();
4642
+ let arrayMode = this.arrayMode();
4643
+ let isp = this.ItemSourceProperty();
4644
+ let customCells = this.UseCustomCells();
4645
+ let dynColDefs = this.DynamicRowColumnsDefinition();
4635
4646
  // Se non ho colonne dinamiche ma sono in modalità dinamica (lo capisco perché c'è una view piena di genericitem) metto il default delle colonne
4636
4647
  this.dynamicMode_H.eventuallyReviewDynamicColumns();
4637
4648
  // Gestisce la richiesta per gruppi o per singoli oggetti
@@ -4639,14 +4650,14 @@ class EsTableComponent {
4639
4650
  // Questo dev'essere per forza lanciato dopo **bindDisplayToLoadedItemsOrGroups** dato che è lì che alcune cose vengono valorizzate
4640
4651
  this.setupPagingInformations();
4641
4652
  // Molte cose sono ovviamente disponibili solo in modalità View
4642
- if ((this.viewMode() || this.arrayMode()) && this.UseCustomCells()) {
4643
- let view = this.viewMode() ? View : null;
4644
- let itemsAndGroups = this.viewMode() ? [...((this.ItemSourceProperty() ? view[this.ItemSourceProperty()] : view.items) || []), ...(view.groups || [])] : View;
4645
- let si = this.viewMode() ? view.selection : this.arraymodeSelection;
4653
+ if ((viewMode || arrayMode) && customCells) {
4654
+ let view = viewMode ? View : null;
4655
+ let itemsAndGroups = viewMode ? [...((isp ? view[isp] : view.items) || []), ...(view.groups || [])] : View;
4656
+ let si = viewMode ? view.selection : this.arraymodeSelection;
4646
4657
  // N.B: Rispettare l'ordine di queste 3 macrocategorie è VITALE
4647
4658
  // ************************************* Sistemazioni di TH, TD, e visibilità varie *************************************
4648
4659
  // Se ho definizioni dinamiche, prima di qualsiasi altra cosa devo trasformarle in th/td in modo che poi il codice qui sotto faccia le sue magie
4649
- if ((this.DynamicRowColumnsDefinition()?.length || 0) > 0) {
4660
+ if ((dynColDefs?.length || 0) > 0) {
4650
4661
  this.logger.log("Generating ths and tds from Dynamic definition");
4651
4662
  let ret = this.dynamicMode_H.emitThsAndTdsBasedOnDynamicDefinition();
4652
4663
  this.EsThs = ret.ths;
@@ -4672,7 +4683,7 @@ class EsTableComponent {
4672
4683
  // Prepassaggio per tirare fuori tutte le info utili sugli headers in modo da non ricacolarseli sempre dopo
4673
4684
  let hI = this.columnMetadata_H.evaluateHeadersGroupingInfos(this.EsThs);
4674
4685
  // Valuta lo stato iniziale di selezione a range
4675
- this.selection_H.evaluateSingleCellSelection(itemsAndGroups, hI.leafs, this.DynamicRowColumnsDefinition());
4686
+ this.selection_H.evaluateSingleCellSelection(itemsAndGroups, hI.leafs, dynColDefs);
4676
4687
  if (this.arrayMode()) // In modalità array non ho un backend...
4677
4688
  this.rowGrouping_H.arrayModeReviewGroupings(hI.leafs); // ... i raggruppamenti li devo fare lato client
4678
4689
  this.columnMetadata_H.reviewColumnsList(hI.leafs); // Aggiorna la lista delle colonne da mostrare nella dialog per ordinamento ecc
@@ -4696,10 +4707,10 @@ class EsTableComponent {
4696
4707
  this.ResearchNeeded = false;
4697
4708
  }
4698
4709
  }
4699
- else if ((this.viewMode() || this.arrayMode()) && !this.UseCustomCells()) {
4710
+ else if ((viewMode || arrayMode) && !customCells) {
4700
4711
  // Riallineo le info di selezione degli elementi della View
4701
- let items = this.viewMode() ? (this.ItemSourceProperty() ? View[this.ItemSourceProperty()] : View.items) : View;
4702
- let si = this.viewMode() ? View.selection : this.arraymodeSelection;
4712
+ let items = viewMode ? (isp ? View[isp] : View.items) : View;
4713
+ let si = viewMode ? View.selection : this.arraymodeSelection;
4703
4714
  this.selection_H.evaluateSelection(items, si);
4704
4715
  }
4705
4716
  // Per essere sicuro che dopo un bind di oggetti la es-table aggiorni la grafica
@@ -4853,11 +4864,12 @@ class EsTableComponent {
4853
4864
  columnsCache[col.id] = col;
4854
4865
  }
4855
4866
  this.TMPRowTDs = {};
4867
+ let bs = this.boundSource();
4868
+ let defaultAlignment = this.DefaultAlignment();
4856
4869
  // Variabile d'appoggio per permettermi di inserire tutte le colonne "Fixed" davanti
4857
4870
  let contextFixeds = {};
4858
4871
  for (let i = 0; i < tds.length; i++) {
4859
4872
  let td = tds[i];
4860
- let bs = this.boundSource();
4861
4873
  for (let i = 0; i < bs.length; i++) {
4862
4874
  let item = bs[i];
4863
4875
  let ctx = item._hash;
@@ -4890,7 +4902,7 @@ class EsTableComponent {
4890
4902
  Multi: td._multi,
4891
4903
  MultiProp: td._multi ? td.td.split('_')[0] : null,
4892
4904
  MultiIndex: td._multi ? td.td.split('_')[1] : null,
4893
- Alignment: (td.tdAlignment || th.thAlignment || this.DefaultAlignment()).toLowerCase(),
4905
+ Alignment: (td.tdAlignment || th.thAlignment || defaultAlignment).toLowerCase(),
4894
4906
  Format: td.tdFormat || th.thFormat,
4895
4907
  PropertyName: th.thProperty,
4896
4908
  PropertyType: th.thType,
@@ -5078,10 +5090,10 @@ class EsTableComponent {
5078
5090
  * @param {boolean} forcedVal Valore forzato di check da assegnare agli oggetti
5079
5091
  */
5080
5092
  globalCheckChanged(forcedVal = null) {
5081
- debugger;
5082
5093
  this.selection_H.clearSelectionStatusExcluding(null);
5094
+ let bs = this.boundSource();
5083
5095
  // Prendo tutti gli elementi presenti in questa vista. Se ho gruppi prendo solo i gruppi a livello 0, altrimenti prendo tutti gli oggetti per selezionarli
5084
- let items = this.boundSource().find(t => t._group) ? this.boundSource().filter(t => t._group && !t._parent) : this.boundSource();
5096
+ let items = bs.find(t => t._group) ? bs.filter(t => t._group && !t._parent) : bs;
5085
5097
  var itemSelection = this.selection_H.handleItemsSelection(items, forcedVal, this.globalCheck());
5086
5098
  this.changed();
5087
5099
  this.onSelectionChanged.emit(itemSelection);
@@ -5268,9 +5280,9 @@ class EsTableComponent {
5268
5280
  * Helper per effettuare chiamate interne di allineamento alla funzione **writeValue**,
5269
5281
  * impostando prima **internalWriteCall** in modo da non effettuare operazioni inutili
5270
5282
  */
5271
- internalWriteValue() {
5283
+ async internalWriteValue() {
5272
5284
  this.internalWriteCall = true;
5273
- this.writeValue(this.View);
5285
+ await this.writeValue(this.View);
5274
5286
  this.internalWriteCall = false;
5275
5287
  }
5276
5288
  /** Metodo eventualmente richiamabile anche dal componente esterno che permette di forzare un refresh della tabella */
@@ -5321,8 +5333,10 @@ class EsTableComponent {
5321
5333
  * @param {any} item Item che rappresenta il contesto su cui è stato effettuato un click
5322
5334
  */
5323
5335
  dbClickEditOrSingleClickRowSelection($event, rowItem, item) {
5336
+ let rowItm = rowItem();
5337
+ let selection = this.Selection();
5324
5338
  // Prima cosa da fare è controllare se ci sono dei range lasciati da operazioni precedenti (se applicabile) e ripulirli
5325
- if (this.rangeSelected && !$event.ctrlKey && this.Selection()) {
5339
+ if (this.rangeSelected && !$event.ctrlKey && selection) {
5326
5340
  this.logger.log("clearing previously selected range");
5327
5341
  this.selection_H.clearSelectionStatusExcluding(null);
5328
5342
  this.rangeSelected = false;
@@ -5332,11 +5346,11 @@ class EsTableComponent {
5332
5346
  if (this.Editable()) {
5333
5347
  // Secondo click: se il timer non è scaduto è un doppio click ed eseguo il resto
5334
5348
  if (this.cellDbClickTimer) {
5335
- this.logger.log("handling doubleclick on editable cell: " + (rowItem().PropertyName ? 'edit mode for property ' + rowItem().PropertyName : 'no property set, fallback to simple click'));
5336
- if (rowItem().PropertyName)
5349
+ this.logger.log("handling doubleclick on editable cell: " + (rowItm.PropertyName ? 'edit mode for property ' + rowItm.PropertyName : 'no property set, fallback to simple click'));
5350
+ if (rowItm.PropertyName)
5337
5351
  this.setupUserEdit(rowItem, item);
5338
5352
  else
5339
- this.handleRowClick($event, item, this.Selection(), true);
5353
+ this.handleRowClick($event, item, selection, true);
5340
5354
  this.clearCellClickTimer();
5341
5355
  return;
5342
5356
  }
@@ -5345,7 +5359,7 @@ class EsTableComponent {
5345
5359
  this.clearCellClickTimer();
5346
5360
  if (!this.RangeSelection() || !this.mouseIsDown) {
5347
5361
  this.logger.log("time's up for second click, handling single click");
5348
- this.handleRowClick($event, item, this.Selection(), true);
5362
+ this.handleRowClick($event, item, selection, true);
5349
5363
  }
5350
5364
  }, this.doubleClickBufferMs);
5351
5365
  }
@@ -5357,11 +5371,11 @@ class EsTableComponent {
5357
5371
  if ($event.ctrlKey)
5358
5372
  return;
5359
5373
  // Tutti i click su una cella già in edit non devono effettuare la selezione della riga
5360
- if (rowItem()._editing)
5374
+ if (rowItm._editing)
5361
5375
  return;
5362
5376
  // Per evitare di rallentare a prescindere
5363
5377
  if (!this.Editable()) {
5364
- this.handleRowClick($event, item, this.Selection(), true);
5378
+ this.handleRowClick($event, item, selection, true);
5365
5379
  return;
5366
5380
  }
5367
5381
  }
@@ -5465,10 +5479,11 @@ class EsTableComponent {
5465
5479
  */
5466
5480
  setupUserEdit(rowItem, item) {
5467
5481
  this.selection_H.clearSelectionStatusExcluding(null);
5468
- if (this.Editable() && rowItem().PropertyName) {
5482
+ let rowItm = rowItem();
5483
+ if (this.Editable() && rowItm.PropertyName) {
5469
5484
  let dynMode = (this.DynamicRowColumnsDefinition()?.length || 0) > 0;
5470
- let newValues = { _editing: true, old_value: dynMode ? item.properties[rowItem().PropertyName] : item[rowItem().PropertyName] };
5471
- rowItem.set(Object.assign(rowItem(), newValues));
5485
+ let newValues = { _editing: true, old_value: dynMode ? item.properties[rowItm.PropertyName] : item[rowItm.PropertyName] };
5486
+ rowItem.set(Object.assign(rowItm, newValues));
5472
5487
  }
5473
5488
  this.cdr.detectChanges();
5474
5489
  requestAnimationFrame(() => { this.FocusSubject.next(); });
@@ -5485,14 +5500,15 @@ class EsTableComponent {
5485
5500
  requestAnimationFrame(() => {
5486
5501
  let dynMode = (this.DynamicRowColumnsDefinition()?.length || 0) > 0;
5487
5502
  let newValues = { _editing: false };
5488
- rowItem.set(Object.assign(rowItem(), newValues));
5489
- let old = rowItem().old_value;
5490
- let niu = dynMode ? item.properties[rowItem().PropertyName] : item[rowItem().PropertyName];
5503
+ let newRowItem = Object.assign(rowItem(), newValues);
5504
+ rowItem.set(newRowItem);
5505
+ let old = newRowItem.old_value;
5506
+ let niu = dynMode ? item.properties[newRowItem.PropertyName] : item[newRowItem.PropertyName];
5491
5507
  let olddate = this.dateExts.getDateConvertion(old);
5492
5508
  let niudate = this.dateExts.getDateConvertion(niu);
5493
5509
  if ((olddate && niudate && olddate.isSame && olddate.isSame(niudate)) || old === niu)
5494
5510
  return;
5495
- this.onModelChange.emit([new EsTableModelChange(item, rowItem().ID, rowItem().PropertyName, old, niu)]);
5511
+ this.onModelChange.emit([new EsTableModelChange(item, newRowItem.ID, newRowItem.PropertyName, old, niu)]);
5496
5512
  this.selectionStatus[item._ordinal][columnIndex].val_setter(niu);
5497
5513
  });
5498
5514
  }