Compare commits
No commits in common. "0fd2dc3ddb73977416cc573b6c23729a5a4d0c31" and "6a8a163d0a303400906a3d381372a28deb138326" have entirely different histories.
0fd2dc3ddb
...
6a8a163d0a
@ -79,8 +79,6 @@ String getBaseUri() {
|
|||||||
|
|
||||||
List<Validator> getSettingValidators(String settingPath) {
|
List<Validator> getSettingValidators(String settingPath) {
|
||||||
switch (settingPath) {
|
switch (settingPath) {
|
||||||
case 'ApiAuth':
|
|
||||||
return [(value) => value.isNotEmpty];
|
|
||||||
case 'EncryptConfig.EncryptionToken':
|
case 'EncryptConfig.EncryptionToken':
|
||||||
return [(value) => value.isNotEmpty];
|
return [(value) => value.isNotEmpty];
|
||||||
case 'EncryptConfig.Path':
|
case 'EncryptConfig.Path':
|
||||||
@ -110,11 +108,11 @@ List<Validator> getSettingValidators(String settingPath) {
|
|||||||
case 'HostConfig.Protocol':
|
case 'HostConfig.Protocol':
|
||||||
return [(value) => value == "http" || value == "https"];
|
return [(value) => value == "http" || value == "https"];
|
||||||
case 'S3Config.AccessKey':
|
case 'S3Config.AccessKey':
|
||||||
return [(value) => value.trim().isNotEmpty];
|
return [(value) => value.isNotEmpty];
|
||||||
case 'S3Config.Bucket':
|
case 'S3Config.Bucket':
|
||||||
return [(value) => value.trim().isNotEmpty];
|
return [(value) => value.trim().isNotEmpty];
|
||||||
case 'S3Config.SecretKey':
|
case 'S3Config.SecretKey':
|
||||||
return [(value) => value.trim().isNotEmpty];
|
return [(value) => value.isNotEmpty];
|
||||||
case 'S3Config.URL':
|
case 'S3Config.URL':
|
||||||
return [(value) => Uri.tryParse(value) != null];
|
return [(value) => Uri.tryParse(value) != null];
|
||||||
case 'SiaConfig.Bucket':
|
case 'SiaConfig.Bucket':
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:provider/provider.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';
|
||||||
@ -99,9 +98,6 @@ class _AddMountScreenState extends State<AddMountScreen> {
|
|||||||
autofocus: true,
|
autofocus: true,
|
||||||
controller: _mountNameController,
|
controller: _mountNameController,
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
inputFormatters: [
|
|
||||||
FilteringTextInputFormatter.deny(RegExp(r'\s')),
|
|
||||||
],
|
|
||||||
onChanged: (_) => _handleChange(_mountType),
|
onChanged: (_) => _handleChange(_mountType),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -26,8 +26,6 @@ class MountSettingsWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
||||||
static const _padding = 15.0;
|
|
||||||
|
|
||||||
void _addBooleanSetting(list, root, key, value, isAdvanced) {
|
void _addBooleanSetting(list, root, key, value, isAdvanced) {
|
||||||
if (!isAdvanced || widget.showAdvanced) {
|
if (!isAdvanced || widget.showAdvanced) {
|
||||||
list.add(
|
list.add(
|
||||||
@ -183,87 +181,13 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addPasswordSetting(
|
void _addPasswordSetting(list, root, key, value, isAdvanced) {
|
||||||
list,
|
|
||||||
root,
|
|
||||||
key,
|
|
||||||
value,
|
|
||||||
isAdvanced, {
|
|
||||||
List<Validator> validators = const [],
|
|
||||||
}) {
|
|
||||||
if (!isAdvanced || widget.showAdvanced) {
|
if (!isAdvanced || widget.showAdvanced) {
|
||||||
list.add(
|
list.add(
|
||||||
SettingsTile.navigation(
|
SettingsTile.navigation(
|
||||||
leading: Icon(Icons.password),
|
leading: Icon(Icons.password),
|
||||||
title: Text(key),
|
title: Text(key),
|
||||||
value: Text('*' * (value as String).length),
|
value: Text('*' * (value as String).length),
|
||||||
onPressed: (_) {
|
|
||||||
String updatedValue1 = value;
|
|
||||||
String updatedValue2 = value;
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return AlertDialog(
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
child: Text('Cancel'),
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
child: Text('OK'),
|
|
||||||
onPressed: () {
|
|
||||||
if (updatedValue1 != updatedValue2) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text("'$key' does not match")),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final result = validators.firstWhereOrNull(
|
|
||||||
(validator) => !validator(updatedValue1),
|
|
||||||
);
|
|
||||||
if (result != null) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text("'$key' is not valid")),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
root[key] = updatedValue1;
|
|
||||||
widget.onChanged?.call(widget.settings);
|
|
||||||
});
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
content: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
TextField(
|
|
||||||
autofocus: true,
|
|
||||||
controller: TextEditingController(text: updatedValue1),
|
|
||||||
obscureText: true,
|
|
||||||
obscuringCharacter: '*',
|
|
||||||
onChanged: (value) => updatedValue1 = value,
|
|
||||||
),
|
|
||||||
const SizedBox(height: _padding),
|
|
||||||
TextField(
|
|
||||||
autofocus: false,
|
|
||||||
controller: TextEditingController(text: updatedValue2),
|
|
||||||
obscureText: true,
|
|
||||||
obscuringCharacter: '*',
|
|
||||||
onChanged: (value) => updatedValue2 = value,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
title: Text(key),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -318,9 +242,6 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
content: TextField(
|
content: TextField(
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
controller: TextEditingController(text: updatedValue),
|
controller: TextEditingController(text: updatedValue),
|
||||||
inputFormatters: [
|
|
||||||
FilteringTextInputFormatter.deny(RegExp(r'\s')),
|
|
||||||
],
|
|
||||||
onChanged: (value) => updatedValue = value,
|
onChanged: (value) => updatedValue = value,
|
||||||
),
|
),
|
||||||
title: Text(key),
|
title: Text(key),
|
||||||
@ -345,14 +266,7 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
|
|
||||||
widget.settings.forEach((key, value) {
|
widget.settings.forEach((key, value) {
|
||||||
if (key == 'ApiAuth') {
|
if (key == 'ApiAuth') {
|
||||||
_addPasswordSetting(
|
_addPasswordSetting(commonSettings, widget.settings, key, value, true);
|
||||||
commonSettings,
|
|
||||||
widget.settings,
|
|
||||||
key,
|
|
||||||
value,
|
|
||||||
true,
|
|
||||||
validators: getSettingValidators(key),
|
|
||||||
);
|
|
||||||
} else if (key == 'ApiPort') {
|
} else if (key == 'ApiPort') {
|
||||||
_addIntSetting(
|
_addIntSetting(
|
||||||
commonSettings,
|
commonSettings,
|
||||||
@ -482,7 +396,6 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
subKey,
|
subKey,
|
||||||
subValue,
|
subValue,
|
||||||
false,
|
false,
|
||||||
validators: getSettingValidators('$key.$subKey'),
|
|
||||||
);
|
);
|
||||||
} else if (subKey == 'Path') {
|
} else if (subKey == 'Path') {
|
||||||
_addStringSetting(
|
_addStringSetting(
|
||||||
@ -515,7 +428,6 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
subKey,
|
subKey,
|
||||||
subValue,
|
subValue,
|
||||||
false,
|
false,
|
||||||
validators: getSettingValidators('$key.$subKey'),
|
|
||||||
);
|
);
|
||||||
} else if (subKey == 'ApiPort') {
|
} else if (subKey == 'ApiPort') {
|
||||||
_addIntSetting(
|
_addIntSetting(
|
||||||
@ -594,7 +506,6 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
subKey,
|
subKey,
|
||||||
subValue,
|
subValue,
|
||||||
false,
|
false,
|
||||||
validators: getSettingValidators('$key.$subKey'),
|
|
||||||
);
|
);
|
||||||
} else if (subKey == 'HostNameOrIp') {
|
} else if (subKey == 'HostNameOrIp') {
|
||||||
_addStringSetting(
|
_addStringSetting(
|
||||||
@ -672,21 +583,18 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
subKey,
|
subKey,
|
||||||
subValue,
|
subValue,
|
||||||
false,
|
false,
|
||||||
validators: getSettingValidators('$key.$subKey'),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (key == 'S3Config') {
|
} else if (key == 'S3Config') {
|
||||||
value.forEach((subKey, subValue) {
|
value.forEach((subKey, subValue) {
|
||||||
if (subKey == 'AccessKey') {
|
if (subKey == 'AccessKey') {
|
||||||
_addStringSetting(
|
_addPasswordSetting(
|
||||||
s3ConfigSettings,
|
s3ConfigSettings,
|
||||||
widget.settings[key],
|
widget.settings[key],
|
||||||
subKey,
|
subKey,
|
||||||
subValue,
|
subValue,
|
||||||
Icons.key,
|
|
||||||
false,
|
false,
|
||||||
validators: getSettingValidators('$key.$subKey'),
|
|
||||||
);
|
);
|
||||||
} else if (subKey == 'Bucket') {
|
} else if (subKey == 'Bucket') {
|
||||||
_addStringSetting(
|
_addStringSetting(
|
||||||
@ -705,7 +613,6 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
subKey,
|
subKey,
|
||||||
subValue,
|
subValue,
|
||||||
false,
|
false,
|
||||||
validators: getSettingValidators('$key.$subKey'),
|
|
||||||
);
|
);
|
||||||
} else if (subKey == 'Region') {
|
} else if (subKey == 'Region') {
|
||||||
_addStringSetting(
|
_addStringSetting(
|
||||||
@ -724,7 +631,6 @@ class _MountSettingsWidgetState extends State<MountSettingsWidget> {
|
|||||||
subKey,
|
subKey,
|
||||||
subValue,
|
subValue,
|
||||||
false,
|
false,
|
||||||
validators: getSettingValidators('$key.$subKey'),
|
|
||||||
);
|
);
|
||||||
} else if (subKey == 'TimeoutMs') {
|
} else if (subKey == 'TimeoutMs') {
|
||||||
_addIntSetting(
|
_addIntSetting(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user