Spaces:
Sleeping
Sleeping
ichieh commited on
Commit ·
08eba66
1
Parent(s): 8eeb102
Update frontend to show circular tables with interactive seats
Browse files- templates/index.html +167 -79
templates/index.html
CHANGED
|
@@ -14,39 +14,27 @@
|
|
| 14 |
justify-content: center;
|
| 15 |
margin: 20px;
|
| 16 |
}
|
| 17 |
-
.
|
| 18 |
width: 200px;
|
| 19 |
height: 200px;
|
| 20 |
border-radius: 50%;
|
| 21 |
-
|
|
|
|
| 22 |
display: flex;
|
| 23 |
-
flex-direction: column;
|
| 24 |
align-items: center;
|
| 25 |
justify-content: center;
|
|
|
|
|
|
|
| 26 |
cursor: pointer;
|
| 27 |
transition: all 0.3s ease;
|
| 28 |
-
background-color: white;
|
| 29 |
-
}
|
| 30 |
-
.table-circle:hover {
|
| 31 |
-
border-color: #007bff;
|
| 32 |
-
background-color: #f8f9fa;
|
| 33 |
}
|
| 34 |
-
.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
}
|
| 38 |
-
.
|
|
|
|
| 39 |
cursor: not-allowed;
|
| 40 |
-
opacity: 0.7;
|
| 41 |
-
}
|
| 42 |
-
.table-name {
|
| 43 |
-
font-size: 1.5rem;
|
| 44 |
-
font-weight: bold;
|
| 45 |
-
margin-bottom: 5px;
|
| 46 |
-
}
|
| 47 |
-
.seats-info {
|
| 48 |
-
font-size: 1rem;
|
| 49 |
-
color: #666;
|
| 50 |
}
|
| 51 |
.table-info {
|
| 52 |
position: absolute;
|
|
@@ -60,36 +48,64 @@
|
|
| 60 |
z-index: 2;
|
| 61 |
white-space: nowrap;
|
| 62 |
}
|
| 63 |
-
.
|
| 64 |
position: absolute;
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
transform: translateX(-50%);
|
| 68 |
-
background-color: white;
|
| 69 |
-
padding: 10px;
|
| 70 |
-
border-radius: 5px;
|
| 71 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
| 72 |
-
width: 200px;
|
| 73 |
-
display: none;
|
| 74 |
-
z-index: 3;
|
| 75 |
}
|
| 76 |
-
.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
-
.
|
| 84 |
-
|
|
|
|
| 85 |
}
|
| 86 |
-
.
|
| 87 |
background-color: #007bff;
|
| 88 |
color: white;
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
</style>
|
| 95 |
</head>
|
|
@@ -99,7 +115,7 @@
|
|
| 99 |
|
| 100 |
<div class="row">
|
| 101 |
<div class="col-md-12">
|
| 102 |
-
<div id="
|
| 103 |
<!-- 桌子將由 JavaScript 動態生成 -->
|
| 104 |
</div>
|
| 105 |
</div>
|
|
@@ -172,7 +188,7 @@
|
|
| 172 |
if (isFull) return;
|
| 173 |
|
| 174 |
// 移除之前選擇的桌子的選中狀態
|
| 175 |
-
const previousSelected = document.querySelector('.
|
| 176 |
if (previousSelected) {
|
| 177 |
previousSelected.classList.remove('selected');
|
| 178 |
}
|
|
@@ -186,19 +202,89 @@
|
|
| 186 |
}
|
| 187 |
}
|
| 188 |
|
| 189 |
-
function
|
| 190 |
-
const
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
`;
|
| 200 |
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
}
|
| 203 |
|
| 204 |
async function loadTables() {
|
|
@@ -206,7 +292,7 @@
|
|
| 206 |
const response = await fetch('/api/tables');
|
| 207 |
const tables = await response.json();
|
| 208 |
|
| 209 |
-
const tablesContainer = document.getElementById('
|
| 210 |
tablesContainer.innerHTML = '';
|
| 211 |
|
| 212 |
tables.forEach(table => {
|
|
@@ -217,28 +303,30 @@
|
|
| 217 |
const participantsCount = table.participants.length;
|
| 218 |
const isFull = participantsCount >= table.capacity;
|
| 219 |
|
| 220 |
-
// 創建
|
| 221 |
-
const
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
${p.is_table_leader ? '<span class="table-leader-badge">桌長</span>' : ''}
|
| 225 |
-
</div>
|
| 226 |
-
`).join('');
|
| 227 |
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
| 241 |
|
|
|
|
|
|
|
|
|
|
| 242 |
tablesContainer.appendChild(tableElement);
|
| 243 |
});
|
| 244 |
} catch (error) {
|
|
|
|
| 14 |
justify-content: center;
|
| 15 |
margin: 20px;
|
| 16 |
}
|
| 17 |
+
.round-table {
|
| 18 |
width: 200px;
|
| 19 |
height: 200px;
|
| 20 |
border-radius: 50%;
|
| 21 |
+
background-color: #f8f9fa;
|
| 22 |
+
border: 2px solid #dee2e6;
|
| 23 |
display: flex;
|
|
|
|
| 24 |
align-items: center;
|
| 25 |
justify-content: center;
|
| 26 |
+
margin: 50px;
|
| 27 |
+
position: relative;
|
| 28 |
cursor: pointer;
|
| 29 |
transition: all 0.3s ease;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
+
.round-table:hover {
|
| 32 |
+
transform: scale(1.05);
|
| 33 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
| 34 |
}
|
| 35 |
+
.round-table.full {
|
| 36 |
+
background-color: #e9ecef;
|
| 37 |
cursor: not-allowed;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
.table-info {
|
| 40 |
position: absolute;
|
|
|
|
| 48 |
z-index: 2;
|
| 49 |
white-space: nowrap;
|
| 50 |
}
|
| 51 |
+
.seats-circle {
|
| 52 |
position: absolute;
|
| 53 |
+
width: 100%;
|
| 54 |
+
height: 100%;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
+
.seat {
|
| 57 |
+
position: absolute;
|
| 58 |
+
width: 40px;
|
| 59 |
+
height: 40px;
|
| 60 |
+
border-radius: 50%;
|
| 61 |
+
background-color: #fff;
|
| 62 |
+
border: 2px solid #dee2e6;
|
| 63 |
+
display: flex;
|
| 64 |
+
align-items: center;
|
| 65 |
+
justify-content: center;
|
| 66 |
+
cursor: pointer;
|
| 67 |
+
font-size: 0.8rem;
|
| 68 |
+
transition: all 0.3s ease;
|
| 69 |
}
|
| 70 |
+
.seat:hover {
|
| 71 |
+
transform: scale(1.1);
|
| 72 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 73 |
}
|
| 74 |
+
.seat.occupied {
|
| 75 |
background-color: #007bff;
|
| 76 |
color: white;
|
| 77 |
+
border-color: #0056b3;
|
| 78 |
+
}
|
| 79 |
+
.seat.table-leader {
|
| 80 |
+
background-color: #28a745;
|
| 81 |
+
color: white;
|
| 82 |
+
border-color: #1e7e34;
|
| 83 |
+
}
|
| 84 |
+
.participant-card {
|
| 85 |
+
display: none;
|
| 86 |
+
position: absolute;
|
| 87 |
+
background: white;
|
| 88 |
+
border-radius: 8px;
|
| 89 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
| 90 |
+
padding: 15px;
|
| 91 |
+
width: 250px;
|
| 92 |
+
z-index: 1000;
|
| 93 |
+
}
|
| 94 |
+
.participant-card h5 {
|
| 95 |
+
margin-bottom: 10px;
|
| 96 |
+
color: #333;
|
| 97 |
+
}
|
| 98 |
+
.participant-card p {
|
| 99 |
+
margin-bottom: 8px;
|
| 100 |
+
font-size: 0.9rem;
|
| 101 |
+
color: #666;
|
| 102 |
+
}
|
| 103 |
+
.participant-card .social-link {
|
| 104 |
+
color: #007bff;
|
| 105 |
+
text-decoration: none;
|
| 106 |
+
}
|
| 107 |
+
.participant-card .social-link:hover {
|
| 108 |
+
text-decoration: underline;
|
| 109 |
}
|
| 110 |
</style>
|
| 111 |
</head>
|
|
|
|
| 115 |
|
| 116 |
<div class="row">
|
| 117 |
<div class="col-md-12">
|
| 118 |
+
<div id="tables">
|
| 119 |
<!-- 桌子將由 JavaScript 動態生成 -->
|
| 120 |
</div>
|
| 121 |
</div>
|
|
|
|
| 188 |
if (isFull) return;
|
| 189 |
|
| 190 |
// 移除之前選擇的桌子的選中狀態
|
| 191 |
+
const previousSelected = document.querySelector('.round-table.selected');
|
| 192 |
if (previousSelected) {
|
| 193 |
previousSelected.classList.remove('selected');
|
| 194 |
}
|
|
|
|
| 202 |
}
|
| 203 |
}
|
| 204 |
|
| 205 |
+
function createSeatElement(participant, seatIndex, totalSeats) {
|
| 206 |
+
const seat = document.createElement('div');
|
| 207 |
+
seat.className = `seat${participant ? ' occupied' : ''}${participant?.is_table_leader ? ' table-leader' : ''}`;
|
| 208 |
+
|
| 209 |
+
// 計算座位位置
|
| 210 |
+
const angle = (seatIndex * (360 / totalSeats)) * (Math.PI / 180);
|
| 211 |
+
const radius = 80; // 調整這個值來改變座位到圓桌中心的距離
|
| 212 |
+
const left = 100 + radius * Math.cos(angle);
|
| 213 |
+
const top = 100 + radius * Math.sin(angle);
|
| 214 |
+
|
| 215 |
+
seat.style.left = `${left}px`;
|
| 216 |
+
seat.style.top = `${top}px`;
|
| 217 |
+
|
| 218 |
+
if (participant) {
|
| 219 |
+
seat.textContent = participant.nickname;
|
| 220 |
+
|
| 221 |
+
// 添加點擊事件顯示參與者資訊
|
| 222 |
+
seat.addEventListener('click', (e) => {
|
| 223 |
+
e.stopPropagation();
|
| 224 |
+
showParticipantInfo(participant, e.clientX, e.clientY);
|
| 225 |
+
});
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
return seat;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
function showParticipantInfo(participant, x, y) {
|
| 232 |
+
// 移除舊的卡片
|
| 233 |
+
const oldCard = document.querySelector('.participant-card');
|
| 234 |
+
if (oldCard) {
|
| 235 |
+
oldCard.remove();
|
| 236 |
+
}
|
| 237 |
|
| 238 |
+
// 創建新的卡片
|
| 239 |
+
const card = document.createElement('div');
|
| 240 |
+
card.className = 'participant-card';
|
| 241 |
+
card.innerHTML = `
|
| 242 |
+
<h5>${participant.nickname}</h5>
|
| 243 |
+
<p>${participant.is_table_leader ? '<span class="badge bg-success">桌長</span>' : ''}</p>
|
| 244 |
+
<p><strong>Email:</strong> ${participant.email}</p>
|
| 245 |
+
${participant.fb_link ? `
|
| 246 |
+
<p><strong>FB:</strong>
|
| 247 |
+
<a href="${participant.fb_link}" target="_blank" class="social-link">
|
| 248 |
+
個人檔案
|
| 249 |
+
</a>
|
| 250 |
+
</p>
|
| 251 |
+
` : ''}
|
| 252 |
+
${participant.introduction ? `
|
| 253 |
+
<p><strong>自我介紹:</strong><br>
|
| 254 |
+
${participant.introduction}</p>
|
| 255 |
+
` : ''}
|
| 256 |
`;
|
| 257 |
|
| 258 |
+
// 調整卡片位置
|
| 259 |
+
card.style.display = 'block';
|
| 260 |
+
document.body.appendChild(card);
|
| 261 |
+
|
| 262 |
+
// 確保卡片不會超出視窗
|
| 263 |
+
const rect = card.getBoundingClientRect();
|
| 264 |
+
const viewportWidth = window.innerWidth;
|
| 265 |
+
const viewportHeight = window.innerHeight;
|
| 266 |
+
|
| 267 |
+
let left = x + 10;
|
| 268 |
+
let top = y + 10;
|
| 269 |
+
|
| 270 |
+
if (left + rect.width > viewportWidth) {
|
| 271 |
+
left = x - rect.width - 10;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
if (top + rect.height > viewportHeight) {
|
| 275 |
+
top = y - rect.height - 10;
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
card.style.left = `${left}px`;
|
| 279 |
+
card.style.top = `${top}px`;
|
| 280 |
+
|
| 281 |
+
// 點擊其他地方關閉卡片
|
| 282 |
+
document.addEventListener('click', function closeCard(e) {
|
| 283 |
+
if (!card.contains(e.target)) {
|
| 284 |
+
card.remove();
|
| 285 |
+
document.removeEventListener('click', closeCard);
|
| 286 |
+
}
|
| 287 |
+
});
|
| 288 |
}
|
| 289 |
|
| 290 |
async function loadTables() {
|
|
|
|
| 292 |
const response = await fetch('/api/tables');
|
| 293 |
const tables = await response.json();
|
| 294 |
|
| 295 |
+
const tablesContainer = document.getElementById('tables');
|
| 296 |
tablesContainer.innerHTML = '';
|
| 297 |
|
| 298 |
tables.forEach(table => {
|
|
|
|
| 303 |
const participantsCount = table.participants.length;
|
| 304 |
const isFull = participantsCount >= table.capacity;
|
| 305 |
|
| 306 |
+
// 創建圓桌元素
|
| 307 |
+
const roundTable = document.createElement('div');
|
| 308 |
+
roundTable.className = `round-table${isFull ? ' full' : ''}`;
|
| 309 |
+
roundTable.onclick = isFull ? null : () => selectTable(table.id);
|
|
|
|
|
|
|
|
|
|
| 310 |
|
| 311 |
+
// 添加桌次資訊
|
| 312 |
+
const tableInfo = document.createElement('div');
|
| 313 |
+
tableInfo.className = 'table-info';
|
| 314 |
+
tableInfo.textContent = `${table.name} (${participantsCount}/${table.capacity})`;
|
| 315 |
+
|
| 316 |
+
// 創建座位圈
|
| 317 |
+
const seatsCircle = document.createElement('div');
|
| 318 |
+
seatsCircle.className = 'seats-circle';
|
| 319 |
+
|
| 320 |
+
// 創建所有座位
|
| 321 |
+
for (let i = 0; i < table.capacity; i++) {
|
| 322 |
+
const participant = table.participants[i];
|
| 323 |
+
const seat = createSeatElement(participant, i, table.capacity);
|
| 324 |
+
seatsCircle.appendChild(seat);
|
| 325 |
+
}
|
| 326 |
|
| 327 |
+
roundTable.appendChild(seatsCircle);
|
| 328 |
+
tableElement.appendChild(tableInfo);
|
| 329 |
+
tableElement.appendChild(roundTable);
|
| 330 |
tablesContainer.appendChild(tableElement);
|
| 331 |
});
|
| 332 |
} catch (error) {
|