@one-paragon/angular-utilities 2.2.5 → 2.2.7

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.
@@ -861,6 +861,7 @@ class TableSettings {
861
861
  this.rowHeight = undefined;
862
862
  this.groupHeaderHeight = undefined;
863
863
  this.rowClick = undefined;
864
+ this.exportSettings = undefined;
864
865
  }
865
866
  }
866
867
  class PersistedTableSettings {
@@ -898,6 +899,7 @@ class NotPersistedTableSettings {
898
899
  this.groupHeaderHeight = undefined;
899
900
  this.headerHeight = undefined;
900
901
  this.rowClick = undefined;
902
+ this.exportSettings = undefined;
901
903
  }
902
904
  merge(tableSettings) {
903
905
  const newNpts = merge$1(this, new NotPersistedTableSettings());
@@ -921,6 +923,7 @@ class NotPersistedTableSettings {
921
923
  newNpts.rowClasses = tableSettings.tableSettings?.rowClasses ?? newNpts.rowClasses;
922
924
  newNpts.rowStyles = tableSettings.tableSettings?.rowStyles ?? newNpts.rowStyles;
923
925
  newNpts.rowClick = tableSettings.tableSettings?.rowClick ?? newNpts.rowClick;
926
+ newNpts.exportSettings = tableSettings.tableSettings?.exportSettings ?? newNpts.exportSettings;
924
927
  if (tableSettings.tableSettings?.virtualScrollSettings) {
925
928
  const currVirt = tableSettings.tableSettings?.virtualScrollSettings || newNpts.virtualSettings;
926
929
  if (!currVirt.headerHeight) {
@@ -4538,6 +4541,17 @@ class ExportToCsvService {
4538
4541
  this.state = inject(TableStore);
4539
4542
  this.config = inject(TableBuilderConfigToken);
4540
4543
  this.datePipe = inject(DatePipe);
4544
+ this.$exportSettings = computed(() => {
4545
+ const globalSettings = this.config?.defaultTableSettings?.tableSettings?.exportSettings
4546
+ || this.config?.export
4547
+ || {};
4548
+ const globalLinkOptions = globalSettings.mapLinkOptions || {};
4549
+ const flattenedGlobal = { ...globalSettings, ...globalLinkOptions };
4550
+ const tableSettings = (this.state.$notPersistedTableSettings()?.exportSettings || {});
4551
+ const tableLinkOptions = tableSettings.mapLinkOptions || {};
4552
+ const flattenedTable = { ...tableSettings, ...tableLinkOptions };
4553
+ return merge$1(flattenedGlobal, flattenedTable);
4554
+ });
4541
4555
  this.exportToCsv = (data) => {
4542
4556
  const hiddenKeys = this.state.selectSignal(s => s.hiddenKeys)();
4543
4557
  const meta = this.state.$metaDataArray().filter(md => !md.noExport && !hiddenKeys.includes(md.key));
@@ -4550,6 +4564,10 @@ class ExportToCsvService {
4550
4564
  return res.join('\n');
4551
4565
  };
4552
4566
  this.metaToField = (meta, row) => {
4567
+ const metaExport = meta.additional?.export;
4568
+ if (metaExport?.mapForExport)
4569
+ return metaExport.mapForExport(row);
4570
+ const exportForCol = merge$1({}, this.$exportSettings(), metaExport);
4553
4571
  let val = getFactory(meta.key)(row);
4554
4572
  if (val == null && !meta.transform)
4555
4573
  return val;
@@ -4557,39 +4575,56 @@ class ExportToCsvService {
4557
4575
  const transform = meta.transform;
4558
4576
  return isPipe(transform) ? transform.transform(val) : transform(val);
4559
4577
  }
4560
- if (meta.map) {
4561
- return meta.map(row);
4562
- }
4563
- switch (meta.fieldType) {
4564
- case FieldType.Date:
4565
- const dateFormat = meta.additional?.export?.dateFormat || this.config?.export?.dateFormat || meta.additional?.dateFormat;
4566
- val = this.transform(val, dateFormat);
4567
- break;
4568
- case FieldType.DateTime:
4569
- const dateTimeFormat = meta.additional?.export?.dateTimeFormat || this.config?.export?.dateTimeFormat || meta.additional?.dateTimeOptions?.format;
4570
- val = this.transform(val, dateTimeFormat);
4571
- break;
4572
- case FieldType.String:
4573
- const prepend = meta.additional?.export?.prepend || this.config?.export?.prepend || '';
4574
- val = prepend + val;
4575
- break;
4576
- case FieldType.Array:
4577
- const style = meta.additional.arrayStyle ?? this.config.arrayDefaults?.arrayStyle;
4578
- const limit = meta.additional.limit ?? this.config.arrayDefaults?.limit;
4579
- val = val.slice(0, limit).join(style === ArrayStyle.NewLine ? '\n' : ', ');
4580
- break;
4581
- case FieldType.Expression:
4582
- val = meta.transform(row);
4583
- break;
4584
- }
4585
- if (typeof val === 'string' && (val.includes(',') || val.includes('"') || val.includes('\n'))) {
4586
- val = val.replaceAll('"', '""');
4587
- val = '"' + val + '"';
4578
+ if (meta.additional?.link && exportForCol.mapLinkToString) {
4579
+ let mapper = this.state.$getLinkInfo(meta)()?.link;
4580
+ if (mapper) {
4581
+ let mapped = mapper(row);
4582
+ if (exportForCol.domainPrefix) {
4583
+ mapped = `${exportForCol.domainPrefix}/${mapped}`;
4584
+ }
4585
+ if (exportForCol.excellStyle) {
4586
+ mapped = this.cleanValForCsv(`=hyperlink("${mapped}", "${this.stringByType(meta, row, val, exportForCol)}")`);
4587
+ }
4588
+ return mapped;
4589
+ }
4588
4590
  }
4591
+ val = this.cleanValForCsv(this.stringByType(meta, row, val, exportForCol));
4589
4592
  return val;
4590
4593
  };
4591
4594
  }
4592
- transform(val, dateFormat) {
4595
+ stringByType(meta, row, val, exportForCol) {
4596
+ if (meta.map) {
4597
+ return meta.map(row);
4598
+ }
4599
+ switch (meta.fieldType) {
4600
+ case FieldType.Date:
4601
+ const dateFormat = meta.additional?.export?.dateFormat || exportForCol?.dateFormat || meta.additional?.dateFormat;
4602
+ return this.transformDate(val, dateFormat);
4603
+ case FieldType.DateTime:
4604
+ const dateTimeFormat = meta.additional?.export?.dateTimeFormat || exportForCol?.dateTimeFormat || meta.additional?.dateTimeOptions?.format;
4605
+ return this.transformDate(val, dateTimeFormat);
4606
+ case FieldType.String:
4607
+ const prepend = meta.additional?.export?.prepend || exportForCol?.prepend || '';
4608
+ return prepend + val;
4609
+ case FieldType.Array:
4610
+ const style = meta.additional.arrayStyle ?? this.config.arrayDefaults?.arrayStyle;
4611
+ const limit = meta.additional.limit ?? this.config.arrayDefaults?.limit;
4612
+ return val.slice(0, limit).join(style === ArrayStyle.NewLine ? '\n' : ', ');
4613
+ case FieldType.Expression:
4614
+ return meta.transform(row);
4615
+ case FieldType.Enum:
4616
+ return exportForCol?.mapEnumToString ? spaceCase(meta.additional.enumMap[val]) : val;
4617
+ }
4618
+ return val;
4619
+ }
4620
+ cleanValForCsv(val) {
4621
+ if (typeof val === 'string' && (val.includes(', ') || val.includes('"') || val.includes('\n'))) {
4622
+ val = val.replaceAll('"', '""');
4623
+ val = '"' + val + '"';
4624
+ }
4625
+ return val;
4626
+ }
4627
+ transformDate(val, dateFormat) {
4593
4628
  if (this.config.transformers && this.config.transformers[FieldType.Date]) {
4594
4629
  return this.config.transformers[FieldType.Date](val);
4595
4630
  }