Skip to content

Commit

Permalink
Add VoteWeight documentation and translated search for detail poll vi…
Browse files Browse the repository at this point in the history
…ew (#4379)
  • Loading branch information
anbebe authored Dec 12, 2024
1 parent 277cf22 commit adf4778
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) =>
Expand All @@ -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);
}

/**
Expand All @@ -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) =>
Expand Down Expand Up @@ -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
},
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{{ entry.user.getLevelAndNumber() }}
</div>
}
<!-- Vote weight -->
@if (displayVoteWeight) {
<div>{{ 'Vote weight' | translate }}: {{ entry.user.vote_weight() }}</div>
}
<!-- Delegation -->
@if (entry.vote_delegated_to_user_id && !entry.delegation_user_merged_into_id) {
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export class EntitledUsersTableComponent {
return this._isViewingThis;
}

@Input()
public displayVoteWeight: boolean;

public readonly permission = Permission;

public filterPropsEntitledUsersTable = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ <h1>{{ poll.title }}</h1>
</mat-tab>
<mat-tab label="{{ 'Entitled users' | translate }}">
<os-entitled-users-table
[displayVoteWeight]="displayVoteWeight"
[entitledUsersObservable]="entitledUsersObservable"
[isViewingThis]="isViewingEntitledUserslist"
></os-entitled-users-table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ export class AssignmentPollDetailComponent
return this.hasPerms() || this.poll.isPublished;
}

public displayVoteWeight: boolean;

public constructor(
pollService: AssignmentPollService,
private pollDialog: AssignmentPollDialogService,
pollPdfService: AssignmentPollPdfService
) {
super(pollService, pollPdfService);
this.subscriptions.push(this.voteWeightEnabled.subscribe(data => (this.displayVoteWeight = data)));
}

public openDialog(poll: ViewPoll): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h1>{{ poll.title | translate }}</h1>
<mat-tab label="{{ 'Single votes' | translate }}">
<div class="named-result-table">
<os-votes-table
[filterProps]="filterPropsSingleVotesTable"
[isViewingThis]="isViewingVoteslist"
[parent]="self"
[votesDataObservable]="votesDataObservable"
Expand All @@ -54,6 +55,7 @@ <h1>{{ poll.title | translate }}</h1>
</mat-tab>
<mat-tab label="{{ 'Entitled users' | translate }}">
<os-entitled-users-table
[displayVoteWeight]="displayVoteWeight"
[entitledUsersObservable]="entitledUsersObservable"
[isViewingThis]="isViewingEntitledUserslist"
></os-entitled-users-table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { MotionPollService } from '../../../../modules/motion-poll/services';
import { MotionPollDialogService } from '../../../../modules/motion-poll/services/motion-poll-dialog.service';
import { MotionPollPdfService } from '../../../../modules/motion-poll/services/motion-poll-pdf.service';

export interface ExtendedVoteData extends BaseVoteData {
vote_verbose_translated?: string | null;
}

@Component({
selector: `os-motion-poll-detail`,
templateUrl: `./motion-poll-detail.component.html`,
Expand All @@ -19,23 +23,34 @@ import { MotionPollPdfService } from '../../../../modules/motion-poll/services/m
encapsulation: ViewEncapsulation.None
})
export class MotionPollDetailComponent extends BasePollDetailComponent<ViewMotion, MotionPollService> {
public filterPropsSingleVotesTable = [`user.full_name`, `valueVerbose`];
public filterPropsSingleVotesTable = [`user.full_name`, `valueVerbose`, `vote_verbose_translated`];

public get showResults(): boolean {
return this.hasPerms() || this.poll.isPublished;
}

public displayVoteWeight: boolean;

public constructor(
protected override translate: TranslateService,
pollService: MotionPollService,
private pollDialog: MotionPollDialogService,
pollPdfService: MotionPollPdfService
) {
super(pollService, pollPdfService);
this.subscriptions.push(this.voteWeightEnabled.subscribe(data => (this.displayVoteWeight = data)));
}

protected createVotesData(): BaseVoteData[] {
return this.poll?.options[0]?.votes;
protected createVotesData(): ExtendedVoteData[] {
const voteData = this.poll?.options[0]?.votes;
const extendedVoteData: ExtendedVoteData[] = this.poll?.options[0]?.votes;
if (extendedVoteData) {
extendedVoteData.map(
(element, index) =>
(element.vote_verbose_translated = this.translate.instant(voteData[index].vote.valueVerbose))
);
}
return extendedVoteData;
}

public openDialog(): void {
Expand Down

0 comments on commit adf4778

Please sign in to comment.