2023-02-24 16:45:32 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-02-16 07:01:05 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2020-12-03 16:52:53 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:selfprivacy/config/brand_theme.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart';
|
2022-02-16 07:09:53 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/dns_records/dns_records_cubit.dart';
|
2020-12-10 20:33:19 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/providers/providers_cubit.dart';
|
2022-05-18 10:39:11 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2022-08-24 23:45:02 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_volumes/server_volume_cubit.dart';
|
2020-12-03 16:52:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
2022-09-15 21:08:14 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
2020-12-03 16:52:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
2023-02-24 16:45:32 +00:00
|
|
|
import 'package:selfprivacy/ui/router/router.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/utils/breakpoints.dart';
|
2021-03-26 13:38:39 +00:00
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
2020-12-03 16:52:53 +00:00
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2020-12-03 16:52:53 +00:00
|
|
|
class ProvidersPage extends StatefulWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const ProvidersPage({super.key});
|
2020-12-03 16:52:53 +00:00
|
|
|
|
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<ProvidersPage> createState() => _ProvidersPageState();
|
2020-12-03 16:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _ProvidersPageState extends State<ProvidersPage> {
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final bool isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2022-06-05 22:40:34 +00:00
|
|
|
final bool isBackupInitialized =
|
|
|
|
context.watch<BackupsCubit>().state.isInitialized;
|
|
|
|
final DnsRecordsStatus dnsStatus =
|
|
|
|
context.watch<DnsRecordsCubit>().state.dnsState;
|
2022-02-16 07:09:53 +00:00
|
|
|
|
2022-09-16 11:28:17 +00:00
|
|
|
final diskStatus = context.watch<ApiServerVolumeCubit>().state.diskStatus;
|
2022-09-15 21:08:14 +00:00
|
|
|
|
|
|
|
final ServerInstallationState appConfig =
|
|
|
|
context.watch<ServerInstallationCubit>().state;
|
|
|
|
|
|
|
|
StateType getServerStatus() {
|
|
|
|
if (!isReady) {
|
|
|
|
return StateType.uninitialized;
|
|
|
|
}
|
|
|
|
if (!diskStatus.isDiskOkay) {
|
|
|
|
return StateType.warning;
|
|
|
|
}
|
|
|
|
return StateType.stable;
|
|
|
|
}
|
|
|
|
|
2022-02-16 07:09:53 +00:00
|
|
|
StateType getDnsStatus() {
|
|
|
|
if (dnsStatus == DnsRecordsStatus.uninitialized ||
|
|
|
|
dnsStatus == DnsRecordsStatus.refreshing) {
|
|
|
|
return StateType.uninitialized;
|
|
|
|
}
|
|
|
|
if (dnsStatus == DnsRecordsStatus.error) {
|
|
|
|
return StateType.warning;
|
|
|
|
}
|
|
|
|
return StateType.stable;
|
|
|
|
}
|
2021-01-06 17:35:57 +00:00
|
|
|
|
2020-12-03 16:52:53 +00:00
|
|
|
return Scaffold(
|
2023-02-23 14:49:14 +00:00
|
|
|
appBar: Breakpoints.small.isActive(context)
|
|
|
|
? PreferredSize(
|
|
|
|
preferredSize: const Size.fromHeight(52),
|
|
|
|
child: BrandHeader(
|
|
|
|
title: 'basis.providers_title'.tr(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
2020-12-03 16:52:53 +00:00
|
|
|
body: ListView(
|
2021-05-25 21:53:54 +00:00
|
|
|
padding: paddingH15V0,
|
2021-01-06 17:35:57 +00:00
|
|
|
children: [
|
|
|
|
if (!isReady) ...[
|
2022-05-24 18:55:39 +00:00
|
|
|
const NotReadyCard(),
|
2023-01-31 22:29:17 +00:00
|
|
|
const SizedBox(height: 16),
|
2021-01-06 17:35:57 +00:00
|
|
|
],
|
2022-09-15 21:08:14 +00:00
|
|
|
_Card(
|
|
|
|
state: getServerStatus(),
|
|
|
|
icon: BrandIcons.server,
|
2022-10-03 23:32:35 +00:00
|
|
|
title: 'server.card_title'.tr(),
|
2022-09-15 21:08:14 +00:00
|
|
|
subtitle: diskStatus.isDiskOkay
|
2022-10-03 23:32:35 +00:00
|
|
|
? 'storage.status_ok'.tr()
|
|
|
|
: 'storage.status_error'.tr(),
|
2023-02-24 16:45:32 +00:00
|
|
|
onTap: () => context.pushRoute(const ServerDetailsRoute()),
|
2022-09-15 21:08:14 +00:00
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
_Card(
|
|
|
|
state: getDnsStatus(),
|
|
|
|
icon: BrandIcons.globe,
|
2022-10-03 23:32:35 +00:00
|
|
|
title: 'domain.screen_title'.tr(),
|
2022-09-15 21:08:14 +00:00
|
|
|
subtitle: appConfig.isDomainSelected
|
|
|
|
? appConfig.serverDomain!.domainName
|
|
|
|
: '',
|
2023-02-24 16:45:32 +00:00
|
|
|
onTap: () => context.pushRoute(const DnsDetailsRoute()),
|
2022-09-15 21:08:14 +00:00
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
// TODO: When backups are fixed, show this card
|
2023-06-29 09:52:09 +00:00
|
|
|
_Card(
|
|
|
|
state: isBackupInitialized
|
|
|
|
? StateType.stable
|
|
|
|
: StateType.uninitialized,
|
|
|
|
icon: BrandIcons.save,
|
|
|
|
title: 'backup.card_title'.tr(),
|
|
|
|
subtitle: isBackupInitialized ? 'backup.card_subtitle'.tr() : '',
|
|
|
|
onTap: () => context.pushRoute(const BackupDetailsRoute()),
|
|
|
|
),
|
2021-01-06 17:35:57 +00:00
|
|
|
],
|
2020-12-03 16:52:53 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _Card extends StatelessWidget {
|
2022-09-15 21:08:14 +00:00
|
|
|
const _Card({
|
2022-10-26 16:26:09 +00:00
|
|
|
required this.state,
|
|
|
|
required this.icon,
|
|
|
|
required this.title,
|
|
|
|
required this.subtitle,
|
|
|
|
this.onTap,
|
2022-09-15 21:08:14 +00:00
|
|
|
});
|
2021-01-27 18:33:00 +00:00
|
|
|
|
2022-09-15 21:08:14 +00:00
|
|
|
final Function()? onTap;
|
|
|
|
final StateType state;
|
|
|
|
final IconData icon;
|
|
|
|
final String title;
|
|
|
|
final String subtitle;
|
2021-03-26 13:38:39 +00:00
|
|
|
|
2022-09-15 21:08:14 +00:00
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) => Card(
|
2022-09-15 22:01:41 +00:00
|
|
|
clipBehavior: Clip.antiAlias,
|
2022-09-15 21:08:14 +00:00
|
|
|
child: InkResponse(
|
|
|
|
highlightShape: BoxShape.rectangle,
|
|
|
|
onTap: onTap,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
IconStatusMask(
|
|
|
|
status: state,
|
2022-10-04 18:58:25 +00:00
|
|
|
icon: Icon(icon, size: 30, color: Colors.white),
|
2022-09-15 21:08:14 +00:00
|
|
|
),
|
|
|
|
if (state != StateType.uninitialized)
|
|
|
|
IconStatusMask(
|
|
|
|
status: state,
|
2022-10-04 18:58:25 +00:00
|
|
|
icon: Icon(
|
2022-09-15 21:08:14 +00:00
|
|
|
state == StateType.stable
|
|
|
|
? Icons.check_circle_outline
|
|
|
|
: state == StateType.warning
|
|
|
|
? Icons.warning_amber_outlined
|
|
|
|
: Icons.error_outline,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
Text(
|
|
|
|
title,
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
),
|
|
|
|
if (state != StateType.uninitialized)
|
|
|
|
Text(
|
|
|
|
subtitle,
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
],
|
2022-08-24 05:35:49 +00:00
|
|
|
),
|
2022-09-15 21:08:14 +00:00
|
|
|
),
|
2020-12-06 07:28:31 +00:00
|
|
|
),
|
2022-09-15 21:08:14 +00:00
|
|
|
);
|
2020-12-06 07:28:31 +00:00
|
|
|
}
|