From 3543c0b23757c56590b4e946a9b11138bb9f3920 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 23 Jan 2023 18:43:54 +0100 Subject: [PATCH] Provide a dropdown for disk mounting --- src/js/client.js | 9 +++++++++ src/views/volumes.html | 5 +++-- src/views/volumes.js | 24 ++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/js/client.js b/src/js/client.js index 49f2637e0..26a89af1a 100644 --- a/src/js/client.js +++ b/src/js/client.js @@ -1973,6 +1973,15 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout }); }; + Client.prototype.getBlockDevices = function (callback) { + get('/api/v1/cloudron/block_devices', null, function (error, data, status) { + if (error) return callback(error); + if (status !== 200) return callback(new ClientError(status, data)); + + callback(null, data.devices); + }); + }; + Client.prototype.disks = function (callback) { get('/api/v1/cloudron/disks', null, function (error, data, status) { if (error) return callback(error); diff --git a/src/views/volumes.html b/src/views/volumes.html index 9e15074f1..1723c6ed0 100644 --- a/src/views/volumes.html +++ b/src/views/volumes.html @@ -35,8 +35,9 @@
- - + + +
diff --git a/src/views/volumes.js b/src/views/volumes.js index 68a4f9ad3..dba1e90df 100644 --- a/src/views/volumes.js +++ b/src/views/volumes.js @@ -11,6 +11,7 @@ angular.module('Application').controller('VolumesController', ['$scope', '$locat $scope.config = Client.getConfig(); $scope.volumes = []; + $scope.devices = []; $scope.ready = false; $scope.mountTypes = [ @@ -104,6 +105,7 @@ angular.module('Application').controller('VolumesController', ['$scope', '$locat $scope.volumeAdd.username = ''; $scope.volumeAdd.password = ''; $scope.volumeAdd.diskPath = ''; + $scope.volumeAdd.customDiskPath = ''; $scope.volumeAdd.user = ''; $scope.volumeAdd.seal = false; $scope.volumeAdd.port = 22; @@ -116,7 +118,25 @@ angular.module('Application').controller('VolumesController', ['$scope', '$locat show: function () { $scope.volumeAdd.reset(); - $('#volumeAddModal').modal('show'); + $scope.blockDevices = []; + + Client.getBlockDevices(function (error, result) { + if (error) console.error('Failed to list blockdevices:', error); + + // only offer unmounted disks + result = result.filter(function (d) { return !d.mountpoint; }); + + // amend label for UI + result.forEach(function (d) { d.label = d.path; }); + + // add custom fake option + result.push({ path: 'custom', label: 'Custom' }); + + $scope.blockDevices = result; + $scope.volumeAdd.diskPath = $scope.blockDevices[0].path; + + $('#volumeAddModal').modal('show'); + }); }, submit: function () { @@ -148,7 +168,7 @@ angular.module('Application').controller('VolumesController', ['$scope', '$locat }; } else if ($scope.volumeAdd.mountType === 'ext4' || $scope.volumeAdd.mountType === 'xfs') { mountOptions = { - diskPath: $scope.volumeAdd.diskPath + diskPath: $scope.volumeAdd.diskPath === 'custom' ? $scope.volumeAdd.customDiskPath : $scope.volumeAdd.diskPath }; }