ichieh commited on
Commit
29dd674
·
1 Parent(s): 63a8f38

Redesign table display with rectangular layout and add participant info cards

Browse files
Files changed (1) hide show
  1. templates/index.html +105 -42
templates/index.html CHANGED
@@ -35,19 +35,17 @@
35
  }
36
 
37
  .table-circle {
38
- width: 180px;
39
- height: 180px;
40
- border-radius: 50%;
41
  border: 2px solid #ddd;
42
  display: flex;
43
  flex-direction: column;
44
- align-items: center;
45
- justify-content: center;
46
- cursor: pointer;
47
- transition: all 0.3s ease;
48
- background-color: white;
49
  margin: 15px;
50
- position: relative;
 
51
  }
52
 
53
  .table-circle:hover {
@@ -65,10 +63,51 @@
65
  opacity: 0.7;
66
  }
67
 
 
 
 
 
 
 
 
 
 
68
  .table-name {
69
- font-size: 1.5rem;
70
  font-weight: bold;
71
- margin-bottom: 5px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
 
74
  .seats-info {
@@ -144,21 +183,42 @@
144
  function selectTable(tableId) {
145
  if (!tableId) return;
146
 
147
- // 移除之前選擇的桌子的選中狀態
148
- const previousSelected = document.querySelector('.table-circle.selected');
149
- if (previousSelected) {
150
- previousSelected.classList.remove('selected');
151
- }
152
 
153
- // 設置新選擇的桌子
154
- const selectedTable = document.querySelector(`.table-circle[data-table-id="${tableId}"]`);
155
- if (selectedTable) {
156
- selectedTable.classList.add('selected');
157
- // 啟用確認按鈕
158
- document.getElementById('confirmBtn').disabled = false;
159
- // 儲存選擇的桌號
160
- selectedTableId = tableId;
161
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  }
163
 
164
  async function loadTables() {
@@ -173,51 +233,54 @@
173
  const tableElement = document.createElement('div');
174
  tableElement.className = 'table-container';
175
 
176
- // 計算已坐人數
177
  const participantsCount = table.participants.length;
178
  const isFull = participantsCount >= table.capacity;
179
 
180
- // 創建桌次元素
181
  const circle = document.createElement('div');
182
  circle.className = `table-circle${isFull ? ' full' : ''}`;
183
  circle.setAttribute('data-table-id', table.id);
184
- circle.onclick = isFull ? null : () => selectTable(table.id);
185
 
186
- // 桌次名稱
 
 
187
  const tableName = document.createElement('div');
188
  tableName.className = 'table-name';
189
  tableName.textContent = table.name;
190
 
191
- // 座位資訊
192
  const seatsInfo = document.createElement('div');
193
  seatsInfo.className = 'seats-info';
194
  seatsInfo.textContent = `${participantsCount}/${table.capacity} 個座位`;
195
 
196
- // 參與者列表
 
 
 
 
 
 
 
 
 
 
 
197
  const participantsList = document.createElement('div');
198
  participantsList.className = 'participants-list';
199
 
200
- // 先顯示桌長(如果有)
201
  table.participants.forEach(participant => {
202
  const participantDiv = document.createElement('div');
203
- if (participant.is_table_leader) {
204
- participantDiv.className = 'table-leader';
205
- participantDiv.textContent = `桌長:${participant.nickname}`;
206
- } else {
207
- participantDiv.className = 'participant';
208
- participantDiv.textContent = participant.nickname;
209
- }
210
  participantsList.appendChild(participantDiv);
211
  });
212
 
213
- circle.appendChild(tableName);
214
- circle.appendChild(seatsInfo);
215
  circle.appendChild(participantsList);
216
  tableElement.appendChild(circle);
217
  tablesContainer.appendChild(tableElement);
218
  });
219
  } catch (error) {
220
- console.error('Error:', error);
221
  Swal.fire('錯誤', '載入桌次資料失敗', 'error');
222
  }
223
  }
 
35
  }
36
 
37
  .table-circle {
38
+ min-width: 200px;
39
+ height: auto;
40
+ border-radius: 8px;
41
  border: 2px solid #ddd;
42
  display: flex;
43
  flex-direction: column;
44
+ align-items: stretch;
45
+ padding: 15px;
 
 
 
46
  margin: 15px;
47
+ background-color: white;
48
+ transition: all 0.3s ease;
49
  }
50
 
51
  .table-circle:hover {
 
63
  opacity: 0.7;
64
  }
65
 
66
+ .table-header {
67
+ display: flex;
68
+ justify-content: space-between;
69
+ align-items: center;
70
+ margin-bottom: 10px;
71
+ padding-bottom: 10px;
72
+ border-bottom: 1px solid #eee;
73
+ }
74
+
75
  .table-name {
76
+ font-size: 1.2rem;
77
  font-weight: bold;
78
+ margin: 0;
79
+ }
80
+
81
+ .select-seat-btn {
82
+ padding: 4px 8px;
83
+ font-size: 0.9rem;
84
+ }
85
+
86
+ .participants-list {
87
+ display: flex;
88
+ flex-direction: column;
89
+ gap: 5px;
90
+ }
91
+
92
+ .participant-item {
93
+ padding: 8px;
94
+ border-radius: 4px;
95
+ background-color: #f8f9fa;
96
+ cursor: pointer;
97
+ transition: all 0.2s ease;
98
+ }
99
+
100
+ .participant-item:hover {
101
+ background-color: #e9ecef;
102
+ }
103
+
104
+ .participant-item.table-leader {
105
+ background-color: #d4edda;
106
+ border-left: 4px solid #28a745;
107
+ }
108
+
109
+ .table-circle.full .select-seat-btn {
110
+ display: none;
111
  }
112
 
113
  .seats-info {
 
183
  function selectTable(tableId) {
184
  if (!tableId) return;
185
 
186
+ selectedTableId = tableId;
187
+ document.getElementById('confirmBtn').disabled = false;
 
 
 
188
 
189
+ // 更新所有按鈕的狀態
190
+ document.querySelectorAll('.select-seat-btn').forEach(btn => {
191
+ if (btn.getAttribute('data-table-id') === tableId.toString()) {
192
+ btn.classList.remove('btn-outline-primary');
193
+ btn.classList.add('btn-primary');
194
+ } else {
195
+ btn.classList.remove('btn-primary');
196
+ btn.classList.add('btn-outline-primary');
197
+ }
198
+ });
199
+ }
200
+
201
+ function showParticipantInfo(participant) {
202
+ Swal.fire({
203
+ title: participant.nickname,
204
+ html: `
205
+ ${participant.fb_link ? `<p><a href="${participant.fb_link}" target="_blank" class="btn btn-outline-primary btn-sm">
206
+ <i class="bi bi-facebook"></i> Facebook
207
+ </a></p>` : ''}
208
+ ${participant.introduction ? `
209
+ <div class="text-start">
210
+ <h6>自我介紹:</h6>
211
+ <p class="text-muted">${participant.introduction}</p>
212
+ </div>
213
+ ` : ''}
214
+ ${participant.is_table_leader ? '<div class="badge bg-success">桌長</div>' : ''}
215
+ `,
216
+ showConfirmButton: false,
217
+ showCloseButton: true,
218
+ customClass: {
219
+ container: 'participant-modal'
220
+ }
221
+ });
222
  }
223
 
224
  async function loadTables() {
 
233
  const tableElement = document.createElement('div');
234
  tableElement.className = 'table-container';
235
 
 
236
  const participantsCount = table.participants.length;
237
  const isFull = participantsCount >= table.capacity;
238
 
 
239
  const circle = document.createElement('div');
240
  circle.className = `table-circle${isFull ? ' full' : ''}`;
241
  circle.setAttribute('data-table-id', table.id);
 
242
 
243
+ const tableHeader = document.createElement('div');
244
+ tableHeader.className = 'table-header';
245
+
246
  const tableName = document.createElement('div');
247
  tableName.className = 'table-name';
248
  tableName.textContent = table.name;
249
 
 
250
  const seatsInfo = document.createElement('div');
251
  seatsInfo.className = 'seats-info';
252
  seatsInfo.textContent = `${participantsCount}/${table.capacity} 個座位`;
253
 
254
+ if (!isFull) {
255
+ const selectButton = document.createElement('button');
256
+ selectButton.className = `btn ${selectedTableId === table.id ? 'btn-primary' : 'btn-outline-primary'} btn-sm select-seat-btn`;
257
+ selectButton.textContent = '選擇此桌';
258
+ selectButton.setAttribute('data-table-id', table.id);
259
+ selectButton.onclick = () => selectTable(table.id);
260
+ tableHeader.appendChild(selectButton);
261
+ }
262
+
263
+ tableHeader.appendChild(tableName);
264
+ tableHeader.appendChild(seatsInfo);
265
+
266
  const participantsList = document.createElement('div');
267
  participantsList.className = 'participants-list';
268
 
 
269
  table.participants.forEach(participant => {
270
  const participantDiv = document.createElement('div');
271
+ participantDiv.className = `participant-item${participant.is_table_leader ? ' table-leader' : ''}`;
272
+ participantDiv.textContent = participant.nickname;
273
+ participantDiv.onclick = () => showParticipantInfo(participant);
 
 
 
 
274
  participantsList.appendChild(participantDiv);
275
  });
276
 
277
+ circle.appendChild(tableHeader);
 
278
  circle.appendChild(participantsList);
279
  tableElement.appendChild(circle);
280
  tablesContainer.appendChild(tableElement);
281
  });
282
  } catch (error) {
283
+ console.error('載入桌次資料失敗:', error);
284
  Swal.fire('錯誤', '載入桌次資料失敗', 'error');
285
  }
286
  }