-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
240 lines (201 loc) · 6.84 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Room Information</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
#individual-room {
border: 1px solid #ddd;
padding: 8px;
margin-top: 10px;
}
#individual-room table {
margin-bottom: 20px;
}
.student-container {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
.student-details-container {
border: 1px solid #ddd;
padding: 8px;
margin: 10px;
min-width: 200px;
}
.container {
display: flex;
justify-content: space-between;
}
.rooms-table-container {
width: 50%;
}
#room-details-container {
width: 50%;
}
</style>
</head>
<body>
<div id="header-container">
<!-- The header will be inserted here -->
</div>
<h1>Room Information</h1>
<div class="container">
<div class="rooms-table-container">
<h2>All Rooms</h2>
<table id="rooms-table">
<thead>
<tr>
<th>Room Number</th>
<th>Room Status</th>
<th>Admin Notes</th>
<th>Room Notes</th>
<th>Assignees</th>
</tr>
</thead>
</table>
</div>
<div id="room-details-container"></div>
</div>
<button id="addStudentButton">Add Student</button>
<h2>Individual Room Details</h2>
<label for="room-select">Select a room:</label>
<select id="room-select" onchange="fetchIndividualRoom()">
<option value="">--Please choose a room--</option>
</select>
<div id="individual-room"></div>
<script>
window.onload = async () => {
await fetchAllRooms();
};
async function fetchAllRooms() {
try{
const response = await fetch('/api/rooms');
const rooms = await response.json();
const table = document.getElementById('rooms-table');
const tableBody = document.createElement('tbody');
table.appendChild(tableBody);
const select = document.getElementById('room-select');
for (const room of rooms) {
// Add room to the table
const row = tableBody.insertRow();
const roomNumberCell = row.insertCell(0);
roomNumberCell.innerText = room.room_number;
roomNumberCell.style.cursor = 'pointer';
roomNumberCell.addEventListener('click', () => openEditRoomPage(room.room_number));
row.insertCell(1).innerText = room.room_status;
row.insertCell(2).innerText = room.admin_notes;
row.insertCell(3).innerText = room.room_notes;
row.insertCell(4).innerText = (room.assignees || []).join(', ');
// Add room to the select dropdown
const option = document.createElement('option');
option.value = room.room_number;
option.innerText = room.room_number;
select.appendChild(option);
}
} catch (error) {
console.error("Error fetching all rooms data:", error);
}
}
async function fetchIndividualRoom() {
try {
const roomNumber = document.getElementById('room-select').value;
const response = await fetch('/api/rooms/number/' + roomNumber);
const room = await response.json();
const container = document.getElementById('individual-room');
container.innerHTML = ''; // Clear previous content
// Create and populate the room details table
const table = document.createElement('table');
const headerRow = table.insertRow(-1);
headerRow.insertCell(0).innerText = 'Room Number';
headerRow.insertCell(1).innerText = 'Room Status';
headerRow.insertCell(2).innerText = 'Admin Notes';
headerRow.insertCell(3).innerText = 'Room Notes';
headerRow.insertCell(4).innerText = 'Assignees';
const row = table.insertRow(-1);
row.insertCell(0).innerText = room.room_number;
row.insertCell(1).innerText = room.room_status;
row.insertCell(2).innerText = room.admin_notes;
row.insertCell(3).innerText = room.room_notes;
row.insertCell(4).innerText = (room.currentAssignees ? room.currentAssignees.join(', ') : '');
container.appendChild(table);
// Fetch student data by their IDs
if (room.currentAssignees && room.currentAssignees.length > 0) {
const studentIds = room.currentAssignees.join(',');
const studentResponse = await fetch(`/api/students/ids/${studentIds}`);
const students = await studentResponse.json();
const studentsContainer = document.createElement('div');
studentsContainer.classList.add('student-container');
studentsContainer.style.marginTop = '20px';
container.appendChild(studentsContainer);
for (const student of students) {
// Create a button to toggle student details
const button = document.createElement('button');
button.innerText = student.pratt_id;
button.style.marginRight = '10px';
button.style.marginBottom = '10px';
// Create a div to hold student details
const studentDetails = document.createElement('div');
studentDetails.innerText = formatStudentData(student);
studentDetails.style.display = 'none';
button.addEventListener('click', () => {
studentDetails.style.display = studentDetails.style.display === 'none' ? 'block' : 'none';
});
const studentDetailsContainer = document.createElement('div');
studentDetailsContainer.classList.add('student-details-container');
studentDetailsContainer.appendChild(button);
studentDetailsContainer.appendChild(studentDetails);
studentsContainer.appendChild(studentDetailsContainer);
}
}
} catch (error) {
console.error("Error fetching individual room data:", error);
}
}
function formatStudentData(student) {
return `Pratt ID: ${student.pratt_id}
First Name: ${student.first_name}
Last Name: ${student.last_name}
Email: ${student.email}
Admin Notes: ${student.admin_notes}`
}
async function openEditRoomPage(roomNumber) {
const container = document.getElementById('room-details-container');
const response = await fetch('edit-room.html');
const html = await response.text();
container.innerHTML = html;
const script = document.createElement('script');
script.src = 'edit-room.js';
script.onload = async () => {
await window.showEditRoom(roomNumber);
};
document.body.appendChild(script);
document.getElementById('addStudentButton').addEventListener('click', function() {
fetch('add-student.html')
.then(response => response.text())
.then(data => {
document.getElementById('room-details-container').innerHTML = data;
const script = document.createElement('script');
script.src = 'add-student.js';
document.body.appendChild(script);
});
});
fetch('header.html')
.then(response => response.text())
.then(data => {
document.getElementById('header-container').innerHTML = data;
});
}
</script>
</body>
</html>