- Introduced tests for case creation commands, ensuring proper handling of UUIDs and payloads. - Added tests for v5 assignment functionality, validating employee identification and group assignment. - Implemented tests for remote recovery scenarios, including handling network failures and response validation. - Created tests for hardware label generation and validation, ensuring proper URL formatting and QR code generation. - Developed extensive tests for remote control functionality, covering connection isolation, command execution, and user permissions. - Added tests for workflow timer registration, ensuring correct handling of timer states and ownership validation.
46 lines
2.9 KiB
JavaScript
46 lines
2.9 KiB
JavaScript
import {api, bootstrap, element} from './remote-api.js';
|
|
const $ = id => document.getElementById(id);
|
|
let busy = false;
|
|
async function action(work) {
|
|
if (busy) return;
|
|
busy = true; $('notice').textContent = '';
|
|
document.querySelectorAll('button').forEach(b => { b.disabled = true; });
|
|
try { await work(); await load(); }
|
|
catch (error) { $('notice').textContent = error.message; }
|
|
finally { busy = false; document.querySelectorAll('button').forEach(b => { b.disabled = false; }); }
|
|
}
|
|
function showCode(result) { $('code').textContent = result.code; $('new-code').hidden = false; }
|
|
function hideCode() { $('code').textContent = ''; $('new-code').hidden = true; }
|
|
async function load() {
|
|
const result = await api('/admin');
|
|
$('remotes').replaceChildren(); $('devices').replaceChildren();
|
|
result.remotes.forEach(remote => {
|
|
const row = element('div', remote.name + (remote.revoked ? ' · Tilbagekaldt' : ''), 'row');
|
|
if (!remote.revoked) {
|
|
const rotate = element('button', 'Ny kode');
|
|
rotate.onclick = () => { if (confirm('Udskift koden og afbryd alle enheder til denne fjernbetjening?')) action(async () => showCode(await api(`/admin/remotes/${remote.id}/rotate`, {}))); };
|
|
const revoke = element('button', 'Tilbagekald', 'secondary');
|
|
revoke.onclick = () => { if (confirm('Tilbagekald denne fjernbetjening og dens enheder?')) action(() => api(`/admin/remotes/${remote.id}`, {}, 'DELETE')); };
|
|
row.append(rotate, revoke);
|
|
}
|
|
$('remotes').append(row);
|
|
});
|
|
result.devices.forEach(device => {
|
|
const row = element('div', `${device.name} · Senest aktiv ${new Date(device.last_seen_at).toLocaleString('da-DK')} · ${device.revoked ? 'Tilbagekaldt' : 'Udløber ' + new Date(device.expires_at).toLocaleDateString('da-DK')}`, 'row');
|
|
if (!device.revoked) {
|
|
const revoke = element('button', 'Afbryd enhed', 'secondary');
|
|
revoke.onclick = () => action(() => api(`/admin/devices/${device.id}`, {}, 'DELETE')); row.append(revoke);
|
|
}
|
|
$('devices').append(row);
|
|
});
|
|
if (!result.remotes.length) $('remotes').textContent = 'Ingen fjernbetjeninger endnu';
|
|
if (!result.devices.length) $('devices').textContent = 'Ingen forbundne enheder';
|
|
if (!result.pin_set) $('notice').textContent = 'Opret din 4-cifrede PIN før din første fjernbetjening.';
|
|
}
|
|
$('pin-form').onsubmit = event => { event.preventDefault(); action(async () => { await api('/admin/pin', {pin: $('pin').value}, 'PUT'); $('pin').value = ''; }); };
|
|
$('create-form').onsubmit = event => { event.preventDefault(); action(async () => showCode(await api('/admin/remotes', {name: $('name').value}))); };
|
|
$('hide-code').onclick = hideCode;
|
|
window.addEventListener('pagehide', hideCode);
|
|
document.addEventListener('visibilitychange', () => { if (document.hidden) hideCode(); });
|
|
try { await bootstrap(); await load(); } catch (error) { $('notice').textContent = error.message; }
|