intelica-library-ui 0.1.189 → 0.1.190

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.
@@ -6424,7 +6424,7 @@ class HtmlToExcelService {
6424
6424
  horizontal: "center",
6425
6425
  wrapText: true,
6426
6426
  };
6427
- async ExportToExcel(excelName, reportTitle, filterTitle, rowsSerializate, columns, filters, subtitles = [], showTotalRow = false, headerGroups = []) {
6427
+ async ExportToExcel(excelName, reportTitle, filterTitle, rowsSerializate, columns, filters, subtitles = [], showTotalRow = false, headerGroups = [], childKey) {
6428
6428
  const workbook = new Workbook();
6429
6429
  const worksheet = workbook.addWorksheet(reportTitle);
6430
6430
  worksheet.views = [{ showGridLines: false }];
@@ -6432,7 +6432,7 @@ class HtmlToExcelService {
6432
6432
  base64: this.Logo,
6433
6433
  extension: "png",
6434
6434
  });
6435
- this.SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles, showTotalRow, headerGroups);
6435
+ this.SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles, showTotalRow, headerGroups, childKey);
6436
6436
  this.SetTitle(worksheet, reportTitle);
6437
6437
  if (filters.length > 0) {
6438
6438
  const worksheetFilter = workbook.addWorksheet(filterTitle);
@@ -6454,9 +6454,13 @@ class HtmlToExcelService {
6454
6454
  };
6455
6455
  titleCell.alignment = this.ColumnAligment;
6456
6456
  }
6457
- SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles = [], showTotalRow = false, headerGroups = []) {
6457
+ SetReportPage(rowsSerializate, worksheet, columns, imageId, subtitles = [], showTotalRow = false, headerGroups = [], childKey) {
6458
6458
  let columnsCell = [];
6459
6459
  let rows = JSON.parse(rowsSerializate);
6460
+ const isHierarchical = this.DetectsHierarchy(rows, childKey);
6461
+ if (isHierarchical) {
6462
+ rows = this.FlattenRowsForHierarchy(rows, childKey);
6463
+ }
6460
6464
  let isHeaderGood = headerGroups.length > 0;
6461
6465
  const imageRows = 5;
6462
6466
  const numberRows = rows.length;
@@ -6574,24 +6578,60 @@ class HtmlToExcelService {
6574
6578
  startRow++;
6575
6579
  }
6576
6580
  //Inserción de filas
6581
+ const numberColIdx = (() => {
6582
+ const byEmpty = columns.findIndex(c => (c.columnName ?? "").trim() === "");
6583
+ if (byEmpty !== -1)
6584
+ return byEmpty;
6585
+ const isNumDisplay = (s) => (s ?? "").trim().toLowerCase().replace("º", "°") === "n°";
6586
+ const byDisplay = columns.findIndex(c => isNumDisplay(c.displayColumnName));
6587
+ const byColumnName = columns.findIndex(c => isNumDisplay(c.columnName));
6588
+ const i = byDisplay !== -1 ? byDisplay : byColumnName;
6589
+ return i; // -1 si no hay numeración
6590
+ })(); // Detecta la columna de numeración ("", "N°" o "Nº") si existe
6591
+ const hasNumbering = numberColIdx !== -1;
6592
+ // Columna a indentar:
6593
+ let indentColIdx = null;
6594
+ if (hasNumbering && numberColIdx + 1 < columns.length) {
6595
+ indentColIdx = numberColIdx + 1;
6596
+ }
6597
+ else {
6598
+ const nameIdx = columns.findIndex(c => (c.columnName ?? "").trim().toLowerCase() === "name" ||
6599
+ (c.displayColumnName ?? "").trim().toLowerCase().includes("name"));
6600
+ if (nameIdx !== -1)
6601
+ indentColIdx = nameIdx;
6602
+ }
6577
6603
  for (let rowIndex = 0; rowIndex < numberRows; rowIndex++) {
6578
6604
  const rowValues = [];
6579
6605
  for (let colIndex = 0; colIndex < columns.length; colIndex++) {
6580
- rowValues.push(colIndex === 0 ? `${rowIndex + 1}` : rows[rowIndex][columns[colIndex].columnName] ?? "");
6606
+ if (hasNumbering && colIndex === numberColIdx) {
6607
+ rowValues.push(isHierarchical ? rows[rowIndex].__hier : (rowIndex + 1));
6608
+ }
6609
+ else {
6610
+ rowValues.push(rows[rowIndex][columns[colIndex].columnName] ?? "");
6611
+ }
6581
6612
  }
6582
6613
  const insertedRow = worksheet.addRow(rowValues);
6583
6614
  insertedRow.eachCell((cell, colNumber) => {
6584
6615
  const col = columns[colNumber - 1];
6585
- if (col.formatNumber) {
6586
- cell.numFmt = this.GetNumberFormat(col.formatNumber);
6587
- cell.value = Number(cell.value);
6616
+ if (col?.formatNumber) {
6617
+ const fmt = this.GetNumberFormat(col.formatNumber);
6618
+ if (fmt)
6619
+ cell.numFmt = fmt;
6588
6620
  }
6589
6621
  cell.alignment = {
6590
6622
  vertical: "middle",
6591
- horizontal: col.alignHorizontal ?? "left",
6623
+ horizontal: col?.alignHorizontal ?? "left",
6592
6624
  wrapText: true,
6593
6625
  };
6594
6626
  });
6627
+ // Indentación: si hay jerarquía y hay columna definida para indentar
6628
+ if (isHierarchical && indentColIdx !== null && indentColIdx < columns.length) {
6629
+ const indentCell = insertedRow.getCell(indentColIdx + 1); // 1-based
6630
+ indentCell.alignment = {
6631
+ ...(indentCell.alignment ?? {}),
6632
+ indent: Math.min(rows[rowIndex].__level, 10),
6633
+ };
6634
+ }
6595
6635
  }
6596
6636
  //Formato nombre de columnas
6597
6637
  columnsCell.forEach(cellRef => {
@@ -6627,6 +6667,13 @@ class HtmlToExcelService {
6627
6667
  name: "Arial",
6628
6668
  size: 10,
6629
6669
  color: { argb: "203764" },
6670
+ ...(isHierarchical
6671
+ ? (() => {
6672
+ const dataIndex = rowIndex - firstDataRow;
6673
+ const hasKids = rows?.[dataIndex]?.__hasChildren;
6674
+ return hasKids ? { bold: true } : {};
6675
+ })()
6676
+ : {}),
6630
6677
  };
6631
6678
  });
6632
6679
  });
@@ -6741,7 +6788,7 @@ class HtmlToExcelService {
6741
6788
  rows.forEach((rowData, rowIndex) => {
6742
6789
  const rowValues = allColumns.map((col, colIndex) => {
6743
6790
  if (orderColumn && colIndex === 0) {
6744
- return (rowIndex + 1).toString();
6791
+ return (rowIndex + 1);
6745
6792
  }
6746
6793
  const originalColIndex = orderColumn ? colIndex - 1 : colIndex;
6747
6794
  return rowData[columns[originalColIndex].columnName]?.toString() || "";
@@ -6789,6 +6836,28 @@ class HtmlToExcelService {
6789
6836
  };
6790
6837
  return formats[formatNumber] || "";
6791
6838
  }
6839
+ FlattenRowsForHierarchy(rows, childKey = "details", path = []) {
6840
+ const flat = [];
6841
+ rows?.forEach((item, idx) => {
6842
+ const seq = [...path, idx + 1];
6843
+ const hasChildren = Array.isArray(item?.[childKey]) && item[childKey].length > 0;
6844
+ const copy = { ...item };
6845
+ delete copy[childKey];
6846
+ flat.push({
6847
+ ...copy,
6848
+ __hier: seq.join("."), // "1" | "1.1" | "2.2.1" ...
6849
+ __level: seq.length - 1, // 0 = raíz, 1 = hijo, 2 = nieto...
6850
+ __hasChildren: hasChildren // para formateo en negrita
6851
+ });
6852
+ if (hasChildren) {
6853
+ flat.push(...this.FlattenRowsForHierarchy(item[childKey], childKey, seq));
6854
+ }
6855
+ });
6856
+ return flat;
6857
+ }
6858
+ DetectsHierarchy(rows, childKey = "details") {
6859
+ return rows?.some(r => Array.isArray(r?.[childKey]) && r[childKey].length > 0) ?? false;
6860
+ }
6792
6861
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: HtmlToExcelService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
6793
6862
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: HtmlToExcelService, providedIn: "root" });
6794
6863
  }