TSK-1467: Update report table to split rows into chunks
This commit is contained in:
parent
43fbe91a6b
commit
c3632c9a7d
|
@ -36,6 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
<button mat-flat-button color="accent" (click)="addRows()">Add more rows</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-footer">
|
<div class="table-footer">
|
||||||
<ng-container *ngFor="let row of reportData.sumRow; let i = index">
|
<ng-container *ngFor="let row of reportData.sumRow; let i = index">
|
||||||
|
@ -61,4 +62,5 @@
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,17 +1,50 @@
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input, OnChanges, OnInit } from '@angular/core';
|
||||||
import { ReportData } from 'app/monitor/models/report-data';
|
import { ReportData } from 'app/monitor/models/report-data';
|
||||||
|
import { ReportRow } from '../../models/report-row';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'taskana-monitor-report-table',
|
selector: 'taskana-monitor-report-table',
|
||||||
templateUrl: './report-table.component.html',
|
templateUrl: './report-table.component.html',
|
||||||
styleUrls: ['./report-table.component.scss']
|
styleUrls: ['./report-table.component.scss']
|
||||||
})
|
})
|
||||||
export class ReportTableComponent {
|
export class ReportTableComponent implements OnChanges {
|
||||||
currentExpHeaders = 0;
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
reportData: ReportData;
|
reportData: ReportData;
|
||||||
|
|
||||||
|
fullReportData: ReportData;
|
||||||
|
fullRowsData: ReportRow[][];
|
||||||
|
currentExpHeaders = 0;
|
||||||
|
|
||||||
|
ngOnChanges() {
|
||||||
|
this.fullReportData = { ...this.reportData };
|
||||||
|
this.fullRowsData = this.fullReportData.rows?.reduce((resultArray: ReportRow[][], item, index) => {
|
||||||
|
const itemsPerChunk = 20;
|
||||||
|
if (this.fullReportData.rows.length > itemsPerChunk) {
|
||||||
|
const chunkIndex = Math.floor(index / itemsPerChunk);
|
||||||
|
|
||||||
|
if (!resultArray[chunkIndex]) {
|
||||||
|
resultArray[chunkIndex] = []; // start a new chunk
|
||||||
|
}
|
||||||
|
|
||||||
|
resultArray[chunkIndex].push(item);
|
||||||
|
} else {
|
||||||
|
return [this.fullReportData.rows];
|
||||||
|
}
|
||||||
|
return resultArray;
|
||||||
|
}, []);
|
||||||
|
if (this.fullRowsData) {
|
||||||
|
this.reportData.rows = this.fullRowsData[0];
|
||||||
|
this.fullRowsData.splice(0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addRows() {
|
||||||
|
if (typeof this.fullRowsData !== 'undefined' && this.fullRowsData[0]) {
|
||||||
|
this.reportData.rows = [...this.reportData.rows, ...this.fullRowsData[0]];
|
||||||
|
this.fullRowsData.splice(0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toggleFold(indexNumber: number, sumRow: boolean = false) {
|
toggleFold(indexNumber: number, sumRow: boolean = false) {
|
||||||
let rows = sumRow ? this.reportData.sumRow : this.reportData.rows;
|
let rows = sumRow ? this.reportData.sumRow : this.reportData.rows;
|
||||||
let index = indexNumber;
|
let index = indexNumber;
|
||||||
|
|
Loading…
Reference in New Issue