Skip to content

Commit

Permalink
fix(core/reports): export also dynamic table widget both with rowspan…
Browse files Browse the repository at this point in the history
… or colspan
  • Loading branch information
sara-gnucoop authored and trik committed Oct 28, 2021
1 parent 6d0811f commit 0d19c88
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/core/reports/widget-export.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ describe('widget-export', () => {

const dataTableXlsx: AjfTableCell[][] = [
[
{value: {changingThisBreaksApplicationSecurity: 'a'}},
{value: {changingThisBreaksApplicationSecurity: 'b'}},
{value: {changingThisBreaksApplicationSecurity: 'a'}, colspan: 2},
{value: {changingThisBreaksApplicationSecurity: 'c'}},
],
[
Expand Down Expand Up @@ -57,7 +56,7 @@ describe('widget-export', () => {
const testSpy = spyOn(XLSX.utils, 'aoa_to_sheet').and.callThrough();
widgetExport.exportCsv();
const toEqual: unknown[][] = [
['a', 'b', 'c'],
['a', ' ', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i'],
];
Expand Down
62 changes: 48 additions & 14 deletions src/core/reports/widget-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,61 @@ export class AjfWidgetExport {
xlsxData.push(row);
}
break;
case AjfWidgetType.DynamicTable:
case AjfWidgetType.Table:
this.data = this.data as AjfTableCell[][];
this.data.forEach((row: AjfTableCell[], idxRow: number) => {
const res: unknown[] = [];
if (idxRow === 0) {
row.forEach((elem: AjfTableCell) => {
labels.push(elem.value.changingThisBreaksApplicationSecurity);
const tableData = this.data as AjfTableCell[][];
if (tableData.length > 1) {
xlsxData = [];
const nextRows: unknown[][] = [];
let nextRow: unknown[] = [];
let totRowSpan = 0;
let nextRowspanNum = 0;

for (let i = 0; i < tableData.length; i++) {
let isNewRowAfterRowspan = false;
let res: unknown[] = [];

nextRow = [];
if (totRowSpan > 0) {
res = [...nextRows[nextRowspanNum - 1]];
isNewRowAfterRowspan = true;
}
tableData[i].forEach((elem: AjfTableCell, idxElem: number) => {
res.push(elem.value.changingThisBreaksApplicationSecurity);

if (elem.colspan && elem.colspan > 1) {
for (let i = 1; i < elem.colspan; i++) {
labels.push(' ');
for (let j = 1; j < elem.colspan; j++) {
res.push(' ');
}
}
if (isNewRowAfterRowspan) {
if (elem.rowspan && elem.rowspan > 1) {
for (let idx = 1; idx < elem.rowspan; idx++) {
nextRow.push(' ');
nextRows[nextRowspanNum] = nextRows[nextRowspanNum].concat(nextRow);
}
}
if (idxElem === tableData[i].length - 1 && nextRowspanNum > 0) {
nextRowspanNum++;
if (nextRowspanNum === totRowSpan) {
totRowSpan = 0;
nextRowspanNum = 0;
}
}
} else {
if (elem.rowspan && elem.rowspan > 1) {
totRowSpan = elem.rowspan;
nextRowspanNum = 1;
for (let idx = 1; idx < elem.rowspan; idx++) {
nextRow.push(' ');
nextRows[idx - 1] = nextRow;
}
}
}
});
xlsxData.push(labels);
} else {
row.forEach((elem: AjfTableCell) => {
res.push(elem.value.changingThisBreaksApplicationSecurity);
});
xlsxData.push(res);
}
});
}
break;
}

Expand Down
51 changes: 51 additions & 0 deletions src/dev-app/mat-reports/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const testReport = {
},
{
'widgetType': 5,
'exportable': true,
'dataset': [
[
{
Expand All @@ -70,6 +71,7 @@ export const testReport = {
'aggregation': {
'aggregation': 0,
},
'colspan': 2,
},
{
'label': '',
Expand Down Expand Up @@ -100,6 +102,15 @@ export const testReport = {
'aggregation': 0,
},
},
{
'label': '',
'formula': {
'formula': '"2a1"',
},
'aggregation': {
'aggregation': 0,
},
},
{
'label': '',
'formula': {
Expand Down Expand Up @@ -129,6 +140,15 @@ export const testReport = {
'aggregation': 0,
},
},
{
'label': '',
'formula': {
'formula': '"3a1"',
},
'aggregation': {
'aggregation': 0,
},
},
{
'label': '',
'formula': {
Expand Down Expand Up @@ -170,6 +190,37 @@ export const testReport = {
},
],
},
{
'widgetType': 5,
'exportable': true,
'dataset': [
[
{
'label': '',
'formula': {'formula': '"Header A "'},
'aggregation': {'aggregation': 0},
'rowspan': 2,
},
{
'label': '',
'formula': {'formula': '"Header B "'},
'aggregation': {'aggregation': 0},
'rowspan': 2,
},
{
'label': '',
'formula': {'formula': '"Header C "'},
'aggregation': {'aggregation': 0},
},
],
[{'label': '', 'formula': {'formula': '"2c"'}, 'aggregation': {'aggregation': 0}}],
[
{'label': '', 'formula': {'formula': '"3a"'}, 'aggregation': {'aggregation': 0}},
{'label': '', 'formula': {'formula': '"3b"'}, 'aggregation': {'aggregation': 0}},
{'label': '', 'formula': {'formula': '"3c"'}, 'aggregation': {'aggregation': 0}},
],
],
},
],
'styles': {},
},
Expand Down

0 comments on commit 0d19c88

Please sign in to comment.