perspective rows

This commit is contained in:
Jan Prochazka
2022-06-30 19:13:01 +02:00
parent 8228afd725
commit b0eed05a1a
2 changed files with 103 additions and 38 deletions

View File

@@ -1,4 +1,4 @@
import { PerspectiveTableNode, PerspectiveTreeNode } from './PerspectiveTreeNode'; import { getTableChildPerspectiveNodes, PerspectiveTableNode, PerspectiveTreeNode } from './PerspectiveTreeNode';
import _max from 'lodash/max'; import _max from 'lodash/max';
import _range from 'lodash/max'; import _range from 'lodash/max';
import _fill from 'lodash/fill'; import _fill from 'lodash/fill';
@@ -43,21 +43,32 @@ export class PerspectiveDisplayColumn {
// } // }
} }
class PerspectiveSubRowCollection { interface PerspectiveSubRowCollection {
rows: CollectedPerspectiveDisplayRow[] = []; rows: CollectedPerspectiveDisplayRow[];
// startIndex = 0;
} }
export class CollectedPerspectiveDisplayRow { interface CollectedPerspectiveDisplayRow {
// startIndex = 0; // startIndex = 0;
columnIndexes: number[] = []; columnIndexes: number[];
rowData: any[] = []; rowData: any[];
// rowSpans: number[] = null; // rowSpans: number[] = null;
subRowCollections: PerspectiveSubRowCollection[] = []; subRowCollections: PerspectiveSubRowCollection[];
} }
export class PerspectiveDisplayRow { export class PerspectiveDisplayRow {
constructor(public display: PerspectiveDisplay) {} constructor(public display: PerspectiveDisplay) {
this.rowData = _fill(Array(display.columns.length), undefined);
}
getRow(rowIndex): PerspectiveDisplayRow {
if (rowIndex == 0) return this;
while (this.subrows.length < rowIndex) {
this.subrows.push(new PerspectiveDisplayRow(this.display));
}
return this.subrows[rowIndex - 1];
}
subrows: PerspectiveDisplayRow[] = [];
rowData: any[] = []; rowData: any[] = [];
rowSpans: number[] = null; rowSpans: number[] = null;
@@ -74,6 +85,8 @@ export class PerspectiveDisplay {
const collectedRows = this.collectRows(rows, root.childNodes); const collectedRows = this.collectRows(rows, root.childNodes);
console.log('COLLECTED', collectedRows); console.log('COLLECTED', collectedRows);
// this.mergeRows(collectedRows); // this.mergeRows(collectedRows);
this.mergeRows(collectedRows);
console.log('MERGED', this.rows);
} }
fillColumns(children: PerspectiveTreeNode[], parentNodes: PerspectiveTreeNode[]) { fillColumns(children: PerspectiveTreeNode[], parentNodes: PerspectiveTreeNode[]) {
@@ -128,10 +141,9 @@ export class PerspectiveDisplay {
const res: CollectedPerspectiveDisplayRow[] = []; const res: CollectedPerspectiveDisplayRow[] = [];
for (const sourceRow of sourceRows) { for (const sourceRow of sourceRows) {
// console.log('PROCESS SOURCE', sourceRow); // console.log('PROCESS SOURCE', sourceRow);
const row = new CollectedPerspectiveDisplayRow();
// row.startIndex = startIndex; // row.startIndex = startIndex;
row.rowData = columnNodes.map(node => sourceRow[node.codeName]); const rowData = columnNodes.map(node => sourceRow[node.codeName]);
row.columnIndexes = columnIndexes; const subRowCollections = [];
for (const node of treeNodes) { for (const node of treeNodes) {
// if (sourceRow.AlbumId == 1) { // if (sourceRow.AlbumId == 1) {
@@ -144,42 +156,95 @@ export class PerspectiveDisplay {
// } // }
// console.log('sourceRow[node.fieldName]', sourceRow[node.fieldName]); // console.log('sourceRow[node.fieldName]', sourceRow[node.fieldName]);
if (sourceRow[node.fieldName]) { if (sourceRow[node.fieldName]) {
const subrows = new PerspectiveSubRowCollection(); const subrows = {
// subrows.startIndex = nodeStartIndexes.get(node); rows: this.collectRows(sourceRow[node.fieldName], node.childNodes),
subrows.rows = this.collectRows(sourceRow[node.fieldName], node.childNodes); };
row.subRowCollections.push(subrows); subRowCollections.push(subrows);
} }
} }
res.push(row); res.push({
rowData,
columnIndexes,
subRowCollections,
});
} }
return res; return res;
} }
// mergeRows(rows: PerspectiveDisplayRow[]) {} flushFlatRows(row: PerspectiveDisplayRow) {
this.rows.push(row);
for (const child of row.subrows) {
this.flushFlatRows(child);
}
}
// flattenRows(sourceRow: CollectedPerspectiveDisplayRow) { mergeRows(collectedRows: CollectedPerspectiveDisplayRow[]) {
// let rowIndex = 0; const rows = [];
for (const collectedRow of collectedRows) {
const resultRow = new PerspectiveDisplayRow(this);
this.mergeRow(collectedRow, resultRow);
rows.push(resultRow);
}
for (const row of rows) {
this.flushFlatRows(row);
}
}
mergeRow(collectedRow: CollectedPerspectiveDisplayRow, resultRow: PerspectiveDisplayRow) {
for (let i = 0; i < collectedRow.columnIndexes.length; i++) {
resultRow.rowData[collectedRow.columnIndexes[i]] = collectedRow.rowData[i];
}
for (const subrows of collectedRow.subRowCollections) {
let rowIndex = 0;
for (const subrow of subrows.rows) {
const targetRow = resultRow.getRow(rowIndex);
this.mergeRow(subrow, targetRow);
rowIndex++;
}
}
}
// rowToFlatRows(sourceRow: CollectedPerspectiveDisplayRow) {
// const res = []; // const res = [];
// while (true) {
// const row = new PerspectiveDisplayRow(this); // const row = new PerspectiveDisplayRow(this);
// row.rowData = _fill(Array(this.columns.length), undefined); // row.rowData = _fill(Array(this.columns.length), undefined);
// row.rowSpans = _fill(Array(this.columns.length), 0); // row.rowSpans = _fill(Array(this.columns.length), 1);
// for (let colIndex = 0; colIndex < this.columns.length; colIndex++) { // res.push(row)
// if (colIndex < sourceRow.startIndex) {
// continue; // for (let i = 0; i < sourceRow.columnIndexes.length; i++) {
// } // row.rowData[sourceRow.columnIndexes[i]] = sourceRow.rowData[i];
// if (colIndex < sourceRow.startIndex + sourceRow.rowData.length) { // }
// if (rowIndex == 0) {
// row.rowData[colIndex] = sourceRow.rowData[sourceRow.startIndex + colIndex]; // for(const subrows of sourceRow.subRowCollections) {
// row.rowSpans[colIndex] = 1; // let rowIndex=0;
// } else { // for(const subrow of subrows.rows) {
// row.rowSpans[colIndex] += 1; // if ()
// } // rowIndex++;
// }
// const subrows = sourceRow.subRowCollections.find(x=>x.);
// } // }
// } // }
// return res;
// // while (true) {
// // for (let colIndex = 0; colIndex < this.columns.length; colIndex++) {
// // if (colIndex < sourceRow.startIndex) {
// // continue;
// // }
// // if (colIndex < sourceRow.startIndex + sourceRow.rowData.length) {
// // if (rowIndex == 0) {
// // row.rowData[colIndex] = sourceRow.rowData[sourceRow.startIndex + colIndex];
// // row.rowSpans[colIndex] = 1;
// // } else {
// // row.rowSpans[colIndex] += 1;
// // }
// // }
// // const subrows = sourceRow.subRowCollections.find(x=>x.);
// // }
// // }
// } // }
} }

View File

@@ -96,7 +96,7 @@
{#each display.rows as row} {#each display.rows as row}
<tr> <tr>
{#each display.columns as column} {#each display.columns as column}
<td>{row[column.dataField]}</td> <td>{row.rowData[column.columnIndex]}</td>
{/each} {/each}
</tr> </tr>
{/each} {/each}