Compare commits

..

No commits in common. "71f35673750070d17be07b109a74fdc20d7bc00a" and "4b3890809d106191df6c1d428a6a4754cd40b2d8" have entirely different histories.

8 changed files with 25 additions and 144 deletions

View File

@ -0,0 +1,6 @@
class DuplicateMountException implements Exception {
final String _name;
const DuplicateMountException({required name}) : _name = name, super();
String get name => _name;
}

View File

@ -1,5 +1,3 @@
import 'package:flutter/foundation.dart';
String formatMountName(String type, String name) {
if (type == "remote") {
return name.replaceAll("_", ":");
@ -7,13 +5,6 @@ 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

@ -4,7 +4,6 @@ import 'package:repertory/constants.dart' as constants;
import 'package:repertory/helpers.dart';
import 'package:repertory/models/mount.dart';
import 'package:repertory/models/mount_list.dart';
import 'package:repertory/widgets/add_mount_widget.dart';
import 'package:repertory/widgets/mount_list_widget.dart';
import 'package:repertory/widgets/mount_settings.dart';
@ -73,10 +72,6 @@ class MyHomePage extends StatefulWidget {
}
class _MyHomePageState extends State<MyHomePage> {
bool _allowAdd = true;
String _mountType = "S3";
String _mountName = "";
@override
Widget build(BuildContext context) {
return Scaffold(
@ -90,73 +85,8 @@ class _MyHomePageState extends State<MyHomePage> {
child: MountListWidget(),
),
floatingActionButton: FloatingActionButton(
onPressed:
_allowAdd
? () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Add Mount'),
content: Consumer<MountList>(
builder: (_, mountList, __) {
return AddMountWidget(
allowEncrypt:
!mountList.items.contains(
(item) => item.type == "encrypt",
),
mountName: _mountName,
mountType: _mountType,
onNameChanged:
(mountName) => setState(
() => _mountName = mountName ?? "",
),
onTypeChanged:
(mountType) => setState(
() => _mountType = mountType ?? "S3",
),
);
},
),
actions: [
TextButton(
child: const Text('Cancel'),
onPressed: () {
setState(() {
_mountType = "S3";
_mountName = "";
});
Navigator.of(context).pop();
},
),
TextButton(
child: const Text('OK'),
onPressed: () {
setState(() => _allowAdd = false);
Provider.of<MountList>(context, listen: false)
.add(_mountType, _mountName)
.then((_) {
setState(() {
_allowAdd = true;
_mountType = "S3";
_mountName = "";
});
})
.catchError((_) {
setState(() => _allowAdd = true);
});
Navigator.of(context).pop();
},
),
],
);
},
);
}
: null,
tooltip: 'Add Mount',
onPressed: () {},
tooltip: 'Add',
child: const Icon(Icons.add),
),
);

View File

@ -2,7 +2,6 @@ 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 {
@ -19,7 +18,7 @@ class Mount with ChangeNotifier {
Future<void> _fetch() async {
final response = await http.get(
Uri.parse(
Uri.encodeFull('${getBaseUri()}/api/v1/mount?name=$name&type=$type'),
Uri.encodeFull('${Uri.base.origin}/api/v1/mount?name=$name&type=$type'),
),
);
@ -36,7 +35,7 @@ class Mount with ChangeNotifier {
final response = await http.get(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/mount_status?name=$name&type=$type',
'${Uri.base.origin}/api/v1/mount_status?name=$name&type=$type',
),
),
);
@ -53,7 +52,7 @@ class Mount with ChangeNotifier {
await http.post(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
'${Uri.base.origin}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location',
),
),
);
@ -70,7 +69,7 @@ class Mount with ChangeNotifier {
await http.put(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/set_value_by_name?name=$name&type=$type&key=$key&value=$value',
'${Uri.base.origin}/api/v1/set_value_by_name?name=$name&type=$type&key=$key&value=$value',
),
),
);

View File

@ -3,7 +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/errors/duplicate_mount_exception.dart';
import 'package:repertory/types/mount_config.dart';
class MountList with ChangeNotifier {
@ -17,7 +17,7 @@ class MountList with ChangeNotifier {
Future<void> _fetch() async {
final response = await http.get(
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
Uri.parse('${Uri.base.origin}/api/v1/mount_list'),
);
if (response.statusCode == 200) {
@ -47,16 +47,16 @@ class MountList with ChangeNotifier {
});
}
Future<void> add(String type, String name) async {
await http.post(
Uri.parse(
Uri.encodeFull(
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type',
),
),
);
void add(MountConfig config) {
var item = _mountList.firstWhereOrNull((cfg) => cfg.name == config.name);
if (item != null) {
throw DuplicateMountException(name: config.name);
}
return _fetch();
_mountList.add(config);
_sort(_mountList);
notifyListeners();
}
void remove(String name) {

View File

@ -1,45 +0,0 @@
import 'package:flutter/material.dart';
class AddMountWidget extends StatelessWidget {
final bool allowEncrypt;
final String mountName;
final String mountType;
final void Function(String? newName) onNameChanged;
final void Function(String? newType) onTypeChanged;
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) {
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(),
// ),
TextField(
decoration: InputDecoration(labelText: 'Name'),
onChanged: onNameChanged,
),
],
);
}
}

View File

@ -15,7 +15,7 @@ class _MountListWidgetState extends State<MountListWidget> {
@override
Widget build(BuildContext context) {
return Consumer<MountList>(
builder: (context, mountList, _) {
builder: (context, mountList, widget) {
return ListView.builder(
itemBuilder: (context, idx) {
return ChangeNotifierProvider(

View File

@ -20,7 +20,7 @@ class _MountWidgetState extends State<MountWidget> {
Widget build(BuildContext context) {
return Card(
child: Consumer<Mount>(
builder: (context, mount, _) {
builder: (context, mount, widget) {
final textColor = Theme.of(context).colorScheme.onSurface;
final subTextColor =
Theme.of(context).brightness == Brightness.dark