ichieh commited on
Commit
9d5d9ea
·
1 Parent(s): 08eba66

Restore original circular table display with proper table leader formatting

Browse files
Files changed (2) hide show
  1. sync_settings.gs +26 -20
  2. templates/index.html +75 -187
sync_settings.gs CHANGED
@@ -23,13 +23,14 @@ function doPost(e) {
23
  // 如果是第一次儲存,建立標題列
24
  if (participantsSheet.getLastRow() === 0) {
25
  participantsSheet.getRange('A1:I1').setValues([[
26
- '暱稱', 'Email', 'FB連結', '自我介紹', '桌次', '座位號', '是否為桌長', '報名時間', 'ID'
27
  ]]);
28
  }
29
 
30
  // 儲存參與者資料
31
  var participant = data.participant;
32
  participantsSheet.appendRow([
 
33
  participant.nickname,
34
  participant.email,
35
  participant.fb_link || '',
@@ -37,8 +38,7 @@ function doPost(e) {
37
  participant.table_id,
38
  participant.seat_number,
39
  participant.is_table_leader || false,
40
- participant.created_at,
41
- participant.id
42
  ]);
43
 
44
  return ContentService.createTextOutput(JSON.stringify({
@@ -114,7 +114,7 @@ function doPost(e) {
114
  .setMimeType(ContentService.MimeType.JSON);
115
  }
116
 
117
- function doGet(e) {
118
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
119
 
120
  // 讀取桌次設定
@@ -122,13 +122,18 @@ function doGet(e) {
122
  var tables = [];
123
  if (settingsSheet) {
124
  var settingsData = settingsSheet.getDataRange().getValues();
125
- // 跳過標題列
126
- for (var i = 1; i < settingsData.length; i++) {
127
- tables.push({
128
- id: i,
129
- name: '第' + i + '桌',
130
- capacity: settingsData[i][1] // 每桌人數
131
- });
 
 
 
 
 
132
  }
133
  }
134
 
@@ -139,16 +144,17 @@ function doGet(e) {
139
  var participantsData = participantsSheet.getDataRange().getValues();
140
  // 跳過標題列
141
  for (var i = 1; i < participantsData.length; i++) {
 
142
  participants.push({
143
- nickname: participantsData[i][0],
144
- email: participantsData[i][1],
145
- fb_link: participantsData[i][2],
146
- introduction: participantsData[i][3],
147
- table_id: participantsData[i][4],
148
- seat_number: participantsData[i][5],
149
- is_table_leader: participantsData[i][6],
150
- created_at: participantsData[i][7],
151
- id: participantsData[i][8]
152
  });
153
  }
154
  }
 
23
  // 如果是第一次儲存,建立標題列
24
  if (participantsSheet.getLastRow() === 0) {
25
  participantsSheet.getRange('A1:I1').setValues([[
26
+ 'ID', '暱稱', 'Email', 'FB連結', '自我介紹', '桌次', '座位號', '是否為桌長', '報名時間'
27
  ]]);
28
  }
29
 
30
  // 儲存參與者資料
31
  var participant = data.participant;
32
  participantsSheet.appendRow([
33
+ participant.id,
34
  participant.nickname,
35
  participant.email,
36
  participant.fb_link || '',
 
38
  participant.table_id,
39
  participant.seat_number,
40
  participant.is_table_leader || false,
41
+ participant.created_at
 
42
  ]);
43
 
44
  return ContentService.createTextOutput(JSON.stringify({
 
114
  .setMimeType(ContentService.MimeType.JSON);
115
  }
116
 
117
+ function doGet() {
118
  var sheet = SpreadsheetApp.getActiveSpreadsheet();
119
 
120
  // 讀取桌次設定
 
122
  var tables = [];
123
  if (settingsSheet) {
124
  var settingsData = settingsSheet.getDataRange().getValues();
125
+ if (settingsData.length > 1) { // 確保有數據
126
+ var totalTables = settingsData[1][0]; // 總桌數
127
+ var seatsPerTable = settingsData[1][1]; // 每桌人數
128
+
129
+ // 創建所有桌次
130
+ for (var i = 1; i <= totalTables; i++) {
131
+ tables.push({
132
+ id: i,
133
+ name: '第' + i + '桌',
134
+ capacity: seatsPerTable
135
+ });
136
+ }
137
  }
138
  }
139
 
 
144
  var participantsData = participantsSheet.getDataRange().getValues();
145
  // 跳過標題列
146
  for (var i = 1; i < participantsData.length; i++) {
147
+ var row = participantsData[i];
148
  participants.push({
149
+ id: row[0],
150
+ nickname: row[1],
151
+ email: row[2],
152
+ fb_link: row[3],
153
+ introduction: row[4],
154
+ table_id: row[5],
155
+ seat_number: row[6],
156
+ is_table_leader: row[7],
157
+ created_at: row[8]
158
  });
159
  }
160
  }
templates/index.html CHANGED
@@ -7,105 +7,66 @@
7
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
8
  <link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.min.css" rel="stylesheet">
9
  <style>
10
- .table-container {
11
- display: flex;
12
- flex-wrap: wrap;
13
- gap: 20px;
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;
41
- top: -30px;
42
- left: 50%;
43
- transform: translateX(-50%);
44
- background-color: rgba(255, 255, 255, 0.9);
45
- padding: 5px 10px;
46
- border-radius: 5px;
47
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
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>
@@ -188,7 +149,7 @@
188
  if (isFull) return;
189
 
190
  // 移除之前選擇的桌子的選中狀態
191
- const previousSelected = document.querySelector('.round-table.selected');
192
  if (previousSelected) {
193
  previousSelected.classList.remove('selected');
194
  }
@@ -202,91 +163,6 @@
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() {
291
  try {
292
  const response = await fetch('/api/tables');
@@ -303,30 +179,42 @@
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) {
 
7
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
8
  <link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.3.0/dist/sweetalert2.min.css" rel="stylesheet">
9
  <style>
10
+ .table-circle {
 
 
 
 
 
 
 
11
  width: 200px;
12
  height: 200px;
13
  border-radius: 50%;
14
+ border: 2px solid #ddd;
 
15
  display: flex;
16
+ flex-direction: column;
17
  align-items: center;
18
  justify-content: center;
 
 
19
  cursor: pointer;
20
  transition: all 0.3s ease;
21
+ background-color: white;
22
+ margin: 20px;
23
+ position: relative;
24
  }
25
+
26
+ .table-circle:hover {
27
+ border-color: #007bff;
28
+ background-color: #f8f9fa;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  }
30
+
31
+ .table-circle.selected {
32
+ border-color: #007bff;
33
+ background-color: #e7f1ff;
34
  }
35
+
36
+ .table-circle.full {
37
+ cursor: not-allowed;
38
+ opacity: 0.7;
 
 
 
 
 
 
 
 
 
39
  }
40
+
41
+ .table-name {
42
+ font-size: 1.5rem;
43
+ font-weight: bold;
44
+ margin-bottom: 5px;
45
  }
46
+
47
+ .seats-info {
48
+ font-size: 1rem;
49
+ color: #666;
50
  }
51
+
52
+ .table-leader {
53
  background-color: #28a745;
54
  color: white;
55
+ padding: 2px 8px;
56
+ border-radius: 4px;
57
+ margin-bottom: 4px;
 
 
 
 
 
 
 
 
 
 
 
 
58
  }
59
+
60
+ .participant {
61
+ padding: 2px 8px;
62
+ margin-bottom: 2px;
63
+ border-radius: 4px;
 
 
 
64
  }
65
+
66
+ .table-container {
67
+ display: inline-block;
68
+ margin: 15px;
69
+ text-align: center;
70
  }
71
  </style>
72
  </head>
 
149
  if (isFull) return;
150
 
151
  // 移除之前選擇的桌子的選中狀態
152
+ const previousSelected = document.querySelector('.table-circle.selected');
153
  if (previousSelected) {
154
  previousSelected.classList.remove('selected');
155
  }
 
163
  }
164
  }
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  async function loadTables() {
167
  try {
168
  const response = await fetch('/api/tables');
 
179
  const participantsCount = table.participants.length;
180
  const isFull = participantsCount >= table.capacity;
181
 
182
+ // 創建桌次元素
183
+ const circle = document.createElement('div');
184
+ circle.className = `table-circle${isFull ? ' full' : ''}`;
185
+ circle.onclick = isFull ? null : () => selectTable(table.id);
186
+
187
+ // 桌次名稱
188
+ const tableName = document.createElement('div');
189
+ tableName.className = 'table-name';
190
+ tableName.textContent = table.name;
191
 
192
+ // 座位資訊
193
+ const seatsInfo = document.createElement('div');
194
+ seatsInfo.className = 'seats-info';
195
+ seatsInfo.textContent = `${participantsCount}/${table.capacity} 個座位`;
196
 
197
+ // 參與者列表
198
+ const participantsList = document.createElement('div');
199
+ participantsList.className = 'participants-list';
200
 
201
+ // 先顯示桌長(如果有)
202
+ table.participants.forEach(participant => {
203
+ const participantDiv = document.createElement('div');
204
+ if (participant.is_table_leader) {
205
+ participantDiv.className = 'table-leader';
206
+ participantDiv.textContent = `桌長:${participant.nickname}`;
207
+ } else {
208
+ participantDiv.className = 'participant';
209
+ participantDiv.textContent = participant.nickname;
210
+ }
211
+ participantsList.appendChild(participantDiv);
212
+ });
213
 
214
+ circle.appendChild(tableName);
215
+ circle.appendChild(seatsInfo);
216
+ circle.appendChild(participantsList);
217
+ tableElement.appendChild(circle);
218
  tablesContainer.appendChild(tableElement);
219
  });
220
  } catch (error) {