Skip to content

Commit

Permalink
Work for #260: show footer row in list mode (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 authored Aug 7, 2023
1 parent 8a231e1 commit d50296f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/flat_layout/flat_matrixmultiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ export class FlatMatrixMultiple extends FlatQuestion {
super(survey, question, controller);
this.question = <QuestionMatrixDropdownModelBase>question;
}
private visibleRowsValue: QuestionMatrixDropdownRenderedRow[];
private get visibleRows() {
return this.question.renderedTable.rows.filter(row => row.visible);
if(!this.visibleRowsValue) {
this.visibleRowsValue = this.question.renderedTable.rows.filter(row => row.visible);
}
return this.visibleRowsValue;
}
private async generateFlatsCell(point: IPoint, cell: QuestionMatrixDropdownRenderedCell,
isHeader: boolean): Promise<CompositeBrick> {
Expand Down Expand Up @@ -194,6 +198,15 @@ export class FlatMatrixMultiple extends FlatQuestion {
const columnWidthSum = this.calculateColumnWidth(rows, colCount).reduce((widthSum: number, width: number) => widthSum += width, 0);
return this.question.renderAs !== 'list' && this.controller.matrixRenderAs !== 'list' && Math.floor(columnWidthSum) <= Math.floor(this.getAvalableWidth(colCount));
}
private getRowsToRender(table: QuestionMatrixDropdownRenderedTable, isVertical: boolean, isWide: boolean) {
const rows: QuestionMatrixDropdownRenderedRow[] = [];
const renderedRows = this.visibleRows;
if (table.showHeader && isWide) rows.push(table.headerRow);
rows.push(...renderedRows);
if (table.hasRemoveRows && isVertical) rows.pop();
if (table.showFooter) rows.push(table.footerRow);
return rows;
}
public async generateFlatsContent(point: IPoint): Promise<IPdfBrick[]> {
const table: QuestionMatrixDropdownRenderedTable = this.question.renderedTable;
const renderedRows = this.visibleRows;
Expand All @@ -208,12 +221,8 @@ export class FlatMatrixMultiple extends FlatQuestion {
if (colCount === 0) {
return [new CompositeBrick(SurveyHelper.createRowlineFlat(point, this.controller))];
}
const rows: QuestionMatrixDropdownRenderedRow[] = [];
const isWide = this.calculateIsWide(table, colCount);
if (table.showHeader && isWide) rows.push(table.headerRow);
rows.push(...renderedRows);
if (table.hasRemoveRows && isVertical) rows.pop();
if (table.showFooter && isWide) rows.push(table.footerRow);
const rows = this.getRowsToRender(table, isVertical, isWide);
return await this.generateFlatsRows(point, rows, colCount, isWide);
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/flat_matrixmultiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,4 +659,45 @@ test('Check matrix dynamic column min widths with detailPanel', async () => {
let widths = flat['calculateColumnWidth'](flat['visibleRows'], 4);
let restWidth = (flat['getAvalableWidth'](4) - 112.5 - 150) / 2;
expect(widths).toEqual([112.5, restWidth, 150, restWidth]);
});
test('Check getRowsToRender method', async () => {
const json = {
pages: [
{
name: 'page1',
elements: [
{
type: 'matrixdropdown',
name: 'question1',
columns: [
{
name: 'Column 1',
title: 'Column 1',
totalType: 'sum'
},
],
choices: [1, 2, 3, 4, 5],
rows: ['Row 1']
}
]
}
]
};
const survey: SurveyPDF = new SurveyPDF(json, TestHelper.defaultOptions);
const question = <QuestionMatrixDropdownModel>survey.getAllQuestions()[0];
const controller: DocController = new DocController(TestHelper.defaultOptions);
let flat = new FlatMatrixMultiple(survey, survey.getAllQuestions()[0], controller);
let table = question.renderedTable;
let rows = flat['getRowsToRender'](question.renderedTable, false, true);
expect(rows.length).toBe(3);

expect(rows[0] === table.headerRow).toBeTruthy();
expect(rows[1] === table.rows[1]).toBeTruthy();
expect(rows[2] === table.footerRow).toBeTruthy();

rows = flat['getRowsToRender'](question.renderedTable, false, false);
expect(rows.length).toBe(2);

expect(rows[0] === table.rows[1]).toBeTruthy();
expect(rows[1] === table.footerRow).toBeTruthy();
});

0 comments on commit d50296f

Please sign in to comment.