mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-11 18:39:45 +00:00
update
This commit is contained in:
parent
84e9259ec2
commit
26607251d9
|
@ -90,8 +90,13 @@ class ServerApi extends ApiMap {
|
||||||
close(client);
|
close(client);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
Future<void> switchService(ServiceTypes type, bool needToTurnOn) async {
|
||||||
|
var client = await getClient();
|
||||||
|
client.post('/services/${type.url}/${needToTurnOn ? 'enable' : 'disable'}');
|
||||||
|
client.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension UrlServerExt on ServiceTypes {
|
extension UrlServerExt on ServiceTypes {
|
||||||
String get url {
|
String get url {
|
||||||
|
@ -116,4 +121,4 @@ extension UrlServerExt on ServiceTypes {
|
||||||
throw Exception('wrong state');
|
throw Exception('wrong state');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/jobs/job.dart';
|
import 'package:selfprivacy/logic/models/job.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:selfprivacy/utils/password_generator.dart';
|
import 'package:selfprivacy/utils/password_generator.dart';
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/jobs/job.dart';
|
import 'package:selfprivacy/logic/models/job.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
export 'package:provider/provider.dart';
|
export 'package:provider/provider.dart';
|
||||||
|
@ -40,6 +40,23 @@ class JobsCubit extends Cubit<JobsState> {
|
||||||
emit(newState);
|
emit(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void createOrRemove(ServiceToggleJob job) {
|
||||||
|
var newJobsList = <Job>[];
|
||||||
|
if (state is JobsStateWithJobs) {
|
||||||
|
newJobsList.addAll((state as JobsStateWithJobs).jobList);
|
||||||
|
}
|
||||||
|
var needToRemoveJob =
|
||||||
|
newJobsList.any((el) => el is ServiceToggleJob && el.type == job.type);
|
||||||
|
if (needToRemoveJob) {
|
||||||
|
var removingJob = newJobsList
|
||||||
|
.firstWhere(((el) => el is ServiceToggleJob && el.type == job.type));
|
||||||
|
removeJob(removingJob.id);
|
||||||
|
} else {
|
||||||
|
newJobsList.add(job);
|
||||||
|
emit(JobsStateWithJobs(newJobsList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> applyAll() async {
|
Future<void> applyAll() async {
|
||||||
if (state is JobsStateWithJobs) {
|
if (state is JobsStateWithJobs) {
|
||||||
var jobs = (state as JobsStateWithJobs).jobList;
|
var jobs = (state as JobsStateWithJobs).jobList;
|
||||||
|
@ -50,6 +67,13 @@ class JobsCubit extends Cubit<JobsState> {
|
||||||
if (job is CreateUserJob) {
|
if (job is CreateUserJob) {
|
||||||
newUsers.add(job.user);
|
newUsers.add(job.user);
|
||||||
await api.createUser(job.user);
|
await api.createUser(job.user);
|
||||||
|
} else if (job is ServiceToggleJob) {
|
||||||
|
await api.switchService(job.type, job.needToTurnOn);
|
||||||
|
if (job.needToTurnOn) {
|
||||||
|
servicesCubit.turnOnist([job.type]);
|
||||||
|
} else {
|
||||||
|
servicesCubit.turnOffList([job.type]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,4 +81,21 @@ class ServicesState extends Equatable {
|
||||||
isSocialNetworkEnable,
|
isSocialNetworkEnable,
|
||||||
isVpnEnable
|
isVpnEnable
|
||||||
];
|
];
|
||||||
|
|
||||||
|
bool isEnableByType(ServiceTypes type) {
|
||||||
|
switch (type) {
|
||||||
|
case ServiceTypes.passwordManager:
|
||||||
|
return isPasswordManagerEnable;
|
||||||
|
case ServiceTypes.cloud:
|
||||||
|
return isCloudEnable;
|
||||||
|
case ServiceTypes.socialNetwork:
|
||||||
|
return isSocialNetworkEnable;
|
||||||
|
case ServiceTypes.git:
|
||||||
|
return isGitEnable;
|
||||||
|
case ServiceTypes.vpn:
|
||||||
|
return isVpnEnable;
|
||||||
|
default:
|
||||||
|
throw Exception('wrong state');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||||
import 'package:selfprivacy/utils/password_generator.dart';
|
import 'package:selfprivacy/utils/password_generator.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
import '../user.dart';
|
import 'user.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class Job extends Equatable {
|
class Job extends Equatable {
|
||||||
|
@ -28,18 +28,20 @@ class CreateUserJob extends Job {
|
||||||
final User user;
|
final User user;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [id, title];
|
List<Object> get props => [id, title, user];
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServiceToggleJob extends Job {
|
class ServiceToggleJob extends Job {
|
||||||
ServiceToggleJob({
|
ServiceToggleJob({
|
||||||
required this.type,
|
required this.type,
|
||||||
required this.needToTurnOn,
|
required this.needToTurnOn,
|
||||||
}) : super(title: '${needToTurnOn ? "jobs.serviceTurnOn".tr() : "jobs.serviceTurnOff".tr()} ');
|
}) : super(
|
||||||
|
title:
|
||||||
|
'${needToTurnOn ? "jobs.serviceTurnOn".tr() : "jobs.serviceTurnOff".tr()} ${type.title}');
|
||||||
|
|
||||||
final ServiceTypes type;
|
final ServiceTypes type;
|
||||||
final bool needToTurnOn;
|
final bool needToTurnOn;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [id, title];
|
List<Object> get props => [id, title, type, needToTurnOn];
|
||||||
}
|
}
|
|
@ -36,11 +36,7 @@ class JobsContent extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: BrandCards.small(
|
child: BrandCards.small(
|
||||||
child: Row(
|
child: Text(j.title),
|
||||||
children: [
|
|
||||||
BrandText.body1(j.title),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: 10),
|
SizedBox(width: 10),
|
||||||
|
|
|
@ -4,10 +4,14 @@ import 'package:selfprivacy/config/brand_theme.dart';
|
||||||
import 'package:selfprivacy/config/text_themes.dart';
|
import 'package:selfprivacy/config/text_themes.dart';
|
||||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
|
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
||||||
|
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/job.dart';
|
||||||
import 'package:selfprivacy/logic/models/state_types.dart';
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.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_header/brand_header.dart';
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
||||||
|
import 'package:selfprivacy/ui/components/brand_switch/brand_switch.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
||||||
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
||||||
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
||||||
|
@ -65,6 +69,11 @@ class _Card extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var isReady = context.watch<AppConfigCubit>().state.isFullyInitilized;
|
var isReady = context.watch<AppConfigCubit>().state.isFullyInitilized;
|
||||||
var changeTab = context.read<ChangeTab>().onPress;
|
var changeTab = context.read<ChangeTab>().onPress;
|
||||||
|
|
||||||
|
var serviceState = context.watch<ServicesCubit>().state;
|
||||||
|
var jobsCubit = context.watch<JobsCubit>();
|
||||||
|
var hasSwitcher = switchableServices.contains(serviceType);
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: isReady
|
onTap: isReady
|
||||||
? () => showDialog<void>(
|
? () => showDialog<void>(
|
||||||
|
@ -87,9 +96,43 @@ class _Card extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
IconStatusMask(
|
Row(
|
||||||
status: isReady ? StateType.stable : StateType.uninitialized,
|
children: [
|
||||||
child: Icon(serviceType.icon, size: 30, color: Colors.white),
|
IconStatusMask(
|
||||||
|
status: isReady ? StateType.stable : StateType.uninitialized,
|
||||||
|
child: Icon(serviceType.icon, size: 30, color: Colors.white),
|
||||||
|
),
|
||||||
|
if (hasSwitcher) ...[
|
||||||
|
Spacer(),
|
||||||
|
Builder(
|
||||||
|
builder: (context) {
|
||||||
|
late bool isActive;
|
||||||
|
var jobState = jobsCubit.state;
|
||||||
|
if (jobState is JobsStateWithJobs &&
|
||||||
|
jobState.jobList.any((el) =>
|
||||||
|
el is ServiceToggleJob &&
|
||||||
|
el.type == serviceType)) {
|
||||||
|
isActive = (jobState.jobList.firstWhere((el) =>
|
||||||
|
el is ServiceToggleJob &&
|
||||||
|
el.type == serviceType) as ServiceToggleJob)
|
||||||
|
.needToTurnOn;
|
||||||
|
} else {
|
||||||
|
isActive = serviceState.isEnableByType(serviceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return BrandSwitch(
|
||||||
|
value: isActive,
|
||||||
|
onChanged: (value) => jobsCubit.createOrRemove(
|
||||||
|
ServiceToggleJob(
|
||||||
|
type: serviceType,
|
||||||
|
needToTurnOn: value,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
BrandText.h2(serviceType.title),
|
BrandText.h2(serviceType.title),
|
||||||
|
@ -306,6 +349,7 @@ class _ServiceDetails extends StatelessWidget {
|
||||||
'services.vpn.bottom_sheet.1'.tr(),
|
'services.vpn.bottom_sheet.1'.tr(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Dialog(
|
return Dialog(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
|
|
@ -6,7 +6,7 @@ import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/jobs/job.dart';
|
import 'package:selfprivacy/logic/models/job.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/user.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||||
|
|
Loading…
Reference in a new issue