convert VolumesModel to use [error, result] pattern
This commit is contained in:
@@ -125,9 +125,14 @@ async function refresh() {
|
||||
busy.value = false;
|
||||
|
||||
for (const v of volumes.value) {
|
||||
const status = await volumesModel.getStatus(v.id);
|
||||
v.state = ledState(status.state);
|
||||
v.message = status.message;
|
||||
const [error, status] = await volumesModel.getStatus(v.id);
|
||||
if (error) {
|
||||
v.state = 'warning';
|
||||
v.message = error.message;
|
||||
} else {
|
||||
v.state = ledState(status.state);
|
||||
v.message = status.message;
|
||||
}
|
||||
v.busy = false;
|
||||
}
|
||||
};
|
||||
@@ -152,16 +157,19 @@ async function openVolumeDialog(volume) {
|
||||
volumeDialogData.value.hostPath = volume ? volume.mountOptions.hostPath : '';
|
||||
volumeDialogData.value.privateKey = volume ? volume.mountOptions.privateKey : '';
|
||||
|
||||
let blockDevices = await volumesModel.getBlockDevices();
|
||||
const [error, blockDevices] = await volumesModel.getBlockDevices();
|
||||
if (error) return console.error(error);
|
||||
|
||||
// only offer unmounted disks
|
||||
blockDevices = blockDevices.filter(d => !d.mountpoint);
|
||||
const ext4BlockDevices = [], xfsBlockDevices = [];
|
||||
for (const blockDevice of blockDevices) {
|
||||
if (!blockDevice.mountpoint) continue; // only offer unmounted disks
|
||||
blockDevice.label = blockDevice.path; // // amend label for UI
|
||||
if (blockDevice.type === 'ext4') ext4BlockDevices.push(blockDevice);
|
||||
else if (blockDevice.type === 'xfs') xfsBlockDevices.push(blockDevice);
|
||||
}
|
||||
|
||||
// amend label for UI
|
||||
blockDevices.forEach(d => d.label = d.path);
|
||||
|
||||
volumeDialogData.value.ext4BlockDevices = blockDevices.filter(d => d.type === 'ext4');
|
||||
volumeDialogData.value.xfsBlockDevices = blockDevices.filter(d => d.type === 'xfs');
|
||||
volumeDialogData.value.ext4BlockDevices = ext4BlockDevices;
|
||||
volumeDialogData.value.xfsBlockDevices = xfsBlockDevices;
|
||||
|
||||
volumeDialog.value.open();
|
||||
}
|
||||
@@ -182,13 +190,14 @@ async function submitVolumeDialog() {
|
||||
privateKey: volumeDialogData.value.privateKey,
|
||||
};
|
||||
|
||||
try {
|
||||
if (volumeDialogData.value.mode === 'new') {
|
||||
await volumesModel.add(volumeDialogData.value.name, volumeDialogData.value.mountType, mountOptions);
|
||||
} else {
|
||||
await volumesModel.update(volumeDialogData.value.id, volumeDialogData.value.mountType, mountOptions);
|
||||
}
|
||||
} catch (error) {
|
||||
let error;
|
||||
if (volumeDialogData.value.mode === 'new') {
|
||||
[error] = await volumesModel.add(volumeDialogData.value.name, volumeDialogData.value.mountType, mountOptions);
|
||||
} else {
|
||||
[error] = await volumesModel.update(volumeDialogData.value.id, volumeDialogData.value.mountType, mountOptions);
|
||||
}
|
||||
|
||||
if (error) {
|
||||
volumeDialogData.value.error = error.body ? error.body.message : 'Internal error';
|
||||
volumeDialogData.value.busy = false;
|
||||
console.error(error);
|
||||
@@ -211,7 +220,12 @@ async function onRemove(volume) {
|
||||
|
||||
if (!yes) return;
|
||||
|
||||
await volumesModel.remove(volume.id);
|
||||
const [error] = await volumesModel.remove(volume.id);
|
||||
if (error) {
|
||||
if (error.status === 409) window.pankow.notify({ text: error.body.message || `Volume is still in use.`, type: 'danger', persistent: true });
|
||||
return console.error(error);
|
||||
}
|
||||
|
||||
await refresh();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user