This commit is contained in:
@@ -11,6 +11,7 @@ import 'package:repertory/models/mount_list.dart';
|
|||||||
import 'package:repertory/types/mount_config.dart';
|
import 'package:repertory/types/mount_config.dart';
|
||||||
import 'package:repertory/utils/safe_set_state_mixin.dart';
|
import 'package:repertory/utils/safe_set_state_mixin.dart';
|
||||||
import 'package:repertory/widgets/app_dropdown.dart';
|
import 'package:repertory/widgets/app_dropdown.dart';
|
||||||
|
import 'package:repertory/widgets/app_outlined_icon_button.dart';
|
||||||
import 'package:repertory/widgets/app_scaffold.dart';
|
import 'package:repertory/widgets/app_scaffold.dart';
|
||||||
import 'package:repertory/widgets/mount_settings.dart';
|
import 'package:repertory/widgets/mount_settings.dart';
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ class _AddMountScreenState extends State<AddMountScreen>
|
|||||||
Mount? _mount;
|
Mount? _mount;
|
||||||
final _mountNameController = TextEditingController();
|
final _mountNameController = TextEditingController();
|
||||||
String _mountType = "";
|
String _mountType = "";
|
||||||
|
bool _enabled = true;
|
||||||
|
|
||||||
final Map<String, Map<String, dynamic>> _settings = {
|
final Map<String, Map<String, dynamic>> _settings = {
|
||||||
"": {},
|
"": {},
|
||||||
@@ -107,95 +109,78 @@ class _AddMountScreenState extends State<AddMountScreen>
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
IntrinsicWidth(
|
IntrinsicWidth(
|
||||||
child: ElevatedButton.icon(
|
child: AppOutlinedIconButton(
|
||||||
label: const Text('Test'),
|
enabled: _enabled,
|
||||||
icon: const Icon(Icons.check),
|
icon: Icons.check,
|
||||||
style: ElevatedButton.styleFrom(
|
text: 'Test',
|
||||||
backgroundColor: scheme.primary.withValues(
|
|
||||||
alpha: constants.primaryAlpha,
|
|
||||||
),
|
|
||||||
foregroundColor: scheme.primary,
|
|
||||||
elevation: 0,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(
|
|
||||||
constants.borderRadius,
|
|
||||||
),
|
|
||||||
side: BorderSide(
|
|
||||||
color: scheme.outlineVariant.withValues(
|
|
||||||
alpha: constants.outlineAlpha,
|
|
||||||
),
|
|
||||||
width: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: _handleProviderTest,
|
onPressed: _handleProviderTest,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: constants.padding),
|
const SizedBox(width: constants.padding),
|
||||||
IntrinsicWidth(
|
IntrinsicWidth(
|
||||||
child: ElevatedButton.icon(
|
child: AppOutlinedIconButton(
|
||||||
label: const Text('Add'),
|
enabled: _enabled,
|
||||||
icon: const Icon(Icons.add),
|
icon: Icons.add,
|
||||||
style: ElevatedButton.styleFrom(
|
text: 'Add',
|
||||||
backgroundColor: scheme.primary,
|
|
||||||
foregroundColor: scheme.onPrimary,
|
|
||||||
elevation: 8,
|
|
||||||
shadowColor: scheme.primary.withValues(
|
|
||||||
alpha: constants.secondaryAlpha,
|
|
||||||
),
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(
|
|
||||||
constants.borderRadius,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final mountList = Provider.of<MountList>(
|
setState(() {
|
||||||
context,
|
_enabled = false;
|
||||||
listen: false,
|
});
|
||||||
);
|
|
||||||
|
|
||||||
List<String> failed = [];
|
try {
|
||||||
if (!validateSettings(_settings[_mountType]!, failed)) {
|
final mountList = Provider.of<MountList>(
|
||||||
for (var key in failed) {
|
|
||||||
displayErrorMessage(
|
|
||||||
context,
|
|
||||||
"Setting '$key' is not valid",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mountList.hasConfigName(_mountNameController.text)) {
|
|
||||||
return displayErrorMessage(
|
|
||||||
context,
|
context,
|
||||||
"Configuration name '${_mountNameController.text}' already exists",
|
listen: false,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (_mountType == "Sia" || _mountType == "S3") {
|
List<String> failed = [];
|
||||||
final bucket =
|
if (!validateSettings(_settings[_mountType]!, failed)) {
|
||||||
_settings[_mountType]!["${_mountType}Config"]["Bucket"]
|
for (var key in failed) {
|
||||||
as String;
|
displayErrorMessage(
|
||||||
if (mountList.hasBucketName(_mountType, bucket)) {
|
context,
|
||||||
|
"Setting '$key' is not valid",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mountList.hasConfigName(_mountNameController.text)) {
|
||||||
return displayErrorMessage(
|
return displayErrorMessage(
|
||||||
context,
|
context,
|
||||||
"Bucket '$bucket' already exists",
|
"Configuration name '${_mountNameController.text}' already exists",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_mountType == "Sia" || _mountType == "S3") {
|
||||||
|
final bucket =
|
||||||
|
_settings[_mountType]!["${_mountType}Config"]["Bucket"]
|
||||||
|
as String;
|
||||||
|
if (mountList.hasBucketName(_mountType, bucket)) {
|
||||||
|
return displayErrorMessage(
|
||||||
|
context,
|
||||||
|
"Bucket '$bucket' already exists",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final success = await mountList.add(
|
||||||
|
_mountType,
|
||||||
|
_mountType == 'Remote'
|
||||||
|
? '${_settings[_mountType]!['RemoteConfig']['HostNameOrIp']}_${_settings[_mountType]!['RemoteConfig']['ApiPort']}'
|
||||||
|
: _mountNameController.text,
|
||||||
|
_settings[_mountType]!,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!success || !context.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_enabled = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final success = await mountList.add(
|
|
||||||
_mountType,
|
|
||||||
_mountType == 'Remote'
|
|
||||||
? '${_settings[_mountType]!['RemoteConfig']['HostNameOrIp']}_${_settings[_mountType]!['RemoteConfig']['ApiPort']}'
|
|
||||||
: _mountNameController.text,
|
|
||||||
_settings[_mountType]!,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!success || !context.mounted) return;
|
|
||||||
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -233,14 +218,28 @@ class _AddMountScreenState extends State<AddMountScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleProviderTest() async {
|
Future<void> _handleProviderTest() async {
|
||||||
if (_mount == null) return;
|
setState(() {
|
||||||
|
_enabled = false;
|
||||||
|
});
|
||||||
|
|
||||||
final success = await _mount!.test();
|
try {
|
||||||
if (!mounted) return;
|
if (_mount == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
displayErrorMessage(
|
final success = await _mount!.test();
|
||||||
context,
|
if (!mounted) {
|
||||||
success ? "Success" : "Provider settings are invalid!",
|
return;
|
||||||
);
|
}
|
||||||
|
|
||||||
|
displayErrorMessage(
|
||||||
|
context,
|
||||||
|
success ? "Success" : "Provider settings are invalid!",
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_enabled = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,20 @@
|
|||||||
// app_edit_path_button.dart
|
// app_outlined_icon_button.dart
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:repertory/constants.dart' as constants;
|
import 'package:repertory/constants.dart' as constants;
|
||||||
|
|
||||||
class AppEditPathButton extends StatelessWidget {
|
class AppOutlinedIconButton extends StatelessWidget {
|
||||||
|
final IconData icon;
|
||||||
final bool enabled;
|
final bool enabled;
|
||||||
|
final String text;
|
||||||
final VoidCallback onPressed;
|
final VoidCallback onPressed;
|
||||||
|
|
||||||
const AppEditPathButton({
|
const AppOutlinedIconButton({
|
||||||
super.key,
|
super.key,
|
||||||
|
required this.icon,
|
||||||
required this.enabled,
|
required this.enabled,
|
||||||
required this.onPressed,
|
required this.onPressed,
|
||||||
|
required this.text,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -21,8 +25,8 @@ class AppEditPathButton extends StatelessWidget {
|
|||||||
opacity: enabled ? 1.0 : constants.secondaryAlpha,
|
opacity: enabled ? 1.0 : constants.secondaryAlpha,
|
||||||
child: OutlinedButton.icon(
|
child: OutlinedButton.icon(
|
||||||
onPressed: enabled ? onPressed : null,
|
onPressed: enabled ? onPressed : null,
|
||||||
icon: const Icon(Icons.edit, size: constants.smallIconSize),
|
icon: Icon(icon, size: constants.smallIconSize),
|
||||||
label: const Text('Edit path'),
|
label: Text(text),
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
foregroundColor: scheme.primary,
|
foregroundColor: scheme.primary,
|
||||||
side: BorderSide(
|
side: BorderSide(
|
@@ -7,7 +7,7 @@ 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/utils/safe_set_state_mixin.dart';
|
import 'package:repertory/utils/safe_set_state_mixin.dart';
|
||||||
import 'package:repertory/widgets/app_edit_path_button.dart';
|
import 'package:repertory/widgets/app_outlined_icon_button.dart';
|
||||||
import 'package:repertory/widgets/app_icon_button_framed.dart';
|
import 'package:repertory/widgets/app_icon_button_framed.dart';
|
||||||
import 'package:repertory/widgets/app_toggle_button_framed.dart';
|
import 'package:repertory/widgets/app_toggle_button_framed.dart';
|
||||||
|
|
||||||
@@ -93,7 +93,9 @@ class _MountWidgetState extends State<MountWidget>
|
|||||||
const SizedBox(height: constants.padding),
|
const SizedBox(height: constants.padding),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
AppEditPathButton(
|
AppOutlinedIconButton(
|
||||||
|
text: 'Edit path',
|
||||||
|
icon: Icons.edit,
|
||||||
enabled: mount.mounted == false,
|
enabled: mount.mounted == false,
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (!_editEnabled) {
|
if (!_editEnabled) {
|
||||||
|
Reference in New Issue
Block a user