Merge pull request #5729 from FinnStutzenstein/fixAssignmentOptionSorting
Fix sorting of assignment options
This commit is contained in:
commit
b318bfda99
@ -117,19 +117,30 @@ export class AssignmentPollService extends PollService {
|
|||||||
const tableData: PollTableData[] = poll.options
|
const tableData: PollTableData[] = poll.options
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
if (this.sortByVote) {
|
if (this.sortByVote) {
|
||||||
|
let compareValue;
|
||||||
if (poll.pollmethod === AssignmentPollMethod.N) {
|
if (poll.pollmethod === AssignmentPollMethod.N) {
|
||||||
// most no on top:
|
|
||||||
// return b.no - a.no;
|
|
||||||
// least no on top:
|
// least no on top:
|
||||||
return a.no - b.no;
|
compareValue = a.no - b.no;
|
||||||
} else {
|
} else {
|
||||||
return b.yes - a.yes;
|
// most yes on top
|
||||||
|
compareValue = b.yes - a.yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Equal votes, sort by weight to have equal votes correctly sorted.
|
||||||
|
if (compareValue === 0 && a.weight && b.weight) {
|
||||||
|
// least weight on top
|
||||||
|
return a.weight - b.weight;
|
||||||
|
} else {
|
||||||
|
return compareValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PollData does not have weight, we need to rely on the order of things.
|
||||||
|
if (a.weight && b.weight) {
|
||||||
|
// least weight on top
|
||||||
|
return a.weight - b.weight;
|
||||||
} else {
|
} else {
|
||||||
// PollData does not have weight, we need to rely on the order of things.
|
return 0;
|
||||||
if (a.weight && b.weight) {
|
|
||||||
return b.weight - a.weight;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map((candidate: ViewAssignmentOption) => {
|
.map((candidate: ViewAssignmentOption) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user