-
Notifications
You must be signed in to change notification settings - Fork 1
/
rate.html
560 lines (494 loc) · 18 KB
/
rate.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
<!DOCTYPE html>
<html>
<head>
<title>Hobby-ever</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://cdn.firebase.com/libs/firebaseui/3.1.1/firebaseui.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/3.1.1/firebaseui.css" />
</head>
<script src="https://www.gstatic.com/firebasejs/5.8.5/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyCZ59-0Z7syxxHyDbV1O8I1B8Uxq6swBV0",
authDomain: "cs179-final.firebaseapp.com",
databaseURL: "https://cs179-final.firebaseio.com",
projectId: "cs179-final",
storageBucket: "cs179-final.appspot.com",
messagingSenderId: "863057579113"
};
firebase.initializeApp(config);
</script>
<script type="text/javascript">
function getQuery(query) {
var request = window.location.search.substr(1);
var queries = request.split("&");
for(var i=0; i<queries.length; i++) {
query_pair = queries[i].split("=");
if(query_pair[0] == query)
return query_pair[1];
}
return (false);
}
var tutor_id = getQuery("tutor_id");
var course_name = getQuery("course_name");
var course_date = getQuery("course_date").substr(0,10);
console.log("tutor_id: " + tutor_id + "\n course_name: " + course_name + "\n course_date: " + course_date);
var firestore = firebase.firestore();
window.onload = function () {
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
var uid = user.uid;
var email, credit, gender, username, phone, interests, skills, rate;
const usersRef = firestore.doc("users/" + uid);
const courseRef = firestore.doc("course/1");
document.getElementById('signup').style.display = 'none';
document.getElementById('login').style.display = 'none';
document.getElementById('top1').style.display = 'none';
document.getElementById('top2').style.display = 'none';
document.getElementById('user').style.display = 'block';
document.getElementById('top3').style.display = 'block';
document.getElementById('signout').style.display = 'block';
usersRef.get().then(function (doc) {
if (doc && doc.exists) {
const curData = doc.data();
user.email = curData.email;
user.credit = curData.credit;
user.gender = curData.gender;
user.username = curData.username;
user.phone = curData.phone;
user.interests = curData.interests;
user.skills = curData.skills;
user.rate = curData.rate;
user.rate_amount = curData.rate_amount;
loadPage(user);
}
}).catch(function (error) {
console.log("Got an error: " + error);
});
}
});
};
function loadPage(user) {
if (user.username) {
document.getElementById('username').textContent = user.username;
}
else if (user.email) {
document.getElementById('username').textContent = user.email;
}
const tutorRef = firestore.doc("users/" + tutor_id);
tutorRef.get().then(function (doc) {
if (doc && doc.exists) {
const curData = doc.data();
var tutor_email = curData.email;
var tutor_username = curData.username;
if(tutor_username) document.getElementById("rate_email").textContent = tutor_username;
else document.getElementById("rate_email").textContent = tutor_email;
document.getElementById("rate_subject").textContent = course_name;
document.getElementById("rate_time").textContent = course_date;
}
}).catch(function (error) {
console.log("Got an error: " + error);
});
}
function signout() {
firebase.auth().signOut().then(function () {
// Sign-out successful.
window.location.href = "login.html";
}, function (error) {
// An error happened.
alert(error);
});
}
function updateRate() {
var interests, skills, gender, credit, rate, email, phone, username, rate_amount;
const tutorRef = firestore.doc("users/" + tutor_id);
tutorRef.get().then(function (doc) {
if (doc && doc.exists) {
const curData = doc.data();
email = curData.email;
credit = curData.credit;
gender = curData.gender;
username = curData.username;
phone = curData.phone;
interests = curData.interests;
skills = curData.skills;
rate = curData.rate;
rate_amount = curData.rate_amount;
var rate_score = new Array();
var quest1 = document.getElementsByName('question1');
var quest2 = document.getElementsByName('question2');
var quest3 = document.getElementsByName('question3');
var quest4 = document.getElementsByName('question4');
var quest5 = document.getElementsByName('question5');
var count = 0;
var score = 0;
var newRate = rate;
rate_score[0] = 0;
rate_score[1] = 0;
rate_score[2] = 0;
rate_score[3] = 0;
rate_score[4] = 0;
for(var i=0; i<5; i++){
if(quest1[i].checked) {rate_score[0] = quest1[i].value;count = count+1;}
if(quest2[i].checked) {rate_score[1] = quest2[i].value;count = count+1;}
if(quest3[i].checked) {rate_score[2] = quest3[i].value;count = count+1;}
if(quest4[i].checked) {rate_score[3] = quest4[i].value;count = count+1;}
if(quest5[i].checked) {rate_score[4] = quest5[i].value;count = count+1;}
}
if(count!=0) {
score = (parseInt(rate_score[0]) + parseInt(rate_score[1]) + parseInt(rate_score[2]) + parseInt(rate_score[3]) + parseInt(rate_score[4])) / parseInt(count);
newRate = (parseFloat(rate*rate_amount) + score) / (parseInt(rate_amount) + 1);
newRate = newRate.toFixed(2);
rate_amount = parseInt(rate_amount) + 1
tutorRef.set({
email: email,
phone: phone,
gender: gender,
interests: interests,
skills: skills,
credit: credit,
rate: newRate,
username: username,
rate_amount: rate_amount
}).then(function () {
alert("Thank you for your feedback!");
resetRate();
console.log("score: " + score + " rate: " + rate + " newRate: " + newRate + " rate_amount: " + rate_amount);
window.location.href = "personal.html?coursePage=" + "true";
console.log("New rate status saved");
}).catch(function (error) {
console.log("Got an error: " + error);
});
}
else{
alert("Please rate at least one question!");
}
}
}).catch(function (error) {
console.log("Got an error: " + error);
});
}
function resetRate() {
for(var i=0; i<5; i++){
$('[name="question1"]').prop("checked", false);
$('[name="question2"]').prop("checked", false);
$('[name="question3"]').prop("checked", false);
$('[name="question4"]').prop("checked", false);
$('[name="question5"]').prop("checked", false);
}
}
</script>
<style>
#top {
background-color: white;
width: 100%;
height: 31px;
position: relative;
}
#top_content {
width: 900px;
height: 30px;
position: absolute;
left: 0;
right: 0;
margin: auto;
}
#top ul {
display: block;
height: 30px;
float: right;
line-height: 30px;
margin-top: 0;
}
#top ul li {
float: left;
list-style: none;
color: rgb(110, 110, 110);
font-size: 14px;
}
#top ul li a {
list-style: none;
text-decoration: none;
color: rgb(110, 110, 110);
font-size: 14px;
}
#signup,
#login,
#signout {
float: left;
list-style: none;
text-decoration: none;
color: rgb(110, 110, 110);
font-size: 14px;
display: block;
height: 30px;
line-height: 30px;
text-align: center;
margin-left: 10px;
margin-right: 10px;
}
#user {
float: left;
list-style: none;
text-decoration: none;
color: rgb(110, 110, 110);
font-size: 14px;
display: block;
height: 30px;
line-height: 30px;
text-align: center;
margin-left: 10px;
}
#signout,
#user,
#top2,
#top3 {
display: none;
}
#username {
margin-right: 10px;
}
#menu {
background-color: #162f59;
width: 100%;
height: 60px;
}
#menu_content {
width: 975px;
height: 60px;
line-height: 60px;
position: relative;
left: 0;
right: 0;
margin: auto;
}
#menu_content ul {
display: block;
height: 30px;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
}
#menu_content ul li {
float: left;
display: block;
}
#menu_content ul li a {
list-style: none;
text-decoration: none;
color: #f9fcfd;
}
#menu_homepage {
width: 100px;
}
#menu_match,
#menu_search,
#menu_personal,
#menu_rate,
#menu_course {
width: 75px;
text-align: center;
}
#title {
width: 800px;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
#title p {
font-size: 36px;
}
#middle {
width: 100%;
height: 800px;
margin-top: 40px;
background: linear-gradient(to bottom, white, #e5f2f8);
}
#middle_content {
width: 800px;
height: 750px;
background: linear-gradient(to bottom, white, #e5f2f8);
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
#middle_content table {
width: 460px;
height: 580px;
left: 0;
right: 0;
margin: auto;
padding-top: 30px;
}
#middle_content tr {
margin-top: 8px;
display: block;
}
#middle_content tr td {
width: 475px;
}
#info {
width: 600px;
padding-left: 25px;
line-height: 20px;
font-size: 20px;
}
#rate_email, #rate_time, #rate_subject {
font-size: 16px;
margin-left: 10px;
}
#quest,
#answer {
padding-left: 25px;
height: 30px;
line-height: 20px;
font-size: 16px;
}
#quest {
padding-left: 25px;
}
#answer {
padding-left: 40px;
}
#ra {
margin-left: 40px;
font-size: 16px;
text-align: center;
}
#comment {
margin-left: 25px;
width: 345px;
height: 100px;
line-height: 20px;
font-size: 16px;
}
#butto {
text-align: center;
padding-top: 75px;
}
#butto input {
width: 120px;
height: 30px;
font-size: 16px;
}
form.card {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
</style>
<body>
<div id="top">
<div id="top_content">
<ul>
<li id="signup"><a href="signup.html">Sign Up</a></li>
<li id="top1"> / </li>
<li id="login"><a href="login.html">Log In</a></li>
<li id="top2"> / </li>
<li id="user">Welcome, <a href="personal.html" id="username"></a></li>
<li id="top3"> / </li>
<li id="signout" onclick="signout()">Sign Out</li>
</ul>
</div>
</div>
<div id="menu">
<div id="menu_content">
<ul>
<li id="menu_homepage"><a href="main.html">Homepage</a></li>
<li id="menu_match"><a href="match.html">Match</a></li>
<li id="menu_search"><a href="search.html">Search</a></li>
<li id="menu_rate"><a href="rate.html">Rate</a></li>
<li id="menu_course"><a href="course.html">Course</a></li>
<li id="menu_personal"><a href="personal.html">Personal</a></li>
</ul>
</div>
</div>
<div id="title">
<p>Rate your paired-user</p>
</div>
<div id="middle">
<form id="middle_content" class="card">
<table>
<tr>
<td id="info" name="rate_email" colspan="2">User: <span id="rate_email"></span></td>
</tr>
<tr>
<td id="info" name="rate_subject">Subject: <span id="rate_subject"></span></td>
<td id="info" name="rate_time">Date: <span id="rate_time"></span></td>
</tr>
<tr style="margin-top:20px;">
<td colspan="2"> </td>
</tr>
<tr>
<td id="quest" colspan="2">Q1. Is the course content match how your paired-user described?</td>
</tr>
<tr>
<td id="answer" colspan="2">
<label><input id="ra" name="question1" type="radio" value="5">5</label>
<label><input id="ra" name="question1" type="radio" value="4">4</label>
<label><input id="ra" name="question1" type="radio" value="3">3</label>
<label><input id="ra" name="question1" type="radio" value="2">2</label>
<label><input id="ra" name="question1" type="radio" value="1">1</label>
</td>
</tr>
<tr>
<td id="quest" colspan="2">Q2. How would you rate your paired-user's ability in this aspect?</td>
</tr>
<tr>
<td id="answer" colspan="2">
<label><input id="ra" name="question2" type="radio" value="5">5</label>
<label><input id="ra" name="question2" type="radio" value="4">4</label>
<label><input id="ra" name="question2" type="radio" value="3">3</label>
<label><input id="ra" name="question2" type="radio" value="2">2</label>
<label><input id="ra" name="question2" type="radio" value="1">1</label>
</td>
</tr>
<tr>
<td id="quest" colspan="2">Q3. How was your paired-user's attitude??</td>
</tr>
<tr>
<td id="answer" colspan="2">
<label><input id="ra" name="question3" type="radio" value="5">5</label>
<label><input id="ra" name="question3" type="radio" value="4">4</label>
<label><input id="ra" name="question3" type="radio" value="3">3</label>
<label><input id="ra" name="question3" type="radio" value="2">2</label>
<label><input id="ra" name="question3" type="radio" value="1">1</label>
</td>
</tr>
<tr>
<td id="quest" colspan="2">Q4. How difficult do you think about this course?</td>
</tr>
<tr>
<td id="answer" colspan="2">
<label><input id="ra" name="question4" type="radio" value="5">5</label>
<label><input id="ra" name="question4" type="radio" value="4">4</label>
<label><input id="ra" name="question4" type="radio" value="3">3</label>
<label><input id="ra" name="question4" type="radio" value="2">2</label>
<label><input id="ra" name="question4" type="radio" value="1">1</label>
</td>
</tr>
<tr>
<td id="quest" colspan="2">Q5. How would you overall rate your paired-user?</td>
</tr>
<tr>
<td id="answer" colspan="2">
<label><input id="ra" name="question5" type="radio" value="5">5</label>
<label><input id="ra" name="question5" type="radio" value="4">4</label>
<label><input id="ra" name="question5" type="radio" value="3">3</label>
<label><input id="ra" name="question5" type="radio" value="2">2</label>
<label><input id="ra" name="question5" type="radio" value="1">1</label>
</td>
</tr>
<tr>
<td id="butto"><input type="button" value="Submit" onclick="updateRate()"></td>
<td id="butto"><input type="button" value="Reset" onclick="resetRate()"></td>
</tr>
</table>
</form>
</div>
</body>
</html>