diff --git a/web/repertory/lib/types/mount_config.dart b/web/repertory/lib/types/mount_config.dart index 7b95b38b..9cdd5a4e 100644 --- a/web/repertory/lib/types/mount_config.dart +++ b/web/repertory/lib/types/mount_config.dart @@ -11,7 +11,8 @@ class MountConfig { String get name => _name; String get path => _path; - UnmodifiableMapView get settings => UnmodifiableMapView(_settings); + UnmodifiableMapView get settings => + UnmodifiableMapView(_settings); IconData get state => _state; String get type => _type; diff --git a/web/repertory/lib/widgets/mount_settings.dart b/web/repertory/lib/widgets/mount_settings.dart index 2ee8286b..e9130258 100644 --- a/web/repertory/lib/widgets/mount_settings.dart +++ b/web/repertory/lib/widgets/mount_settings.dart @@ -16,44 +16,184 @@ class MountSettingsWidget extends StatefulWidget { } class _MountSettingsWidgetState extends State { - MountConfig? config; + Map? _settings; + + void _addBooleanSetting(list, key, value) { + list.add( + SettingsTile.switchTile( + leading: Icon(Icons.check), + title: Text(key), + initialValue: (value as bool), + onPressed: (_) { + setState(() { + _settings?[key] = !value; + }); + }, + onToggle: (bool nextValue) { + setState(() { + _settings?[key] = nextValue; + }); + }, + ), + ); + } + + void _addIntSetting(list, key, value) { + list.add( + SettingsTile.navigation( + leading: Icon(Icons.onetwothree), + title: Text(key), + value: Text((value as int).toString()), + ), + ); + } + + void _addPasswordSetting(list, String key, value) { + list.add( + SettingsTile.navigation( + leading: Icon(Icons.password), + title: Text(key), + value: Text('*' * (value as String).length), + ), + ); + } + + void _addStringSetting(list, String key, value, icon) { + list.add( + SettingsTile.navigation( + leading: Icon(icon), + title: Text(key), + value: Text(value), + ), + ); + } @override Widget build(BuildContext context) { List commonSettings = []; - config?.settings.forEach((key, value) { + List hostConfigSettings = []; + List remoteMountSettings = []; + List s3ConfigSettings = []; + List siaConfigSettings = []; + + _settings?.forEach((key, value) { if (key == "ApiAuth") { - commonSettings.add( - SettingsTile.navigation( - leading: Icon(Icons.password), - title: Text(key), - value: Text('*' * (value as String).length), - ), - ); + _addPasswordSetting(commonSettings, key, value); } else if (key == "ApiPort") { - commonSettings.add( - SettingsTile.navigation( - leading: Icon(Icons.onetwothree), - title: Text(key), - value: Text((value as int).toString()), - ), - ); + _addIntSetting(commonSettings, key, value); } else if (key == "ApiUser") { - commonSettings.add( - SettingsTile.navigation( - leading: Icon(Icons.person), - title: Text(key), - value: Text(value), - ), - ); + _addStringSetting(commonSettings, key, value, Icons.person); } else if (key == "DatabaseType") { - commonSettings.add( - SettingsTile.navigation( - leading: Icon(Icons.dataset), - title: Text(key), - value: Text(value), - ), - ); + _addStringSetting(commonSettings, key, value, Icons.dataset); + } else if (key == "DownloadTimeoutSeconds") { + _addIntSetting(commonSettings, key, value); + } else if (key == "EnableDownloadTimeout") { + _addBooleanSetting(commonSettings, key, value); + } else if (key == "EnableDriveEvents") { + _addBooleanSetting(commonSettings, key, value); + } else if (key == "EventLevel") { + _addStringSetting(commonSettings, key, value, Icons.event); + } else if (key == "EvictionDelayMinutes") { + _addIntSetting(commonSettings, key, value); + } else if (key == "EvictionUseAccessedTime") { + _addBooleanSetting(commonSettings, key, value); + } else if (key == "MaxCacheSizeBytes") { + _addIntSetting(commonSettings, key, value); + } else if (key == "MaxUploadCount") { + _addIntSetting(commonSettings, key, value); + } else if (key == "OnlineCheckRetrySeconds") { + _addIntSetting(commonSettings, key, value); + } else if (key == "PreferredDownloadType") { + _addStringSetting(commonSettings, key, value, Icons.download); + } else if (key == "RetryReadCount") { + _addIntSetting(commonSettings, key, value); + } else if (key == "RingBufferFileSize") { + _addIntSetting(commonSettings, key, value); + } else if (key == "HostConfig") { + value.forEach((subKey, subValue) { + if (subKey == "AgentString") { + _addStringSetting( + hostConfigSettings, + subKey, + subValue, + Icons.support_agent, + ); + } else if (subKey == "ApiPassword") { + _addPasswordSetting(hostConfigSettings, subKey, subValue); + } else if (subKey == "ApiPort") { + _addIntSetting(hostConfigSettings, subKey, subValue); + } else if (subKey == "ApiUser") { + _addStringSetting( + hostConfigSettings, + subKey, + subValue, + Icons.person, + ); + } else if (subKey == "HostNameOrIp") { + _addStringSetting( + hostConfigSettings, + subKey, + subValue, + Icons.computer, + ); + } else if (subKey == "Path") { + _addStringSetting( + hostConfigSettings, + subKey, + subValue, + Icons.route, + ); + } else if (subKey == "Protocol") { + _addStringSetting(hostConfigSettings, subKey, subValue, Icons.http); + } else if (subKey == "TimeoutMs") { + _addIntSetting(hostConfigSettings, subKey, subValue); + } + }); + } else if (key == "RemoteMount") { + value.forEach((subKey, subValue) { + if (subKey == "ApiPort") { + _addIntSetting(remoteMountSettings, subKey, subValue); + } else if (subKey == "ClientPoolSize") { + _addIntSetting(remoteMountSettings, subKey, subValue); + } else if (subKey == "Enable") { + _addBooleanSetting(remoteMountSettings, subKey, subValue); + } else if (subKey == "EncryptionToken") { + _addPasswordSetting(remoteMountSettings, subKey, subValue); + } + }); + } else if (key == "S3Config") { + value.forEach((subKey, subValue) { + if (subKey == "AccessKey") { + _addPasswordSetting(s3ConfigSettings, subKey, subValue); + } else if (subKey == "Bucket") { + _addStringSetting(s3ConfigSettings, subKey, subValue, Icons.folder); + } else if (subKey == "EncryptionToken") { + _addPasswordSetting(s3ConfigSettings, subKey, subValue); + } else if (subKey == "Region") { + _addStringSetting(s3ConfigSettings, subKey, subValue, Icons.map); + } else if (subKey == "SecretKey") { + _addPasswordSetting(s3ConfigSettings, subKey, subValue); + } else if (subKey == "TimeoutMs") { + _addIntSetting(s3ConfigSettings, subKey, subValue); + } else if (subKey == "URL") { + _addStringSetting(s3ConfigSettings, subKey, subValue, Icons.http); + } else if (subKey == "UsePathStyle") { + _addBooleanSetting(s3ConfigSettings, subKey, subValue); + } else if (subKey == "UseRegionInURL") { + _addBooleanSetting(s3ConfigSettings, subKey, subValue); + } + }); + } else if (key == "SiaConfig") { + value.forEach((subKey, subValue) { + if (subKey == "Bucket") { + _addStringSetting( + siaConfigSettings, + subKey, + subValue, + Icons.folder, + ); + } + }); } }); @@ -65,10 +205,24 @@ class _MountSettingsWidgetState extends State { body: SettingsList( shrinkWrap: false, sections: [ - SettingsSection( - title: Text('Common Settings'), - tiles: commonSettings.toList(), - ), + if (hostConfigSettings.isNotEmpty) + SettingsSection( + title: Text('Host Config'), + tiles: hostConfigSettings, + ), + if (remoteMountSettings.isNotEmpty) + SettingsSection( + title: Text('Remote Mount'), + tiles: remoteMountSettings, + ), + if (s3ConfigSettings.isNotEmpty) + SettingsSection(title: Text('S3 Config'), tiles: s3ConfigSettings), + if (siaConfigSettings.isNotEmpty) + SettingsSection( + title: Text('Sia Config'), + tiles: siaConfigSettings, + ), + SettingsSection(title: Text('Settings'), tiles: commonSettings), ], ), ); @@ -76,7 +230,7 @@ class _MountSettingsWidgetState extends State { @override void initState() { - config = widget.config; + _settings = Map.from(widget.config.settings); super.initState(); } }