diff --git a/client/src/app/core/repositories/assignments/assignment-repository.service.ts b/client/src/app/core/repositories/assignments/assignment-repository.service.ts index 794f7da79..77b234da2 100644 --- a/client/src/app/core/repositories/assignments/assignment-repository.service.ts +++ b/client/src/app/core/repositories/assignments/assignment-repository.service.ts @@ -220,23 +220,15 @@ export class AssignmentRepositoryService extends BaseIsAgendaItemAndListOfSpeake */ public async updateVotes(poll: Partial, originalPoll: ViewAssignmentPoll): Promise { poll.options.sort((a, b) => a.weight - b.weight); + const votes = poll.options.map(option => { - switch (poll.pollmethod) { - case 'votes': - return { Votes: option.votes.find(v => v.value === 'Votes').weight }; - case 'yn': - return { - Yes: option.votes.find(v => v.value === 'Yes').weight, - No: option.votes.find(v => v.value === 'No').weight - }; - case 'yna': - return { - Yes: option.votes.find(v => v.value === 'Yes').weight, - No: option.votes.find(v => v.value === 'No').weight, - Abstain: option.votes.find(v => v.value === 'Abstain').weight - }; + const voteObject = {}; + for (const vote of option.votes) { + voteObject[vote.value] = vote.weight; } + return voteObject; }); + const data = { assignment_id: originalPoll.assignment_id, votes: votes, @@ -246,6 +238,7 @@ export class AssignmentRepositoryService extends BaseIsAgendaItemAndListOfSpeake votesno: poll.votesno || null, votesvalid: poll.votesvalid || null }; + await this.httpService.put(`${this.restPollPath}${originalPoll.id}/`, data); } diff --git a/client/src/app/site/assignments/components/assignment-poll-dialog/assignment-poll-dialog.component.ts b/client/src/app/site/assignments/components/assignment-poll-dialog/assignment-poll-dialog.component.ts index 13b281d1c..1fe9d7ac5 100644 --- a/client/src/app/site/assignments/components/assignment-poll-dialog/assignment-poll-dialog.component.ts +++ b/client/src/app/site/assignments/components/assignment-poll-dialog/assignment-poll-dialog.component.ts @@ -6,6 +6,7 @@ import { TranslateService } from '@ngx-translate/core'; import { UserRepositoryService } from 'app/core/repositories/users/user-repository.service'; import { CalculablePollKey, PollVoteValue } from 'app/core/ui-services/poll.service'; +import { AssignmentPoll } from 'app/shared/models/assignments/assignment-poll'; import { AssignmentPollOption } from 'app/shared/models/assignments/assignment-poll-option'; import { AssignmentPollService, SummaryPollKey } from '../../services/assignment-poll.service'; import { ViewAssignmentPoll } from '../../models/view-assignment-poll'; @@ -25,6 +26,11 @@ type summaryPollKey = 'votescast' | 'votesvalid' | 'votesinvalid' | 'votesno' | styleUrls: ['./assignment-poll-dialog.component.scss'] }) export class AssignmentPollDialogComponent { + /** + * The actual poll data to work on + */ + public poll: AssignmentPoll; + /** * The summary values that will have fields in the dialog */ @@ -62,7 +68,9 @@ export class AssignmentPollDialogComponent { private userRepo: UserRepositoryService ) { this.specialValues = this.pollService.specialPollVotes; - switch (this.data.pollmethod) { + this.poll = this.data.poll; + + switch (this.poll.pollmethod) { case 'votes': this.optionPollKeys = ['Votes']; break; @@ -104,7 +112,7 @@ export class AssignmentPollDialogComponent { } ); } else { - this.dialogRef.close(this.data); + this.dialogRef.close(this.poll); } } @@ -166,7 +174,7 @@ export class AssignmentPollDialogComponent { * @param weight */ public setSumValue(value: SummaryPollKey, weight: string): void { - this.data[value] = parseFloat(weight); + this.poll[value] = parseFloat(weight); } public getGridClass(): string { diff --git a/client/src/app/site/assignments/components/assignment-poll/assignment-poll.component.html b/client/src/app/site/assignments/components/assignment-poll/assignment-poll.component.html index ebf258414..92e2766c0 100644 --- a/client/src/app/site/assignments/components/assignment-poll/assignment-poll.component.html +++ b/client/src/app/site/assignments/components/assignment-poll/assignment-poll.component.html @@ -157,7 +157,7 @@ {{ pollService.getLabel(key) | translate }}: -
+
{{ pollService.getSpecialLabel(poll[key]) | translate }} ({{ pollService.getValuePercent(poll, key) }} %) diff --git a/client/src/app/site/assignments/components/assignment-poll/assignment-poll.component.ts b/client/src/app/site/assignments/components/assignment-poll/assignment-poll.component.ts index dffd51c9e..0d6dee5c0 100644 --- a/client/src/app/site/assignments/components/assignment-poll/assignment-poll.component.ts +++ b/client/src/app/site/assignments/components/assignment-poll/assignment-poll.component.ts @@ -197,7 +197,7 @@ export class AssignmentPollComponent extends BaseViewComponent implements OnInit */ public enterVotes(): void { const dialogRef = this.dialog.open(AssignmentPollDialogComponent, { - data: this.poll.copy(), + data: this.poll, ...mediumDialogSettings }); dialogRef.afterClosed().subscribe(result => { diff --git a/client/src/app/site/assignments/models/view-assignment-poll.ts b/client/src/app/site/assignments/models/view-assignment-poll.ts index 23f805a74..ca89e297b 100644 --- a/client/src/app/site/assignments/models/view-assignment-poll.ts +++ b/client/src/app/site/assignments/models/view-assignment-poll.ts @@ -1,5 +1,4 @@ import { AssignmentPoll, AssignmentPollWithoutNestedModels } from 'app/shared/models/assignments/assignment-poll'; -import { AssignmentPollOption } from 'app/shared/models/assignments/assignment-poll-option'; import { BaseProjectableViewModel } from 'app/site/base/base-projectable-view-model'; import { ProjectorElementBuildDeskriptor } from 'app/site/base/projectable'; import { ViewAssignmentPollOption } from './view-assignment-poll-option'; @@ -33,24 +32,6 @@ export class ViewAssignmentPoll extends BaseProjectableViewModel getDialogTitle: () => 'TODO' }; } - - /** - * Creates a copy with deep-copy on all changing numerical values, - * but intact uncopied references to the users - * - * TODO: This MUST NOT be done this way. Do not create ViewModels on your own... - */ - public copy(): ViewAssignmentPoll { - const poll = new ViewAssignmentPoll(new AssignmentPoll(JSON.parse(JSON.stringify(this.poll)))); - (poll)._options = this.options.map(option => { - const polloption = new ViewAssignmentPollOption( - new AssignmentPollOption(JSON.parse(JSON.stringify(option.option))) - ); - (polloption)._user = option.user; - return polloption; - }); - return poll; - } } export interface ViewAssignmentPoll extends AssignmentPollWithoutNestedModels {