refactor
This commit is contained in:
parent
6f45848db4
commit
992a02a6ee
@ -20,6 +20,7 @@ class Mount with ChangeNotifier {
|
|||||||
String get type => mountConfig.type;
|
String get type => mountConfig.type;
|
||||||
|
|
||||||
Future<void> _fetch() async {
|
Future<void> _fetch() async {
|
||||||
|
try {
|
||||||
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('${getBaseUri()}/api/v1/mount?name=$name&type=$type'),
|
||||||
@ -33,9 +34,13 @@ class Mount with ChangeNotifier {
|
|||||||
mountConfig.updateSettings(jsonDecode(response.body));
|
mountConfig.updateSettings(jsonDecode(response.body));
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchStatus() async {
|
Future<void> _fetchStatus() async {
|
||||||
|
try {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
@ -50,9 +55,13 @@ class Mount with ChangeNotifier {
|
|||||||
|
|
||||||
mountConfig.updateStatus(jsonDecode(response.body));
|
mountConfig.updateStatus(jsonDecode(response.body));
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> mount(bool unmount, {String? location}) async {
|
Future<void> mount(bool unmount, {String? location}) async {
|
||||||
|
try {
|
||||||
await http.post(
|
await http.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
@ -62,6 +71,9 @@ class Mount with ChangeNotifier {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return refresh();
|
return refresh();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
@ -70,6 +82,7 @@ class Mount with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setValue(String key, String value) async {
|
Future<void> setValue(String key, String value) async {
|
||||||
|
try {
|
||||||
await http.put(
|
await http.put(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
@ -79,9 +92,13 @@ class Mount with ChangeNotifier {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return refresh();
|
return refresh();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getMountLocation() async {
|
Future<String?> getMountLocation() async {
|
||||||
|
try {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
@ -95,5 +112,10 @@ class Mount with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return jsonDecode(response.body)['Location'] as String;
|
return jsonDecode(response.body)['Location'] as String;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,14 @@ class MountList with ChangeNotifier {
|
|||||||
UnmodifiableListView<MountConfig>(_mountList);
|
UnmodifiableListView<MountConfig>(_mountList);
|
||||||
|
|
||||||
Future<void> _fetch() async {
|
Future<void> _fetch() async {
|
||||||
|
try {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
|
Uri.parse('${getBaseUri()}/api/v1/mount_list'),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode != 200) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
List<MountConfig> nextList = [];
|
List<MountConfig> nextList = [];
|
||||||
|
|
||||||
jsonDecode(response.body).forEach((key, value) {
|
jsonDecode(response.body).forEach((key, value) {
|
||||||
@ -33,7 +36,8 @@ class MountList with ChangeNotifier {
|
|||||||
_mountList = nextList;
|
_mountList = nextList;
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return;
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,25 +54,22 @@ class MountList with ChangeNotifier {
|
|||||||
|
|
||||||
Future<void> add(
|
Future<void> add(
|
||||||
String type,
|
String type,
|
||||||
String name, {
|
String name,
|
||||||
String? apiPassword,
|
Map<String, dynamic> mountConfig,
|
||||||
String? apiPort,
|
) async {
|
||||||
String? bucket,
|
try {
|
||||||
String? encryptionToken,
|
|
||||||
String? hostNameOrIp,
|
|
||||||
String? path,
|
|
||||||
}) async {
|
|
||||||
await http.post(
|
await http.post(
|
||||||
Uri.parse(
|
Uri.parse(
|
||||||
Uri.encodeFull(
|
Uri.encodeFull(
|
||||||
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&bucket=$bucket'
|
'${getBaseUri()}/api/v1/add_mount?name=$name&type=$type&config=${jsonEncode(mountConfig)}',
|
||||||
'&path=$path&apiPassword=$apiPassword&apiPort=$apiPort&hostNameOrIp=$hostNameOrIp'
|
|
||||||
'&encryptionToken=$encryptionToken',
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return _fetch();
|
return _fetch();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('$e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove(String name) {
|
void remove(String name) {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
import 'package:repertory/constants.dart';
|
import 'package:repertory/constants.dart';
|
||||||
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/types/mount_config.dart';
|
import 'package:repertory/types/mount_config.dart';
|
||||||
import 'package:repertory/widgets/mount_settings.dart';
|
import 'package:repertory/widgets/mount_settings.dart';
|
||||||
|
|
||||||
@ -116,6 +118,20 @@ class _AddMountScreenState extends State<AddMountScreen> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (_mount != null)
|
||||||
|
ElevatedButton.icon(
|
||||||
|
onPressed: () {
|
||||||
|
Provider.of<MountList>(context, listen: false).add(
|
||||||
|
_mountType,
|
||||||
|
_mountNameController.text,
|
||||||
|
_settings[_mountType]!,
|
||||||
|
);
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
label: const Text('Add'),
|
||||||
|
icon: Icon(Icons.add),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user