From adf4778a0e11eb30199318234aa9b77179f8abc4 Mon Sep 17 00:00:00 2001 From: anbebe <58171814+anbebe@users.noreply.github.com> Date: Thu, 12 Dec 2024 10:57:48 +0100 Subject: [PATCH] Add VoteWeight documentation and translated search for detail poll view (#4379) --- .../poll/base/base-poll-pdf.service.ts | 106 ++++++++++++------ .../entitled-users-table.component.html | 4 + .../entitled-users-table.component.ts | 3 + .../assignment-poll-detail.component.html | 1 + .../assignment-poll-detail.component.ts | 3 + .../motion-poll-detail.component.html | 2 + .../motion-poll-detail.component.ts | 21 +++- 7 files changed, 100 insertions(+), 40 deletions(-) diff --git a/client/src/app/site/pages/meetings/modules/poll/base/base-poll-pdf.service.ts b/client/src/app/site/pages/meetings/modules/poll/base/base-poll-pdf.service.ts index 9fd2c350f3..2a8930baf0 100644 --- a/client/src/app/site/pages/meetings/modules/poll/base/base-poll-pdf.service.ts +++ b/client/src/app/site/pages/meetings/modules/poll/base/base-poll-pdf.service.ts @@ -64,6 +64,10 @@ export abstract class BasePollPdfService { return this.activeMeetingService.meetingId!; } + private get activeVoteWeight(): boolean { + return this.meetingSettingsService.instant(`users_enable_vote_weight`); + } + protected meetingSettingsService = inject(MeetingSettingsService); protected userRepo = inject(ParticipantControllerService); protected activeMeetingService = inject(ActiveMeetingService); @@ -382,7 +386,7 @@ export abstract class BasePollPdfService { margin: [0, 20, 0, 5], bold: true }); - const votesData = this.createVotesTable(exportInfo.votesData); + const votesData = this.createVotesTable(exportInfo.votesData, poll.type); pollResultPdfContent.push(votesData); } @@ -559,23 +563,31 @@ export abstract class BasePollPdfService { * * @returns the table as pdfmake object */ - private createVotesTable(votesData: BaseVoteData[]): object { - const pollTableBody: any[] = [ - [ - { - text: ``, - style: `tableHeader` - }, - { - text: this.translate.instant(`Participant`), - style: `tableHeader` - }, - { - text: this.translate.instant(`Votes`), - style: `tableHeader` - } - ] + private createVotesTable(votesData: BaseVoteData[], pollType: PollType): object { + const isAnonymised: boolean = votesData[0].user ? false : true; + const showVoteWeight: boolean = this.activeVoteWeight && pollType == PollType.Named && !isAnonymised; + let pollTableBody: any[] = []; + const pollTableHeader = [ + { + text: ``, + style: `tableHeader` + }, + { + text: this.translate.instant(`Participant`), + style: `tableHeader` + }, + { + text: this.translate.instant(`Votes`), + style: `tableHeader` + } ]; + if (showVoteWeight) { + pollTableHeader.splice(2, 0, { + text: this.translate.instant(`Vote Weight`), + style: `tableHeader` + }); + } + pollTableBody = [pollTableHeader]; let index = 1; for (const date of votesData.sort((entryA, entryB) => @@ -592,11 +604,15 @@ export abstract class BasePollPdfService { text: this.parseSingleResult(date[`votes`] ?? date[`value`]) } ]; - + if (showVoteWeight) { + tableLine.splice(2, 0, { + text: this.getUserVoteWeightForExport(date.user) + }); + } pollTableBody.push(tableLine); index++; } - return this.generateTableObject(pollTableBody); + return this.generateTableObject(pollTableBody, showVoteWeight); } /** @@ -605,22 +621,29 @@ export abstract class BasePollPdfService { * @returns the table as pdfmake object */ private createUsersTable(usersData: EntitledUsersTableEntry[]): object { - const pollTableBody: any[] = [ - [ - { - text: ``, - style: `tableHeader` - }, - { - text: this.translate.instant(`Participant`), - style: `tableHeader` - }, - { - text: this.translate.instant(`Has voted`), - style: `tableHeader` - } - ] + const showVoteWeight: boolean = this.activeVoteWeight; + let pollTableBody: any[] = []; + const pollTableHeader = [ + { + text: ``, + style: `tableHeader` + }, + { + text: this.translate.instant(`Participant`), + style: `tableHeader` + }, + { + text: this.translate.instant(`Has voted`), + style: `tableHeader` + } ]; + if (showVoteWeight) { + pollTableHeader.splice(2, 0, { + text: this.translate.instant(`Vote Weight`), + style: `tableHeader` + }); + } + pollTableBody = [pollTableHeader]; let index = 1; for (const date of usersData.sort((entryA, entryB) => @@ -651,18 +674,23 @@ export abstract class BasePollPdfService { text: this.translate.instant(date.voted ? `Yes` : `No`) } ]; + if (showVoteWeight) { + tableLine.splice(2, 0, { + text: this.getUserVoteWeightForExport(date.user) + }); + } pollTableBody.push(tableLine); index++; } - return this.generateTableObject(pollTableBody); + return this.generateTableObject(pollTableBody, showVoteWeight); } - private generateTableObject(pollTableBody: any[]): object { + private generateTableObject(pollTableBody: any[], showVoteWeight: boolean): object { return [ { table: { - widths: [`4%`, `48%`, `48%`], + widths: showVoteWeight ? [`4%`, `32%`, `32%`, `32%`] : [`4%`, `48%`, `48%`], headerRows: 1, body: pollTableBody }, @@ -675,6 +703,10 @@ export abstract class BasePollPdfService { return user?.getShortName() ?? this.translate.instant(`Anonymous`); } + private getUserVoteWeightForExport(user: ViewUser | undefined): string { + return user?.voteWeight.toString(); + } + private parseSingleResult(resultData: any, indent = 0): string { const indentation = ` `.repeat(indent); if (Array.isArray(resultData)) { diff --git a/client/src/app/site/pages/meetings/modules/poll/components/entitled-users-table/entitled-users-table.component.html b/client/src/app/site/pages/meetings/modules/poll/components/entitled-users-table/entitled-users-table.component.html index 3d25052e90..814e7cc20a 100644 --- a/client/src/app/site/pages/meetings/modules/poll/components/entitled-users-table/entitled-users-table.component.html +++ b/client/src/app/site/pages/meetings/modules/poll/components/entitled-users-table/entitled-users-table.component.html @@ -20,6 +20,10 @@ {{ entry.user.getLevelAndNumber() }} } + + @if (displayVoteWeight) { +