-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
341 lines (288 loc) · 10.2 KB
/
index.html
File metadata and controls
341 lines (288 loc) · 10.2 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<script src="Database.js"></script>
<title>Student Database </title>
<script>
"use strict";
function getRandomStudent() {
let keys = Array.from(data.students.keys());
return data.students.get(keys[Math.floor(Math.random() * keys.length)]);
}
function clearTable(tblID) {
let tbl = document.getElementById(tblID);
tbl.innerHTML = "";
}
function clearButton(tblID) {
let tbl = document.getElementById(tblID);
tbl.innerHTML = "";
sIdInput.value="";
cCodeInput.value="";
gpaInput.value="";
eRoomInput.value="";
}
function addStudentTableHead(tblID) {
let tbl = document.getElementById(tblID);
let head=tbl.insertRow(0);
let c1 = head.insertCell(0);
let c2 = head.insertCell(1);
let c3 = head.insertCell(2);
c1.innerHTML = "ID";
c2.innerHTML = "Name";
c3.innerHTML = "GPA";
}
function addCoursesTableHead(tblID) {
let tbl = document.getElementById(tblID);
let head = tbl.insertRow(0);
let c1 = head.insertCell(0);
let c2 = head.insertCell(1);
let c3 = head.insertCell(2);
let c4 = head.insertCell(3);
c1.innerHTML = "CODE";
c2.innerHTML = "TIME";
c3.innerHTML = "DATE";
c4.innerHTML = "ROOMS";
}
function addStudentTableCoursesHead(tblID) {
let tbl = document.getElementById(tblID);
let r1c4 = tbl.rows[0].insertCell(3);
r1c4.innerHTML="Courses";
}
function addTableGivenStudentCourses(student, tblID) {
let tbl = document.getElementById(tblID);
addStudentTableCoursesHead(tblID);
let r2c4 = tbl.rows[1].insertCell(3);
let select = document.createElement("select");
select.size=3;
select.disabled="disabled";
select.style.width="125px";
for(let course of student.courses){
let option = document.createElement("option");
option.text=course.name;
option.style.color="blue";
select.appendChild(option);
}
r2c4.appendChild(select);
}
function addTableGiverCourse(course, tblID,rowIndex) {
let tbl = document.getElementById(tblID);
let head = tbl.insertRow(rowIndex);
let c1 = head.insertCell(0);
let c2 = head.insertCell(1);
let c3 = head.insertCell(2);
let c4 = head.insertCell(3);
c1.innerHTML = course.name;
c2.innerHTML = course.time;
c3.innerHTML = course.date;
let select = document.createElement("select");
select.size=3;
select.disabled="disabled";
select.style.width="125px";
for(let room of course.rooms){
let option = document.createElement("option");
option.text=room.toString();
option.style.color="blue";
select.appendChild(option);
}
c4.appendChild(select);
}
function addTableGivenStudent(student,tblID,rowIndex=1) {
let tbl = document.getElementById(tblID);
let row = tbl.insertRow(rowIndex);
let c1 = row.insertCell(0);
let c2 = row.insertCell(1);
let c3 = row.insertCell(2);
c1.style.width = "100px";
c2.style.width = "130px";
c3.style.width = "70px";
c1.innerHTML = student.id;
c2.innerHTML = student.name;
c3.innerHTML = student.gpa;
}
function randomStudentButton() {
clearTable("tbl");
addStudentTableHead("tbl");
let student = getRandomStudent();
addTableGivenStudent(student,"tbl");
}
function getStudentNumberGPA() {
clearTable("tbl");
if(gpaInput.value!="") {
let tbl = document.getElementById("tbl");
let head = tbl.insertRow(0);
let gpa = gpaInput.value;
let count = 0;
for (let student of data.students.values()) {
let sgp = Number(student.gpa);
if (sgp > gpa) {
count++;
}
}
head.insertCell(0).innerHTML = "The Number of Students of Given GPA: " + count;
}
else{
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
row.insertCell(0).innerHTML = "GPA is Empty!";
}
}
function coursesOfGivenStudentButton() {
clearTable("tbl");
if (sIdInput.value != "") {
addStudentTableHead("tbl");
let sID = sIdInput.value;
let student = data.students.get(sID);
addTableGivenStudent(student, "tbl");
addTableGivenStudentCourses(student, "tbl");
}
else{
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
row.insertCell(0).innerHTML = "Student ID is Empty!";
}
}
function examScheduleButton() {
clearTable("tbl");
if(sIdInput.value!="") {
let student = data.students.get(sIdInput.value);
let rowIndex = 1;
addCoursesTableHead("tbl");
for (let course of student.courses) {
addTableGiverCourse(course, "tbl", rowIndex);
rowIndex++;
}
}
else{
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
row.insertCell(0).innerHTML = "Student ID is Empty!";
}
}
function studentListGivenCourseButton() {
clearTable("tbl");
if(cCodeInput.value!="") {
addStudentTableHead("tbl");
let givenCourse = data.courses.get(cCodeInput.value);
let rowIndex = 1;
for (let student of data.students.values()) {
for (let course of student.courses) {
if (course === givenCourse) {
addTableGivenStudent(student, "tbl", rowIndex);
}
}
}
}
else{
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
row.insertCell(0).innerHTML = "Course Code is Empty!";
}
}
function courseListGivenExamRoomButton() {
clearTable("tbl");
if(eRoomInput.value!="") {
let examRoom = eRoomInput.value;
addCoursesTableHead("tbl");
for (let course of data.courses.values()) {
for (let room of course.rooms) {
if (examRoom == room) {
addTableGiverCourse(course, "tbl");
}
}
}
}
else{
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
row.insertCell(0).innerHTML = "Exam Room is Empty!";
}
}
function numberOfGiverRoom() {
clearTable("tbl");
if(eRoomInput.value!="") {
let givenRoom = eRoomInput.value;
let count = 0;
for (let course of data.courses.values()) {
for (let room of course.rooms) {
if (room == givenRoom) {
count++;
}
}
}
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
let c1 = row.insertCell(0);
c1.style.width = "300px";
c1.innerHTML = "The Number of Courses in Given Exam Room: " + count;
}
else{
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
row.insertCell(0).innerHTML = "Exam Room is Empty!";
}
}
function getTotalCourseHourOfGivenStudent() {
clearTable("tbl");
if(sIdInput.value!="") {
let student = data.students.get(sIdInput.value);
var total = 0;
for (let course of student.courses) {
let time = course.time;
let hours = time.split("-");
let first = hours[0].slice(0, 2);
let last = hours[1].slice(0, 2);
let courseHour = Number(last) - Number(first);
console.log(courseHour);
total = total + courseHour;
}
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
row.insertCell(0).innerHTML = "Total Exam Hours of Given Student: " + total;
}
else{
let tbl = document.getElementById("tbl");
let row = tbl.insertRow(0);
row.insertCell(0).innerHTML = "Exam Room is Empty!";
}
}
</script>
</head>
<body>
<hr />
<h2 id=title></h2>
<hr />
<p><b>Student ID:</b>
<input type=number id=sIdInput style="margin-left: 20px">
</p>
<p><b>Course Code:</b>
<input type=text id=cCodeInput style="margin-left: 7px">
</p>
</p>
<p><b>GPA:</b>
<input type=number id=gpaInput style="margin-left: 63px">
</p>
<p><b>Exam Room:</b>
<input type=text id=eRoomInput style="margin-left: 10px">
</p>
<hr />
<p><b>Get A Random Student:</b> <button onClick='randomStudentButton()' style="width: 100px ; height: 26px ; margin-left:127px;font-weight: bold" >Random</button></p>
<p><b>The Number of Students of Given GPA:</b> <button onClick='getStudentNumberGPA()' style="width: 100px ; height: 26px; margin-left: 20px; font-weight: bold">Get</button></p>
<p><b>The Courses of Given Student:</b> <button onClick='coursesOfGivenStudentButton()' style="width: 100px ; height: 26px; margin-left: 82px; font-weight: bold">Get</button></p>
<p><b>The Exam Schedule of Given Student:</b> <button onClick='examScheduleButton()' style="width: 100px ; height: 26px; margin-left: 33px; font-weight: bold">Get</button></p>
<p><b>Student List of Given Course:</b> <button onClick='studentListGivenCourseButton()' style="width: 100px ; height: 26px; margin-left: 89px; font-weight: bold">Get</button></p>
<p><b>Course List of Given Exam Room:</b> <button onClick='courseListGivenExamRoomButton()' style="width: 100px ; height: 26px; margin-left: 58px; font-weight: bold">Get</button></p>
<p><b>Number of Courses in Given Room: </b> <button onClick='numberOfGiverRoom()' style="width: 100px ; height: 26px; margin-left: 49px; font-weight: bold">Get</button></p>
<p><b>Total Exam Hours of Given Student: </b> <button onClick='getTotalCourseHourOfGivenStudent()' style="width: 100px ; height: 26px; margin-left: 45px; font-weight: bold">Get</button></p>
<hr />
<button onClick='clearButton("tbl")' style="width: 80px ; height: 26px; font-weight: bold">Clear</button>
<br>
<table id=tbl style="width:500px">
</table>
<script>
title.innerText = document.title;
data = new Database();
</script>
</body>
</html>