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 poll display on delegation settings change #3790

Merged
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 @@ -9,6 +9,7 @@ import { VotingService } from 'src/app/site/pages/meetings/modules/poll/services
import { ViewPoll } from 'src/app/site/pages/meetings/pages/polls';
import { ActiveMeetingService } from 'src/app/site/pages/meetings/services/active-meeting.service';
import { ActivePollsService } from 'src/app/site/pages/meetings/services/active-polls.service';
import { MeetingSettingsService } from 'src/app/site/pages/meetings/services/meeting-settings.service';
import { OperatorService } from 'src/app/site/services/operator.service';

import { BannerDefinition, BannerService } from './banner.service';
Expand Down Expand Up @@ -37,7 +38,8 @@ export class VotingBannerService {
private activeMeeting: ActiveMeetingService,
private sendVotesService: VoteControllerService,
private operator: OperatorService,
private activePolls: ActivePollsService
private activePolls: ActivePollsService,
private meetingSettingsService: MeetingSettingsService
) {
combineLatest([
this.activeMeeting.meetingIdObservable.pipe(distinctUntilChanged()),
Expand All @@ -48,7 +50,9 @@ export class VotingBannerService {

return prevStarted.length === currStarted.length && currStarted.equals(prevStarted);
})
)
),
this.meetingSettingsService.get(`users_enable_vote_delegations`).pipe(distinctUntilChanged()),
this.meetingSettingsService.get(`users_forbid_delegator_to_vote`).pipe(distinctUntilChanged())
]).subscribe(([_, polls]) => this.updateVotablePollSubscription(polls));
}

Expand All @@ -60,7 +64,7 @@ export class VotingBannerService {
});
}

private updateBanner(polls: ViewPoll[], voted: { [key: Id]: Id[] }) {
private updateBanner(polls: ViewPoll[], voted: { [key: Id]: Id[] }): void {
if (this.activeMeeting.meetingId) {
const checkUsers = [this.operator.user, ...(this.operator.user.vote_delegations_from() || [])];
this.pollsToVote = polls.filter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectorRef, Directive, inject, Input, OnInit } from '@angular/core';
import { UntypedFormControl, Validators } from '@angular/forms';
import { marker as _ } from '@colsen1991/ngx-translate-extract-marker';
import { BehaviorSubject, debounceTime, Observable } from 'rxjs';
import { BehaviorSubject, combineLatest, debounceTime, distinctUntilChanged, Observable } from 'rxjs';
import { Id } from 'src/app/domain/definitions/key-types';
import {
GlobalVote,
Expand Down Expand Up @@ -453,6 +453,16 @@ export abstract class BasePollVoteComponent<C extends PollContentObject = any> e
}
})
);
this.subscriptions.push(
combineLatest([
this.meetingSettingsService.get(`users_enable_vote_delegations`).pipe(distinctUntilChanged()),
this.meetingSettingsService.get(`users_forbid_delegator_to_vote`).pipe(distinctUntilChanged())
]).subscribe(_ => {
for (const key of Object.keys(this._canVoteForSubjectMap)) {
this._canVoteForSubjectMap[+key].next(this.canVote(this._delegationsMap[+key]));
}
})
);
}

private setupDelegations(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input } from '@angular/core';
import { debounceTime } from 'rxjs';
import { combineLatest, debounceTime, distinctUntilChanged } from 'rxjs';
import { OperatorService } from 'src/app/site/services/operator.service';

import { BaseMeetingComponent } from '../../../../base/base-meeting.component';
Expand Down Expand Up @@ -45,6 +45,14 @@ export class PollCannotVoteMessageComponent extends BaseMeetingComponent {
this.cd.markForCheck();
})
);
this.subscriptions.push(
combineLatest([
this.meetingSettingsService.get(`users_enable_vote_delegations`).pipe(distinctUntilChanged()),
this.meetingSettingsService.get(`users_forbid_delegator_to_vote`).pipe(distinctUntilChanged())
]).subscribe(_ => {
this.cd.markForCheck();
})
);
}

public getVotingError(user: ViewUser = this.user): string {
Expand Down
Loading