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);
|
||||
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 {
|
||||
String get url {
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:cubit_form/cubit_form.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:easy_localization/easy_localization.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/cubit/services/services_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:selfprivacy/logic/models/user.dart';
|
||||
export 'package:provider/provider.dart';
|
||||
|
@ -40,6 +40,23 @@ class JobsCubit extends Cubit<JobsState> {
|
|||
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 {
|
||||
if (state is JobsStateWithJobs) {
|
||||
var jobs = (state as JobsStateWithJobs).jobList;
|
||||
|
@ -50,6 +67,13 @@ class JobsCubit extends Cubit<JobsState> {
|
|||
if (job is CreateUserJob) {
|
||||
newUsers.add(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,
|
||||
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:easy_localization/easy_localization.dart';
|
||||
|
||||
import '../user.dart';
|
||||
import 'user.dart';
|
||||
|
||||
@immutable
|
||||
class Job extends Equatable {
|
||||
|
@ -28,18 +28,20 @@ class CreateUserJob extends Job {
|
|||
final User user;
|
||||
|
||||
@override
|
||||
List<Object> get props => [id, title];
|
||||
List<Object> get props => [id, title, user];
|
||||
}
|
||||
|
||||
class ServiceToggleJob extends Job {
|
||||
ServiceToggleJob({
|
||||
required this.type,
|
||||
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 bool needToTurnOn;
|
||||
|
||||
@override
|
||||
List<Object> get props => [id, title];
|
||||
List<Object> get props => [id, title, type, needToTurnOn];
|
||||
}
|
|
@ -36,11 +36,7 @@ class JobsContent extends StatelessWidget {
|
|||
children: [
|
||||
Expanded(
|
||||
child: BrandCards.small(
|
||||
child: Row(
|
||||
children: [
|
||||
BrandText.body1(j.title),
|
||||
],
|
||||
),
|
||||
child: Text(j.title),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
|
|
|
@ -4,10 +4,14 @@ import 'package:selfprivacy/config/brand_theme.dart';
|
|||
import 'package:selfprivacy/config/text_themes.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/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/ui/components/brand_button/brand_button.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_switch/brand_switch.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/not_ready_card/not_ready_card.dart';
|
||||
|
@ -65,6 +69,11 @@ class _Card extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
var isReady = context.watch<AppConfigCubit>().state.isFullyInitilized;
|
||||
var changeTab = context.read<ChangeTab>().onPress;
|
||||
|
||||
var serviceState = context.watch<ServicesCubit>().state;
|
||||
var jobsCubit = context.watch<JobsCubit>();
|
||||
var hasSwitcher = switchableServices.contains(serviceType);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: isReady
|
||||
? () => showDialog<void>(
|
||||
|
@ -86,11 +95,45 @@ class _Card extends StatelessWidget {
|
|||
child: BrandCards.big(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
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),
|
||||
BrandText.h2(serviceType.title),
|
||||
SizedBox(height: 10),
|
||||
|
@ -306,6 +349,7 @@ class _ServiceDetails extends StatelessWidget {
|
|||
'services.vpn.bottom_sheet.1'.tr(),
|
||||
);
|
||||
}
|
||||
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
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/jobs/jobs_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/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||
|
|
Loading…
Reference in a new issue