mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-27 11:16:45 +00:00
Implement service page enabling/disabling and service restart
This commit is contained in:
parent
58479256c5
commit
8d2fbb5100
|
@ -192,8 +192,14 @@
|
||||||
"in_menu": "Server is not set up yet. Please finish setup using setup wizard for further work."
|
"in_menu": "Server is not set up yet. Please finish setup using setup wizard for further work."
|
||||||
},
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"_comment": "Вкладка сервисы",
|
"_comment": "Services",
|
||||||
"title": "Your personal, private and independent services.",
|
"title": "Your personal, private and independent services.",
|
||||||
|
"service_page": {
|
||||||
|
"restart": "Restart service",
|
||||||
|
"disable": "Disable service",
|
||||||
|
"enable": "Enable service",
|
||||||
|
"move": "Move to another volume"
|
||||||
|
},
|
||||||
"mail": {
|
"mail": {
|
||||||
"title": "E-Mail",
|
"title": "E-Mail",
|
||||||
"subtitle": "E-Mail for company and family.",
|
"subtitle": "E-Mail for company and family.",
|
||||||
|
|
|
@ -194,6 +194,12 @@
|
||||||
"services": {
|
"services": {
|
||||||
"_comment": "Вкладка сервисы",
|
"_comment": "Вкладка сервисы",
|
||||||
"title": "Ваши личные, приватные и независимые сервисы:",
|
"title": "Ваши личные, приватные и независимые сервисы:",
|
||||||
|
"service_page": {
|
||||||
|
"restart": "Перезапустить сервис",
|
||||||
|
"disable": "Выключить сервис",
|
||||||
|
"enable": "Включить сервис",
|
||||||
|
"move": "Переместить на другой диск"
|
||||||
|
},
|
||||||
"mail": {
|
"mail": {
|
||||||
"title": "Почта",
|
"title": "Почта",
|
||||||
"subtitle": "Электронная почта для семьи или компании.",
|
"subtitle": "Электронная почта для семьи или компании.",
|
||||||
|
|
|
@ -37,6 +37,10 @@ class ServicesCubit extends ServerInstallationDependendCubit<ServicesState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> restart(final String serviceId) async {
|
||||||
|
await api.restartService(serviceId);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void clear() async {
|
void clear() async {
|
||||||
emit(const ServicesState.empty());
|
emit(const ServicesState.empty());
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
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:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||||
|
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/services/services_cubit.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/components/brand_cards/brand_cards.dart';
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
||||||
|
@ -32,6 +35,10 @@ class _ServicePageState extends State<ServicePage> {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final bool serviceDisabled = service.status == ServiceStatus.inactive ||
|
||||||
|
service.status == ServiceStatus.off;
|
||||||
|
|
||||||
return BrandHeroScreen(
|
return BrandHeroScreen(
|
||||||
hasBackButton: true,
|
hasBackButton: true,
|
||||||
children: [
|
children: [
|
||||||
|
@ -73,19 +80,30 @@ class _ServicePageState extends State<ServicePage> {
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
ListTile(
|
ListTile(
|
||||||
iconColor: Theme.of(context).colorScheme.onBackground,
|
iconColor: Theme.of(context).colorScheme.onBackground,
|
||||||
onTap: () => {},
|
onTap: () => {
|
||||||
|
context.read<ServicesCubit>().restart(service.id),
|
||||||
|
},
|
||||||
leading: const Icon(Icons.restart_alt_outlined),
|
leading: const Icon(Icons.restart_alt_outlined),
|
||||||
title: Text(
|
title: Text(
|
||||||
'Restart service',
|
'services.service_page.restart'.tr(),
|
||||||
style: Theme.of(context).textTheme.titleMedium,
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
iconColor: Theme.of(context).colorScheme.onBackground,
|
iconColor: Theme.of(context).colorScheme.onBackground,
|
||||||
onTap: () => {},
|
onTap: () => {
|
||||||
|
context.read<JobsCubit>().createOrRemoveServiceToggleJob(
|
||||||
|
ServiceToggleJob(
|
||||||
|
type: _idToLegacyType(service.id),
|
||||||
|
needToTurnOn: serviceDisabled,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
leading: const Icon(Icons.power_settings_new),
|
leading: const Icon(Icons.power_settings_new),
|
||||||
title: Text(
|
title: Text(
|
||||||
'Disable service',
|
serviceDisabled
|
||||||
|
? 'services.service_page.enable'.tr()
|
||||||
|
: 'services.service_page.disable'.tr(),
|
||||||
style: Theme.of(context).textTheme.titleMedium,
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -95,13 +113,35 @@ class _ServicePageState extends State<ServicePage> {
|
||||||
onTap: () => {},
|
onTap: () => {},
|
||||||
leading: const Icon(Icons.drive_file_move_outlined),
|
leading: const Icon(Icons.drive_file_move_outlined),
|
||||||
title: Text(
|
title: Text(
|
||||||
'Move to another volume',
|
'services.service_page.move'.tr(),
|
||||||
style: Theme.of(context).textTheme.titleMedium,
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Get rid as soon as possible
|
||||||
|
ServiceTypes _idToLegacyType(final String serviceId) {
|
||||||
|
switch (serviceId) {
|
||||||
|
case 'mailserver':
|
||||||
|
return ServiceTypes.mailserver;
|
||||||
|
case 'jitsi':
|
||||||
|
return ServiceTypes.jitsi;
|
||||||
|
case 'bitwarden':
|
||||||
|
return ServiceTypes.bitwarden;
|
||||||
|
case 'nextcloud':
|
||||||
|
return ServiceTypes.nextcloud;
|
||||||
|
case 'pleroma':
|
||||||
|
return ServiceTypes.pleroma;
|
||||||
|
case 'gitea':
|
||||||
|
return ServiceTypes.gitea;
|
||||||
|
case 'ocserv':
|
||||||
|
return ServiceTypes.ocserv;
|
||||||
|
default:
|
||||||
|
throw Exception('wrong state');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServiceStatusCard extends StatelessWidget {
|
class ServiceStatusCard extends StatelessWidget {
|
||||||
|
|
Loading…
Reference in a new issue