2015-11-03 12:57:41 +01:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
classNames: ['evaluation-summary'],
|
|
|
|
|
|
|
|
evaluationBestOptions: function() {
|
2016-01-19 05:46:52 +01:00
|
|
|
let options = [];
|
|
|
|
let bestOptions = [];
|
2015-11-03 12:57:41 +01:00
|
|
|
// can not evaluate answer type free text
|
2016-01-19 05:46:52 +01:00
|
|
|
if (this.get('poll.isFreeText')) {
|
2015-11-03 12:57:41 +01:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// can not evaluate a poll without users
|
2016-01-19 05:46:52 +01:00
|
|
|
if (Ember.isEmpty(this.get('poll.users'))) {
|
2015-11-03 12:57:41 +01:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
this.get('poll.users').forEach(function(user) {
|
|
|
|
user.get('selections').forEach(function(selection, i) {
|
|
|
|
if (options.length - 1 < i) {
|
2015-11-03 12:57:41 +01:00
|
|
|
options.push({
|
|
|
|
answers: [],
|
|
|
|
key: i,
|
|
|
|
score: 0
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
if (typeof options[i].answers[selection.get('type')] === 'undefined') {
|
2015-11-03 12:57:41 +01:00
|
|
|
options[i].answers[selection.get('type')] = 0;
|
|
|
|
}
|
|
|
|
options[i].answers[selection.get('type')]++;
|
|
|
|
|
|
|
|
switch (selection.get('type')) {
|
|
|
|
case 'yes':
|
|
|
|
options[i].score += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'maybe':
|
|
|
|
options[i].score += 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'no':
|
|
|
|
options[i].score -= 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
options.sort(function(a, b) {
|
|
|
|
return a.score < b.score;
|
|
|
|
});
|
|
|
|
|
|
|
|
bestOptions.push(
|
|
|
|
options[0]
|
|
|
|
);
|
2016-01-19 05:46:52 +01:00
|
|
|
let i = 1;
|
2015-11-03 12:57:41 +01:00
|
|
|
while(true) {
|
|
|
|
if (
|
|
|
|
typeof options[i] !== 'undefined' &&
|
|
|
|
bestOptions[0].score === options[i].score
|
|
|
|
) {
|
|
|
|
bestOptions.push(
|
|
|
|
options[i]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2016-01-19 05:46:52 +01:00
|
|
|
bestOptions.forEach((bestOption, i) => {
|
|
|
|
if (this.get('poll.isFindADate')) {
|
|
|
|
bestOptions[i].title = this.get('dates')[bestOption.key].title;
|
2015-11-03 12:57:41 +01:00
|
|
|
}
|
|
|
|
else {
|
2016-01-19 05:46:52 +01:00
|
|
|
bestOptions[i].title = this.get('poll.options')[bestOption.key].title;
|
2015-11-03 12:57:41 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return bestOptions;
|
|
|
|
}.property('poll.users.@each'),
|
|
|
|
|
|
|
|
evaluationBestOptionsMultiple: function(){
|
|
|
|
if (this.get('evaluationBestOptions.length') > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}.property('evaluationBestOptions'),
|
|
|
|
|
|
|
|
evaluationLastParticipation: function(){
|
|
|
|
return this.get('sortedUsers.lastObject.creationDate');
|
|
|
|
}.property('sortedUsers.@each'),
|
|
|
|
|
|
|
|
evaluationParticipants: function(){
|
|
|
|
return this.get('poll.users.length');
|
|
|
|
}.property('poll.users.@each')
|
|
|
|
});
|