-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_schedule.html
330 lines (288 loc) · 13.6 KB
/
student_schedule.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>EVENTS</title>
<link rel="stylesheet" href="assets/css/Navigation-Dark-Clean.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="assets/css/Google-Stylel-Login.css">
<link rel="stylesheet" href="assets/css/calendar.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css">
</head>
<body>
<nav class="navbar navbar-dark navbar-expand-md bg-dark navigation-clean">
<div class="container">
<a class="navbar-brand" href="#">Student Placement System</a>
<button class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navcol-1">
<span class="visually-hidden">Toggle navigation</span>
<span class="navbar-toggler-icon"></span>
</button>
<div id="navcol-1" class="collapse navbar-collapse">
<ul class="nav navbar-nav ms-auto">
</ul>
<button id="students" class="btn btn-secondary" type="button" href="students.html">Students</button>
<button id="home" class="btn btn-secondary" type="button" href="home.html">Home</button>
<button id="out" class="btn btn-primary" type="button" href="index.html">Sign Out</button>
</div>
</div>
</nav>
<hr>
<form>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="eventName">Event Name:</label>
<select id="activitySelector">
<option value="select">Select Specialty</option>
<option value="anatomy">Anatomy</option>
<option value="paeds">Paediatrics</option>
<option value="psych">Psychiatry</option>
<option value="obs">Obstetrics and Gynaecology</option>
<option value="ortho">Surgery and Orthopedics</option>
<option value="anesthesia">Anesthesia</option>
<option value="internal">Internal Medicine</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="fromDate">From:</label>
<input type="date" class="form-control" placeholder="Enter from date" id="fromDate">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="toDate">To:</label>
<input type="date" class="form-control" id="toDate">
</div>
</div>
</div>
<button type="button" class="btn btn-primary" id="addEvent">Add Event</button>
</form>
<hr>
<div class="container">
<div id='calendar'></div>
</div>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-app.js";
import { query, where, collection, getFirestore, doc, getDocs, setDoc, deleteDoc } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-firestore.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.11/firebase-analytics.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
//--------------------------CONFIGURATION----------------------------------------//
const firebaseConfig = {
apiKey: "AIzaSyAZVQZO8XWR0UTPoSMLrRN7nSltUDW9Xzs",
authDomain: "dfmpc-student-placement-system.firebaseapp.com",
databaseURL: "https://dfmpc-student-placement-system-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "dfmpc-student-placement-system",
storageBucket: "dfmpc-student-placement-system.appspot.com",
messagingSenderId: "295214875936",
appId: "1:295214875936:web:546dcdb4f822d1c4c84345",
measurementId: "G-1JPG0HXVWQ"
};
const app = initializeApp(firebaseConfig);
function getData() {
firebaseConfig.da
}
const analytics = getAnalytics(app);
// retrieve student_id, PostKey and id stored from students page
var student_id = localStorage.getItem("myValue");
var PostKey = localStorage.getItem("myPostKey");
var id = localStorage.getItem("myId");
console.log(student_id,PostKey, id); //confirm student id is correct
const db = getFirestore(); //Firestore
//initialise variables which we will be using to add documents to firestore
var start;
var duration; // is stored in weeks
var end = document.getElementById("toDate");
var date;
var specialtyName;
var specialtyId;
//create date variable to store time that a record was entered into the database
var today = new Date();
var today_date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds() + today.getMilliseconds();
var dateTime = today_date+' '+time;
//function to add schedule information to database
async function addToSchedule(PostKey, dateTime, start, date, id, specialtyId, student_id, duration, specialtyName)
{
await setDoc(doc(db, "schedules", PostKey), {
created_at: dateTime,
updated_at: dateTime,
start_date: start,
end_date: date,
hospital_id: "1",
id: id,
specialty_id: specialtyId,
student_id: student_id,
specialty_duration: duration,
SpecialtyName: specialtyName
}).then(() =>{
alert("Schedule Updated Succefully");
window.location.reload(true); //reload window after closing alert
})
.catch((error)=>{
alert("Unsuccesful. Please Try Again." + error)
});
}
//function to calculate the end date of a placement given the start date and duration
function getEndDate(start, duration)
{
duration = duration * 6.048* Math.pow(10,8);
var startDate = Date.parse(start)
var endDate = startDate + duration;
var end = new Date(endDate).toISOString().split('T')[0];
return end;
}
document.addEventListener('DOMContentLoaded', function () {
//create event listener for drop down menu selection
var activities = document.getElementById("activitySelector");
activities.addEventListener("change", function() {
// actions are dependent on selection
//Each option defines a specific specialty, specialtyId and duration
//We autfill the end date of the placement based on start date and duration
if (activities.value == "anatomy")
{
specialtyName = "Anatomy";
specialtyId = 1;
start = document.getElementById("fromDate").value;
duration = 2;
date = getEndDate(start, duration)
end.value = date;
}
if (activities.value == "paeds")
{
specialtyName = "Paediatrics";
specialtyId = 2;
start = document.getElementById("fromDate").value;
duration = 4
date = getEndDate(start, duration);
end.value = date;
}
if (activities.value == "psych")
{
specialtyName = "Psychiatry";
specialtyId = 3;
start = document.getElementById("fromDate").value;
duration = 2
date = getEndDate(start, duration);
end.value = date;
}
if (activities.value == "obs")
{
specialtyName = "Obstetrics and Gynaecology";
specialtyId = 4;
start = document.getElementById("fromDate").value;
duration = 4
date = getEndDate(start, duration);
end.value = date;
}
if (activities.value == "ortho")
{
specialtyName = "Surgery and Orthopedics";
specialtyId = 5;
start = document.getElementById("fromDate").value;
duration = 6
date = getEndDate(start, duration);
end.value = date;
}
if (activities.value == "anesthesia")
{
specialtyName = "Anesthesia";
specialtyId = 6;
start = document.getElementById("fromDate").value;
duration = 3
date = getEndDate(start, duration);
end.value = date;
}
if (activities.value == "internal")
{
specialtyName = "Internal Medicine";
specialtyId = 7;
start = document.getElementById("fromDate").value;
duration = 6
date = getEndDate(start, duration)
end.value = date;
}
//button calls the function that submits information to database and reloads the page
var button = document.getElementById("addEvent");
button.addEventListener("click", function(){
addToSchedule(PostKey, dateTime, start, date, id, specialtyId, student_id, duration, specialtyName);
});
});
//initialise calendar element
var calendarEl = document.getElementById('calendar');
var events =[]; //initialise empty array to store events
async function getEvents()
{
//query schedule documents matching the student_id so that we retrieve student specific schedule information
const q = query(collection(db, "schedules"), where("student_id", "==", student_id));
//retrieve these documents and add information to events array
const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
var name = doc.data().SpecialtyName;
var start = doc.data().start_date;
var end = doc.data().end_date;
console.log(name, student_id);
events.push({
title: name,
start: start,
end: end,
});
calendar.refetchEvents(); // refresh calendar
});
}
//call function to populate events array
getEvents();
//initialise and create calendar
var calendar = new FullCalendar.Calendar(calendarEl, { //initialise calendar
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
initialView: 'dayGridMonth', //initialview shows us month
selectable: true,
editable: false,
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
customButtons: {
today: {
text: 'Today',
click: function () {
calendar.today(); //this button takes us to today's date. Only works when we are viewing another month, week or day
}
},
},
//function to add schedule events to calendar
events: function(info, successCallback, failureCallback ) {
successCallback(events);
},
});
calendar.render();
});
</script>
<script>
var sign_out = document.getElementById("out");
sign_out.addEventListener("click", function () {
document.location.href = "index.html";
});
var home_element = document.getElementById("home");
home_element.addEventListener("click", function () {
document.location.href = "home.html";
});
var students = document.getElementById("students");
students.addEventListener("click", function () {
document.location.href = "students.html";
});
</script>
</body>