forked from HarishGangula/quizServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player_old.html
189 lines (179 loc) · 7.29 KB
/
player_old.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE html>
<html lang="en" ng-app="playerApp">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Quiz</title>
<link rel="stylesheet" href="./semantic/semantic.min.css" />
</head>
<body ng-controller="playerAppController as player">
<div class="ui huge segment" style="height: 100vh;" ng-show="player.showScan">
<div class="login-body">
<canvas style="width: 100%;" id="canvas"></canvas>
<label class="mb-3">( OR )</label>
<label class="mb-1 d-block" for="input-QR">Enter QR Code</label>
<input name="input-QR" id="qrcode" class="w-100 my-3 py-2" />
<button type="button" onclick="verifyQrCode
(document.getElementById('qrcode').value)" class="btn btn-primary btn-block mb-3 rounded-0">
Login
</button>
</div>
</div>
<div class="ui huge placeholder segment" style="height: 100vh;">
<div ng-hide="quizStarted">
<img src="please_wait.jpg" alt="" style="display: block;width: 50%;margin: auto;" />
</div>
<div class="ui active inverted dimmer" ng-show="quizEnded && !showResults">
<div class="ui text loader">
Hurray! The quiz is complete. Results will be shown in a moment...
</div>
</div>
<div ng-show="quizStarted && !quizEnded">
<h1 ng-bind-html="question.text" style="font-size:2em;"></h1>
<img class="ui centered huge image" ng-src="{{question.image}}" alt="" ng-if="question.image" />
<div class="ui fluid vertical large menu">
<a class="item" ng-repeat="option in options" ng-click="selectOption(option)" ng-class="{'active': option === selectedOption }">
<span ng-bind-html="option.text"> </span>
<i class="check icon" style="position: absolute;right: 20px;top: 20px;color: green;" ng-if="option === selectedOption"></i>
</a>
</div>
<div class="field">
<button class="ui primary button" ng-click="sendResponse()" ng-show="!disableOptionContainer">
Submit
</button>
<button class="ui primary button" ng-click="sendResponse()" ng-show="disableOptionContainer" ng-disabled="true">
Choice Submitted
</button>
</div>
</div>
<div ng-show="showResults">
<img src="first.jpg" alt="" ng-if="rank === 1" style="width: 50%;display: block;margin: 0 auto;" />
<img src="second.jpg" alt="" ng-if="rank === 2" style="width: 50%;display: block;margin: 0 auto;" />
<img src="third.jpg" alt="" ng-if="rank === 3" style="width: 50%;display: block;margin: 0 auto;" />
<img src="last.jpg" alt="" ng-if="rank === 4" style="width: 50%;display: block;margin: 0 auto;" />
</div>
<div class="ui button primary huge" ng-show="showResults" ng-click="restartQuiz()">
Start
</div>
</div>
</body>
<script src="angular.js"></script>
<script src="angular-sanitize.min.js"></script>
<script src="./node_modules/timer.js/dist/timer.min.js"></script>
<script src="./node_modules/jquery/dist/jquery.min.js"></script>
<script src="./semantic/semantic.min.js"></script>
<script src="socket.io.js"></script>
<script src="lodash.min.js"></script>
<script src="socket.js"></script>
<script src="uuid.min.js"></script>
<script src="faker.js"></script>
<script>
angular.module("playerApp", ["ngSanitize"])
.controller("playerAppController", function(
$interval,
$timeout,
$scope
) {
var questionTimer = Date.now();
var player = this;
var socket = io();
faker.locale = "en_IND";
var user = {
code: faker.random.uuid(),
name: faker.name.findName()
}
player.showOptions = false;
player.showScan = false;
player.optionsLoader = false;
$scope.selectedOption = null;
$scope.quizEnded = false;
$scope.disableOptionContainer = true;
$scope.loadingMessage = "Waiting for Quiz to start......";
$scope.rank = 0;
$scope.questionAnswered = false;
$scope.firstQuestion = true;
socket.on("question", function(data) {
if(!$scope.firstQuestion && !$scope.questionAnswered) {
$scope.sendResponse();
}
if($scope.firstQuestion) {
$scope.quizStarted = true;
$scope.firstQuestion = false;
}
$scope.selectedOption = null;
$scope.questionAnswered = false;
console.log("Question received", data);
$scope.showOptions = true;
$scope.disableOptionContainer = false;
$scope.options = _.get(
JSON.parse(_.get(data, "data.body")),
"data.data.options"
);
$scope.question = _.get(
JSON.parse(_.get(data, "data.body")),
"data.data.question"
);
$(".ui.radio.checkbox").checkbox();
console.log("Question Options", player.options);
questionTimer = Date.now();
$scope.$apply();
// 'https://dev.ekstep.in'
});
socket.on("endQuiz", function(data) {
if(!$scope.questionAnswered) {
$scope.sendResponse();
}
$scope.quizEnded = true;
$scope.$apply();
});
socket.on("results", function(data) {
$scope.showResults = true;
console.log("Ending quiz...", data);
$scope.loadingMessage = "Preparing results......";
var id = user.code;
r = _.find(data.results, { code: user.code });
console.log(r);
$scope.rank = r.rank;
$scope.$apply();
});
$scope.selectOption = function(option) {
console.log(option);
$scope.selectedOption = option;
};
$scope.sendResponse = function() {
var data = {};
if($scope.selectedOption) {
data.option = _.clone($scope.selectedOption);
} else {
data.option = {
isCorrect: false
}
}
$scope.questionAnswered = true;
data.option.time = Date.now() - questionTimer;
$scope.disableOptionContainer = true;
data.user = user;
var settings = {
async: true,
crossDomain: true,
url: "/userResponse",
method: "POST",
headers: {
"Content-Type": "application/json",
"cache-control": "no-cache",
"Postman-Token": "c36c5931-fbf2-436f-9481-26f3ad9d0b55"
},
processData: false,
data: JSON.stringify(data)
};
$.ajax(settings).done(function(response) {
console.log(response);
});
};
$scope.restartQuiz = function() {
window.location.replace("/player.html");
};
});
</script>
</html>