diff --git a/CHANGELOG.md b/CHANGELOG.md index 61bb6133..e099c911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * \#46 [bug] Changes to maximum cache size should be updated live * \#47 [bug] Windows-to-Linux remote mount is allowing directory rename when directory is not empty * \#48 [bug] Windows-to-Linux remote mount overlapped I/O is not detecting EOF for read operations +* \#49 [ui] Implement provider test button ### Changes from v2.0.5-rc diff --git a/web/repertory/lib/models/mount.dart b/web/repertory/lib/models/mount.dart index a2d40058..eefb8326 100644 --- a/web/repertory/lib/models/mount.dart +++ b/web/repertory/lib/models/mount.dart @@ -282,4 +282,27 @@ class Mount with ChangeNotifier { debugPrint('$e'); } } + + Future test() async { + try { + final auth = await _auth.createAuth(); + final response = await http.put( + Uri.parse( + Uri.encodeFull( + '${getBaseUri()}/api/v1/test?auth=$auth&name=$name&type=$type&settings=${jsonEncode(mountConfig.settings)}', + ), + ), + ); + + if (response.statusCode == 401) { + _auth.logoff(); + } + + return (response.statusCode == 200); + } catch (e) { + debugPrint('$e'); + } + + return false; + } } diff --git a/web/repertory/lib/screens/add_mount_screen.dart b/web/repertory/lib/screens/add_mount_screen.dart index 82f2e588..f2841ba6 100644 --- a/web/repertory/lib/screens/add_mount_screen.dart +++ b/web/repertory/lib/screens/add_mount_screen.dart @@ -113,8 +113,8 @@ class _AddMountScreenState extends State { ), ), ), - if (_mount != null) const SizedBox(height: constants.padding), - if (_mount != null) + if (_mount != null) ...[ + const SizedBox(height: constants.padding), Expanded( child: Card( margin: EdgeInsets.all(0.0), @@ -129,8 +129,7 @@ class _AddMountScreenState extends State { ), ), ), - if (_mount != null) const SizedBox(height: constants.padding), - if (_mount != null) + const SizedBox(height: constants.padding), Row( children: [ ElevatedButton.icon( @@ -189,16 +188,15 @@ class _AddMountScreenState extends State { Navigator.pop(context); }, ), - if (_mountType == 'Sia' || _mountType == 'S3') ...[ - const SizedBox(width: constants.padding), - ElevatedButton.icon( - label: const Text('Test'), - icon: const Icon(Icons.check), - onPressed: () async {}, - ), - ], + const SizedBox(width: constants.padding), + ElevatedButton.icon( + label: const Text('Test'), + icon: const Icon(Icons.check), + onPressed: _handleProviderTest, + ), ], ), + ], ], ); }, @@ -234,6 +232,22 @@ class _AddMountScreenState extends State { }); } + Future _handleProviderTest() async { + if (_mount == null) { + return; + } + + final success = await _mount!.test(); + if (!mounted) { + return; + } + + displayErrorMessage( + context, + success ? "Success!" : "Provider settings are invalid!", + ); + } + @override void setState(VoidCallback fn) { if (!mounted) {