Update admin pricing recalc flow
This commit is contained in:
@@ -1185,16 +1185,41 @@ function processMetaPrices(metaPrices, originalLotName) {
|
|||||||
|
|
||||||
async function recalculateAll() {
|
async function recalculateAll() {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch('/api/admin/pricing/recalculate-all', {method: 'POST'});
|
const resp = await fetch('/api/admin/pricing/recalculate-all?force=1', {method: 'POST'});
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (data.task_id) {
|
if (data.task_id) {
|
||||||
showToast('Пересчёт цен запущен в фоне', 'info');
|
showToast('Пересчёт цен запущен в фоне', 'info');
|
||||||
|
await waitForTaskCompletion(data.task_id);
|
||||||
|
if (currentTab === 'component-settings') {
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showToast('Ошибка запуска пересчёта', 'error');
|
showToast('Ошибка запуска пересчёта', 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitForTaskCompletion(taskId) {
|
||||||
|
if (!taskId) return;
|
||||||
|
for (;;) {
|
||||||
|
await sleep(2500);
|
||||||
|
try {
|
||||||
|
const resp = await fetch(`/api/tasks/${taskId}`);
|
||||||
|
if (!resp.ok) return;
|
||||||
|
const task = await resp.json();
|
||||||
|
if (task.status === 'completed' || task.status === 'error') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Close modal on click outside
|
// Close modal on click outside
|
||||||
document.getElementById('price-modal').addEventListener('click', function(e) {
|
document.getElementById('price-modal').addEventListener('click', function(e) {
|
||||||
if (e.target === this) {
|
if (e.target === this) {
|
||||||
|
|||||||
Reference in New Issue
Block a user