- sort answers based on number of votes

- limit display of responses to 7 to prevent squishing of display in the whiteboard
This commit is contained in:
Richard Alam 2021-04-28 21:34:21 +00:00
parent 414716d23b
commit 39c69675a4

View File

@ -259,9 +259,25 @@ object Polls {
shape += "status" -> WhiteboardKeyUtil.DRAW_END_STATUS
val answers = new ArrayBuffer[SimpleVoteOutVO]
result.answers.foreach(ans => {
answers += SimpleVoteOutVO(ans.id, ans.key, ans.numVotes)
})
def sortByNumVotes(s1: SimpleVoteOutVO, s2: SimpleVoteOutVO) = {
s1.numVotes > s2.numVotes
}
val sorted_answers = result.answers.sortWith(sortByNumVotes)
// Limit the number of answers displayed to minimize
// squishing the display.
if (sorted_answers.length < 7) {
sorted_answers.foreach(ans => {
answers += SimpleVoteOutVO(ans.id, ans.key, ans.numVotes)
})
} else {
for (i <- 0 until 7) {
val ans = sorted_answers(i)
answers += SimpleVoteOutVO(ans.id, ans.key, ans.numVotes)
}
}
shape += "result" -> answers