-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseating.js
More file actions
295 lines (235 loc) · 10 KB
/
seating.js
File metadata and controls
295 lines (235 loc) · 10 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
let positions = [];
let students = [
"Aarav", "Aditya", "Amogh", "Anshruta", "Arham", "Arnav", "Arpita", "Ashmita",
"Atharva", "Bhavisha", "B.Vamsi", "B.Varnika", "Dhruv", "Dhruti", "Gautham",
"Iniya", "Jagrith", "Kenisha", "L.Vinod", "Moksha", "Pratham", "Reya", "Samarth",
"Sanjana", "Smera", "Tanishka", "Tushar", "Vanshika", "Varsha"
];
let og_students_list = students
// Permanent example list that never changes
const EXAMPLE_STUDENTS = [
"Aarav", "Aditya", "Amogh", "Anshruta", "Arham", "Arnav", "Arpita", "Ashmita",
"Atharva", "Bhavisha", "B.Vamsi", "B.Varnika", "Dhruv", "Dhruti", "Gautham",
"Iniya", "Jagrith", "Kenisha", "L.Vinod", "Moksha", "Pratham", "Reya", "Samarth",
"Sanjana", "Smera", "Tanishka", "Tushar", "Vanshika", "Varsha"
];
let useRollNumbersState = false; // Track checkbox state
let studentCountValue = 29; // Track student count
let sub_list = [];
function toggleInputMode() {
const checkbox = document.getElementById('role_numbers');
const textArea = document.getElementById('student_names');
const numberInput = document.getElementById('student_count');
const studentCountLabel = document.querySelector('.student-count-label');
const exampleLink = document.querySelector('.clickable-text');
if (checkbox.checked) {
textArea.style.display = 'none';
numberInput.style.display = 'block';
studentCountLabel.style.display = 'block';
exampleLink.style.display = 'none';
} else {
textArea.style.display = 'block';
numberInput.style.display = 'none';
studentCountLabel.style.display = 'none';
exampleLink.style.display = 'inline';
}
}
function isEven(num) {
return Number.isInteger(num/2)
}
async function edit() {
const response = await fetch("page_1.html"); // Wait for the fetch to complete
// Step 2: Convert the response to text
const data = await response.text(); // Wait for the text conversion
// Step 3: Inject the content into the page
document.getElementById('page_code').innerHTML = data; // Update the content
document.body.style.backgroundImage = "url('school_background.png')";
// Restore the previous state
const checkbox = document.getElementById('role_numbers');
const studentCount = document.getElementById('student_count');
const textArea = document.getElementById('student_names');
if (useRollNumbersState) {
checkbox.checked = true;
studentCount.value = studentCountValue;
toggleInputMode();
} else {
// Load the current students, not the example
let current_value = ""
for (let index = 0; index < og_students_list.length; index++) {
current_value = current_value + og_students_list[index]
if (index != og_students_list.length - 1) {
current_value = current_value + "\n"
}
}
textArea.value = current_value;
}
}
async function loadPage_1() {
// Step 1: Fetch the page
const response = await fetch("page_1.html"); // Wait for the fetch to complete
// Step 2: Convert the response to text
const data = await response.text(); // Wait for the text conversion
// Step 3: Inject the content into the page
document.getElementById('page_code').innerHTML = data; // Update the content
document.body.style.backgroundImage = "url('school_background.png')";
}
function load_example_values() {
let example_value = ""
for (let index = 0; index < EXAMPLE_STUDENTS.length; index++) {
example_value= example_value + EXAMPLE_STUDENTS[index]
if (index!=EXAMPLE_STUDENTS.length-1) {
example_value = example_value + "\n"
}
}
document.getElementById("student_names").value = example_value
}
loadPage_1()
function create_arrangement() {
const useRollNumbers = document.getElementById("role_numbers").checked;
// Save the state for when edit is clicked
useRollNumbersState = useRollNumbers;
if (useRollNumbers) {
// Get the number of students from the number input
const studentCount = parseInt(document.getElementById("student_count").value);
if (isNaN(studentCount) || studentCount < 1) {
alert("Please enter a valid number of students");
return;
}
// Save student count
studentCountValue = studentCount;
// Generate roll numbers
students = [];
for (let i = 1; i <= studentCount; i++) {
students.push("Roll No " + i);
}
} else {
// Use names from textarea
students = document.getElementById("student_names").value.split("\n");
students = students.filter(name => name !== "");
}
og_students_list = students.slice();
loadPage_2();
}
let your_name = "John" //edit this
let your_name_lower_case = your_name.toLowerCase()
let friend_name = "x"
let friend_name_lower_case = friend_name.toLowerCase()
function fix_case(array) {
if (array.includes(your_name_lower_case)) {
//array.indexof("tushar") = "Tushar"
array[array.indexOf(your_name_lower_case)] = your_name
}
if (array.includes(friend_name_lower_case)) {
array[array.indexOf(friend_name_lower_case)] = friend_name
}
}
function assign_positions() {
students = og_students_list.slice()
console.log("shuffled list = " + students);
fix_case(students)
let extra_push_list = []
if (students.includes(your_name)&&students.includes(friend_name)) {
extra_push_list = [your_name,friend_name]
students.splice(students.indexOf(friend_name),1)
students.splice(students.indexOf(your_name),1)
}
let random_number_1 = Math.floor(Math.random() *students.length)
let students_length = students.length
for (let index = 0; index < students_length/2; index++) {
sub_list = [];
random_number_1 = Math.floor(Math.random() *students.length)
sub_list.push(students[random_number_1]);
students.splice(random_number_1,1)
if (students.length != 0) {
random_number_1 = Math.floor(Math.random() *students.length)
sub_list.push(students[random_number_1]);
students.splice(random_number_1,1)
}
positions.push(sub_list.slice());
}
if (extra_push_list.length != 0){
positions.splice((Math.floor(Math.random() *positions.length)), 0, extra_push_list)
}
console.log(positions);
}
function assign_benches() {
const benchesData = positions;
const classroom = document.getElementById('classroom');
function createBench(benchNumber, studentNames) {
const benchGroup = document.createElement('div');
benchGroup.classList.add('bench-group');
const bench = document.createElement('div');
bench.classList.add('bench');
bench.innerHTML = `<div class="bench-number">Bench ${benchNumber}</div>`;
const studentsDiv = document.createElement('div');
studentsDiv.classList.add('students');
studentNames.forEach(name => {
const studentDiv = createStudent(name);
studentsDiv.appendChild(studentDiv);
});
benchGroup.appendChild(studentsDiv);
benchGroup.appendChild(bench);
return benchGroup;
}
function createStudent(name) {
const studentDiv = document.createElement('div');
studentDiv.classList.add('student');
const headDiv = document.createElement('div');
headDiv.classList.add('head');
const bodyDiv = document.createElement('div');
bodyDiv.classList.add('body');
bodyDiv.textContent = name || 'Empty';
studentDiv.appendChild(headDiv);
studentDiv.appendChild(bodyDiv);
return studentDiv;
}
function populateClassroom(benchesData) {
classroom.innerHTML = ''; // Clear previous content
let benchNumber = 1;
benchesData.forEach(studentNames => {
const bench = createBench(benchNumber++, studentNames);
classroom.appendChild(bench);
});
adjustGridLayout();
}
function adjustGridLayout() {
const benches = document.querySelectorAll('.bench-group');
classroom.style.gridTemplateColumns = `repeat(3, minmax(300px, 1fr))`;
classroom.style.gridAutoRows = `minmax(100px, auto)`; // Adjust row height dynamically
}
// Populate the classroom with the provided benches data
populateClassroom(benchesData);
}
async function loadPage_2() {
// Step 1: Fetch the page
const response = await fetch("page_2.html"); // Wait for the fetch to complete
// Step 2: Convert the response to text
const data = await response.text(); // Wait for the text conversion
// Step 3: Inject the content into the page
document.getElementById('page_code').innerHTML = data; // Update the content
document.body.style.backgroundImage = ""; // Clear the background image
document.body.style.backgroundColor = "bisque";
document.getElementById("classroom").innerHTML = ""
positions = []
//all other code is below
assign_positions()
assign_benches()
}
//loadPage_2();
function downloadPageAsImage() {
const classroomDiv = document.getElementById("classroom");
// Use html2canvas to capture the div, ensuring full scrollable content is included
html2canvas(classroomDiv, {
backgroundColor: '#ffe5c4',
useCORS: true, // Allows cross-origin resources if needed
scrollX: 0, // Ignore scroll position
scrollY: 0,
windowWidth: classroomDiv.scrollWidth, // Ensure full width is captured
windowHeight: classroomDiv.scrollHeight // Ensure full height is captured
}).then(canvas => {
const link = document.createElement("a");
link.download = "classroom.png"; // File name for the download
link.href = canvas.toDataURL("image/png"); // Convert canvas to image
link.click(); // Trigger download
});
}