-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
412 lines (361 loc) · 13.9 KB
/
index.html
File metadata and controls
412 lines (361 loc) · 13.9 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Seating Chart Generator</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--primary-color: #4a90e2;
--secondary-color: #f5f7fa;
--border-color: #e1e4e8;
--text-color: #2c3e50;
--success-color: #2ecc71;
--shadow: 0 2px 4px rgba(0,0,0,0.1);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Inter', sans-serif;
line-height: 1.6;
color: var(--text-color);
background-color: #f8f9fa;
padding: 20px;
}
.container {
max-width: 1000px;
margin: 0 auto;
padding: 30px;
background: white;
border-radius: 12px;
box-shadow: var(--shadow);
}
h1 {
color: var(--primary-color);
margin-bottom: 30px;
text-align: center;
font-size: 2.2em;
}
h2 {
color: var(--text-color);
margin-bottom: 15px;
font-size: 1.5em;
font-weight: 600;
}
.controls {
background: var(--secondary-color);
padding: 25px;
margin-bottom: 30px;
border-radius: 8px;
border: 1px solid var(--border-color);
}
.input-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 500;
}
input[type="text"],
input[type="number"],
textarea,
select {
width: 100%;
padding: 10px;
border: 1px solid var(--border-color);
border-radius: 6px;
font-size: 1em;
font-family: inherit;
transition: border-color 0.2s;
}
input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
outline: none;
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.2);
}
textarea {
min-height: 120px;
resize: vertical;
}
#groupSize {
width: 100px;
}
.button-group {
display: flex;
gap: 10px;
margin-top: 15px;
}
button {
padding: 12px 20px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 1em;
font-weight: 500;
transition: background-color 0.2s;
}
button:hover {
background-color: #357abd;
}
button:active {
transform: translateY(1px);
}
.grouping-strategy {
background: white;
padding: 15px;
border-radius: 6px;
margin: 15px 0;
border: 1px solid var(--border-color);
}
.grouping-strategy label {
display: inline;
margin-right: 15px;
font-weight: normal;
}
.radio-group {
display: flex;
gap: 20px;
margin-top: 8px;
}
#groupsDisplay {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
margin-top: 30px;
}
.group {
background: #fff;
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 15px;
box-shadow: var(--shadow);
transition: transform 0.2s;
}
.group:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.group h3 {
color: var(--primary-color);
margin-bottom: 10px;
padding-bottom: 8px;
border-bottom: 2px solid var(--secondary-color);
}
.group div {
padding: 5px 0;
}
@media (max-width: 768px) {
.container {
padding: 15px;
}
.button-group {
flex-direction: column;
}
button {
width: 100%;
}
#groupsDisplay {
grid-template-columns: 1fr;
}
}
/* Tooltip styles for [data-tooltip] */
[data-tooltip] {
position: relative;
cursor: pointer;
}
[data-tooltip]::after {
content: attr(data-tooltip);
position: absolute;
left: 100%;
top: 50%;
transform: translateY(-50%) translateX(8px);
background: #2c3e50;
color: #fff;
padding: 7px 12px;
border-radius: 6px;
font-size: 0.95em;
white-space: pre-line;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s;
min-width: 180px;
z-index: 10;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus::after {
opacity: 1;
pointer-events: auto;
}
</style>
</head>
<body>
<div class="container">
<h1>Student Seating Chart Generator</h1>
<div class="controls">
<h2>Student List Management</h2>
<div class="input-group">
<label for="listName">List Name</label>
<input type="text" id="listName" placeholder="Enter a name for this list" aria-label="List Name" data-tooltip="Name for your student list. Used to save and retrieve lists.">
</div>
<div class="input-group">
<label for="studentNames">Student Names</label>
<textarea id="studentNames" placeholder="Enter student names, one per line" aria-label="Student Names" data-tooltip="Enter one student name per line."></textarea>
</div>
<div class="input-group">
<label for="savedLists">Saved Lists</label>
<select id="savedLists" onchange="loadList()" aria-label="Saved Lists" data-tooltip="Select a previously saved student list.">
<option value="">Select a saved list</option>
</select>
</div>
<div class="button-group">
<button onclick="saveList()" aria-label="Save List" data-tooltip="Save the current student list with the given name.">Save List</button>
</div>
</div>
<div class="controls">
<h2>Group Generator</h2>
<div class="input-group">
<label for="groupSize">Students per group:</label>
<input type="number" id="groupSize" value="2" min="2" aria-label="Students per group" data-tooltip="Number of students in each group. Minimum 2.">
</div>
<div class="grouping-strategy">
<label>Grouping Strategy:</label>
<div class="radio-group">
<div>
<input type="radio" id="maxSameSize" name="strategy" value="maxSameSize" checked aria-label="Balanced group sizes" data-tooltip="Distributes students so group sizes are more even, even if not all groups are the same size.">
<label for="maxSameSize">Balanced group sizes</label>
</div>
<div>
<input type="radio" id="maxNSized" name="strategy" value="maxNSized" aria-label="Maximize full groups" data-tooltip="Creates as many full-size groups as possible, putting any extra students in a smaller group.">
<label for="maxNSized">Maximize full groups</label>
</div>
</div>
</div>
<div class="button-group">
<button onclick="generateGroups()" aria-label="Generate Groups" data-tooltip="Create groups based on the current student list and settings.">Generate Groups</button>
<button onclick="regenerateGroups()" aria-label="Regenerate Groups" data-tooltip="Shuffle and re-create groups with the same settings.">Regenerate Groups</button>
</div>
</div>
<div id="groupsDisplay" aria-live="polite"></div>
</div>
<script>
let currentStudents = [];
function saveList() {
const listName = document.getElementById('listName').value;
const students = document.getElementById('studentNames').value
.split('\n')
.filter(name => name.trim() !== '');
if (!listName) {
alert('Please enter a list name');
return;
}
const savedLists = JSON.parse(localStorage.getItem('studentLists') || '{}');
savedLists[listName] = students;
localStorage.setItem('studentLists', JSON.stringify(savedLists));
updateSavedListsDropdown();
}
function loadList() {
const selectedList = document.getElementById('savedLists').value;
if (!selectedList) return;
const savedLists = JSON.parse(localStorage.getItem('studentLists') || '{}');
const students = savedLists[selectedList];
document.getElementById('listName').value = selectedList;
document.getElementById('studentNames').value = students.join('\n');
currentStudents = students;
}
function updateSavedListsDropdown() {
const dropdown = document.getElementById('savedLists');
const savedLists = JSON.parse(localStorage.getItem('studentLists') || '{}');
dropdown.innerHTML = '<option value="">Select a saved list</option>';
Object.keys(savedLists).forEach(listName => {
const option = document.createElement('option');
option.value = listName;
option.textContent = listName;
dropdown.appendChild(option);
});
}
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
function generateGroups() {
const students = document.getElementById('studentNames').value
.split('\n')
.filter(name => name.trim() !== '');
currentStudents = students;
displayGroups();
}
function regenerateGroups() {
if (currentStudents.length === 0) {
alert('Please generate groups first');
return;
}
displayGroups();
}
function displayGroups() {
const groupSize = parseInt(document.getElementById('groupSize').value);
if (groupSize < 2) {
alert('Group size must be at least 2');
return;
}
const shuffledStudents = shuffleArray([...currentStudents]);
const groups = [];
const strategy = document.querySelector('input[name="strategy"]:checked').value;
if (strategy === 'maxSameSize') {
const numStudents = shuffledStudents.length;
const numGroups = Math.ceil(numStudents / groupSize);
const baseGroupSize = Math.floor(numStudents / numGroups);
const remainder = numStudents % numGroups;
let studentIndex = 0;
// Create groups with baseGroupSize + 1 students
for (let i = 0; i < remainder; i++) {
groups.push(shuffledStudents.slice(studentIndex, studentIndex + baseGroupSize + 1));
studentIndex += baseGroupSize + 1;
}
// Create remaining groups with baseGroupSize students
while (studentIndex < numStudents) {
groups.push(shuffledStudents.slice(studentIndex, studentIndex + baseGroupSize));
studentIndex += baseGroupSize;
}
} else {
// Create as many groups of exactly groupSize as possible
const numFullGroups = Math.floor(shuffledStudents.length / groupSize);
const remainingStudents = shuffledStudents.length % groupSize;
// Create full-sized groups
for (let i = 0; i < numFullGroups * groupSize; i += groupSize) {
groups.push(shuffledStudents.slice(i, i + groupSize));
}
// Add remaining students as a smaller group if any
if (remainingStudents > 0) {
groups.push(shuffledStudents.slice(numFullGroups * groupSize));
}
}
const display = document.getElementById('groupsDisplay');
display.innerHTML = '';
groups.forEach((group, index) => {
const groupDiv = document.createElement('div');
groupDiv.className = 'group';
groupDiv.innerHTML = `
<h3>Group ${index + 1}</h3>
${group.map(student => `<div>${student}</div>`).join('')}
`;
display.appendChild(groupDiv);
});
}
// Initialize the saved lists dropdown
updateSavedListsDropdown();
</script>
</body>
</html>