grab mount settings and status
This commit is contained in:
@ -7,7 +7,7 @@ import 'package:repertory/types/mount_config.dart';
|
||||
class Mount with ChangeNotifier {
|
||||
final MountConfig mountConfig;
|
||||
Mount(this.mountConfig) {
|
||||
_fetch();
|
||||
refresh();
|
||||
}
|
||||
|
||||
String get name => mountConfig.name;
|
||||
@ -20,15 +20,33 @@ class Mount with ChangeNotifier {
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
mountConfig.updateSettings(jsonDecode(response.body));
|
||||
|
||||
notifyListeners();
|
||||
if (response.statusCode != 200) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountConfig.updateSettings(jsonDecode(response.body));
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
_fetch();
|
||||
Future<void> _fetchStatus() async {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
Uri.encodeFull(
|
||||
'${Uri.base.origin}/api/v1/mount_status?name=$name&type=$type',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return;
|
||||
}
|
||||
|
||||
mountConfig.updateStatus(jsonDecode(response.body));
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
await _fetch();
|
||||
return _fetchStatus();
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,12 @@ class MountConfig {
|
||||
final String _name;
|
||||
final String _type;
|
||||
Map<String, dynamic> _settings = {};
|
||||
Map<String, dynamic> _status = {};
|
||||
MountConfig({required name, required type}) : _name = name, _type = type;
|
||||
|
||||
UnmodifiableMapView get items => UnmodifiableMapView(_settings);
|
||||
UnmodifiableMapView get settings => UnmodifiableMapView(_settings);
|
||||
UnmodifiableMapView get status => UnmodifiableMapView(_status);
|
||||
|
||||
String get name => _name;
|
||||
String get type => _type;
|
||||
|
||||
@ -17,4 +20,8 @@ class MountConfig {
|
||||
void updateSettings(Map<String, dynamic> settings) {
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
void updateStatus(Map<String, dynamic> status) {
|
||||
_status = status;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user