Compare commits

...

5 Commits

Author SHA1 Message Date
bbd4cc0eed changed icon
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
2025-03-24 13:19:20 -05:00
c3dca76690 layout fixes 2025-03-24 13:13:36 -05:00
7607fe68e2 refactor 2025-03-24 13:02:59 -05:00
2496679165 added clear mount location 2025-03-24 13:00:55 -05:00
89507bd0bd added clear mount location 2025-03-24 12:57:47 -05:00
4 changed files with 80 additions and 13 deletions

View File

@ -74,6 +74,9 @@ private:
[[nodiscard]] auto data_directory_exists(provider_type prov,
std::string_view name) const -> bool;
void handle_delete_mount_location(const httplib::Request &req,
httplib::Response &res) const;
void handle_get_available_locations(httplib::Response &res) const;
void handle_get_mount(const httplib::Request &req,

View File

@ -168,6 +168,10 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
: http_error_codes::internal_error;
});
server->Delete("/api/v1/mount_location", [this](auto &&req, auto &&res) {
handle_delete_mount_location(req, res);
});
server->Get("/api/v1/locations", [this](auto && /* req */, auto &&res) {
handle_get_available_locations(res);
});
@ -298,6 +302,22 @@ auto handlers::data_directory_exists(provider_type prov,
return ret;
}
void handlers::handle_delete_mount_location(const httplib::Request &req,
httplib::Response &res) const {
REPERTORY_USES_FUNCTION_NAME();
auto prov = provider_type_from_string(req.get_param_value("type"));
auto name = req.get_param_value("name");
if (not data_directory_exists(prov, name)) {
res.status = http_error_codes::not_found;
return;
}
config_->set_mount_location(prov, name, "");
res.status = http_error_codes::ok;
}
void handlers::handle_get_available_locations(httplib::Response &res) const {
#if defined(_WIN32)
constexpr const std::array<std::string_view, 26U> letters{

View File

@ -101,6 +101,35 @@ class Mount with ChangeNotifier {
}
}
Future<void> clearMountLocation() async {
try {
mountConfig.path = "";
final auth = await _auth.createAuth();
final response = await http.delete(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/mount_location?auth=$auth&name=$name&type=$type',
),
),
);
if (response.statusCode == 401) {
_auth.logoff();
return;
}
if (response.statusCode == 404) {
_mountList?.reset();
return;
}
return refresh();
} catch (e) {
debugPrint('$e');
}
}
Future<List<String>> getAvailableLocations() async {
try {
final auth = await _auth.createAuth();

View File

@ -61,19 +61,34 @@ class _MountWidgetState extends State<MountWidget> {
mount.provider,
style: TextStyle(color: textColor, fontWeight: FontWeight.bold),
),
trailing: IconButton(
icon: Icon(
mount.mounted == null
? Icons.hourglass_top
: mount.mounted!
? Icons.toggle_on
: Icons.toggle_off,
color:
mount.mounted ?? false
? Color.fromARGB(255, 163, 96, 76)
: subTextColor,
),
onPressed: _createMountHandler(context, mount),
trailing: Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (mount.path.isNotEmpty &&
mount.mounted != null &&
!mount.mounted!)
IconButton(
icon: const Icon(Icons.backspace),
color: subTextColor,
onPressed: () => mount.clearMountLocation(),
),
IconButton(
icon: Icon(
mount.mounted == null
? Icons.hourglass_top
: mount.mounted!
? Icons.toggle_on
: Icons.toggle_off,
color:
mount.mounted ?? false
? Color.fromARGB(255, 163, 96, 76)
: subTextColor,
),
onPressed: _createMountHandler(context, mount),
),
],
),
);
},