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

Add live vote register to motion/assignment-poll-detail #4565

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
4 changes: 2 additions & 2 deletions client/src/app/domain/models/poll/poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Poll extends BaseDecimalModel<Poll> {
public votesvalid!: number;
public votesinvalid!: number;
public votescast!: number;
public vote_count!: number;
public has_voted_user_ids: number[];
public onehundred_percent_base!: PollPercentBase;

/**
Expand Down Expand Up @@ -169,7 +169,7 @@ export class Poll extends BaseDecimalModel<Poll> {
`votesinvalid`,
`votescast`,
`entitled_users_at_stop`,
`vote_count`,
`has_voted_user_ids`,
`sequential_number`,
`content_object_id`,
`option_ids`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { filter, map } from 'rxjs/operators';
import { Id } from 'src/app/domain/definitions/key-types';
import { Identifiable } from 'src/app/domain/interfaces';
import { PollContentObject } from 'src/app/domain/models/poll';
import { MeetingUserRepositoryService } from 'src/app/gateways/repositories/meeting_user';
import { Deferred } from 'src/app/infrastructure/utils/promises';
import { BaseMeetingComponent } from 'src/app/site/pages/meetings/base/base-meeting.component';
import { PollControllerService } from 'src/app/site/pages/meetings/modules/poll/services/poll-controller.service/poll-controller.service';
Expand Down Expand Up @@ -81,6 +82,11 @@ export abstract class BasePollDetailComponent<V extends PollContentObject, S ext
return this._entitledUsersSubject;
}

// the observable for the live-register
public get liveRegisterObservable(): Observable<EntitledUsersTableEntry[]> {
return this._liveRegisterObservable;
}

public get self(): BasePollDetailComponent<V, S> {
return this;
}
Expand Down Expand Up @@ -115,6 +121,7 @@ export abstract class BasePollDetailComponent<V extends PollContentObject, S ext
private _votesDataSubject = new BehaviorSubject<BaseVoteData[]>([]);
private _currentOperator!: ViewUser;
private _pollId!: Id;
private _liveRegisterObservable = new BehaviorSubject<EntitledUsersTableEntry[]>([]);

protected repo = inject(PollControllerService);
protected route = inject(ActivatedRoute);
Expand All @@ -125,6 +132,7 @@ export abstract class BasePollDetailComponent<V extends PollContentObject, S ext
protected cd = inject(ChangeDetectorRef);
protected userRepo = inject(ParticipantControllerService);
private scrollTableManage = inject(ScrollingTableManageService);
private meetingUserRepo = inject(MeetingUserRepositoryService);

public constructor(
protected pollService: S,
Expand Down Expand Up @@ -220,6 +228,7 @@ export abstract class BasePollDetailComponent<V extends PollContentObject, S ext
this.setVotesData(this.createVotesData());
this.onAfterSetVotesData();
this.setEntitledUsersData();
this.setLiveRegisterData();
}

private setEntitledUsersData(): void {
Expand Down Expand Up @@ -276,6 +285,49 @@ export abstract class BasePollDetailComponent<V extends PollContentObject, S ext
);
}

private setLiveRegisterData(): void {
const userIds = new Set<Id>([]);
for (const group of this.poll.entitled_groups) {
const meetingUserIds = group.meeting_user_ids ?? [];
meetingUserIds.forEach(mu_id => userIds.add(this.meetingUserRepo.getViewModel(mu_id)?.user_id));
}
const delegates = new Set<Id>([]);
Array.from(userIds).forEach(userId => {
if (this.userRepo.getViewModel(userId)?.vote_delegated_to_id()) {
delegates.add(this.userRepo.getViewModel(userId)?.vote_delegated_to_id());
}
});
userIds.update(delegates);

this.subscriptions.push(
this.userRepo
.getViewModelListObservable()
.pipe(
filter(users => !!users.length),
map(users => users.filter(user => userIds.has(user.id)))
)
.subscribe(users => {
const entries: EntitledUsersTableEntry[] = [];
for (const user of users || []) {
const delegateToId = user.vote_delegated_to_id();
const voted = (this.poll.has_voted_user_ids ?? []).includes(user.id);
entries.push({
id: user.id,
user: user,
voted_verbose: `voted:${voted}`,
user_id: user.id,
present: user?.isPresentInMeeting(),
voted: voted,
vote_delegated_to_user_id: delegateToId,
vote_delegated_to: delegateToId ? users.find(utmp => utmp.id === delegateToId) : null
});
}
this._liveRegisterObservable.next(entries);
this.cd.markForCheck();
})
);
}

public hasUserVoteDelegation(user: ViewUser): boolean {
if (user.isVoteRightDelegated || this._currentOperator.canVoteFor(user)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PollProgressComponent extends BaseUiComponent implements OnInit {
public max = 1;

public get votescast(): number {
return this.poll?.vote_count || 0;
return this.poll?.has_voted_user_ids?.length || 0;
}

public get canSeeProgressBar(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,19 @@ <h3 class="result-title">
}
<!-- No results yet -->
@if (!hasResults) {
<div>
<i>
{{ 'No results yet.' | translate }}
</i>
</div>
@if (isStarted) {
<div>
<i>
{{ 'Voting in progress.' | translate }}
</i>
</div>
} @else {
<div>
<i>
{{ 'No results yet.' | translate }}
</i>
</div>
}
}
<!-- Has results, but user cannot see -->
@if (hasResults && !canSeeResults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export class AssignmentPollDetailContentComponent implements OnInit {
return this.method === PollMethod.YNA;
}

public get isStarted(): boolean {
return this.state === PollState.Started;
}

public get isFinished(): boolean {
return this.state === PollState.Finished;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ <h1>{{ poll.title }}</h1>
<div class="assignment-result-wrapper">
<!-- Result -->
<os-assignment-poll-detail-content [poll]="poll"></os-assignment-poll-detail-content>
@if (showResults && poll.stateHasVotes && poll.isEVoting) {
<mat-tab-group (selectedTabChange)="onTabChange()">
@if (poll.isStarted) {
<os-poll-progress [poll]="poll"></os-poll-progress>
}
<mat-tab-group (selectedTabChange)="onTabChange()">
@if (showResults && poll.stateHasVotes && poll.isEVoting) {
<mat-tab label="{{ 'Single votes' | translate }}">
<!-- Single Votes Table -->
<div class="named-result-table">
Expand All @@ -62,8 +65,20 @@ <h1>{{ poll.title }}</h1>
[isViewingThis]="isViewingEntitledUserslist"
></os-entitled-users-table>
</mat-tab>
</mat-tab-group>
}
} @else if (poll.isEVoting && poll.isStarted) {
<mat-tab label="{{ 'Single votes' | translate }}">
<!-- Single Votes Table -->
<div class="named-result-table">{{ 'No data available' | translate }}</div>
</mat-tab>
<mat-tab *osPerms="permission.pollCanManage" label="{{ 'Entitled users' | translate }}">
<os-entitled-users-table
[displayVoteWeight]="displayVoteWeight"
[entitledUsersObservable]="liveRegisterObservable"
[isViewingThis]="isViewingEntitledUserslist"
></os-entitled-users-table>
</mat-tab>
}
</mat-tab-group>
</div>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
</i>
</div>
}
} @else if (isStarted) {
<div>
<i>
{{ 'Voting in progress.' | translate }}
</i>
</div>
} @else {
<div>
<i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class MotionPollDetailContentComponent extends BaseUiComponent implements
return this.isFinished || this.isPublished;
}

public get isStarted(): boolean {
return this.state === PollState.Started;
}

public get isFinished(): boolean {
return this.state === PollState.Finished;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ <h1>{{ poll.title | translate }}</h1>
</span>
</div>
<os-motion-poll-detail-content [poll]="poll"></os-motion-poll-detail-content>

@if (poll.isStarted) {
<os-poll-progress [poll]="poll"></os-poll-progress>
}
<!-- Named table: only show if votes are present -->
@if (showResults && poll.stateHasVotes && poll.isEVoting) {
@if (poll.type === 'named') {
<os-poll-filted-votes-chart [poll]="poll"></os-poll-filted-votes-chart>
}
@if (showResults && poll.stateHasVotes && poll.isEVoting && poll.type === 'named') {
<os-poll-filted-votes-chart [poll]="poll"></os-poll-filted-votes-chart>
}

<mat-tab-group (selectedTabChange)="onTabChange()">
<mat-tab-group (selectedTabChange)="onTabChange()">
@if (showResults && poll.stateHasVotes && poll.isEVoting) {
<mat-tab label="{{ 'Single votes' | translate }}">
<div class="named-result-table">
<os-votes-table
Expand All @@ -60,10 +62,23 @@ <h1>{{ poll.title | translate }}</h1>
[isViewingThis]="isViewingEntitledUserslist"
></os-entitled-users-table>
</mat-tab>
</mat-tab-group>
}
<os-motion-poll-meta-information [poll]="poll"></os-motion-poll-meta-information>
} @else if (poll.isEVoting && poll.isStarted) {
<mat-tab label="{{ 'Single votes' | translate }}">
<div class="named-result-table">
{{ 'No data available' | translate }}
</div>
</mat-tab>
<mat-tab *osPerms="permission.motionCanManagePolls" label="{{ 'Entitled users' | translate }}">
<os-entitled-users-table
[displayVoteWeight]="displayVoteWeight"
[entitledUsersObservable]="liveRegisterObservable"
[isViewingThis]="isViewingEntitledUserslist"
></os-entitled-users-table>
</mat-tab>
}
</mat-tab-group>
}
<os-motion-poll-meta-information [poll]="poll"></os-motion-poll-meta-information>
</ng-template>

<!-- More Menu -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ export const getPollDetailSubscriptionConfig: SubscriptionConfigGenerator = (...
idField: `global_option_id`,
fieldset: FULL_FIELDSET,
follow: [{ idField: `vote_ids` }]
},
{
idField: `entitled_group_ids`,
fieldset: [],
follow: [
{
idField: `meeting_user_ids`,
fieldset: [`user_id`]
}
]
}
]
},
Expand Down
Loading