2021-08-29 09:50:24 +00:00
|
|
|
part of 'services_cubit.dart';
|
|
|
|
|
2022-05-17 13:31:34 +00:00
|
|
|
class ServicesState extends ServerInstallationDependendState {
|
2021-08-29 13:54:28 +00:00
|
|
|
const ServicesState({
|
2022-08-29 20:35:06 +00:00
|
|
|
required this.services,
|
2021-08-29 13:54:28 +00:00
|
|
|
});
|
|
|
|
|
2022-08-29 20:35:06 +00:00
|
|
|
const ServicesState.empty() : this(services: const []);
|
2021-08-29 13:54:28 +00:00
|
|
|
|
2022-08-29 20:35:06 +00:00
|
|
|
final List<Service> services;
|
|
|
|
bool get isPasswordManagerEnable => services.firstWhere((final service) => service.id == 'bitwarden', orElse: () => Service.empty).isEnabled;
|
|
|
|
bool get isCloudEnable => services.firstWhere((final service) => service.id == 'nextcloud', orElse: () => Service.empty).isEnabled;
|
|
|
|
bool get isGitEnable => services.firstWhere((final service) => service.id == 'gitea', orElse: () => Service.empty).isEnabled;
|
|
|
|
bool get isSocialNetworkEnable => services.firstWhere((final service) => service.id == 'pleroma', orElse: () => Service.empty).isEnabled;
|
|
|
|
bool get isVpnEnable => services.firstWhere((final service) => service.id == 'ocserv', orElse: () => Service.empty).isEnabled;
|
2021-08-29 13:54:28 +00:00
|
|
|
|
2022-08-29 20:35:06 +00:00
|
|
|
Service? getServiceById(final String id) {
|
|
|
|
final service = services.firstWhere((final service) => service.id == id, orElse: () => Service.empty);
|
|
|
|
if (service.id == 'empty') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return service;
|
|
|
|
}
|
2021-08-29 09:50:24 +00:00
|
|
|
|
|
|
|
@override
|
2021-08-29 13:54:28 +00:00
|
|
|
List<Object> get props => [
|
2022-08-29 20:35:06 +00:00
|
|
|
services,
|
2021-08-29 13:54:28 +00:00
|
|
|
];
|
2021-08-29 15:02:51 +00:00
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
bool isEnableByType(final ServiceTypes type) {
|
2021-08-29 15:02:51 +00:00
|
|
|
switch (type) {
|
2022-08-29 20:35:06 +00:00
|
|
|
case ServiceTypes.bitwarden:
|
2021-08-29 15:02:51 +00:00
|
|
|
return isPasswordManagerEnable;
|
2022-08-29 20:35:06 +00:00
|
|
|
case ServiceTypes.nextcloud:
|
2021-08-29 15:02:51 +00:00
|
|
|
return isCloudEnable;
|
2022-08-29 20:35:06 +00:00
|
|
|
case ServiceTypes.pleroma:
|
2021-08-29 15:02:51 +00:00
|
|
|
return isSocialNetworkEnable;
|
2022-08-29 20:35:06 +00:00
|
|
|
case ServiceTypes.gitea:
|
2021-08-29 15:02:51 +00:00
|
|
|
return isGitEnable;
|
2022-08-29 20:35:06 +00:00
|
|
|
case ServiceTypes.ocserv:
|
2021-08-29 15:02:51 +00:00
|
|
|
return isVpnEnable;
|
|
|
|
default:
|
|
|
|
throw Exception('wrong state');
|
|
|
|
}
|
|
|
|
}
|
2021-08-29 09:50:24 +00:00
|
|
|
}
|