This commit is contained in:
@@ -244,6 +244,14 @@
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.dashboard-backfill-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.dashboard-focus-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
@@ -1276,6 +1284,10 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dashboard-backfill-actions {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dashboard-search,
|
||||
.dashboard-select,
|
||||
.dashboard-segmented {
|
||||
|
||||
@@ -287,10 +287,12 @@ let priceChartInstance = null;
|
||||
return {
|
||||
card,
|
||||
trigger: document.querySelector('[data-pchome-backfill-trigger]'),
|
||||
refreshStaleTrigger: document.querySelector('[data-pchome-refresh-stale-trigger]'),
|
||||
status: document.querySelector('[data-pchome-backfill-status]'),
|
||||
result: document.querySelector('[data-pchome-backfill-result]'),
|
||||
progress: document.querySelector('[data-pchome-backfill-progress]'),
|
||||
backfillEndpoint: card ? card.dataset.backfillEndpoint : '/api/ai/pchome-match/backfill',
|
||||
refreshStaleEndpoint: card ? card.dataset.refreshStaleEndpoint : '/api/ai/pchome-match/refresh-stale',
|
||||
statusEndpoint: card ? card.dataset.statusEndpoint : '/api/ai/pchome-match/backfill/status'
|
||||
};
|
||||
}
|
||||
@@ -366,9 +368,16 @@ let priceChartInstance = null;
|
||||
elements.trigger.disabled = running;
|
||||
elements.trigger.classList.toggle('is-loading', running);
|
||||
elements.trigger.innerHTML = running
|
||||
? '<i class="fas fa-spinner fa-spin"></i> 補抓中'
|
||||
? '<i class="fas fa-spinner fa-spin"></i> 執行中'
|
||||
: '<i class="fas fa-search"></i> 補抓 60 筆';
|
||||
}
|
||||
if (elements.refreshStaleTrigger) {
|
||||
elements.refreshStaleTrigger.disabled = running;
|
||||
elements.refreshStaleTrigger.classList.toggle('is-loading', running);
|
||||
elements.refreshStaleTrigger.innerHTML = running
|
||||
? '<i class="fas fa-spinner fa-spin"></i> 執行中'
|
||||
: '<i class="fas fa-rotate"></i> 刷新過期 120 筆';
|
||||
}
|
||||
|
||||
if (running) {
|
||||
schedulePchomeBackfillPoll();
|
||||
@@ -430,10 +439,50 @@ let priceChartInstance = null;
|
||||
});
|
||||
}
|
||||
|
||||
function refreshStalePchomeMatches() {
|
||||
const elements = getPchomeBackfillElements();
|
||||
if (!elements.card || !elements.refreshStaleTrigger) return;
|
||||
const limit = Number(elements.refreshStaleTrigger.dataset.limit || 120);
|
||||
if (!confirm(`啟動 PChome 過期價格刷新 ${limit} 筆?`)) return;
|
||||
|
||||
elements.refreshStaleTrigger.disabled = true;
|
||||
if (elements.status) {
|
||||
elements.status.textContent = '正在送出過期價格刷新任務';
|
||||
}
|
||||
fetch(elements.refreshStaleEndpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': getCSRFToken()
|
||||
},
|
||||
body: JSON.stringify({ limit })
|
||||
})
|
||||
.then(response => response.json().then(data => ({ ok: response.ok, status: response.status, data })))
|
||||
.then(({ ok, status, data }) => {
|
||||
renderPchomeBackfillStatus(data);
|
||||
if (!ok && status !== 409) {
|
||||
throw new Error(data.message || data.error || 'PChome 過期價格刷新啟動失敗');
|
||||
}
|
||||
schedulePchomeBackfillPoll();
|
||||
})
|
||||
.catch(error => {
|
||||
if (elements.status) {
|
||||
elements.status.textContent = error.message || 'PChome 過期價格刷新啟動失敗';
|
||||
}
|
||||
if (elements.refreshStaleTrigger) {
|
||||
elements.refreshStaleTrigger.disabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.backfillPchomeMatches = backfillPchomeMatches;
|
||||
window.refreshStalePchomeMatches = refreshStalePchomeMatches;
|
||||
document.querySelectorAll('[data-pchome-backfill-trigger]').forEach(button => {
|
||||
button.addEventListener('click', backfillPchomeMatches);
|
||||
});
|
||||
document.querySelectorAll('[data-pchome-refresh-stale-trigger]').forEach(button => {
|
||||
button.addEventListener('click', refreshStalePchomeMatches);
|
||||
});
|
||||
loadPchomeBackfillStatus();
|
||||
|
||||
function runPchomeReviewDecision(button) {
|
||||
|
||||
Reference in New Issue
Block a user