From d50296fd6ca82fed355fd2de2c4f09d92426685b Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 7 Aug 2023 12:04:21 +0400 Subject: [PATCH] Work for #260: show footer row in list mode (#262) --- src/flat_layout/flat_matrixmultiple.ts | 21 +++++++++---- tests/flat_matrixmultiple.test.ts | 41 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/flat_layout/flat_matrixmultiple.ts b/src/flat_layout/flat_matrixmultiple.ts index 53f8f11..d9535c6 100644 --- a/src/flat_layout/flat_matrixmultiple.ts +++ b/src/flat_layout/flat_matrixmultiple.ts @@ -21,8 +21,12 @@ export class FlatMatrixMultiple extends FlatQuestion { super(survey, question, controller); this.question = 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 { @@ -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 { const table: QuestionMatrixDropdownRenderedTable = this.question.renderedTable; const renderedRows = this.visibleRows; @@ -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); } } diff --git a/tests/flat_matrixmultiple.test.ts b/tests/flat_matrixmultiple.test.ts index b68127f..f1d09cd 100644 --- a/tests/flat_matrixmultiple.test.ts +++ b/tests/flat_matrixmultiple.test.ts @@ -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 = 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(); }); \ No newline at end of file