Merge pull request #5122 from tsiegleauq/fix-regression-in-assignments

Fix regression in assignments
This commit is contained in:
Finn Stutzenstein 2019-11-08 11:45:42 +01:00 committed by GitHub
commit d248f5fbc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 38 deletions

View File

@ -220,23 +220,15 @@ export class AssignmentRepositoryService extends BaseIsAgendaItemAndListOfSpeake
*/
public async updateVotes(poll: Partial<AssignmentPoll>, originalPoll: ViewAssignmentPoll): Promise<void> {
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);
}

View File

@ -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 {

View File

@ -157,7 +157,7 @@
<span>{{ pollService.getLabel(key) | translate }}</span
>:
</div>
<div>
<div *ngIf="poll[key]">
{{ pollService.getSpecialLabel(poll[key]) | translate }}
<span *ngIf="!pollService.isAbstractValue(poll, key)">
({{ pollService.getValuePercent(poll, key) }} %)

View File

@ -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 => {

View File

@ -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<AssignmentPoll>
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))));
(<any>poll)._options = this.options.map(option => {
const polloption = new ViewAssignmentPollOption(
new AssignmentPollOption(JSON.parse(JSON.stringify(option.option)))
);
(<any>polloption)._user = option.user;
return polloption;
});
return poll;
}
}
export interface ViewAssignmentPoll extends AssignmentPollWithoutNestedModels {