Skip to content

Commit

Permalink
Merge pull request #15 from Shiti/master
Browse files Browse the repository at this point in the history
fixed result view and merged with Kiran's changes
  • Loading branch information
sridharpg committed Dec 14, 2012
2 parents 7a85a7c + 477067c commit 3f2fadc
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 38 deletions.
10 changes: 10 additions & 0 deletions app/fixtures/questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"answers": [
"true", "false"
],
"correctAnswer":"false",
"weight": 2,
"type": "radio"
},
Expand All @@ -14,6 +15,7 @@
"answers": [
8, 13, 21, 26, 31
],
"correctAnswer":"21",
"weight": 2,
"type": "radio"
},
Expand All @@ -22,6 +24,7 @@
"answers": [
"dog", "mouse", "lion", "snake", "elephant"
],
"correctAnswer":"snake",
"weight": 4,
"type": "radio"
},
Expand All @@ -30,6 +33,7 @@
"answers": [
20, 24, 25, 26, 28
],
"correctAnswer":"24",
"weight": 4,
"type": "radio"
},
Expand All @@ -38,6 +42,7 @@
"answers": [
3, 7, 8, 15, 30
],
"correctAnswer":"8",
"weight": 4,
"type": "radio"
},
Expand All @@ -46,6 +51,7 @@
"answers": [
"twig", "tree", "branch", "blossom"
],
"correctAnswer":"twig",
"weight": 5,
"type": "radio"
},
Expand All @@ -54,6 +60,7 @@
"answers": [
"city", "animal", "ocean", "river", "country"
],
"correctAnswer":"ocean",
"weight": 2,
"type": "radio"
},
Expand All @@ -62,6 +69,7 @@
"answers": [
2, 5, 10, 25, 50
],
"correctAnswer":"10",
"weight": 4,
"type": "radio"
},
Expand All @@ -70,12 +78,14 @@
"answers": [
2, 4, 4.5, 5, 6
],
"correctAnswer": "5",
"weight": 6,
"type": "radio"
},
{
"question": "Who is the famous personality?",
"imageURL": "http://ia.media-imdb.com/images/M/MV5BMTIwMzAwMzg1MV5BMl5BanBnXkFtZTYwMjc4ODQ2._V1._SX214_CR0,0,214,314_.jpg",
"correctAnswer":"Stanley Kubrick",
"weight": 8,
"type": "fillin"
}
Expand Down
14 changes: 7 additions & 7 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!doctype html>
<html data-ng-app="quizApp" ng-controller="AppCtrl">
<head>
<title>Quiz</title>
<title>{{locale['Quiz']}}</title>
</head>
<body class='quiz-body' ng-init="loadLang()">
<div id="floating-toolbar">
<select id="language-select" data-ng-change="selectAction()"data-ng-model="selected" data-ng-options="l.id as l.label for l in languages"></select>
<div ng-controller="ThemeCtrl" class="theme-bar">
<link rel="stylesheet" href="css/themes/{{theme}}/theme.css">
<div class='dark' data-ng-click="changeTheme('dark')"></div><div class='funky' data-ng-click="changeTheme('funky')"></div>
</div>
<div id="floating-toolbar">
<select id="language-select" data-ng-change="selectAction()"data-ng-model="selected" data-ng-options="l.id as l.label for l in languages"></select>
<div ng-controller="ThemeCtrl" class="theme-bar">
<link rel="stylesheet" href="css/themes/{{theme}}/theme.css">
<div class='dark' data-ng-click="changeTheme('dark')"></div><div class='funky' data-ng-click="changeTheme('funky')"></div>
</div>
</div>

<div data-ng-view></div>
<script src="js/thirdparty/jquery-1.8.3.js"></script>
Expand Down
15 changes: 9 additions & 6 deletions app/js/controllers/quizCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ quizApp.controller('QuizCtrl', function QuizCtrl($rootScope, $scope, $resource,
$scope.quiz = quizModel.initialize(data);
$scope.currentPosition = -1;

$scope.user = userModel.initialize($rootScope.userName);

if ($scope.quiz.isRandom) {
$scope.quiz.questionnaire = $scope.shuffle($scope.quiz.questionnaire);
}
Expand All @@ -26,16 +28,14 @@ quizApp.controller('QuizCtrl', function QuizCtrl($rootScope, $scope, $resource,
$scope.currentQuestion = $scope.quiz.questionnaire[++$scope.currentPosition];
};

$scope.user = {};

$scope.submitAns = function (id) {
var question = $scope.quiz.questionnaire.filter(function (value) {
return value.id === id;
});

if ($scope.user.response === question.answer) {
if ($scope.currentResponse === question[0].answer) {
$scope.user.correct = $scope.user.correct + 1;
$scope.user.score = $scope.user.score + question.weightage;
$scope.user.score = $scope.user.score + question[0].weightage;
}
$scope.next();
};
Expand All @@ -46,13 +46,13 @@ quizApp.controller('QuizCtrl', function QuizCtrl($rootScope, $scope, $resource,
};

$scope.isAnswered = function () {
return ($scope.user.response !== "" && $scope.user.response !== undefined)
return ($scope.currentResponse !== "" && $scope.currentResponse !== undefined)
};

$scope.next=function(){
var valid = $scope.hasNext();
if (valid !== true) {
$scope.user.response = "";
$scope.currentResponse = "";
$scope.updatePage();
timerController.restart();
} else {
Expand All @@ -67,4 +67,7 @@ quizApp.controller('QuizCtrl', function QuizCtrl($rootScope, $scope, $resource,
$rootScope.userName="";
$location.path('/');
};
$scope.back=function(){
$location.path('/');
};
});
12 changes: 9 additions & 3 deletions app/js/i18n/de.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"locale-id": "de",
"appTitle": "Quiz Anwendung",
"home-title": "Quiz",
"home-text": "geben Sie Ihren Namen",
"Quiz": "Quiz",
"enter-your-name": "Geben Sie Ihren Namen",
"start-quiz": "Quiz starten",
"help": "helfen",
"results":"Ergebnisse",
"congrats":"Herzlichen Glückwunsch!",
"score-msg":"Ihr Ergebnis ist ",
"play-again":"spiele wieder",
"new-game":"neues Spiel"
"new-game":"neues Spiel",
"next":"neben",
"pass":"gehen",
"question":"Frage",
"weight":"Gewicht",
"quit":"verlassen",
"back":"zurück"
}
12 changes: 9 additions & 3 deletions app/js/i18n/en.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{
"locale-id": "en",
"appTitle": "Quiz Application",
"home-title": "Quiz",
"home-text": "Enter your name",
"Quiz": "Quiz",
"enter-your-name": "Enter your name",
"start-quiz": "Start Quiz",
"help": "Help",
"results":"Results",
"congrats":"Congratulations!",
"score-msg":"Your score is",
"play-again":"Play Again",
"new-game":"New Game"
"new-game":"New Game",
"next":"Next",
"pass":"Pass",
"question":"Question",
"weight":"Weight",
"quit":"Quit" ,
"back":"Back"
}
1 change: 0 additions & 1 deletion app/js/models/userModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ quizApp.factory('userModel', function () {
initialize: function (name) {
var user = {};
user.name = name;
user.response = "";
user.correct = 0;
user.score = 0;
return user;
Expand Down
18 changes: 9 additions & 9 deletions app/js/views/templates/helpView.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<section class='help-view' data-ng-controller="HelpCtrl">
<ul>
<li>The score obtained at the end of the Quiz is sum of weights of the questions answered correctly</li>
<li>All the questions do not have the same weight</li>
<li>If you do not answer the question in the time limit the question is passed</li>
<li>There are {{quiz.questionnaire.length}} questions</li>
<li>Each question has time limit of {{quiz.duration}} seconds </li>
</ul>
<button data-ng-click="back()">Back</button>
<section class='help-view' data-ng-controller="QuizCtrl">
<div>
<p>The score obtained at the end of the Quiz is the sum of weights of the questions answered correctly.</p>
<p>There are {{quiz.questionnaire.length}} questions</p>
<p>All the questions do not have the same weight.</p>
<p>Each question has time limit of {{quiz.duration}} seconds </p>
<p>If you do not answer the question in the time limit the question is passed</p>
<button data-ng-click="back()">{{locale['back']}}</button>
</div>
</section>
2 changes: 1 addition & 1 deletion app/js/views/templates/homeView.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<section class='home-view' data-ng-controller="HomeCtrl">
<div class='logo'></div>
<label class='name-label'>
<span>Enter your name</span>
<span>{{locale['enter-your-name']}}</span>
<input type='text' data-ng-model='userName'/>
</label>
<div class='button-bar'>
Expand Down
15 changes: 8 additions & 7 deletions app/js/views/templates/quizView.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<section class="quiz-view" data-ng-controller="QuizCtrl">
<header class='header'>
<span class='question-number'>Question {{currentPosition+1}}/{{quiz.questionnaire.length}}</span>
<span class='question-number'>{{locale['question']}} {{currentPosition+1}}/{{quiz.questionnaire.length}}</span>
<timer duration='{{quiz.duration}}' autostart='true'></timer>
<span class='weight'>Weight {{currentQuestion.weightage}}</span>
<span class='weight'>{{locale['weight']}} {{currentQuestion.weightage}}</span>
</header>
<section class='content'>
<div class='question'>{{currentQuestion.statement}}</div>
<div class='options-container'>
<label class='option' data-ng-repeat="option in currentQuestion.options">
<span class='inner'>
<input type="radio" value="{{option}}" data-ng-model="user.response"><div class='tick'>&nbsp;</div><span>{{option}}</span>
<input type="radio" value="{{option}}" data-ng-model="$parent.currentResponse"><div class='tick'>&nbsp;</div><span>{{option}}</span>
</span>
</label>

<!-- for image -->
<img class='picture' data-ng-show="currentQuestion.imgPath.length>0" src="{{currentQuestion.imgPath}}">
<span data-ng-show="currentQuestion.isFillIn()">
<input type="text" data-ng-model="user.response">
<input type="text" data-ng-model="currentResponse">
</span>
</div>
</section>
<footer class='footer'>
<a class='quit' data-ng-click="quit()"><span>&lt;</span> Quit</a>
<button data-ng-disabled="!isAnswered()" data-ng-click="submitAns()">Next</button>
<a class='pass' data-ng-click="next()">Pass <span>&gt;</span></a>
<a class='quit' data-ng-click="quit()"><span>&lt;</span> {{locale['quit']}}</a>
<button data-ng-disabled="!isAnswered()" data-ng-click="submitAns(currentQuestion.id)">{{locale['next']}}</button>
<a class='pass' data-ng-click="next()">{{locale['pass']}}<span>&gt;</span></a>
</footer>
</section>
2 changes: 1 addition & 1 deletion app/js/views/templates/resultView.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<header>{{locale['results']}}</header>
<div class='result-content'>
{{locale['congrats']}}
<div class='score-container'>{{locale['score-msg']}}<br>{{score}}</div>
<div class='score-container'>{{locale['score-msg']}}<br>{{user.score}}</div>
</div>
</div>
<div class='score-content'>
Expand Down

0 comments on commit 3f2fadc

Please sign in to comment.