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.
virt/web/public/cloud/app.js

57 lines
1.7 KiB
JavaScript

const pageModules = Object.freeze({
instances: '/cloud/instances.js',
detail: '/cloud/detail.js',
deploy: '/cloud/deploy.js',
backups: '/cloud/backups.js',
'cloud-snapshots': '/cloud/cloud-snapshots.js',
traffic: '/cloud/traffic.js',
vpcs: '/cloud/vpcs.js',
isos: '/cloud/iso-images.js',
keys: '/cloud/ssh-keys.js',
invoices: '/cloud/invoices.js',
'invoice-detail': '/cloud/invoice-detail.js',
reinstall: '/cloud/reinstall.js',
});
const page = document.body.dataset.cloudPage || '';
const assetVersion = new URL(import.meta.url).searchParams.get('v');
const i18n = globalThis.VenixUserCopy;
function versionedModuleUrl(path) {
const url = new URL(path, import.meta.url);
url.search = '';
if (assetVersion) url.searchParams.set('v', assetVersion);
return url.href;
}
function showPageError(message) {
const target = document.getElementById('cloud-page-error');
if (target) {
target.textContent = message;
target.hidden = false;
}
}
async function initializeCloudApp() {
const modulePath = pageModules[page];
if (!modulePath) {
showPageError(i18n.text('common.page.error.invalid'));
return;
}
const module = await import(versionedModuleUrl(modulePath));
await module.initialize();
}
// The page and task drawer are independent: a slow drawer must not delay the page.
void import(versionedModuleUrl('./task-center.js')).then(module => {
module.initializeTaskCenter();
}).catch(() => {
const target = document.getElementById('panel-task-state');
if (target) target.textContent = i18n.text('common.tasks.error.unavailable');
});
initializeCloudApp().catch(() => {
showPageError(i18n.text('common.page.error.load_failed'));
});