Spaces:
Sleeping
Sleeping
ichieh commited on
Commit ·
7a04ee7
1
Parent(s): b54e9ca
Add table sorting and improve admin UI
Browse files
.history/sync_settings_20250117183153.gs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function doPost(e) {
|
| 2 |
+
var sheet = SpreadsheetApp.getActiveSpreadsheet();
|
| 3 |
+
var data = JSON.parse(e.postData.contents);
|
| 4 |
+
var action = data.action;
|
| 5 |
+
|
| 6 |
+
if (action === 'backupParticipants') {
|
| 7 |
+
// 備份參與者資料
|
| 8 |
+
var participantsSheet = sheet.getSheetByName('Participants') || sheet.insertSheet('Participants');
|
| 9 |
+
participantsSheet.clear();
|
| 10 |
+
participantsSheet.getRange('A1:K1').setValues([[
|
| 11 |
+
'ID', '暱稱', 'Email', 'FB連結', '自我介紹', '桌次', '座位號', '是否為桌長', '報名時間', '付款狀態', '備註'
|
| 12 |
+
]]);
|
| 13 |
+
|
| 14 |
+
var participants = data.participants;
|
| 15 |
+
if (participants && participants.length > 0) {
|
| 16 |
+
var values = participants.map(function(p) {
|
| 17 |
+
return [
|
| 18 |
+
p.id,
|
| 19 |
+
p.nickname,
|
| 20 |
+
p.email,
|
| 21 |
+
p.fb_link || '',
|
| 22 |
+
p.introduction || '',
|
| 23 |
+
p.table_id,
|
| 24 |
+
p.seat_number,
|
| 25 |
+
p.is_table_leader || false,
|
| 26 |
+
p.created_at,
|
| 27 |
+
p.has_paid || false,
|
| 28 |
+
p.note || ''
|
| 29 |
+
];
|
| 30 |
+
});
|
| 31 |
+
participantsSheet.getRange(2, 1, values.length, 11).setValues(values);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
return ContentService.createTextOutput(JSON.stringify({success: true}))
|
| 35 |
+
.setMimeType(ContentService.MimeType.JSON);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
return ContentService.createTextOutput(JSON.stringify({error: 'Invalid action'}))
|
| 39 |
+
.setMimeType(ContentService.MimeType.JSON);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function doGet() {
|
| 43 |
+
var sheet = SpreadsheetApp.getActiveSpreadsheet();
|
| 44 |
+
var participantsSheet = sheet.getSheetByName('Participants');
|
| 45 |
+
|
| 46 |
+
if (!participantsSheet) {
|
| 47 |
+
return ContentService.createTextOutput(JSON.stringify({
|
| 48 |
+
success: false,
|
| 49 |
+
error: '找不到參與者資料表'
|
| 50 |
+
})).setMimeType(ContentService.MimeType.JSON);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
var range = participantsSheet.getDataRange();
|
| 54 |
+
var values = range.getValues();
|
| 55 |
+
var headers = values[0];
|
| 56 |
+
var participants = [];
|
| 57 |
+
|
| 58 |
+
// 獲取欄位索引
|
| 59 |
+
var idIndex = headers.indexOf('ID');
|
| 60 |
+
var nicknameIndex = headers.indexOf('暱稱');
|
| 61 |
+
var emailIndex = headers.indexOf('Email');
|
| 62 |
+
var fbLinkIndex = headers.indexOf('FB連結');
|
| 63 |
+
var introIndex = headers.indexOf('自我介紹');
|
| 64 |
+
var tableIndex = headers.indexOf('桌次');
|
| 65 |
+
var seatIndex = headers.indexOf('座位號');
|
| 66 |
+
var leaderIndex = headers.indexOf('是否為桌長');
|
| 67 |
+
var timeIndex = headers.indexOf('報名時間');
|
| 68 |
+
var paidIndex = headers.indexOf('付款狀態');
|
| 69 |
+
var noteIndex = headers.indexOf('備註');
|
| 70 |
+
|
| 71 |
+
// 跳過標題列
|
| 72 |
+
for (var i = 1; i < values.length; i++) {
|
| 73 |
+
var row = values[i];
|
| 74 |
+
if (!row[nicknameIndex]) continue; // 跳過空行
|
| 75 |
+
|
| 76 |
+
participants.push({
|
| 77 |
+
id: row[idIndex],
|
| 78 |
+
nickname: row[nicknameIndex],
|
| 79 |
+
email: row[emailIndex],
|
| 80 |
+
fb_link: row[fbLinkIndex] || '',
|
| 81 |
+
introduction: row[introIndex] || '',
|
| 82 |
+
table_id: parseInt(row[tableIndex]) || 0,
|
| 83 |
+
seat_number: parseInt(row[seatIndex]) || 0,
|
| 84 |
+
is_table_leader: row[leaderIndex] === true || row[leaderIndex] === 'TRUE',
|
| 85 |
+
created_at: row[timeIndex],
|
| 86 |
+
has_paid: paidIndex !== -1 ? (row[paidIndex] === true || row[paidIndex] === 'TRUE') : false,
|
| 87 |
+
note: noteIndex !== -1 ? (row[noteIndex] || '') : ''
|
| 88 |
+
});
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return ContentService.createTextOutput(JSON.stringify({
|
| 92 |
+
success: true,
|
| 93 |
+
participants: participants
|
| 94 |
+
})).setMimeType(ContentService.MimeType.JSON);
|
| 95 |
+
}
|
.history/sync_settings_20250117190528.gs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function doPost(e) {
|
| 2 |
+
var sheet = SpreadsheetApp.getActiveSpreadsheet();
|
| 3 |
+
var data = JSON.parse(e.postData.contents);
|
| 4 |
+
var action = data.action;
|
| 5 |
+
|
| 6 |
+
if (action === 'backupParticipants') {
|
| 7 |
+
// 備份參與者資料
|
| 8 |
+
var participantsSheet = sheet.getSheetByName('Participants') || sheet.insertSheet('Participants');
|
| 9 |
+
participantsSheet.clear();
|
| 10 |
+
participantsSheet.getRange('A1:K1').setValues([[
|
| 11 |
+
'ID', '暱稱', 'Email', 'FB連結', '自我介紹', '桌次', '座位號', '是否為桌長', '報名時間', '付款狀態', '備註'
|
| 12 |
+
]]);
|
| 13 |
+
|
| 14 |
+
var participants = data.participants;
|
| 15 |
+
if (participants && participants.length > 0) {
|
| 16 |
+
var values = participants.map(function(p) {
|
| 17 |
+
return [
|
| 18 |
+
p.id,
|
| 19 |
+
p.nickname,
|
| 20 |
+
p.email,
|
| 21 |
+
p.fb_link || '',
|
| 22 |
+
p.introduction || '',
|
| 23 |
+
p.table_id,
|
| 24 |
+
p.seat_number,
|
| 25 |
+
p.is_table_leader || false,
|
| 26 |
+
p.created_at,
|
| 27 |
+
p.has_paid || false,
|
| 28 |
+
p.note || ''
|
| 29 |
+
];
|
| 30 |
+
});
|
| 31 |
+
participantsSheet.getRange(2, 1, values.length, 11).setValues(values);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
return ContentService.createTextOutput(JSON.stringify({success: true}))
|
| 35 |
+
.setMimeType(ContentService.MimeType.JSON);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
return ContentService.createTextOutput(JSON.stringify({error: 'Invalid action'}))
|
| 39 |
+
.setMimeType(ContentService.MimeType.JSON);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function doGet() {
|
| 43 |
+
var sheet = SpreadsheetApp.getActiveSpreadsheet();
|
| 44 |
+
var participantsSheet = sheet.getSheetByName('Participants');
|
| 45 |
+
|
| 46 |
+
if (!participantsSheet) {
|
| 47 |
+
return ContentService.createTextOutput(JSON.stringify({
|
| 48 |
+
success: false,
|
| 49 |
+
error: '找不到參與者資料表'
|
| 50 |
+
})).setMimeType(ContentService.MimeType.JSON);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
var range = participantsSheet.getDataRange();
|
| 54 |
+
var values = range.getValues();
|
| 55 |
+
var headers = values[0];
|
| 56 |
+
var participants = [];
|
| 57 |
+
|
| 58 |
+
// 獲取欄位索引
|
| 59 |
+
var idIndex = headers.indexOf('ID');
|
| 60 |
+
var nicknameIndex = headers.indexOf('暱稱');
|
| 61 |
+
var emailIndex = headers.indexOf('Email');
|
| 62 |
+
var fbLinkIndex = headers.indexOf('FB連結');
|
| 63 |
+
var introIndex = headers.indexOf('自我介紹');
|
| 64 |
+
var tableIndex = headers.indexOf('桌次');
|
| 65 |
+
var seatIndex = headers.indexOf('座位號');
|
| 66 |
+
var leaderIndex = headers.indexOf('是否為桌長');
|
| 67 |
+
var timeIndex = headers.indexOf('報名時間');
|
| 68 |
+
var paidIndex = headers.indexOf('付款狀態');
|
| 69 |
+
var noteIndex = headers.indexOf('備註');
|
| 70 |
+
|
| 71 |
+
// 跳過標題列
|
| 72 |
+
for (var i = 1; i < values.length; i++) {
|
| 73 |
+
var row = values[i];
|
| 74 |
+
if (!row[nicknameIndex]) continue; // 跳過空行
|
| 75 |
+
|
| 76 |
+
participants.push({
|
| 77 |
+
id: row[idIndex],
|
| 78 |
+
nickname: row[nicknameIndex],
|
| 79 |
+
email: row[emailIndex],
|
| 80 |
+
fb_link: row[fbLinkIndex] || '',
|
| 81 |
+
introduction: row[introIndex] || '',
|
| 82 |
+
table_id: parseInt(row[tableIndex]) || 0,
|
| 83 |
+
seat_number: parseInt(row[seatIndex]) || 0,
|
| 84 |
+
is_table_leader: row[leaderIndex] === true || row[leaderIndex] === 'TRUE',
|
| 85 |
+
created_at: row[timeIndex],
|
| 86 |
+
has_paid: paidIndex !== -1 ? (row[paidIndex] === true || row[paidIndex] === 'TRUE') : false,
|
| 87 |
+
note: noteIndex !== -1 ? (row[noteIndex] || '') : ''
|
| 88 |
+
});
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
return ContentService.createTextOutput(JSON.stringify({
|
| 92 |
+
success: true,
|
| 93 |
+
participants: participants
|
| 94 |
+
})).setMimeType(ContentService.MimeType.JSON);
|
| 95 |
+
}
|
templates/admin.html
CHANGED
|
@@ -177,7 +177,22 @@
|
|
| 177 |
try {
|
| 178 |
const response = await fetch('/api/admin/participants');
|
| 179 |
const data = await response.json();
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
tables = data.tables;
|
| 182 |
renderParticipants();
|
| 183 |
} catch (error) {
|
|
@@ -188,65 +203,79 @@
|
|
| 188 |
|
| 189 |
// 渲染參與者列表
|
| 190 |
function renderParticipants() {
|
| 191 |
-
const tbody = document.
|
| 192 |
tbody.innerHTML = '';
|
| 193 |
|
| 194 |
-
participants.forEach(
|
| 195 |
-
const
|
| 196 |
-
|
| 197 |
|
| 198 |
-
//
|
| 199 |
-
const
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
<td>${
|
| 207 |
-
<td>${
|
| 208 |
-
<td>${p.nickname}</td>
|
| 209 |
-
<td>${p.email}</td>
|
| 210 |
-
<td>${p.fb_link ? `<a href="${p.fb_link}" target="_blank">FB連結</a>` : '-'}</td>
|
| 211 |
-
<td>${shortIntro || '-'}</td>
|
| 212 |
<td>
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
</button>
|
| 219 |
</td>
|
| 220 |
<td>
|
| 221 |
-
|
| 222 |
-
<span onclick="
|
| 223 |
-
${
|
| 224 |
-
</span>
|
| 225 |
-
<
|
| 226 |
-
|
| 227 |
-
|
| 228 |
</td>
|
| 229 |
<td>
|
| 230 |
-
${
|
| 231 |
-
|
| 232 |
-
|
| 233 |
</td>
|
| 234 |
-
<td>${
|
| 235 |
<td>
|
| 236 |
-
<
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
</td>
|
| 243 |
`;
|
| 244 |
-
tbody.appendChild(
|
| 245 |
});
|
| 246 |
}
|
| 247 |
|
| 248 |
// 顯示移動座位的 Modal
|
| 249 |
-
function
|
| 250 |
document.getElementById('participantId').value = participantId;
|
| 251 |
const select = document.getElementById('newTableSelect');
|
| 252 |
select.innerHTML = '';
|
|
@@ -317,7 +346,7 @@
|
|
| 317 |
}
|
| 318 |
|
| 319 |
// 查看完整自我介紹
|
| 320 |
-
function
|
| 321 |
document.getElementById('fullIntroText').textContent = intro;
|
| 322 |
new bootstrap.Modal(document.getElementById('viewIntroModal')).show();
|
| 323 |
}
|
|
|
|
| 177 |
try {
|
| 178 |
const response = await fetch('/api/admin/participants');
|
| 179 |
const data = await response.json();
|
| 180 |
+
|
| 181 |
+
// 依照桌次和座位號排序
|
| 182 |
+
data.sort((a, b) => {
|
| 183 |
+
// 先比較桌次
|
| 184 |
+
const tableA = parseInt(a.table_id) || 0;
|
| 185 |
+
const tableB = parseInt(b.table_id) || 0;
|
| 186 |
+
if (tableA !== tableB) {
|
| 187 |
+
return tableA - tableB;
|
| 188 |
+
}
|
| 189 |
+
// 如果桌次相同,再比較座位號
|
| 190 |
+
const seatA = parseInt(a.seat_number) || 0;
|
| 191 |
+
const seatB = parseInt(b.seat_number) || 0;
|
| 192 |
+
return seatA - seatB;
|
| 193 |
+
});
|
| 194 |
+
|
| 195 |
+
participants = data;
|
| 196 |
tables = data.tables;
|
| 197 |
renderParticipants();
|
| 198 |
} catch (error) {
|
|
|
|
| 203 |
|
| 204 |
// 渲染參與者列表
|
| 205 |
function renderParticipants() {
|
| 206 |
+
const tbody = document.querySelector('#participantsTable tbody');
|
| 207 |
tbody.innerHTML = '';
|
| 208 |
|
| 209 |
+
participants.forEach(participant => {
|
| 210 |
+
const tr = document.createElement('tr');
|
| 211 |
+
tr.className = participant.is_table_leader ? 'table-leader' : '';
|
| 212 |
|
| 213 |
+
// 找到對應的桌子
|
| 214 |
+
const table = tables.find(t => t.id === participant.table_id);
|
| 215 |
+
const tableName = table ? table.name : '未分配';
|
| 216 |
+
|
| 217 |
+
tr.innerHTML = `
|
| 218 |
+
<td>${tableName}</td>
|
| 219 |
+
<td>${participant.seat_number || '-'}</td>
|
| 220 |
+
<td>${participant.nickname}</td>
|
| 221 |
+
<td>${participant.email}</td>
|
| 222 |
+
<td>${participant.fb_link ? `<a href="${participant.fb_link}" target="_blank">FB連結</a>` : '-'}</td>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
<td>
|
| 224 |
+
${participant.introduction ?
|
| 225 |
+
`${participant.introduction.length > 10 ?
|
| 226 |
+
participant.introduction.substring(0, 10) + '...' :
|
| 227 |
+
participant.introduction}
|
| 228 |
+
<button class="btn btn-link btn-sm" onclick="showFullIntroduction('${participant.introduction.replace(/'/g, "\\'")}')">
|
| 229 |
+
查看更多
|
| 230 |
+
</button>`
|
| 231 |
+
: '-'}
|
| 232 |
+
</td>
|
| 233 |
+
<td>
|
| 234 |
+
<button class="btn ${participant.has_paid ? 'btn-success' : 'btn-danger'} btn-sm"
|
| 235 |
+
onclick="togglePayment(${participant.id})">
|
| 236 |
+
${participant.has_paid ? '已付款' : '未付款'}
|
| 237 |
</button>
|
| 238 |
</td>
|
| 239 |
<td>
|
| 240 |
+
${participant.note ?
|
| 241 |
+
`<span class="note-preview" onclick="editNote(${participant.id}, '${participant.note.replace(/'/g, "\\'")}')">
|
| 242 |
+
${participant.note.length > 10 ? participant.note.substring(0, 10) + '...' : participant.note}
|
| 243 |
+
</span>`
|
| 244 |
+
: `<button class="btn btn-outline-secondary btn-sm" onclick="editNote(${participant.id}, '')">
|
| 245 |
+
新增備註
|
| 246 |
+
</button>`}
|
| 247 |
</td>
|
| 248 |
<td>
|
| 249 |
+
<span class="${participant.is_table_leader ? 'badge bg-success' : 'badge bg-secondary'}">
|
| 250 |
+
${participant.is_table_leader ? '桌長' : '參與者'}
|
| 251 |
+
</span>
|
| 252 |
</td>
|
| 253 |
+
<td>${new Date(participant.created_at).toLocaleString('zh-TW', { timeZone: 'Asia/Taipei' })}</td>
|
| 254 |
<td>
|
| 255 |
+
<div class="btn-group" role="group">
|
| 256 |
+
<button class="btn btn-primary btn-sm" onclick="showMoveDialog(${participant.id})">
|
| 257 |
+
移動座位
|
| 258 |
+
</button>
|
| 259 |
+
${participant.is_table_leader ?
|
| 260 |
+
`<button class="btn btn-warning btn-sm" onclick="toggleLeader(${participant.id})">
|
| 261 |
+
取消桌長
|
| 262 |
+
</button>` :
|
| 263 |
+
`<button class="btn btn-success btn-sm" onclick="toggleLeader(${participant.id})">
|
| 264 |
+
設為桌長
|
| 265 |
+
</button>`
|
| 266 |
+
}
|
| 267 |
+
<button class="btn btn-danger btn-sm" onclick="deleteParticipant(${participant.id})">
|
| 268 |
+
刪除
|
| 269 |
+
</button>
|
| 270 |
+
</div>
|
| 271 |
</td>
|
| 272 |
`;
|
| 273 |
+
tbody.appendChild(tr);
|
| 274 |
});
|
| 275 |
}
|
| 276 |
|
| 277 |
// 顯示移動座位的 Modal
|
| 278 |
+
function showMoveDialog(participantId) {
|
| 279 |
document.getElementById('participantId').value = participantId;
|
| 280 |
const select = document.getElementById('newTableSelect');
|
| 281 |
select.innerHTML = '';
|
|
|
|
| 346 |
}
|
| 347 |
|
| 348 |
// 查看完整自我介紹
|
| 349 |
+
function showFullIntroduction(intro) {
|
| 350 |
document.getElementById('fullIntroText').textContent = intro;
|
| 351 |
new bootstrap.Modal(document.getElementById('viewIntroModal')).show();
|
| 352 |
}
|