mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-02-03 06:46:36 +00:00
refactor(ui): Refactor Services page
This commit is contained in:
parent
356f094f53
commit
d9b47a4bd3
152
lib/ui/molecules/cards/services_page_card.dart
Normal file
152
lib/ui/molecules/cards/services_page_card.dart
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
import 'package:auto_route/auto_route.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:gap/gap.dart';
|
||||||
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
||||||
|
import 'package:selfprivacy/ui/atoms/masks/icon_status_mask.dart';
|
||||||
|
import 'package:selfprivacy/ui/router/router.dart';
|
||||||
|
import 'package:selfprivacy/utils/launch_url.dart';
|
||||||
|
import 'package:selfprivacy/utils/ui_helpers.dart';
|
||||||
|
|
||||||
|
class ServicesPageCard extends StatelessWidget {
|
||||||
|
const ServicesPageCard({required this.service, super.key});
|
||||||
|
|
||||||
|
final Service service;
|
||||||
|
@override
|
||||||
|
Widget build(final BuildContext context) {
|
||||||
|
final isReady = context.watch<ServerInstallationCubit>().state
|
||||||
|
is ServerInstallationFinished;
|
||||||
|
|
||||||
|
final config = context.watch<ServerInstallationCubit>().state;
|
||||||
|
final domainName = UiHelpers.getDomainName(config);
|
||||||
|
|
||||||
|
StateType getStatus(final ServiceStatus status) {
|
||||||
|
switch (status) {
|
||||||
|
case ServiceStatus.active:
|
||||||
|
return StateType.stable;
|
||||||
|
case ServiceStatus.activating:
|
||||||
|
return StateType.stable;
|
||||||
|
case ServiceStatus.deactivating:
|
||||||
|
return StateType.uninitialized;
|
||||||
|
case ServiceStatus.inactive:
|
||||||
|
return StateType.uninitialized;
|
||||||
|
case ServiceStatus.failed:
|
||||||
|
return StateType.error;
|
||||||
|
case ServiceStatus.off:
|
||||||
|
return StateType.uninitialized;
|
||||||
|
case ServiceStatus.reloading:
|
||||||
|
return StateType.stable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Card(
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
child: InkResponse(
|
||||||
|
highlightShape: BoxShape.rectangle,
|
||||||
|
onTap: isReady
|
||||||
|
? () => context.pushRoute(
|
||||||
|
ServiceRoute(serviceId: service.id),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
IconStatusMask(
|
||||||
|
status: getStatus(service.status),
|
||||||
|
icon: SvgPicture.string(
|
||||||
|
service.svgIcon,
|
||||||
|
width: 32.0,
|
||||||
|
height: 32.0,
|
||||||
|
colorFilter: const ColorFilter.mode(
|
||||||
|
Colors.white,
|
||||||
|
BlendMode.srcIn,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Gap(8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
service.displayName,
|
||||||
|
style: Theme.of(context).textTheme.headlineMedium,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
if (service.url != '' &&
|
||||||
|
service.url != null &&
|
||||||
|
service.isEnabled)
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
_ServiceLink(
|
||||||
|
url: service.url ?? '',
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (service.id == 'simple-nixos-mailserver')
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
_ServiceLink(
|
||||||
|
url: domainName,
|
||||||
|
isActive: false,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
service.description,
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
service.loginInfo,
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ServiceLink extends StatelessWidget {
|
||||||
|
const _ServiceLink({
|
||||||
|
required this.url,
|
||||||
|
this.isActive = true,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String url;
|
||||||
|
final bool isActive;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(final BuildContext context) => GestureDetector(
|
||||||
|
onTap: isActive
|
||||||
|
? () => launchURL(
|
||||||
|
url,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
child: Text(
|
||||||
|
url,
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
decoration: TextDecoration.underline,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
part of '../service_settings_page.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
|
|
||||||
class BasicBoolConfigItem extends StatefulWidget {
|
class BasicBoolConfigItem extends StatefulWidget {
|
||||||
const BasicBoolConfigItem({
|
const BasicBoolConfigItem({
|
|
@ -1,4 +1,6 @@
|
||||||
part of '../service_settings_page.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
|
|
||||||
class BasicEnumConfigItem extends StatefulWidget {
|
class BasicEnumConfigItem extends StatefulWidget {
|
||||||
const BasicEnumConfigItem({
|
const BasicEnumConfigItem({
|
|
@ -1,4 +1,7 @@
|
||||||
part of '../service_settings_page.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:gap/gap.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
|
|
||||||
class BasicStringConfigItem extends StatefulWidget {
|
class BasicStringConfigItem extends StatefulWidget {
|
||||||
const BasicStringConfigItem({
|
const BasicStringConfigItem({
|
|
@ -1,4 +1,9 @@
|
||||||
part of '../service_settings_page.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:gap/gap.dart';
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
|
import 'package:selfprivacy/logic/get_it/resources_model.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
|
|
||||||
class DomainStringConfigItem extends StatefulWidget {
|
class DomainStringConfigItem extends StatefulWidget {
|
||||||
const DomainStringConfigItem({
|
const DomainStringConfigItem({
|
|
@ -4,18 +4,15 @@ import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
|
||||||
import 'package:selfprivacy/logic/bloc/services/services_bloc.dart';
|
import 'package:selfprivacy/logic/bloc/services/services_bloc.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/resources_model.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/job.dart';
|
import 'package:selfprivacy/logic/models/job.dart';
|
||||||
import 'package:selfprivacy/logic/models/service.dart';
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
|
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
|
||||||
|
import 'package:selfprivacy/ui/molecules/config_item_fields/basic_bool_config_item.dart';
|
||||||
part 'config_item_fields/basic_string_config_item.dart';
|
import 'package:selfprivacy/ui/molecules/config_item_fields/basic_enum_config_item.dart';
|
||||||
part 'config_item_fields/basic_bool_config_item.dart';
|
import 'package:selfprivacy/ui/molecules/config_item_fields/basic_string_config_item.dart';
|
||||||
part 'config_item_fields/basic_enum_config_item.dart';
|
import 'package:selfprivacy/ui/molecules/config_item_fields/domain_string_config_item.dart';
|
||||||
part 'config_item_fields/domain_string_config_item.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class ServiceSettingsPage extends StatefulWidget {
|
class ServiceSettingsPage extends StatefulWidget {
|
|
@ -1,23 +1,16 @@
|
||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
|
||||||
import 'package:gap/gap.dart';
|
|
||||||
import 'package:selfprivacy/config/brand_theme.dart';
|
import 'package:selfprivacy/config/brand_theme.dart';
|
||||||
import 'package:selfprivacy/logic/bloc/outdated_server_checker/outdated_server_checker_bloc.dart';
|
import 'package:selfprivacy/logic/bloc/outdated_server_checker/outdated_server_checker_bloc.dart';
|
||||||
import 'package:selfprivacy/logic/bloc/services/services_bloc.dart';
|
import 'package:selfprivacy/logic/bloc/services/services_bloc.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/service.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/state_types.dart';
|
|
||||||
import 'package:selfprivacy/ui/atoms/icons/brand_icons.dart';
|
import 'package:selfprivacy/ui/atoms/icons/brand_icons.dart';
|
||||||
import 'package:selfprivacy/ui/atoms/masks/icon_status_mask.dart';
|
|
||||||
import 'package:selfprivacy/ui/molecules/cards/server_outdated_card.dart';
|
import 'package:selfprivacy/ui/molecules/cards/server_outdated_card.dart';
|
||||||
|
import 'package:selfprivacy/ui/molecules/cards/services_page_card.dart';
|
||||||
import 'package:selfprivacy/ui/molecules/placeholders/empty_page_placeholder.dart';
|
import 'package:selfprivacy/ui/molecules/placeholders/empty_page_placeholder.dart';
|
||||||
import 'package:selfprivacy/ui/organisms/headers/brand_header.dart';
|
import 'package:selfprivacy/ui/organisms/headers/brand_header.dart';
|
||||||
import 'package:selfprivacy/ui/router/router.dart';
|
|
||||||
import 'package:selfprivacy/utils/breakpoints.dart';
|
import 'package:selfprivacy/utils/breakpoints.dart';
|
||||||
import 'package:selfprivacy/utils/launch_url.dart';
|
|
||||||
import 'package:selfprivacy/utils/ui_helpers.dart';
|
|
||||||
|
|
||||||
@RoutePage()
|
@RoutePage()
|
||||||
class ServicesPage extends StatefulWidget {
|
class ServicesPage extends StatefulWidget {
|
||||||
|
@ -72,13 +65,13 @@ class _ServicesPageState extends State<ServicesPage> {
|
||||||
'basis.services_title'.tr(),
|
'basis.services_title'.tr(),
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 16),
|
||||||
...services.map(
|
...services.map(
|
||||||
(final service) => Padding(
|
(final service) => Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
bottom: 30,
|
bottom: 16,
|
||||||
),
|
),
|
||||||
child: _Card(service: service),
|
child: ServicesPageCard(service: service),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -87,144 +80,3 @@ class _ServicesPageState extends State<ServicesPage> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _Card extends StatelessWidget {
|
|
||||||
const _Card({required this.service});
|
|
||||||
|
|
||||||
final Service service;
|
|
||||||
@override
|
|
||||||
Widget build(final BuildContext context) {
|
|
||||||
final isReady = context.watch<ServerInstallationCubit>().state
|
|
||||||
is ServerInstallationFinished;
|
|
||||||
|
|
||||||
final config = context.watch<ServerInstallationCubit>().state;
|
|
||||||
final domainName = UiHelpers.getDomainName(config);
|
|
||||||
|
|
||||||
StateType getStatus(final ServiceStatus status) {
|
|
||||||
switch (status) {
|
|
||||||
case ServiceStatus.active:
|
|
||||||
return StateType.stable;
|
|
||||||
case ServiceStatus.activating:
|
|
||||||
return StateType.stable;
|
|
||||||
case ServiceStatus.deactivating:
|
|
||||||
return StateType.uninitialized;
|
|
||||||
case ServiceStatus.inactive:
|
|
||||||
return StateType.uninitialized;
|
|
||||||
case ServiceStatus.failed:
|
|
||||||
return StateType.error;
|
|
||||||
case ServiceStatus.off:
|
|
||||||
return StateType.uninitialized;
|
|
||||||
case ServiceStatus.reloading:
|
|
||||||
return StateType.stable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Card(
|
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
child: InkResponse(
|
|
||||||
highlightShape: BoxShape.rectangle,
|
|
||||||
onTap: isReady
|
|
||||||
? () => context.pushRoute(
|
|
||||||
ServiceRoute(serviceId: service.id),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
IconStatusMask(
|
|
||||||
status: getStatus(service.status),
|
|
||||||
icon: SvgPicture.string(
|
|
||||||
service.svgIcon,
|
|
||||||
width: 30.0,
|
|
||||||
height: 30.0,
|
|
||||||
colorFilter: const ColorFilter.mode(
|
|
||||||
Colors.white,
|
|
||||||
BlendMode.srcIn,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Gap(8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
service.displayName,
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
if (service.url != '' &&
|
|
||||||
service.url != null &&
|
|
||||||
service.isEnabled)
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
_ServiceLink(
|
|
||||||
url: service.url ?? '',
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
if (service.id == 'mailserver')
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
_ServiceLink(
|
|
||||||
url: domainName,
|
|
||||||
isActive: false,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
service.description,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
service.loginInfo,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
||||||
color: Theme.of(context).colorScheme.secondary,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ServiceLink extends StatelessWidget {
|
|
||||||
const _ServiceLink({
|
|
||||||
required this.url,
|
|
||||||
this.isActive = true,
|
|
||||||
});
|
|
||||||
|
|
||||||
final String url;
|
|
||||||
final bool isActive;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(final BuildContext context) => GestureDetector(
|
|
||||||
onTap: isActive
|
|
||||||
? () => launchURL(
|
|
||||||
url,
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
child: Text(
|
|
||||||
url,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
||||||
color: Theme.of(context).colorScheme.primary,
|
|
||||||
decoration: TextDecoration.underline,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ import 'package:selfprivacy/ui/pages/server_details/server_settings_screen.dart'
|
||||||
import 'package:selfprivacy/ui/pages/server_storage/binds_migration/services_migration.dart';
|
import 'package:selfprivacy/ui/pages/server_storage/binds_migration/services_migration.dart';
|
||||||
import 'package:selfprivacy/ui/pages/server_storage/extending_volume.dart';
|
import 'package:selfprivacy/ui/pages/server_storage/extending_volume.dart';
|
||||||
import 'package:selfprivacy/ui/pages/server_storage/server_storage.dart';
|
import 'package:selfprivacy/ui/pages/server_storage/server_storage.dart';
|
||||||
import 'package:selfprivacy/ui/pages/services/service_page.dart';
|
import 'package:selfprivacy/ui/pages/services/service.dart';
|
||||||
import 'package:selfprivacy/ui/pages/services/service_settings_page.dart';
|
import 'package:selfprivacy/ui/pages/services/service_settings.dart';
|
||||||
import 'package:selfprivacy/ui/pages/services/services.dart';
|
import 'package:selfprivacy/ui/pages/services/services.dart';
|
||||||
import 'package:selfprivacy/ui/pages/setup/initializing/initializing.dart';
|
import 'package:selfprivacy/ui/pages/setup/initializing/initializing.dart';
|
||||||
import 'package:selfprivacy/ui/pages/setup/recovering/recovery_routing.dart';
|
import 'package:selfprivacy/ui/pages/setup/recovering/recovery_routing.dart';
|
||||||
|
|
Loading…
Reference in a new issue