mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-02-04 07:20:39 +00:00
Improve server settings page
This commit is contained in:
parent
b3ba7d959f
commit
c5eed6ace9
|
@ -101,6 +101,13 @@
|
|||
"month": "Month",
|
||||
"day": "Day",
|
||||
"hour": "Hour"
|
||||
},
|
||||
"settings": {
|
||||
"allow_autoupgrade": "Allow auto-upgrade",
|
||||
"allow_autoupgrade_hint": "Allow automatic packages upgrades on server",
|
||||
"reboot_after_upgrade": "Reboot after upgrade",
|
||||
"reboot_after_upgrade_hint": "Reboot without prompt after applying changes on server",
|
||||
"server_timezone": "Server timezone"
|
||||
}
|
||||
},
|
||||
"domain": {
|
||||
|
|
|
@ -101,6 +101,13 @@
|
|||
"month": "Месяц",
|
||||
"day": "День",
|
||||
"hour": "Час"
|
||||
},
|
||||
"settings": {
|
||||
"allow_autoupgrade": "Разрешить авто-обноления",
|
||||
"allow_autoupgrade_hint": "Разрешить автоматичесую установку обновлений на сервер",
|
||||
"reboot_after_upgrade": "Перезагружать после обновлений",
|
||||
"reboot_after_upgrade_hint": "Автоматически перезагружать сервер после применения обновлений",
|
||||
"server_timezone": "Часовой пояс сервера"
|
||||
}
|
||||
},
|
||||
"domain": {
|
||||
|
|
|
@ -126,4 +126,26 @@ class ServerApi extends ApiMap
|
|||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setAutoUpgradeSettings(
|
||||
final bool allowReboot,
|
||||
final bool enableAutoUpgrade,
|
||||
) async {
|
||||
try {
|
||||
final GraphQLClient client = await getClient();
|
||||
final input = Input$AutoUpgradeSettingsInput(
|
||||
allowReboot: allowReboot,
|
||||
enableAutoUpgrade: enableAutoUpgrade,
|
||||
);
|
||||
final variables = Variables$Mutation$ChangeAutoUpgradeSettings(
|
||||
settings: input,
|
||||
);
|
||||
final mutation = Options$Mutation$ChangeAutoUpgradeSettings(
|
||||
variables: variables,
|
||||
);
|
||||
await client.mutate$ChangeAutoUpgradeSettings(mutation);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -603,13 +603,20 @@ class ServerApi extends ApiMap {
|
|||
}
|
||||
|
||||
Future<TimeZoneSettings> getServerTimezone() async {
|
||||
// I am not sure how to initialize TimeZoneSettings with default value...
|
||||
TimeZoneSettings settings = TimeZoneSettings();
|
||||
final Dio client = await getClient();
|
||||
final Response response =
|
||||
await client.get('/system/configuration/timezone');
|
||||
close(client);
|
||||
try {
|
||||
final Response response = await client.get(
|
||||
'/system/configuration/timezone',
|
||||
);
|
||||
settings = TimeZoneSettings.fromString(response.data);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return TimeZoneSettings.fromString(response.data);
|
||||
return settings;
|
||||
}
|
||||
|
||||
Future<void> updateServerTimezone(final TimeZoneSettings settings) async {
|
||||
|
|
|
@ -5,17 +5,14 @@ import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
|||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
|
||||
class ServerDetailsRepository {
|
||||
HetznerApi hetznerAPi = HetznerApi();
|
||||
ServerApi selfprivacyServer = ServerApi();
|
||||
HetznerApi hetzner = HetznerApi();
|
||||
ServerApi server = ServerApi();
|
||||
|
||||
Future<ServerDetailsRepositoryDto> load() async {
|
||||
print('load');
|
||||
return ServerDetailsRepositoryDto(
|
||||
autoUpgradeSettings: await selfprivacyServer.getAutoUpgradeSettings(),
|
||||
hetznerServerInfo: await hetznerAPi.getInfo(),
|
||||
serverTimezone: await selfprivacyServer.getServerTimezone(),
|
||||
);
|
||||
}
|
||||
Future<ServerDetailsRepositoryDto> load() async => ServerDetailsRepositoryDto(
|
||||
autoUpgradeSettings: await server.getAutoUpgradeSettings(),
|
||||
hetznerServerInfo: await hetzner.getInfo(),
|
||||
serverTimezone: await server.getServerTimezone(),
|
||||
);
|
||||
}
|
||||
|
||||
class ServerDetailsRepositoryDto {
|
||||
|
|
|
@ -3,13 +3,16 @@ import 'package:timezone/timezone.dart';
|
|||
class TimeZoneSettings {
|
||||
factory TimeZoneSettings.fromString(final String string) {
|
||||
final Location location = timeZoneDatabase.locations[string]!;
|
||||
return TimeZoneSettings(location);
|
||||
return TimeZoneSettings(timezone: location);
|
||||
}
|
||||
|
||||
TimeZoneSettings(this.timezone);
|
||||
final Location timezone;
|
||||
TimeZoneSettings({this.timezone});
|
||||
final Location? timezone;
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'timezone': timezone.name,
|
||||
'timezone': timezone?.name ?? 'Unknown',
|
||||
};
|
||||
|
||||
@override
|
||||
String toString() => timezone?.name ?? 'Unknown';
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class _ServerSettings extends StatelessWidget {
|
|||
Widget build(final BuildContext context) {
|
||||
final serverDetailsState = context.watch<ServerDetailsCubit>().state;
|
||||
if (serverDetailsState is ServerDetailsNotReady) {
|
||||
return const Text('not ready');
|
||||
return Text('basis.loading'.tr());
|
||||
} else if (serverDetailsState is! Loaded) {
|
||||
return BrandLoader.horizontal();
|
||||
}
|
||||
|
@ -38,19 +38,17 @@ class _ServerSettings extends StatelessWidget {
|
|||
SwitcherBlock(
|
||||
onChange: (final _) {},
|
||||
isActive: serverDetailsState.autoUpgradeSettings.enable,
|
||||
child: const _TextColumn(
|
||||
title: 'Allow Auto-upgrade',
|
||||
value: 'Wether to allow automatic packages upgrades',
|
||||
hasWarning: false,
|
||||
child: _TextColumn(
|
||||
title: 'providers.server.settings.allow_autoupgrade'.tr(),
|
||||
value: 'providers.server.settings.allow_autoupgrade_hint'.tr(),
|
||||
),
|
||||
),
|
||||
SwitcherBlock(
|
||||
onChange: (final _) {},
|
||||
isActive: serverDetailsState.autoUpgradeSettings.allowReboot,
|
||||
child: const _TextColumn(
|
||||
title: 'Reboot after upgrade',
|
||||
value: 'Reboot without prompt after applying updates',
|
||||
hasWarning: false,
|
||||
child: _TextColumn(
|
||||
title: 'providers.server.settings.reboot_after_upgrade'.tr(),
|
||||
value: 'providers.server.settings.reboot_after_upgrade_hint'.tr(),
|
||||
),
|
||||
),
|
||||
_Button(
|
||||
|
@ -58,9 +56,8 @@ class _ServerSettings extends StatelessWidget {
|
|||
Navigator.of(context).push(materialRoute(const SelectTimezone()));
|
||||
},
|
||||
child: _TextColumn(
|
||||
title: 'Server Timezone',
|
||||
value: serverDetailsState.serverTimezone.timezone.name,
|
||||
hasWarning: false,
|
||||
title: 'providers.server.settings.server_timezone'.tr(),
|
||||
value: serverDetailsState.serverTimezone.toString(),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -108,16 +105,12 @@ class _TextColumn extends StatelessWidget {
|
|||
children: [
|
||||
BrandText.body1(
|
||||
title,
|
||||
style: TextStyle(color: hasWarning ? BrandColors.warning : null),
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
BrandText.body1(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
height: 1.53,
|
||||
color: hasWarning ? BrandColors.warning : BrandColors.gray1,
|
||||
),
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue