mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-29 12:16:55 +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:selfprivacy/config/get_it_config.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/backup.dart';
|
||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/user.dart';
|
||||
|
||||
import 'api_map.dart';
|
||||
|
@ -237,11 +239,37 @@ class ServerApi extends ApiMap {
|
|||
return response.statusCode == HttpStatus.ok;
|
||||
}
|
||||
|
||||
Future<bool> autoUpgradeSettings() async {
|
||||
Future<AutoUpgradeSettings> getAutoUpgradeSettings() async {
|
||||
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();
|
||||
return response.statusCode == HttpStatus.ok;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@ import 'package:bloc/bloc.dart';
|
|||
import 'package:equatable/equatable.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/models/auto_upgrade_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/hetzner_server_info.dart';
|
||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
|
||||
part 'server_detailed_info_state.dart';
|
||||
|
||||
|
@ -16,7 +18,12 @@ class ServerDetailsCubit extends Cubit<ServerDetailsState> {
|
|||
if (isReadyToCheck) {
|
||||
emit(ServerDetailsLoading());
|
||||
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 {
|
||||
emit(ServerDetailsNotReady());
|
||||
}
|
||||
|
|
|
@ -1,9 +1,33 @@
|
|||
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/timezone_settings.dart';
|
||||
|
||||
class ServerDetailsRepository {
|
||||
Future<HetznerServerInfo> load() async {
|
||||
var client = HetznerApi();
|
||||
return await client.getInfo();
|
||||
var hetznerAPi = HetznerApi();
|
||||
var selfprivacyServer = ServerApi();
|
||||
|
||||
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 {
|
||||
final HetznerServerInfo serverInfo;
|
||||
|
||||
final TimeZoneSettings serverTimezone;
|
||||
|
||||
final AutoUpgradeSettings autoUpgradeSettings;
|
||||
final DateTime checkTime;
|
||||
|
||||
Loaded({
|
||||
required this.serverInfo,
|
||||
required this.serverTimezone,
|
||||
required this.autoUpgradeSettings,
|
||||
required this.checkTime,
|
||||
});
|
||||
|
||||
@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: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/pages/more/more.dart';
|
||||
import 'package:selfprivacy/ui/pages/providers/providers.dart';
|
||||
|
@ -29,6 +30,8 @@ class _RootPageState extends State<RootPage>
|
|||
tabController.dispose();
|
||||
}
|
||||
|
||||
var selfprivacyServer = ServerApi();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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_header/brand_header.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_text/brand_text.dart';
|
||||
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
||||
|
@ -62,57 +63,57 @@ class _ServerDetailsState extends State<ServerDetails>
|
|||
var isReady = context.watch<AppConfigCubit>().state is AppConfigFinished;
|
||||
var providerState = isReady ? StateType.stable : StateType.uninitialized;
|
||||
|
||||
return Scaffold(
|
||||
appBar: PreferredSize(
|
||||
child: Column(
|
||||
return BlocProvider(
|
||||
create: (context) => ServerDetailsCubit()..check(),
|
||||
child: Scaffold(
|
||||
appBar: PreferredSize(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 51,
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||
child: BrandText.h4('basis.details'.tr()),
|
||||
),
|
||||
BrandDivider(),
|
||||
],
|
||||
),
|
||||
preferredSize: Size.fromHeight(52),
|
||||
),
|
||||
body: TabBarView(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
controller: tabController,
|
||||
children: [
|
||||
Container(
|
||||
height: 51,
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||
child: BrandText.h4('basis.details'.tr()),
|
||||
SingleChildScrollView(
|
||||
physics: ClampingScrollPhysics(),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: paddingH15V0,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_Header(
|
||||
providerState: providerState,
|
||||
tabController: tabController),
|
||||
BrandText.body1('providers.server.bottom_sheet.1'.tr()),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
BlocProvider(
|
||||
create: (context) => HetznerMetricsCubit()..restart(),
|
||||
child: _Chart(),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
_TextDetails(),
|
||||
],
|
||||
),
|
||||
),
|
||||
BrandDivider(),
|
||||
_ServerSettings(tabController: tabController),
|
||||
],
|
||||
),
|
||||
preferredSize: Size.fromHeight(52),
|
||||
),
|
||||
body: TabBarView(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
controller: tabController,
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
physics: ClampingScrollPhysics(),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: paddingH15V0,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_Header(
|
||||
providerState: providerState,
|
||||
tabController: tabController),
|
||||
BrandText.body1('providers.server.bottom_sheet.1'.tr()),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
BlocProvider(
|
||||
create: (context) => HetznerMetricsCubit()..restart(),
|
||||
child: _Chart(),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
BlocProvider(
|
||||
create: (context) => ServerDetailsCubit()..check(),
|
||||
child: _TextDetails(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_ServerSettings(tabController: tabController),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,12 @@ class _ServerSettings extends StatelessWidget {
|
|||
|
||||
@override
|
||||
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(
|
||||
padding: paddingH15V0,
|
||||
children: [
|
||||
|
@ -38,7 +44,7 @@ class _ServerSettings extends StatelessWidget {
|
|||
title: 'Allow Auto-upgrade',
|
||||
value: 'Wether to allow automatic packages upgrades',
|
||||
),
|
||||
isActive: true,
|
||||
isActive: serverDetailsState.autoUpgradeSettings.enable,
|
||||
),
|
||||
SwitcherBlock(
|
||||
onChange: (_) {},
|
||||
|
@ -46,7 +52,7 @@ class _ServerSettings extends StatelessWidget {
|
|||
title: 'Reboot after upgrade',
|
||||
value: 'Reboot without prompt after applying updates',
|
||||
),
|
||||
isActive: false,
|
||||
isActive: serverDetailsState.autoUpgradeSettings.allowReboot,
|
||||
),
|
||||
_Button(
|
||||
onTap: () {
|
||||
|
@ -54,7 +60,7 @@ class _ServerSettings extends StatelessWidget {
|
|||
},
|
||||
child: _TextColumn(
|
||||
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 index = locations.indexWhere((element) =>
|
||||
Duration(milliseconds: element.currentTimeZone.offset) == t);
|
||||
print(t);
|
||||
|
||||
if (index >= 0) {
|
||||
controller.animateTo(40.0 * index,
|
||||
controller.animateTo(60.0 * index,
|
||||
duration: Duration(milliseconds: 300), curve: Curves.easeIn);
|
||||
}
|
||||
}
|
||||
|
@ -68,9 +70,11 @@ class _SelectTimezoneState extends State<SelectTimezone> {
|
|||
return MapEntry(
|
||||
key,
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||
height: 60,
|
||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
BrandText.body1(
|
||||
timezoneName,
|
||||
|
|
Loading…
Reference in a new issue