mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-30 20:56:53 +00:00
update
This commit is contained in:
parent
83ff387998
commit
7eff0968d0
|
@ -4,8 +4,10 @@ import 'dart:io';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_bucket.dart';
|
import 'package:selfprivacy/logic/models/backblaze_bucket.dart';
|
||||||
import 'package:selfprivacy/logic/models/backup.dart';
|
import 'package:selfprivacy/logic/models/backup.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
|
|
||||||
import 'api_map.dart';
|
import 'api_map.dart';
|
||||||
|
@ -237,11 +239,37 @@ class ServerApi extends ApiMap {
|
||||||
return response.statusCode == HttpStatus.ok;
|
return response.statusCode == HttpStatus.ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> autoUpgradeSettings() async {
|
Future<AutoUpgradeSettings> getAutoUpgradeSettings() async {
|
||||||
var client = await getClient();
|
var client = await getClient();
|
||||||
Response response = await client.get('/system/configuration/upgrade');
|
Response response = await client.get('/system/configuration/autoUpgrade');
|
||||||
|
client.close();
|
||||||
|
return AutoUpgradeSettings.fromJson(response.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateAutoUpgradeSettings(AutoUpgradeSettings settings) async {
|
||||||
|
var client = await getClient();
|
||||||
|
await client.put(
|
||||||
|
'/system/configuration/autoUpgrade',
|
||||||
|
data: settings.toJson(),
|
||||||
|
);
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<TimeZoneSettings> getServerTimezone() async {
|
||||||
|
var client = await getClient();
|
||||||
|
Response response = await client.get('/system/configuration/timezone');
|
||||||
|
client.close();
|
||||||
|
|
||||||
|
return TimeZoneSettings.fromString(response.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateServerTimezone(TimeZoneSettings settings) async {
|
||||||
|
var client = await getClient();
|
||||||
|
await client.put(
|
||||||
|
'/system/configuration/timezone',
|
||||||
|
data: settings.toJson(),
|
||||||
|
);
|
||||||
client.close();
|
client.close();
|
||||||
return response.statusCode == HttpStatus.ok;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@ import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/server_detailed_info/server_detailed_info_repository.dart';
|
import 'package:selfprivacy/logic/cubit/server_detailed_info/server_detailed_info_repository.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/hetzner_server_info.dart';
|
import 'package:selfprivacy/logic/models/hetzner_server_info.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||||
|
|
||||||
part 'server_detailed_info_state.dart';
|
part 'server_detailed_info_state.dart';
|
||||||
|
|
||||||
|
@ -16,7 +18,12 @@ class ServerDetailsCubit extends Cubit<ServerDetailsState> {
|
||||||
if (isReadyToCheck) {
|
if (isReadyToCheck) {
|
||||||
emit(ServerDetailsLoading());
|
emit(ServerDetailsLoading());
|
||||||
var data = await repository.load();
|
var data = await repository.load();
|
||||||
emit(Loaded(serverInfo: data, checkTime: DateTime.now()));
|
emit(Loaded(
|
||||||
|
serverInfo: data.hetznerServerInfo,
|
||||||
|
autoUpgradeSettings: data.autoUpgradeSettings,
|
||||||
|
serverTimezone: data.serverTimezone,
|
||||||
|
checkTime: DateTime.now(),
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
emit(ServerDetailsNotReady());
|
emit(ServerDetailsNotReady());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,33 @@
|
||||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||||
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/hetzner_server_info.dart';
|
import 'package:selfprivacy/logic/models/hetzner_server_info.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||||
|
|
||||||
class ServerDetailsRepository {
|
class ServerDetailsRepository {
|
||||||
Future<HetznerServerInfo> load() async {
|
var hetznerAPi = HetznerApi();
|
||||||
var client = HetznerApi();
|
var selfprivacyServer = ServerApi();
|
||||||
return await client.getInfo();
|
|
||||||
|
Future<_ServerDetailsRepositoryDto> load() async {
|
||||||
|
print('load');
|
||||||
|
return _ServerDetailsRepositoryDto(
|
||||||
|
autoUpgradeSettings: await selfprivacyServer.getAutoUpgradeSettings(),
|
||||||
|
hetznerServerInfo: await hetznerAPi.getInfo(),
|
||||||
|
serverTimezone: await selfprivacyServer.getServerTimezone(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _ServerDetailsRepositoryDto {
|
||||||
|
final HetznerServerInfo hetznerServerInfo;
|
||||||
|
|
||||||
|
final TimeZoneSettings serverTimezone;
|
||||||
|
|
||||||
|
final AutoUpgradeSettings autoUpgradeSettings;
|
||||||
|
|
||||||
|
_ServerDetailsRepositoryDto({
|
||||||
|
required this.hetznerServerInfo,
|
||||||
|
required this.serverTimezone,
|
||||||
|
required this.autoUpgradeSettings,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -17,13 +17,24 @@ class Loading extends ServerDetailsState {}
|
||||||
|
|
||||||
class Loaded extends ServerDetailsState {
|
class Loaded extends ServerDetailsState {
|
||||||
final HetznerServerInfo serverInfo;
|
final HetznerServerInfo serverInfo;
|
||||||
|
|
||||||
|
final TimeZoneSettings serverTimezone;
|
||||||
|
|
||||||
|
final AutoUpgradeSettings autoUpgradeSettings;
|
||||||
final DateTime checkTime;
|
final DateTime checkTime;
|
||||||
|
|
||||||
Loaded({
|
Loaded({
|
||||||
required this.serverInfo,
|
required this.serverInfo,
|
||||||
|
required this.serverTimezone,
|
||||||
|
required this.autoUpgradeSettings,
|
||||||
required this.checkTime,
|
required this.checkTime,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [serverInfo, checkTime];
|
List<Object> get props => [
|
||||||
|
serverInfo,
|
||||||
|
serverTimezone,
|
||||||
|
autoUpgradeSettings,
|
||||||
|
checkTime,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:timezone/timezone.dart';
|
|
||||||
|
|
||||||
class ServerTimezone extends Equatable {
|
|
||||||
final Location timezone;
|
|
||||||
|
|
||||||
const ServerTimezone({required this.timezone});
|
|
||||||
|
|
||||||
factory ServerTimezone.fromJson(Map<String, dynamic> json) {
|
|
||||||
var timezone = getLocation(json['timezone']);
|
|
||||||
return ServerTimezone(timezone: timezone);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {'timezone': timezone.name};
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [timezone.name];
|
|
||||||
}
|
|
|
@ -1,116 +0,0 @@
|
||||||
// import 'package:flutter/material.dart';
|
|
||||||
// import 'package:selfprivacy/config/brand_colors.dart';
|
|
||||||
// import 'package:selfprivacy/config/brand_theme.dart';
|
|
||||||
// import 'package:selfprivacy/ui/components/brand_divider/brand_divider.dart';
|
|
||||||
// import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
|
||||||
// import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
|
||||||
// import 'package:selfprivacy/ui/components/switch_block/switch_bloc.dart';
|
|
||||||
// import 'package:easy_localization/easy_localization.dart';
|
|
||||||
// import 'package:selfprivacy/ui/pages/providers/settings/time_zone.dart';
|
|
||||||
// import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
|
||||||
|
|
||||||
// class SettingsPage extends StatelessWidget {
|
|
||||||
// const SettingsPage({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// Widget build(BuildContext context) {
|
|
||||||
// return ListView(
|
|
||||||
// padding: paddingH15V0,
|
|
||||||
// children: [
|
|
||||||
// SizedBox(height: 10),
|
|
||||||
// BrandHeader(title: 'basis.settings'.tr(), hasBackButton: true),
|
|
||||||
// BrandDivider(),
|
|
||||||
// SwitcherBlock(
|
|
||||||
// onChange: (_) {},
|
|
||||||
// child: _TextColumn(
|
|
||||||
// title: 'Allow Auto-upgrade',
|
|
||||||
// value: 'Wether to allow automatic packages upgrades',
|
|
||||||
// ),
|
|
||||||
// isActive: true,
|
|
||||||
// ),
|
|
||||||
// SwitcherBlock(
|
|
||||||
// onChange: (_) {},
|
|
||||||
// child: _TextColumn(
|
|
||||||
// title: 'Reboot after upgrade',
|
|
||||||
// value: 'Reboot without prompt after applying updates',
|
|
||||||
// ),
|
|
||||||
// isActive: false,
|
|
||||||
// ),
|
|
||||||
// _Button(
|
|
||||||
// onTap: () {
|
|
||||||
// print('aaa');
|
|
||||||
// Navigator.of(context).push(
|
|
||||||
// materialRoute(
|
|
||||||
// SelectTimezone(),
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// },
|
|
||||||
// child: _TextColumn(
|
|
||||||
// title: 'Server Timezone',
|
|
||||||
// value: 'Europe/Kyssiv',
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// class _Button extends StatelessWidget {
|
|
||||||
// const _Button({
|
|
||||||
// Key? key,
|
|
||||||
// required this.onTap,
|
|
||||||
// required this.child,
|
|
||||||
// }) : super(key: key);
|
|
||||||
|
|
||||||
// final Widget child;
|
|
||||||
// final VoidCallback onTap;
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// Widget build(BuildContext context) {
|
|
||||||
// return InkWell(
|
|
||||||
// onTap: onTap,
|
|
||||||
// child: Container(
|
|
||||||
// padding: EdgeInsets.only(top: 20, bottom: 5),
|
|
||||||
// decoration: BoxDecoration(
|
|
||||||
// border: Border(
|
|
||||||
// bottom: BorderSide(width: 1, color: BrandColors.dividerColor),
|
|
||||||
// )),
|
|
||||||
// child: child,
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// class _TextColumn extends StatelessWidget {
|
|
||||||
// const _TextColumn({
|
|
||||||
// Key? key,
|
|
||||||
// required this.title,
|
|
||||||
// required this.value,
|
|
||||||
// this.hasWarning = false,
|
|
||||||
// }) : super(key: key);
|
|
||||||
|
|
||||||
// final String title;
|
|
||||||
// final String value;
|
|
||||||
// final bool hasWarning;
|
|
||||||
// @override
|
|
||||||
// Widget build(BuildContext context) {
|
|
||||||
// return Column(
|
|
||||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
// children: [
|
|
||||||
// BrandText.body1(
|
|
||||||
// title,
|
|
||||||
// style: TextStyle(color: hasWarning ? BrandColors.warning : null),
|
|
||||||
// ),
|
|
||||||
// SizedBox(height: 5),
|
|
||||||
// BrandText.body1(
|
|
||||||
// value,
|
|
||||||
// style: TextStyle(
|
|
||||||
// fontSize: 13,
|
|
||||||
// height: 1.53,
|
|
||||||
// color: hasWarning ? BrandColors.warning : BrandColors.gray1,
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_tab_bar/brand_tab_bar.dart';
|
import 'package:selfprivacy/ui/components/brand_tab_bar/brand_tab_bar.dart';
|
||||||
import 'package:selfprivacy/ui/pages/more/more.dart';
|
import 'package:selfprivacy/ui/pages/more/more.dart';
|
||||||
import 'package:selfprivacy/ui/pages/providers/providers.dart';
|
import 'package:selfprivacy/ui/pages/providers/providers.dart';
|
||||||
|
@ -29,6 +30,8 @@ class _RootPageState extends State<RootPage>
|
||||||
tabController.dispose();
|
tabController.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var selfprivacyServer = ServerApi();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
|
|
|
@ -10,6 +10,7 @@ import 'package:selfprivacy/logic/models/state_types.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_divider/brand_divider.dart';
|
import 'package:selfprivacy/ui/components/brand_divider/brand_divider.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
||||||
|
import 'package:selfprivacy/ui/components/brand_loader/brand_loader.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_radio_tile/brand_radio_tile.dart';
|
import 'package:selfprivacy/ui/components/brand_radio_tile/brand_radio_tile.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
||||||
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
||||||
|
@ -62,7 +63,9 @@ class _ServerDetailsState extends State<ServerDetails>
|
||||||
var isReady = context.watch<AppConfigCubit>().state is AppConfigFinished;
|
var isReady = context.watch<AppConfigCubit>().state is AppConfigFinished;
|
||||||
var providerState = isReady ? StateType.stable : StateType.uninitialized;
|
var providerState = isReady ? StateType.stable : StateType.uninitialized;
|
||||||
|
|
||||||
return Scaffold(
|
return BlocProvider(
|
||||||
|
create: (context) => ServerDetailsCubit()..check(),
|
||||||
|
child: Scaffold(
|
||||||
appBar: PreferredSize(
|
appBar: PreferredSize(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
@ -104,16 +107,14 @@ class _ServerDetailsState extends State<ServerDetails>
|
||||||
child: _Chart(),
|
child: _Chart(),
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
BlocProvider(
|
_TextDetails(),
|
||||||
create: (context) => ServerDetailsCubit()..check(),
|
|
||||||
child: _TextDetails(),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_ServerSettings(tabController: tabController),
|
_ServerSettings(tabController: tabController),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,12 @@ class _ServerSettings extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var serverDetailsState = context.watch<ServerDetailsCubit>().state;
|
||||||
|
if (serverDetailsState is ServerDetailsNotReady) {
|
||||||
|
return Text('not ready');
|
||||||
|
} else if (serverDetailsState is! Loaded) {
|
||||||
|
return BrandLoader.horizontal();
|
||||||
|
}
|
||||||
return ListView(
|
return ListView(
|
||||||
padding: paddingH15V0,
|
padding: paddingH15V0,
|
||||||
children: [
|
children: [
|
||||||
|
@ -38,7 +44,7 @@ class _ServerSettings extends StatelessWidget {
|
||||||
title: 'Allow Auto-upgrade',
|
title: 'Allow Auto-upgrade',
|
||||||
value: 'Wether to allow automatic packages upgrades',
|
value: 'Wether to allow automatic packages upgrades',
|
||||||
),
|
),
|
||||||
isActive: true,
|
isActive: serverDetailsState.autoUpgradeSettings.enable,
|
||||||
),
|
),
|
||||||
SwitcherBlock(
|
SwitcherBlock(
|
||||||
onChange: (_) {},
|
onChange: (_) {},
|
||||||
|
@ -46,7 +52,7 @@ class _ServerSettings extends StatelessWidget {
|
||||||
title: 'Reboot after upgrade',
|
title: 'Reboot after upgrade',
|
||||||
value: 'Reboot without prompt after applying updates',
|
value: 'Reboot without prompt after applying updates',
|
||||||
),
|
),
|
||||||
isActive: false,
|
isActive: serverDetailsState.autoUpgradeSettings.allowReboot,
|
||||||
),
|
),
|
||||||
_Button(
|
_Button(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
@ -54,7 +60,7 @@ class _ServerSettings extends StatelessWidget {
|
||||||
},
|
},
|
||||||
child: _TextColumn(
|
child: _TextColumn(
|
||||||
title: 'Server Timezone',
|
title: 'Server Timezone',
|
||||||
value: 'Europe/Kyiv',
|
value: serverDetailsState.serverTimezone.timezone.name,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -24,8 +24,10 @@ class _SelectTimezoneState extends State<SelectTimezone> {
|
||||||
var t = DateTime.now().timeZoneOffset;
|
var t = DateTime.now().timeZoneOffset;
|
||||||
var index = locations.indexWhere((element) =>
|
var index = locations.indexWhere((element) =>
|
||||||
Duration(milliseconds: element.currentTimeZone.offset) == t);
|
Duration(milliseconds: element.currentTimeZone.offset) == t);
|
||||||
|
print(t);
|
||||||
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
controller.animateTo(40.0 * index,
|
controller.animateTo(60.0 * index,
|
||||||
duration: Duration(milliseconds: 300), curve: Curves.easeIn);
|
duration: Duration(milliseconds: 300), curve: Curves.easeIn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,9 +70,11 @@ class _SelectTimezoneState extends State<SelectTimezone> {
|
||||||
return MapEntry(
|
return MapEntry(
|
||||||
key,
|
key,
|
||||||
Container(
|
Container(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
height: 60,
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
BrandText.body1(
|
BrandText.body1(
|
||||||
timezoneName,
|
timezoneName,
|
||||||
|
|
Loading…
Reference in a new issue