Create management portal in Flutter #39
This commit is contained in:
parent
72a2567c83
commit
eb8f66ebe9
@ -26,4 +26,36 @@ String initialCaps(String txt) {
|
||||
return txt[0].toUpperCase() + txt.substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
Map<String, dynamic> createDefaultSettings() => {'EventLevel': 'info'};
|
||||
Map<String, dynamic> createDefaultSettings(String mountType) {
|
||||
switch (mountType) {
|
||||
case 'Encrypt':
|
||||
return {
|
||||
'EncryptConfig': {'EncryptionToken': '', 'Path': ''},
|
||||
};
|
||||
case 'Remote':
|
||||
return {'EventLevel': 'info'};
|
||||
case 'S3':
|
||||
return {
|
||||
'S3Config': {
|
||||
'AccessKey': '',
|
||||
'Bucket': '',
|
||||
'Region': 'any',
|
||||
'SecretKey': '',
|
||||
'URL': '',
|
||||
'UsePathStyle': false,
|
||||
'UseRegionInURL': false,
|
||||
},
|
||||
};
|
||||
case 'Sia':
|
||||
return {
|
||||
'HostConfig': {
|
||||
'ApiPassword': '',
|
||||
'ApiPort': '9980',
|
||||
'HostNameOrIp': 'localhost',
|
||||
},
|
||||
'SiaConfig': {'Bucket': 'default'},
|
||||
};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -19,7 +19,13 @@ class _AddMountScreenState extends State<AddMountScreen> {
|
||||
Mount? _mount;
|
||||
final _mountNameController = TextEditingController();
|
||||
String _mountType = "";
|
||||
var _settings = createDefaultSettings();
|
||||
final Map<String, Map<String, dynamic>> _settings = {
|
||||
"": {},
|
||||
"Encrypt": createDefaultSettings("Encrypt"),
|
||||
"Remote": createDefaultSettings("Remote"),
|
||||
"S3": createDefaultSettings("S3"),
|
||||
"Sia": createDefaultSettings("Sia"),
|
||||
};
|
||||
bool _showAdvanced = false;
|
||||
|
||||
@override
|
||||
@ -45,77 +51,87 @@ class _AddMountScreenState extends State<AddMountScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Card(
|
||||
margin: EdgeInsets.all(_padding),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Provider Type'),
|
||||
const SizedBox(width: _padding),
|
||||
DropdownButton<String>(
|
||||
value: _mountType,
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
_mountType = newValue ?? "";
|
||||
});
|
||||
},
|
||||
items:
|
||||
providerTypeList.map<DropdownMenuItem<String>>((item) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(_padding),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Provider Type'),
|
||||
const SizedBox(width: _padding),
|
||||
DropdownButton<String>(
|
||||
value: _mountType,
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
_mountType = newValue ?? "";
|
||||
});
|
||||
},
|
||||
items:
|
||||
providerTypeList.map<DropdownMenuItem<String>>((
|
||||
item,
|
||||
) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: item,
|
||||
child: Text(item),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_mountType.isNotEmpty) const SizedBox(height: _padding),
|
||||
if (_mountType.isNotEmpty)
|
||||
Card(
|
||||
margin: EdgeInsets.all(_padding),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Configuration Name'),
|
||||
const SizedBox(width: _padding),
|
||||
TextField(
|
||||
autofocus: true,
|
||||
controller: _mountNameController,
|
||||
keyboardType: TextInputType.text,
|
||||
onChanged: (_) {
|
||||
setState(() {
|
||||
_mount =
|
||||
(_mountNameController.text.isEmpty)
|
||||
? null
|
||||
: Mount(
|
||||
MountConfig(
|
||||
name: _mountNameController.text,
|
||||
settings: _settings,
|
||||
type: _mountType,
|
||||
),
|
||||
isAdd: true,
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(_padding),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Configuration Name'),
|
||||
const SizedBox(width: _padding),
|
||||
TextField(
|
||||
autofocus: true,
|
||||
controller: _mountNameController,
|
||||
keyboardType: TextInputType.text,
|
||||
onChanged: (_) {
|
||||
setState(() {
|
||||
_mount =
|
||||
(_mountNameController.text.isEmpty)
|
||||
? null
|
||||
: Mount(
|
||||
MountConfig(
|
||||
name: _mountNameController.text,
|
||||
settings: _settings[_mountType],
|
||||
type: _mountType,
|
||||
),
|
||||
isAdd: true,
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_mount != null)
|
||||
Card(
|
||||
margin: EdgeInsets.all(_padding),
|
||||
child: MountSettingsWidget(
|
||||
isAdd: true,
|
||||
mount: _mount!,
|
||||
onChanged: (settings) => _settings = settings,
|
||||
showAdvanced: _showAdvanced,
|
||||
Expanded(
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(_padding),
|
||||
child: MountSettingsWidget(
|
||||
isAdd: true,
|
||||
mount: _mount!,
|
||||
onChanged: (settings) => _settings[_mountType] = settings,
|
||||
showAdvanced: _showAdvanced,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user