You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
560 lines
22 KiB
JavaScript
560 lines
22 KiB
JavaScript
const assetVersion = new URL(import.meta.url).searchParams.get('v');
|
|
|
|
function versionedModuleUrl(path) {
|
|
const url = new URL(path, import.meta.url);
|
|
url.search = '';
|
|
if (assetVersion) url.searchParams.set('v', assetVersion);
|
|
return url.href;
|
|
}
|
|
|
|
const [taskObserver, operationPresentation] = await Promise.all([
|
|
import(versionedModuleUrl('./task-observer.js')),
|
|
import(versionedModuleUrl('./operation-presentation.js')),
|
|
]);
|
|
const {
|
|
normalizeTask, recoveryTaskFailureNotice, resolvedTaskFailureNotice,
|
|
} = taskObserver;
|
|
const { operationTitle } = operationPresentation;
|
|
|
|
const REFRESH_MS = 10000;
|
|
// Covers the longest server-side absolute task deadline (145 minutes) while
|
|
// remaining finite and GET-only.
|
|
const OBSERVATION_BUDGET_MS = 9_300_000;
|
|
const REQUEST_TIMEOUT_MS = 12000;
|
|
const i18n = globalThis.VenixUserCopy;
|
|
|
|
const byId = id => document.getElementById(id);
|
|
const state = {
|
|
items: [], nextCursor: '', hasMore: false,
|
|
activeCount: 0, recoveringCount: 0, unreadCount: 0,
|
|
loading: false, request: null, serial: 0, timer: null, deadline: 0,
|
|
opener: null, scroll: null, closing: false, initialized: false,
|
|
readQueue: new Set(), readAttempted: new Set(), readInFlight: false,
|
|
readRequest: null, badgeRequest: null, csrfToken: '', reloadRequested: false,
|
|
};
|
|
|
|
class TaskCenterError extends Error {
|
|
constructor(copyKey, copyParameters = {}) {
|
|
super();
|
|
this.copyKey = copyKey;
|
|
this.copyParameters = copyParameters;
|
|
}
|
|
}
|
|
|
|
function taskCenterErrorText(error) {
|
|
if (error instanceof TaskCenterError) {
|
|
return i18n.text(error.copyKey, error.copyParameters);
|
|
}
|
|
return i18n.text('common.tasks.error.unavailable');
|
|
}
|
|
|
|
function element(tag, className = '', value = undefined) {
|
|
const node = document.createElement(tag);
|
|
node.className = className;
|
|
if (value !== undefined) node.textContent = String(value);
|
|
return node;
|
|
}
|
|
|
|
function validCount(value) {
|
|
return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
}
|
|
|
|
function validPagination(value) {
|
|
return value && typeof value === 'object' && !Array.isArray(value)
|
|
&& (value.next_cursor === null || typeof value.next_cursor === 'string')
|
|
&& typeof value.has_more === 'boolean';
|
|
}
|
|
|
|
export function dateText(value) {
|
|
if (!value) return '';
|
|
const numeric = Number(value);
|
|
const parsed = Number.isFinite(numeric) && numeric > 0
|
|
? numeric * (numeric < 1e12 ? 1000 : 1) : Date.parse(String(value));
|
|
return Number.isFinite(parsed)
|
|
? new Date(parsed).toLocaleString(i18n.locale, { hour12: false })
|
|
: String(value);
|
|
}
|
|
|
|
export function taskDurationText(createdAt, terminalAt) {
|
|
const started = Number(createdAt);
|
|
const finished = Number(terminalAt);
|
|
if (!Number.isSafeInteger(started) || started < 1
|
|
|| !Number.isSafeInteger(finished) || finished < started) return '';
|
|
let remaining = finished - started;
|
|
const parts = [];
|
|
for (const [seconds, key] of [
|
|
[86400, 'common.tasks.duration.day'],
|
|
[3600, 'common.tasks.duration.hour'],
|
|
[60, 'common.tasks.duration.minute'],
|
|
[1, 'common.tasks.duration.second'],
|
|
]) {
|
|
const value = Math.floor(remaining / seconds);
|
|
if (value > 0) parts.push(i18n.text(key, { count: value }));
|
|
remaining %= seconds;
|
|
}
|
|
return parts.length ? parts.join(' ')
|
|
: i18n.text('common.tasks.duration.second', { count: 0 });
|
|
}
|
|
|
|
async function csrfToken(controller) {
|
|
if (state.csrfToken) return state.csrfToken;
|
|
const response = await fetch('/api/v1/session', {
|
|
method: 'GET', headers: { Accept: 'application/json' }, credentials: 'same-origin',
|
|
cache: 'no-store', signal: controller.signal,
|
|
});
|
|
const payload = await response.json();
|
|
if (!response.ok || typeof payload?.csrf_token !== 'string' || !payload.csrf_token) {
|
|
throw new Error(i18n.text('common.tasks.error.read_state_unknown'));
|
|
}
|
|
state.csrfToken = payload.csrf_token;
|
|
return state.csrfToken;
|
|
}
|
|
|
|
async function markPresentedRead(items) {
|
|
for (const item of items) {
|
|
const task = normalizeTask(item);
|
|
if (task.terminal && task.id && !state.readAttempted.has(task.id)) {
|
|
state.readQueue.add(task.id);
|
|
}
|
|
}
|
|
if (state.readInFlight || !state.readQueue.size || !canRead()) return;
|
|
const ids = Array.from(state.readQueue).slice(0, 50);
|
|
ids.forEach(id => { state.readQueue.delete(id); state.readAttempted.add(id); });
|
|
state.readInFlight = true;
|
|
const controller = new AbortController();
|
|
state.readRequest = controller;
|
|
const timeout = setTimeout(() => controller.abort('timeout'), REQUEST_TIMEOUT_MS);
|
|
try {
|
|
const token = await csrfToken(controller);
|
|
const response = await fetch('/api/v1/tasks/read', {
|
|
method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'X-CSRF-Token': token },
|
|
credentials: 'same-origin', cache: 'no-store', signal: controller.signal,
|
|
body: JSON.stringify({ ids }),
|
|
});
|
|
const payload = await response.json();
|
|
if (!response.ok || !validCount(payload?.read_count) || !validCount(payload?.unread_count)) {
|
|
throw new Error(i18n.text('common.tasks.error.read_state_failed'));
|
|
}
|
|
const marked = new Set(ids);
|
|
for (const item of state.items) {
|
|
if (marked.has(String(item?.id || ''))) item.unread = false;
|
|
}
|
|
document.querySelectorAll('.panel-task-item[data-task-id]').forEach(article => {
|
|
if (marked.has(article.dataset.taskId || '')) article.classList.remove('is-unread');
|
|
});
|
|
state.unreadCount = payload.unread_count;
|
|
renderBadge();
|
|
} catch {
|
|
// Presentation remains successful. A failed acknowledgement is not
|
|
// automatically retried; another drawer session may acknowledge it.
|
|
} finally {
|
|
clearTimeout(timeout);
|
|
if (state.readRequest === controller) state.readRequest = null;
|
|
state.readInFlight = false;
|
|
if (state.readQueue.size && canRead()) void markPresentedRead([]);
|
|
}
|
|
}
|
|
|
|
export function taskTitle(task) {
|
|
return operationTitle(
|
|
task,
|
|
(key, parameters = {}) => i18n.text(key, parameters),
|
|
'common.tasks.fallback_title',
|
|
);
|
|
}
|
|
|
|
function statusText(task) {
|
|
if (!task.terminal) return i18n.text('common.tasks.status.running');
|
|
if (task.recovery?.pending === true) {
|
|
return task.status === 'failed'
|
|
? i18n.text('common.tasks.status.recovering')
|
|
: i18n.text('common.tasks.status.ledger_error');
|
|
}
|
|
return i18n.text(task.status === 'succeeded'
|
|
? 'common.tasks.status.succeeded' : 'common.tasks.status.failed');
|
|
}
|
|
|
|
function statusClass(task) {
|
|
return task.recovery?.pending === true
|
|
? 'failed' : (task.terminal ? task.status : 'running');
|
|
}
|
|
|
|
function setMessage(message, tone = '') {
|
|
const target = byId('panel-task-state');
|
|
if (!target) return;
|
|
target.textContent = message;
|
|
target.className = `panel-task-state${tone ? ` is-${tone}` : ''}`;
|
|
target.setAttribute('role', tone === 'error' ? 'alert' : 'status');
|
|
}
|
|
|
|
function renderBadge() {
|
|
const badge = byId('cloud-task-center-badge');
|
|
if (!badge) return;
|
|
const count = Math.max(0, Number(state.unreadCount) || Number(state.activeCount) || 0);
|
|
badge.textContent = count > 99 ? '99+' : String(count);
|
|
badge.hidden = count === 0;
|
|
}
|
|
|
|
function detailBlock(task, raw) {
|
|
const details = element('details', 'panel-task-details');
|
|
details.append(element('summary', '', i18n.text('common.tasks.details.open')));
|
|
const list = element('dl', 'panel-task-detail-list');
|
|
const append = (label, value) => {
|
|
if (value === null || value === undefined || value === '') return;
|
|
list.append(element('dt', '', label), element('dd', '', value));
|
|
};
|
|
append(i18n.text('common.tasks.details.id'), task.id);
|
|
append(i18n.text('common.tasks.details.status'), statusText(task));
|
|
append(i18n.text('common.tasks.details.duration'),
|
|
taskDurationText(raw?.created_at, raw?.terminal_at));
|
|
append(i18n.text('common.tasks.details.error_code'), task.error_code);
|
|
if (task.recovery?.pending === true) {
|
|
append(i18n.text('common.tasks.details.recovery_status'),
|
|
i18n.text('common.tasks.recovery.continuing'));
|
|
append(i18n.text('common.tasks.details.last_error'),
|
|
recoveryTaskFailureNotice(task));
|
|
append(i18n.text('common.tasks.details.last_check'),
|
|
dateText(task.recovery.last_checked_at));
|
|
append(i18n.text('common.tasks.details.next_check'),
|
|
dateText(task.recovery.next_check_at)
|
|
|| i18n.text('common.tasks.recovery.waiting'));
|
|
}
|
|
if (task.result !== null && task.result !== undefined) {
|
|
let result = '';
|
|
try { result = typeof task.result === 'string' ? task.result : JSON.stringify(task.result, null, 2); }
|
|
catch { result = i18n.text('common.tasks.result.invalid'); }
|
|
append(i18n.text('common.tasks.details.result'), result);
|
|
}
|
|
details.append(list);
|
|
return details;
|
|
}
|
|
|
|
function renderItems(emptyMessage = i18n.text('common.tasks.empty')) {
|
|
const list = byId('panel-task-list');
|
|
if (!list) return;
|
|
list.replaceChildren();
|
|
const normalized = state.items.map(raw => ({ raw, task: normalizeTask(raw) }));
|
|
for (const group of [
|
|
{ title: i18n.text('common.tasks.group.running'), items: normalized.filter(item => !item.task.terminal) },
|
|
{ title: '', items: normalized.filter(item => item.task.terminal) },
|
|
]) {
|
|
if (!group.items.length) continue;
|
|
const groupNode = element('div', 'panel-task-group');
|
|
if (group.title) groupNode.append(element('h2', 'panel-task-group-title', group.title));
|
|
for (const { raw, task } of group.items) {
|
|
const article = element('article', `panel-task-item is-${statusClass(task)}${raw?.unread === true ? ' is-unread' : ''}`);
|
|
if (task.id) article.dataset.taskId = task.id;
|
|
const heading = element('div', 'panel-task-item-heading');
|
|
heading.append(element('h3', '', taskTitle(raw)), element('span', `panel-task-status is-${statusClass(task)}`, statusText(task)));
|
|
article.append(heading);
|
|
const meta = element('div', 'panel-task-meta');
|
|
const recordedAt = dateText(raw.updated_at || raw.completed_at || raw.created_at);
|
|
if (recordedAt) meta.append(element('time', '', recordedAt));
|
|
if (meta.children.length) article.append(meta);
|
|
const recoveryNotice = recoveryTaskFailureNotice(task);
|
|
if (task.status !== 'failed' && recoveryNotice) {
|
|
article.append(element('p', 'panel-task-warning', recoveryNotice));
|
|
}
|
|
if (task.status === 'failed') {
|
|
const resolvedNotice = resolvedTaskFailureNotice(task);
|
|
if (resolvedNotice) {
|
|
article.append(element('p', 'panel-task-warning', resolvedNotice));
|
|
} else {
|
|
article.append(element('p', 'panel-task-error',
|
|
i18n.text('common.tasks.error.execution_failed')));
|
|
if (recoveryNotice) {
|
|
article.append(element('p', 'panel-task-warning', recoveryNotice));
|
|
} else if (raw?.kind === 'host_storage_configure') {
|
|
article.append(element('p', 'panel-task-warning',
|
|
i18n.text('common.tasks.warning.storage_terminated')));
|
|
} else if (task.effect_may_have_applied) {
|
|
article.append(element('p', 'panel-task-warning',
|
|
i18n.text('common.tasks.warning.effect_unknown')));
|
|
} else if (task.safe_to_resubmit === false) {
|
|
article.append(element('p', 'panel-task-warning',
|
|
i18n.text('common.tasks.warning.no_resubmit')));
|
|
}
|
|
}
|
|
}
|
|
article.append(detailBlock(task, raw));
|
|
groupNode.append(article);
|
|
}
|
|
list.append(groupNode);
|
|
}
|
|
if (!state.items.length) list.append(element('p', 'panel-task-empty', emptyMessage));
|
|
}
|
|
|
|
function renderControls() {
|
|
const refresh = byId('panel-task-refresh');
|
|
const more = byId('panel-task-more');
|
|
if (refresh) refresh.disabled = state.loading;
|
|
if (more) { more.hidden = !state.hasMore; more.disabled = state.loading; }
|
|
const list = byId('panel-task-list');
|
|
if (list) list.setAttribute('aria-busy', String(state.loading));
|
|
const count = byId('panel-task-count');
|
|
if (count) count.textContent = state.items.length
|
|
? i18n.text('common.tasks.count.visible', { count: state.items.length }) : '';
|
|
renderBadge();
|
|
}
|
|
|
|
function clearTimer() {
|
|
if (state.timer !== null) clearTimeout(state.timer);
|
|
state.timer = null;
|
|
}
|
|
|
|
function canRead() {
|
|
const dialog = byId('panel-task-drawer');
|
|
return Boolean(dialog?.open) && !state.closing && document.visibilityState === 'visible';
|
|
}
|
|
|
|
function stopRequest() {
|
|
clearTimer();
|
|
state.request?.abort('stopped');
|
|
state.request = null;
|
|
state.readRequest?.abort('stopped');
|
|
state.readRequest = null;
|
|
state.badgeRequest?.abort('stopped');
|
|
state.badgeRequest = null;
|
|
state.reloadRequested = false;
|
|
state.serial += 1;
|
|
state.loading = false;
|
|
}
|
|
|
|
async function loadBadgeCounts() {
|
|
if (document.visibilityState !== 'visible' || state.badgeRequest) return;
|
|
const controller = new AbortController(); state.badgeRequest = controller;
|
|
const timeout = setTimeout(() => controller.abort('timeout'), REQUEST_TIMEOUT_MS);
|
|
try {
|
|
const response = await fetch('/api/v1/tasks?state=active&limit=1', {
|
|
method: 'GET', headers: { Accept: 'application/json' }, credentials: 'same-origin',
|
|
cache: 'no-store', signal: controller.signal,
|
|
});
|
|
const payload = await response.json();
|
|
if (!response.ok || !Array.isArray(payload?.items) || !validPagination(payload?.pagination)
|
|
|| !validCount(payload?.active_count)
|
|
|| !validCount(payload?.recovering_count)
|
|
|| !validCount(payload?.unread_count)) return;
|
|
state.activeCount = payload.active_count;
|
|
state.recoveringCount = payload.recovering_count;
|
|
state.unreadCount = payload.unread_count;
|
|
renderBadge();
|
|
} catch {
|
|
// This one-shot badge read is optional, never retried automatically, and
|
|
// never changes task read state.
|
|
} finally {
|
|
clearTimeout(timeout);
|
|
if (state.badgeRequest === controller) state.badgeRequest = null;
|
|
}
|
|
}
|
|
|
|
function scheduleRefresh() {
|
|
clearTimer();
|
|
if (!canRead() || state.loading
|
|
|| state.activeCount + state.recoveringCount < 1) return;
|
|
if (state.recoveringCount < 1 && Date.now() >= state.deadline) {
|
|
setMessage(i18n.text('common.tasks.refresh_stopped'));
|
|
return;
|
|
}
|
|
state.timer = setTimeout(() => {
|
|
state.timer = null;
|
|
void load('', 'auto');
|
|
}, REFRESH_MS);
|
|
}
|
|
|
|
async function requestPage(taskState, cursor, controller) {
|
|
const params = new URLSearchParams({ state: taskState, limit: '20' });
|
|
if (cursor) params.set('cursor', cursor);
|
|
const timeout = setTimeout(() => controller.abort('timeout'), REQUEST_TIMEOUT_MS);
|
|
try {
|
|
const response = await fetch(`/api/v1/tasks?${params}`, {
|
|
method: 'GET', headers: { Accept: 'application/json' }, credentials: 'same-origin',
|
|
cache: 'no-store', signal: controller.signal,
|
|
});
|
|
let payload;
|
|
try { payload = await response.json(); }
|
|
catch { throw new TaskCenterError('common.tasks.error.invalid_response'); }
|
|
if (!response.ok) {
|
|
const error = new TaskCenterError('common.tasks.error.unavailable_http', {
|
|
status: response.status,
|
|
});
|
|
error.status = response.status;
|
|
throw error;
|
|
}
|
|
if (!Array.isArray(payload?.items) || !validPagination(payload?.pagination)
|
|
|| !validCount(payload?.active_count)
|
|
|| !validCount(payload?.recovering_count)
|
|
|| !validCount(payload?.unread_count)) {
|
|
throw new TaskCenterError('common.tasks.error.invalid_data');
|
|
}
|
|
return payload;
|
|
} catch (error) {
|
|
if (controller.signal.reason === 'timeout') {
|
|
throw new TaskCenterError('common.tasks.error.timeout');
|
|
}
|
|
throw error;
|
|
} finally { clearTimeout(timeout); }
|
|
}
|
|
|
|
async function load(cursor = '', source = 'manual') {
|
|
if (!canRead() || state.loading) return;
|
|
clearTimer();
|
|
if (source === 'manual') state.deadline = Date.now() + OBSERVATION_BUDGET_MS;
|
|
const controller = new AbortController();
|
|
const serial = ++state.serial;
|
|
state.request = controller;
|
|
state.loading = true;
|
|
renderControls();
|
|
if (source !== 'auto') setMessage(i18n.text('common.tasks.loading'));
|
|
try {
|
|
const payload = cursor
|
|
? await requestPage('completed', cursor, controller)
|
|
: await Promise.all([
|
|
requestPage('active', '', controller),
|
|
requestPage('completed', '', controller),
|
|
]).then(([active, completed]) => ({
|
|
...completed,
|
|
items: [...active.items, ...completed.items],
|
|
active_count: active.active_count,
|
|
recovering_count: Math.max(
|
|
active.recovering_count, completed.recovering_count,
|
|
),
|
|
unread_count: Math.max(active.unread_count, completed.unread_count),
|
|
}));
|
|
if (controller.signal.aborted || serial !== state.serial || !canRead()) return;
|
|
const incoming = payload.items;
|
|
const combined = cursor ? [...state.items, ...incoming] : incoming;
|
|
const seen = new Set();
|
|
state.items = combined.filter(item => {
|
|
const key = normalizeTask(item).id || JSON.stringify(item);
|
|
if (seen.has(key)) return false;
|
|
seen.add(key);
|
|
return true;
|
|
});
|
|
state.nextCursor = String(payload.pagination.next_cursor || '');
|
|
state.hasMore = payload.pagination.has_more === true && Boolean(state.nextCursor);
|
|
state.activeCount = payload.active_count;
|
|
state.recoveringCount = payload.recovering_count;
|
|
state.unreadCount = payload.unread_count;
|
|
renderItems();
|
|
void markPresentedRead(state.items);
|
|
setMessage(state.activeCount > 0
|
|
? i18n.text('common.tasks.summary.active', { count: state.activeCount })
|
|
: (state.recoveringCount > 0
|
|
? i18n.text('common.tasks.summary.recovering', {
|
|
count: state.recoveringCount,
|
|
})
|
|
: i18n.text('common.tasks.summary.current')));
|
|
} catch (error) {
|
|
if (serial !== state.serial || (controller.signal.aborted && controller.signal.reason !== 'timeout')) return;
|
|
if (!state.items.length) {
|
|
renderItems(i18n.text('common.tasks.empty_unavailable'));
|
|
}
|
|
if (source !== 'auto' || !state.items.length) {
|
|
setMessage(taskCenterErrorText(error), 'error');
|
|
}
|
|
} finally {
|
|
if (serial === state.serial) {
|
|
state.request = null;
|
|
state.loading = false;
|
|
renderControls();
|
|
if (state.reloadRequested && canRead()) {
|
|
state.reloadRequested = false;
|
|
void load('', 'receipt');
|
|
} else scheduleRefresh();
|
|
}
|
|
}
|
|
}
|
|
|
|
function finishClose() {
|
|
const dialog = byId('panel-task-drawer');
|
|
state.closing = false;
|
|
stopRequest();
|
|
document.documentElement.classList.remove('panel-task-open');
|
|
document.body.style.removeProperty('--panel-task-scroll-top');
|
|
if (state.scroll) {
|
|
window.scrollTo({ left: state.scroll.x, top: state.scroll.y, behavior: 'instant' });
|
|
state.scroll = null;
|
|
}
|
|
document.querySelectorAll('[data-task-center-open]').forEach(button => button.setAttribute('aria-expanded', 'false'));
|
|
if (state.opener?.isConnected) state.opener.focus({ preventScroll: true });
|
|
state.opener = null;
|
|
if (dialog?.open && !window.VenixDrawerMotion) dialog.close();
|
|
}
|
|
|
|
function close() {
|
|
const dialog = byId('panel-task-drawer');
|
|
if (!dialog || state.closing) return;
|
|
state.closing = true;
|
|
stopRequest();
|
|
if (window.VenixDrawerMotion) {
|
|
void window.VenixDrawerMotion.closeDrawerWithMotion(dialog).then(closed => {
|
|
if (closed) finishClose();
|
|
else state.closing = false;
|
|
});
|
|
} else {
|
|
dialog.close();
|
|
finishClose();
|
|
}
|
|
}
|
|
|
|
function open(opener) {
|
|
const dialog = byId('panel-task-drawer');
|
|
if (!dialog || dialog.open) return;
|
|
state.closing = false;
|
|
state.opener = opener || document.querySelector('[data-task-center-open]');
|
|
state.scroll = { x: window.scrollX, y: window.scrollY };
|
|
document.body.style.setProperty('--panel-task-scroll-top', `${-state.scroll.y}px`);
|
|
document.documentElement.classList.add('panel-task-open');
|
|
if (window.VenixDrawerMotion) window.VenixDrawerMotion.openDrawerWithMotion(dialog);
|
|
else dialog.showModal();
|
|
document.querySelectorAll('[data-task-center-open]').forEach(button => button.setAttribute('aria-expanded', 'true'));
|
|
byId('panel-task-close')?.focus({ preventScroll: true });
|
|
state.deadline = Date.now() + OBSERVATION_BUDGET_MS;
|
|
state.readAttempted.clear();
|
|
void load('', 'initial');
|
|
}
|
|
|
|
export function initializeTaskCenter() {
|
|
const dialog = byId('panel-task-drawer');
|
|
if (!dialog || state.initialized) return;
|
|
state.initialized = true;
|
|
renderItems();
|
|
renderControls();
|
|
document.addEventListener('click', event => {
|
|
const trigger = event.target.closest('[data-task-center-open]');
|
|
if (!trigger || event.defaultPrevented || event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
|
event.preventDefault();
|
|
open(trigger);
|
|
});
|
|
byId('panel-task-close')?.addEventListener('click', close);
|
|
byId('panel-task-refresh')?.addEventListener('click', () => { void load('', 'manual'); });
|
|
byId('panel-task-more')?.addEventListener('click', () => { if (state.nextCursor) void load(state.nextCursor, 'more'); });
|
|
document.addEventListener('visibilitychange', () => {
|
|
if (document.visibilityState === 'hidden') stopRequest();
|
|
else if (dialog.open) void load('', 'visible');
|
|
else void loadBadgeCounts();
|
|
});
|
|
dialog.addEventListener('cancel', event => { event.preventDefault(); close(); });
|
|
dialog.addEventListener('click', event => {
|
|
if (event.target !== dialog) return;
|
|
const rect = dialog.getBoundingClientRect();
|
|
if (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom) close();
|
|
});
|
|
window.addEventListener('pagehide', stopRequest);
|
|
window.addEventListener('pageshow', event => {
|
|
if (!event.persisted) return;
|
|
if (dialog.open) close();
|
|
void loadBadgeCounts();
|
|
});
|
|
window.addEventListener('virt-cloud:task-accepted', () => {
|
|
state.activeCount += 1;
|
|
renderBadge();
|
|
if (!canRead()) return;
|
|
if (state.loading) state.reloadRequested = true;
|
|
else void load('', 'receipt');
|
|
});
|
|
void loadBadgeCounts();
|
|
}
|
|
|
|
export const taskCenterTest = { statusText, taskTitle };
|