Merge pull request #5122 from tsiegleauq/fix-regression-in-assignments
Fix regression in assignments
This commit is contained in:
commit
d248f5fbc1
@ -220,23 +220,15 @@ export class AssignmentRepositoryService extends BaseIsAgendaItemAndListOfSpeake
|
|||||||
*/
|
*/
|
||||||
public async updateVotes(poll: Partial<AssignmentPoll>, originalPoll: ViewAssignmentPoll): Promise<void> {
|
public async updateVotes(poll: Partial<AssignmentPoll>, originalPoll: ViewAssignmentPoll): Promise<void> {
|
||||||
poll.options.sort((a, b) => a.weight - b.weight);
|
poll.options.sort((a, b) => a.weight - b.weight);
|
||||||
|
|
||||||
const votes = poll.options.map(option => {
|
const votes = poll.options.map(option => {
|
||||||
switch (poll.pollmethod) {
|
const voteObject = {};
|
||||||
case 'votes':
|
for (const vote of option.votes) {
|
||||||
return { Votes: option.votes.find(v => v.value === 'Votes').weight };
|
voteObject[vote.value] = vote.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
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
return voteObject;
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
assignment_id: originalPoll.assignment_id,
|
assignment_id: originalPoll.assignment_id,
|
||||||
votes: votes,
|
votes: votes,
|
||||||
@ -246,6 +238,7 @@ export class AssignmentRepositoryService extends BaseIsAgendaItemAndListOfSpeake
|
|||||||
votesno: poll.votesno || null,
|
votesno: poll.votesno || null,
|
||||||
votesvalid: poll.votesvalid || null
|
votesvalid: poll.votesvalid || null
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.httpService.put(`${this.restPollPath}${originalPoll.id}/`, data);
|
await this.httpService.put(`${this.restPollPath}${originalPoll.id}/`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
|
|
||||||
import { UserRepositoryService } from 'app/core/repositories/users/user-repository.service';
|
import { UserRepositoryService } from 'app/core/repositories/users/user-repository.service';
|
||||||
import { CalculablePollKey, PollVoteValue } from 'app/core/ui-services/poll.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 { AssignmentPollOption } from 'app/shared/models/assignments/assignment-poll-option';
|
||||||
import { AssignmentPollService, SummaryPollKey } from '../../services/assignment-poll.service';
|
import { AssignmentPollService, SummaryPollKey } from '../../services/assignment-poll.service';
|
||||||
import { ViewAssignmentPoll } from '../../models/view-assignment-poll';
|
import { ViewAssignmentPoll } from '../../models/view-assignment-poll';
|
||||||
@ -25,6 +26,11 @@ type summaryPollKey = 'votescast' | 'votesvalid' | 'votesinvalid' | 'votesno' |
|
|||||||
styleUrls: ['./assignment-poll-dialog.component.scss']
|
styleUrls: ['./assignment-poll-dialog.component.scss']
|
||||||
})
|
})
|
||||||
export class AssignmentPollDialogComponent {
|
export class AssignmentPollDialogComponent {
|
||||||
|
/**
|
||||||
|
* The actual poll data to work on
|
||||||
|
*/
|
||||||
|
public poll: AssignmentPoll;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The summary values that will have fields in the dialog
|
* The summary values that will have fields in the dialog
|
||||||
*/
|
*/
|
||||||
@ -62,7 +68,9 @@ export class AssignmentPollDialogComponent {
|
|||||||
private userRepo: UserRepositoryService
|
private userRepo: UserRepositoryService
|
||||||
) {
|
) {
|
||||||
this.specialValues = this.pollService.specialPollVotes;
|
this.specialValues = this.pollService.specialPollVotes;
|
||||||
switch (this.data.pollmethod) {
|
this.poll = this.data.poll;
|
||||||
|
|
||||||
|
switch (this.poll.pollmethod) {
|
||||||
case 'votes':
|
case 'votes':
|
||||||
this.optionPollKeys = ['Votes'];
|
this.optionPollKeys = ['Votes'];
|
||||||
break;
|
break;
|
||||||
@ -104,7 +112,7 @@ export class AssignmentPollDialogComponent {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.dialogRef.close(this.data);
|
this.dialogRef.close(this.poll);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +174,7 @@ export class AssignmentPollDialogComponent {
|
|||||||
* @param weight
|
* @param weight
|
||||||
*/
|
*/
|
||||||
public setSumValue(value: SummaryPollKey, weight: string): void {
|
public setSumValue(value: SummaryPollKey, weight: string): void {
|
||||||
this.data[value] = parseFloat(weight);
|
this.poll[value] = parseFloat(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getGridClass(): string {
|
public getGridClass(): string {
|
||||||
|
@ -157,7 +157,7 @@
|
|||||||
<span>{{ pollService.getLabel(key) | translate }}</span
|
<span>{{ pollService.getLabel(key) | translate }}</span
|
||||||
>:
|
>:
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div *ngIf="poll[key]">
|
||||||
{{ pollService.getSpecialLabel(poll[key]) | translate }}
|
{{ pollService.getSpecialLabel(poll[key]) | translate }}
|
||||||
<span *ngIf="!pollService.isAbstractValue(poll, key)">
|
<span *ngIf="!pollService.isAbstractValue(poll, key)">
|
||||||
({{ pollService.getValuePercent(poll, key) }} %)
|
({{ pollService.getValuePercent(poll, key) }} %)
|
||||||
|
@ -197,7 +197,7 @@ export class AssignmentPollComponent extends BaseViewComponent implements OnInit
|
|||||||
*/
|
*/
|
||||||
public enterVotes(): void {
|
public enterVotes(): void {
|
||||||
const dialogRef = this.dialog.open(AssignmentPollDialogComponent, {
|
const dialogRef = this.dialog.open(AssignmentPollDialogComponent, {
|
||||||
data: this.poll.copy(),
|
data: this.poll,
|
||||||
...mediumDialogSettings
|
...mediumDialogSettings
|
||||||
});
|
});
|
||||||
dialogRef.afterClosed().subscribe(result => {
|
dialogRef.afterClosed().subscribe(result => {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { AssignmentPoll, AssignmentPollWithoutNestedModels } from 'app/shared/models/assignments/assignment-poll';
|
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 { BaseProjectableViewModel } from 'app/site/base/base-projectable-view-model';
|
||||||
import { ProjectorElementBuildDeskriptor } from 'app/site/base/projectable';
|
import { ProjectorElementBuildDeskriptor } from 'app/site/base/projectable';
|
||||||
import { ViewAssignmentPollOption } from './view-assignment-poll-option';
|
import { ViewAssignmentPollOption } from './view-assignment-poll-option';
|
||||||
@ -33,24 +32,6 @@ export class ViewAssignmentPoll extends BaseProjectableViewModel<AssignmentPoll>
|
|||||||
getDialogTitle: () => 'TODO'
|
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 {
|
export interface ViewAssignmentPoll extends AssignmentPollWithoutNestedModels {
|
||||||
|
Loading…
Reference in New Issue
Block a user