diff --git a/controllers/mainCtrl.js b/controllers/mainCtrl.js index c56bc89..007a20a 100644 --- a/controllers/mainCtrl.js +++ b/controllers/mainCtrl.js @@ -1,6 +1,7 @@ realoApp.controller('mainCtrl', ['$scope', 'httpPostFactory', function($scope, httpPostFactory) { httpPostFactory('main.php', new FormData(), function(callback) { $scope.voteValues = callback; + $scope.answered = 0; $scope.answer = []; $scope.unansweredQuestions = []; $scope.results = []; @@ -19,34 +20,36 @@ $scope.updateAnswer = function(index) { var name = $scope.unansweredQuestions[index]; var vote = $scope.answer[index]; - //console.log($scope.answer[index]); var currValues = $scope.voteValues[name][vote]; for(var value in currValues) { if(currValues.hasOwnProperty(value)) { $scope.results[index][value] = currValues[value]; } } - console.log($scope.voteValues[name][vote]); updateResults(); } var updateResults = function() { - var answered = 0; + $scope.answered = 0; var sum = {}; angular.forEach($scope.results, function(v, k) { + var empty = false; for(var value in v) { if(v.hasOwnProperty(value)) { - if(v[value] === "") continue; + if(v[value] === "") { + empty = true; + break; + } if(typeof sum[value] === 'undefined') sum[value] = 0; sum[value] += v[value]; } - answered++; } + if(!empty) $scope.answered++; }); - if(answered != 0) { + if($scope.answered != 0) { $scope.result = {}; angular.forEach(sum, function(v, k) { - $scope.result[k] = Math.round((v/answered)*100) + '%'; + $scope.result[k] = Math.round((v/$scope.answered)*100) + '%'; }) } } diff --git a/index.html b/index.html index 5c70b2e..8ad1e7e 100644 --- a/index.html +++ b/index.html @@ -7,22 +7,31 @@
Noch keine Fragen beantwortet.
+- +
- + +
- + +