Compare commits
No commits in common. "71f35673750070d17be07b109a74fdc20d7bc00a" and "4b3890809d106191df6c1d428a6a4754cd40b2d8" have entirely different histories.
71f3567375
...
4b3890809d
6
web/repertory/lib/errors/duplicate_mount_exception.dart
Normal file
6
web/repertory/lib/errors/duplicate_mount_exception.dart
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class DuplicateMountException implements Exception {
|
||||||
|
final String _name;
|
||||||
|
const DuplicateMountException({required name}) : _name = name, super();
|
||||||
|
|
||||||
|
String get name => _name;
|
||||||
|
}
|
@ -1,5 +1,3 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
|
||||||
|
|
||||||
String formatMountName(String type, String name) {
|
String formatMountName(String type, String name) {
|
||||||
if (type == "remote") {
|
if (type == "remote") {
|
||||||
return name.replaceAll("_", ":");
|
return name.replaceAll("_", ":");
|
||||||
@ -7,13 +5,6 @@ String formatMountName(String type, String name) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getBaseUri() {
|
|
||||||
if (kDebugMode) {
|
|
||||||
return "http://127.0.0.1:30000";
|
|
||||||
}
|
|
||||||
return Uri.base.origin;
|
|
||||||
}
|
|
||||||
|
|
||||||
String initialCaps(String txt) {
|
String initialCaps(String txt) {
|
||||||
if (txt.isEmpty) {
|
if (txt.isEmpty) {
|
||||||
return txt;
|
return txt;
|
||||||
|
@ -4,7 +4,6 @@ import 'package:repertory/constants.dart' as constants;
|
|||||||
import 'package:repertory/helpers.dart';
|
import 'package:repertory/helpers.dart';
|
||||||
import 'package:repertory/models/mount.dart';
|
import 'package:repertory/models/mount.dart';
|
||||||
import 'package:repertory/models/mount_list.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_list_widget.dart';
|
||||||
import 'package:repertory/widgets/mount_settings.dart';
|
import 'package:repertory/widgets/mount_settings.dart';
|
||||||
|
|
||||||
@ -73,10 +72,6 @@ class MyHomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
bool _allowAdd = true;
|
|
||||||
String _mountType = "S3";
|
|
||||||
String _mountName = "";
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -90,73 +85,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
child: MountListWidget(),
|
child: MountListWidget(),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed:
|
onPressed: () {},
|
||||||
_allowAdd
|
tooltip: 'Add',
|
||||||
? () {
|
|
||||||
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',
|
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -2,7 +2,6 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:repertory/helpers.dart';
|
|
||||||
import 'package:repertory/types/mount_config.dart';
|
import 'package:repertory/types/mount_config.dart';
|
||||||
|
|
||||||
class Mount with ChangeNotifier {
|
class Mount with ChangeNotifier {
|
||||||
@ -19,7 +18,7 @@ class Mount with ChangeNotifier {
|
|||||||
Future<void> _fetch() async {
|
Future<void> _fetch() async {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse(
|
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(
|
final response = await http.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
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(
|
await http.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
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(
|
await http.put(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
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',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -3,7 +3,7 @@ import 'dart:convert';
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:http/http.dart' as http;
|
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';
|
import 'package:repertory/types/mount_config.dart';
|
||||||
|
|
||||||
class MountList with ChangeNotifier {
|
class MountList with ChangeNotifier {
|
||||||
@ -17,7 +17,7 @@ class MountList with ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> _fetch() async {
|
Future<void> _fetch() async {
|
||||||
final response = await http.get(
|
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) {
|
if (response.statusCode == 200) {
|
||||||
@ -47,16 +47,16 @@ class MountList with ChangeNotifier {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> add(String type, String name) async {
|
void add(MountConfig config) {
|
||||||
await http.post(
|
var item = _mountList.firstWhereOrNull((cfg) => cfg.name == config.name);
|
||||||
Uri.parse(
|
if (item != null) {
|
||||||
Uri.encodeFull(
|
throw DuplicateMountException(name: config.name);
|
||||||
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type',
|
}
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return _fetch();
|
_mountList.add(config);
|
||||||
|
_sort(_mountList);
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove(String name) {
|
void remove(String name) {
|
||||||
|
@ -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,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,7 +15,7 @@ class _MountListWidgetState extends State<MountListWidget> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Consumer<MountList>(
|
return Consumer<MountList>(
|
||||||
builder: (context, mountList, _) {
|
builder: (context, mountList, widget) {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemBuilder: (context, idx) {
|
itemBuilder: (context, idx) {
|
||||||
return ChangeNotifierProvider(
|
return ChangeNotifierProvider(
|
||||||
|
@ -20,7 +20,7 @@ class _MountWidgetState extends State<MountWidget> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
child: Consumer<Mount>(
|
child: Consumer<Mount>(
|
||||||
builder: (context, mount, _) {
|
builder: (context, mount, widget) {
|
||||||
final textColor = Theme.of(context).colorScheme.onSurface;
|
final textColor = Theme.of(context).colorScheme.onSurface;
|
||||||
final subTextColor =
|
final subTextColor =
|
||||||
Theme.of(context).brightness == Brightness.dark
|
Theme.of(context).brightness == Brightness.dark
|
||||||
|
Loading…
x
Reference in New Issue
Block a user