diff --git a/app.js b/app.js new file mode 100644 index 0000000..ccb3568 --- /dev/null +++ b/app.js @@ -0,0 +1,16 @@ +var realoApp = angular.module('tutorialApp', []); + +realoApp.factory('httpPostFactory', function($http) { + return function(file, data, callback) { + $http({ + url: file, + method: "POST", + data: data, + headers: { + 'Content-Type': undefined + } + }).success(function(response) { + callback(response); + }); + } +}); diff --git a/controllers/mainCtrl.js b/controllers/mainCtrl.js new file mode 100644 index 0000000..c56bc89 --- /dev/null +++ b/controllers/mainCtrl.js @@ -0,0 +1,53 @@ +realoApp.controller('mainCtrl', ['$scope', 'httpPostFactory', function($scope, httpPostFactory) { + httpPostFactory('main.php', new FormData(), function(callback) { + $scope.voteValues = callback; + $scope.answer = []; + $scope.unansweredQuestions = []; + $scope.results = []; + angular.forEach($scope.voteValues, function(v, k) { + $scope.unansweredQuestions.push(k); + var parties = {}; + for(var party in v.yes) { + if(v.yes.hasOwnProperty(party)) { + parties[party] = ""; + } + } + $scope.results.push(parties); + }); + }); + + $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; + var sum = {}; + angular.forEach($scope.results, function(v, k) { + for(var value in v) { + if(v.hasOwnProperty(value)) { + if(v[value] === "") continue; + if(typeof sum[value] === 'undefined') sum[value] = 0; + sum[value] += v[value]; + } + answered++; + } + }); + if(answered != 0) { + $scope.result = {}; + angular.forEach(sum, function(v, k) { + $scope.result[k] = Math.round((v/answered)*100) + '%'; + }) + } + } +}]); diff --git a/index.html b/index.html new file mode 100644 index 0000000..5c70b2e --- /dev/null +++ b/index.html @@ -0,0 +1,32 @@ + + + + + + + Real-o-Mat + + +
+

Ergebnis: {{ result }}

+
+

{{ question }}

+

+ + +

+

+ + +

+

+ + +

+
+
+ + + + + diff --git a/main.php b/main.php new file mode 100644 index 0000000..2c2b73c --- /dev/null +++ b/main.php @@ -0,0 +1,5 @@ +