Create management portal in Flutter #39
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2025-03-04 14:48:37 -06:00
parent 865ed5f0c1
commit 71f3567375
4 changed files with 34 additions and 21 deletions

View File

@ -1,3 +1,5 @@
import 'package:flutter/foundation.dart';
String formatMountName(String type, String name) {
if (type == "remote") {
return name.replaceAll("_", ":");
@ -5,6 +7,13 @@ String formatMountName(String type, String name) {
return name;
}
String getBaseUri() {
if (kDebugMode) {
return "http://127.0.0.1:30000";
}
return Uri.base.origin;
}
String initialCaps(String txt) {
if (txt.isEmpty) {
return txt;

View File

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:repertory/helpers.dart';
import 'package:repertory/types/mount_config.dart';
class Mount with ChangeNotifier {
@ -18,7 +19,7 @@ class Mount with ChangeNotifier {
Future<void> _fetch() async {
final response = await http.get(
Uri.parse(
Uri.encodeFull('${Uri.base.origin}/api/v1/mount?name=$name&type=$type'),
Uri.encodeFull('${getBaseUri()}/api/v1/mount?name=$name&type=$type'),
),
);
@ -35,7 +36,7 @@ class Mount with ChangeNotifier {
final response = await http.get(
Uri.parse(
Uri.encodeFull(
'${Uri.base.origin}/api/v1/mount_status?name=$name&type=$type',
'${getBaseUri()}/api/v1/mount_status?name=$name&type=$type',
),
),
);
@ -52,7 +53,7 @@ class Mount with ChangeNotifier {
await http.post(
Uri.parse(
Uri.encodeFull(
'${Uri.base.origin}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
'${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
),
),
);
@ -69,7 +70,7 @@ class Mount with ChangeNotifier {
await http.put(
Uri.parse(
Uri.encodeFull(
'${Uri.base.origin}/api/v1/set_value_by_name?name=$name&type=$type&key=$key&value=$value',
'${getBaseUri()}/api/v1/set_value_by_name?name=$name&type=$type&key=$key&value=$value',
),
),
);

View File

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:repertory/helpers.dart';
import 'package:repertory/types/mount_config.dart';
class MountList with ChangeNotifier {
@ -16,7 +17,7 @@ class MountList with ChangeNotifier {
Future<void> _fetch() async {
final response = await http.get(
Uri.parse('${Uri.base.origin}/api/v1/mount_list'),
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
);
if (response.statusCode == 200) {
@ -50,7 +51,7 @@ class MountList with ChangeNotifier {
await http.post(
Uri.parse(
Uri.encodeFull(
'${Uri.base.origin}/api/v1/add_mount?name=$name&type=$type',
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type',
),
),
);

View File

@ -6,33 +6,35 @@ class AddMountWidget extends StatelessWidget {
final String mountType;
final void Function(String? newName) onNameChanged;
final void Function(String? newType) onTypeChanged;
const AddMountWidget({
final _items = <String>["S3", "Sia"];
AddMountWidget({
super.key,
required this.allowEncrypt,
required this.mountName,
required this.mountType,
required this.onNameChanged,
required this.onTypeChanged,
});
}) {
if (allowEncrypt) {
_items.insert(0, "Encrypt");
}
}
@override
Widget build(BuildContext context) {
var items = ["S3", "Sia"];
if (allowEncrypt) {
items.insert(0, "Encrypt");
}
return Column(
mainAxisSize: MainAxisSize.min,
children: [
DropdownButton<String>(
value: mountType,
onChanged: onTypeChanged,
items:
items.map<DropdownMenuItem<String>>((item) {
return DropdownMenuItem<String>(value: item, child: Text(item));
}).toList(),
),
// DropdownButton<String>(
// value: mountType,
// onChanged: onTypeChanged,
// items:
// _items.map<DropdownMenuItem<String>>((item) {
// return DropdownMenuItem<String>(value: item, child: Text(item));
// }).toList(),
// ),
TextField(
decoration: InputDecoration(labelText: 'Name'),
onChanged: onNameChanged,