Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix polls when delegation settings are changed #3760

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export abstract class BasePollVoteComponent<C extends PollContentObject = any> e
public forbidDelegationToVote: Observable<boolean> =
this.meetingSettingsService.get(`users_forbid_delegator_to_vote`);

private voteDelegationEnabledBoolean: boolean;
private forbidDelegationToVoteBoolean: boolean;

private _isReady = false;
private _poll!: ViewPoll<C>;
private _delegationsMap: { [userId: number]: ViewUser } = {};
Expand Down Expand Up @@ -95,7 +98,9 @@ export abstract class BasePollVoteComponent<C extends PollContentObject = any> e
this.cd.markForCheck();
this._isReady = true;
}
})
}),
this.voteDelegationEnabled.subscribe(enabled => (this.voteDelegationEnabledBoolean = enabled)),
this.forbidDelegationToVote.subscribe(enabled => (this.forbidDelegationToVoteBoolean = enabled))
);
}

Expand All @@ -107,11 +112,16 @@ export abstract class BasePollVoteComponent<C extends PollContentObject = any> e
return this.alreadyVoted[user?.id];
}

public canVoteForObservable(user: ViewUser = this.user): Observable<boolean> {
if (!this._canVoteForSubjectMap[user.id]) {
this._canVoteForSubjectMap[user.id] = new BehaviorSubject(this.canVote(user));
public canSeePoll(user: ViewUser = this.user): boolean {
if (user === this.user) {
return !(
this.user.isVoteRightDelegated &&
this.voteDelegationEnabledBoolean &&
this.forbidDelegationToVoteBoolean
);
} else {
return this.voteDelegationEnabledBoolean;
}
return this._canVoteForSubjectMap[user.id];
}

public getVotingError(user: ViewUser = this.user): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,92 +21,90 @@ <h4 *ngIf="delegation" class="topic-delegation-title">
<span>&nbsp;{{ delegation.getFullName() }}</span>
</h4>

<ng-container *ngIf="{ canVote: canVoteForObservable(delegation) | async } as voting">
<ng-container *ngIf="voting.canVote">
<!-- Leftover votes -->
<h4 *ngIf="(poll.isMethodY || poll.isMethodN) && poll.max_votes_amount > 1">
{{ 'Available votes' | translate }}:
<b>{{ getVotesAvailable(delegation) }}/{{ poll.max_votes_amount }}</b>

<span *ngIf="poll.min_votes_amount > 1">
({{ 'At least' | translate }}
<b>{{ poll.min_votes_amount }}</b>
)
</span>

<span *ngIf="poll.max_votes_per_option > 1">
({{ 'At most' | translate }}
<b>{{ poll.max_votes_per_option }}</b>
{{ 'votes per candidate' | translate }})
</span>
</h4>

<!-- Options and Actions -->
<div *ngFor="let option of poll.options; let i = index">
<div *ngIf="poll.type !== PollType.Analog">
<div
[ngClass]="{
'yna-grid': poll.isMethodYNA,
'yn-grid': poll.isMethodYN,
'single-vote-grid': poll.isMethodY || poll.isMethodN
}"
>
<div class="vote-option-text">
<span *ngIf="option.text">
<span>{{ option.text }}</span>
</span>
<i *ngIf="!option.text">{{ "Text for this option couldn't load." | translate }}</i>
</div>
<ng-container *ngIf="canSeePoll(delegation)">
<!-- Leftover votes -->
<h4 *ngIf="(poll.isMethodY || poll.isMethodN) && poll.max_votes_amount > 1">
{{ 'Available votes' | translate }}:
<b>{{ getVotesAvailable(delegation) }}/{{ poll.max_votes_amount }}</b>

<span *ngIf="poll.min_votes_amount > 1">
({{ 'At least' | translate }}
<b>{{ poll.min_votes_amount }}</b>
)
</span>

<ng-container *ngIf="!poll.max_votes_per_option || poll.max_votes_per_option <= 1">
<div *ngFor="let action of voteActions">
<button
class="vote-button"
mat-raised-button
(click)="saveSingleVote(option.id, action.vote, delegation)"
[disabled]="isDeliveringVote(delegation)"
[ngClass]="getActionButtonClass(action, option, delegation)"
>
<mat-icon>{{ action.icon }}</mat-icon>
</button>
<span *ngIf="poll.isMethodYN || poll.isMethodYNA" class="vote-label">
{{ action.label | translate }}
</span>
</div>
</ng-container>
<mat-form-field appearance="outline" *ngIf="poll.max_votes_per_option > 1" class="vote-input">
<input
type="number"
matInput
[formControl]="getFormControl(option.id)"
(change)="saveMultipleVotes(option.id, $event, delegation)"
min="0"
max="{{ poll.max_votes_per_option }}"
value="0"
required
/>
<mat-error>
{{ getErrorInVoteEntry(option.id) }}
</mat-error>
</mat-form-field>
<span *ngIf="poll.max_votes_per_option > 1">
({{ 'At most' | translate }}
<b>{{ poll.max_votes_per_option }}</b>
{{ 'votes per candidate' | translate }})
</span>
</h4>

<!-- Options and Actions -->
<div *ngFor="let option of poll.options; let i = index">
<div *ngIf="poll.type !== PollType.Analog">
<div
[ngClass]="{
'yna-grid': poll.isMethodYNA,
'yn-grid': poll.isMethodYN,
'single-vote-grid': poll.isMethodY || poll.isMethodN
}"
>
<div class="vote-option-text">
<span *ngIf="option.text">
<span>{{ option.text }}</span>
</span>
<i *ngIf="!option.text">{{ "Text for this option couldn't load." | translate }}</i>
</div>
<mat-divider *ngIf="poll.options.length - 1 > i"></mat-divider>

<ng-container *ngIf="!poll.max_votes_per_option || poll.max_votes_per_option <= 1">
<div *ngFor="let action of voteActions">
<button
class="vote-button"
mat-raised-button
(click)="saveSingleVote(option.id, action.vote, delegation)"
[disabled]="isDeliveringVote(delegation)"
[ngClass]="getActionButtonClass(action, option, delegation)"
>
<mat-icon>{{ action.icon }}</mat-icon>
</button>
<span *ngIf="poll.isMethodYN || poll.isMethodYNA" class="vote-label">
{{ action.label | translate }}
</span>
</div>
</ng-container>
<mat-form-field appearance="outline" *ngIf="poll.max_votes_per_option > 1" class="vote-input">
<input
type="number"
matInput
[formControl]="getFormControl(option.id)"
(change)="saveMultipleVotes(option.id, $event, delegation)"
min="0"
max="{{ poll.max_votes_per_option }}"
value="0"
required
/>
<mat-error>
{{ getErrorInVoteEntry(option.id) }}
</mat-error>
</mat-form-field>
</div>
<mat-divider *ngIf="poll.options.length - 1 > i"></mat-divider>
</div>
</div>

<!-- Submit Vote -->
<ng-container
[ngTemplateOutlet]="sendNow"
[ngTemplateOutletContext]="{ delegation: delegation }"
></ng-container>
</ng-container>

<!-- Submit Vote -->
<ng-container
*ngIf="!voting.canVote"
[ngTemplateOutlet]="cannotVote"
[ngTemplateOutlet]="sendNow"
[ngTemplateOutletContext]="{ delegation: delegation }"
></ng-container>
</ng-container>

<ng-container
*ngIf="!canSeePoll(delegation)"
[ngTemplateOutlet]="cannotVote"
[ngTemplateOutletContext]="{ delegation: delegation }"
></ng-container>
</ng-template>

<ng-template #cannotVote let-delegation="delegation">
Expand Down
Loading
Loading