-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatGridIndex.html
545 lines (474 loc) · 17.5 KB
/
chatGridIndex.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
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: beige;
margin: auto;
height: 100vh;
width: 90%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#parentContainer {
height: 420px;
margin: auto;
width: 100%;
display: flex;
flex-grow: 1;
justify-content: center;
flex-direction: column;
}
#container {
margin: .5rem;
display: flex;
flex-grow: 1;
justify-content: center;
flex-direction: column;
}
.row-container {
display: flex;
align-items: center;
justify-content: center;
}
.grid-item {
background-color: #ffe8bc;
border: 4px solid orange;
border-radius: 0.25em;
flex-grow: 1;
aspect-ratio: 1/1;
margin: .25rem;
cursor: pointer;
}
.grid-item.active-green {
background-color: #d0ffbc;
border: 4px solid #73ff00;
}
/*.grid-item:active-green {*/
/* background-color: #ffeb7a;*/
/* border: 4px solid #ffd932;*/
/*}*/
.grid-item:hover {
scale: 1.05;
}
.blank {
opacity: 0;
cursor: default;
}
#selectors {
margin: 2rem;
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 1rem;
align-items: center;
justify-content: center;
}
#selectors > * {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
#colInput, #rowInput {
width: 1.5rem;
margin: 0 0.5rem;
}
.icon-button {
background: none;
border: none;
padding: 0;
cursor: pointer;
font-size: 3rem;
color: orange;
}
.fa-solid:active {
scale: 1.1;
}
.col-button-label, .row-button-label {
background-color: beige;
border: 4px solid beige;
border-radius: 0.25em;
flex-grow: 1;
margin: .25rem;
cursor: pointer;
position: relative;
}
.col-button-label {
}
.row-button-label {
width: 1rem;
}
.col-label, .row-label {
position: absolute;
/*width: 0;*/
/*height: 0;*/
}
.col-label {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.row-label {
top: -50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* Modal Styles */
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
display: none; /* Hide the modal by default */
}
.modal-option {
width: 50px;
height: 50px;
margin: 5px;
border: none;
cursor: pointer;
}
.modal-content {
background-color: white;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-buttons {
text-align: right;
}
.modal-input {
margin-bottom: 10px;
display: flex;
align-items: center;
}
.modal-input .remove-button {
background: none;
border: none;
padding: 0;
cursor: pointer;
font-size: 1.5rem;
color: red;
margin-left: 0.5rem;
}
.grid-item.active-red {
background-color: #ff9090;
border: 4px solid #ff0000;
}
.grid-item.active-purple {
background-color: #d0a0ff;
border: 4px solid #7a00ff;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
<div id="parentContainer">
<div id="container"></div>
<!-- Add this code inside the <div id="parentContainer"> -->
<div id="modal" class="modal">
<div id="modal-content" class="modal-content">
<div id="modal-inputs">
<!-- Row inputs will be dynamically added here -->
</div>
<tr></tr>
<div id="modal-actions">
<button id="addRowButton">Add Row</button>
<button id="saveButton">Save</button>
<button id="closeModalButton" class="close">Close</button>
</div>
</div>
</div>
</div>
<div id="selectors">
<div>
<label for="rowInput">Rows:</label>
<input type="text" id="rowInput" value="5">
<button id="decrementRows" class="icon-button"><i class="fa-solid fa-caret-down"></i></button>
<button id="incrementRows" class="icon-button"><i class="fa-solid fa-caret-up"></i></button>
</div>
<div>
<label for="colInput">Columns:</label>
<input type="text" id="colInput" value="10">
<button id="decrementCols" class="icon-button"><i class="fa-solid fa-caret-down"></i></button>
<button id="incrementCols" class="icon-button"><i class="fa-solid fa-caret-up"></i></button>
</div>
</div>
<!-- Modal -->
<div id="myModal" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>Edit Row Labels</h2>
<div id="modalInputs"></div>
<div class="modal-buttons">
<button id="addLabel">Add Label</button>
<!-- <button id="removeLabel">Remove Label</button>-->
<button id="updateLabels">Update</button>
</div>
</div>
</div>
<script>
$(document).ready(function() {
let rowLabels = ["cr", "rd", "ht", "ft", "sn", "bd"]; // Array of row labels
let cols = 10;
let activeCells = new Set(); // Track active cells
let makeGrid = function () {
const container = $("#container");
container.empty();
for (let i = 0; i < rowLabels.length; i++) {
let row = $("<div>").addClass("row-container");
let rowLabelButton = $("<button>").addClass("row-button-label");
let rowLabel = $("<div>").addClass("row-label");
rowLabelButton.append(rowLabel);
rowLabel.text(rowLabels[i]);
row.append(rowLabelButton);
for (let j = 0; j < cols; j++) {
let cell = $("<button>").addClass("grid-item");
row.append(cell);
if (activeCells.has(`${i}-${j}`)) {
cell.addClass("active-green");
}
}
container.append(row);
$(".grid-item").click(function () {
let selectedGridItem = $(this);
openModal(selectedGridItem);
});
}
// Create separate divs for row labels and column labels
// let rowLabelsContainer = $("<div>").addClass("row-container");
let colLabelsContainer = $("<div>").addClass("row-container");
container.append(colLabelsContainer);
// Add column labels
for (let j = 0; j < cols + 1; j++) {
// let colLabel = $("<button>").addClass("grid-item label");
let colLabelButton = $("<button>").addClass("col-button-label");
let colLabel = $("<div>").addClass("col-label");
colLabelButton.append(colLabel);
// colLabel.text(i + 1);
if (j > 0) {
colLabel.text(j); // Convert ASCII code to letters (B, C, D, ...)
} else {
colLabelButton.addClass("blank");
}
colLabelsContainer.append(colLabelButton);
}
// Update click event handler for grid items
$(".grid-item").click(function () {
$(this).toggleClass("active-green");
// Track active cells
let row = $(this).closest(".row-container").index() - 1; // Subtract 1 for the label row
let col = $(this).index() - 1; // Subtract 1 for the label column
let cellKey = `${row}-${col}`;
if ($(this).hasClass("active-green")) {
activeCells.add(cellKey);
} else {
activeCells.delete(cellKey);
}
});
// Update long press event handler for row labels
$(".row-button-label").on("mousedown", function (e) {
let timer;
let rowButtonLabel = $(this);
// Start the timer on mouse down
timer = setTimeout(function () {
// Show the modal
showModal(rowButtonLabel);
}, 500);
// Clear the timer on mouse up
$(document).on("mouseup", function () {
clearTimeout(timer);
});
});
};
// ...
// Function to reset active cells outside the grid bounds
let resetActiveCells = function () {
let newActiveCells = new Set();
activeCells.forEach(function (cellKey) {
let [row, col] = cellKey.split("-");
row = parseInt(row);
col = parseInt(col);
if (row < rowLabels.length && col < cols) {
newActiveCells.add(cellKey);
}
});
activeCells = newActiveCells;
};
// Increment Rows
$("#incrementRows").click(function() {
// rowLabels.push("Row " + String.fromCharCode(65 + rowLabels.length)); // Add new row label
rowLabels.push(String.fromCharCode(rowLabels.charCodeAt(rowLabels.length - 1) + 1)); // Add new row label
$("#rowInput").val(rowLabels.length);
resetActiveCells();
makeGrid();
});
// Decrement Rows
$("#decrementRows").click(function() {
if (rowLabels.length > 1) {
rowLabels.pop(); // Remove the last row label
$("#rowInput").val(rowLabels.length);
resetActiveCells();
makeGrid();
}
});
// Increment Columns
$("#incrementCols").click(function() {
cols++;
$("#colInput").val(cols);
resetActiveCells();
makeGrid();
});
// Decrement Columns
$("#decrementCols").click(function() {
if (cols > 1) {
cols--;
$("#colInput").val(cols);
resetActiveCells();
makeGrid();
}
});
makeGrid();
// Modal functionality
let showModal = function (rowButtonLabel) {
let rowIndex = rowButtonLabel.parent().index(); // Get the index of the row
let modal = document.getElementById("myModal");
// let modal = $("#myModal");
let modalContent = document.querySelector(".modal-content");
let modalInputs = document.getElementById("modalInputs");
let addLabelBtn = document.getElementById("addLabel");
let removeLabelBtn = document.getElementById("removeLabel");
let updateLabelsBtn = document.getElementById("updateLabels");
// Clear existing inputs
modalInputs.innerHTML = "";
// Create inputs for row labels
// Create inputs for row labels
for (let i = 0; i < rowLabels.length; i++) {
let inputContainer = document.createElement("div");
inputContainer.classList.add("modal-input");
let labelIndex = i + 1; // Adjust index for display (1-based index)
let inputLabel = document.createElement("label");
inputLabel.innerText = `Row ${labelIndex}:`;
let input = document.createElement("input");
input.type = "text";
input.value = rowLabels[i];
let removeButton = document.createElement("button");
removeButton.classList.add("remove-button");
removeButton.innerHTML = "×";
removeButton.addEventListener("click", function() {
modalInputs.removeChild(inputContainer);
});
inputContainer.appendChild(inputLabel);
inputContainer.appendChild(input);
inputContainer.appendChild(removeButton);
modalInputs.appendChild(inputContainer);
}
// ...
addLabelBtn.onclick = function() {
let inputContainer = document.createElement("div");
inputContainer.classList.add("modal-input");
let labelIndex = rowLabels.length + 1; // Adjust index for display (1-based index)
let inputLabel = document.createElement("label");
inputLabel.innerText = `Row ${labelIndex}:`;
let input = document.createElement("input");
input.type = "text";
let removeButton = document.createElement("button");
removeButton.classList.add("remove-button");
removeButton.innerHTML = "×";
removeButton.addEventListener("click", function() {
modalInputs.removeChild(inputContainer);
});
inputContainer.appendChild(inputLabel);
inputContainer.appendChild(input);
inputContainer.appendChild(removeButton);
modalInputs.appendChild(inputContainer);
};
updateLabelsBtn.onclick = function () {
let inputs = modalInputs.querySelectorAll("input");
let closeModalButton = document.getElementById("closeModalButton");
closeModalButton.addEventListener("click", closeModal);
// Update row labels array
rowLabels = Array.from(inputs).map(function (input) {
return input.value;
});
makeGrid();
closeModal();
};
// Show the modal
modal.style.display = "block";
// Close the modal when the user clicks outside of it
window.onclick = function (event) {
if (event.target == modal) {
closeModal();
}
};
// Close the modal when the user clicks the close button
let closeModalButton = document.querySelector(".close");
closeModalButton.onclick = function () {
closeModal();
};
// Function to close the modal and reset event handlers
let closeModal = function () {
modal.style.display = "none";
modalInputs.innerHTML = "";
window.onclick = null;
closeModalButton.onclick = null;
};
};
function openModal(selectedGridItem) {
let modal = document.getElementById("modal");
let modalContent = document.getElementById("modal-content");
let modalInputs = document.getElementById("modal-inputs");
// Clear existing inputs
modalInputs.innerHTML = "";
// Create color options for the modal
let colors = ["green", "red", "purple"];
for (let i = 0; i < colors.length; i++) {
let colorOption = colors[i];
let optionButton = document.createElement("button");
optionButton.classList.add("modal-option");
optionButton.style.backgroundColor = colorOption;
optionButton.addEventListener("click", function () {
selectedGridItem.removeClass("active active-red active-purple");
selectedGridItem.addClass("active-" + colorOption);
let row = selectedGridItem.closest(".row-container");
let rowGridItems = row.find(".grid-item");
rowGridItems.removeClass("active active-red active-purple");
rowGridItems.addClass("active-" + colorOption);
closeModal();
});
modalInputs.appendChild(optionButton);
}
// Show the modal
modal.style.display = "block";
}
function closeModal() {
let modal = document.getElementById("modal");
modal.style.display = "none";
}
});
</script>
</body>
</html>