mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
fix(job): Fix server settings toogles not creating upgrade server job
This commit is contained in:
parent
e619d6351f
commit
db2f5c1342
|
@ -24,14 +24,10 @@ class JobsCubit extends Cubit<JobsState> {
|
||||||
final ServicesCubit servicesCubit;
|
final ServicesCubit servicesCubit;
|
||||||
|
|
||||||
void addJob(final ClientJob job) {
|
void addJob(final ClientJob job) {
|
||||||
final List<ClientJob> newJobsList = [];
|
_updateJobsState([
|
||||||
if (state is JobsStateWithJobs) {
|
...currentJobList,
|
||||||
final JobsStateWithJobs jobsState = state as JobsStateWithJobs;
|
...[job]
|
||||||
newJobsList.addAll(jobsState.clientJobList);
|
]);
|
||||||
}
|
|
||||||
newJobsList.add(job);
|
|
||||||
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
|
||||||
emit(JobsStateWithJobs(newJobsList));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeJob(final String id) {
|
void removeJob(final String id) {
|
||||||
|
@ -58,17 +54,28 @@ class JobsCubit extends Cubit<JobsState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void createShhJobIfNotExist(final CreateSSHKeyJob job) {
|
List<ClientJob> get currentJobList {
|
||||||
final List<ClientJob> newJobsList = <ClientJob>[];
|
final List<ClientJob> jobs = <ClientJob>[];
|
||||||
if (state is JobsStateWithJobs) {
|
if (state is JobsStateWithJobs) {
|
||||||
newJobsList.addAll((state as JobsStateWithJobs).clientJobList);
|
jobs.addAll((state as JobsStateWithJobs).clientJobList);
|
||||||
}
|
}
|
||||||
final bool isExistInJobList =
|
|
||||||
newJobsList.any((final el) => el is CreateSSHKeyJob);
|
return jobs;
|
||||||
if (!isExistInJobList) {
|
}
|
||||||
newJobsList.add(job);
|
|
||||||
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
void _updateJobsState(final List<ClientJob> newJobs) {
|
||||||
emit(JobsStateWithJobs(newJobsList));
|
getIt<NavigationService>().showSnackBar('jobs.job_added'.tr());
|
||||||
|
emit(JobsStateWithJobs(newJobs));
|
||||||
|
}
|
||||||
|
|
||||||
|
void addUniqueJob<J extends ClientJob>(final J job) {
|
||||||
|
final List<ClientJob> jobs = currentJobList;
|
||||||
|
final bool exists = jobs.any((final el) => el is J);
|
||||||
|
if (!exists) {
|
||||||
|
_updateJobsState([
|
||||||
|
...jobs,
|
||||||
|
...[job]
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ class _ServerSettings extends StatefulWidget {
|
||||||
class _ServerSettingsState extends State<_ServerSettings> {
|
class _ServerSettingsState extends State<_ServerSettings> {
|
||||||
bool? allowAutoUpgrade;
|
bool? allowAutoUpgrade;
|
||||||
bool? rebootAfterUpgrade;
|
bool? rebootAfterUpgrade;
|
||||||
bool? didSomethingChange;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(final BuildContext context) {
|
Widget build(final BuildContext context) {
|
||||||
|
@ -25,18 +24,14 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
||||||
rebootAfterUpgrade = serverDetailsState.autoUpgradeSettings.allowReboot;
|
rebootAfterUpgrade = serverDetailsState.autoUpgradeSettings.allowReboot;
|
||||||
}
|
}
|
||||||
|
|
||||||
didSomethingChange ??= false;
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: allowAutoUpgrade ?? false,
|
value: allowAutoUpgrade ?? false,
|
||||||
onChanged: (final switched) {
|
onChanged: (final switched) {
|
||||||
if (didSomethingChange == false) {
|
context.read<JobsCubit>().addUniqueJob(
|
||||||
context.read<JobsCubit>().addJob(
|
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
context
|
context
|
||||||
.read<ServerDetailsCubit>()
|
.read<ServerDetailsCubit>()
|
||||||
.repository
|
.repository
|
||||||
|
@ -48,7 +43,6 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
allowAutoUpgrade = switched;
|
allowAutoUpgrade = switched;
|
||||||
didSomethingChange = true;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
title: Text('server.allow_autoupgrade'.tr()),
|
title: Text('server.allow_autoupgrade'.tr()),
|
||||||
|
@ -60,11 +54,9 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: rebootAfterUpgrade ?? false,
|
value: rebootAfterUpgrade ?? false,
|
||||||
onChanged: (final switched) {
|
onChanged: (final switched) {
|
||||||
if (didSomethingChange == false) {
|
context.read<JobsCubit>().addUniqueJob(
|
||||||
context.read<JobsCubit>().addJob(
|
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
context
|
context
|
||||||
.read<ServerDetailsCubit>()
|
.read<ServerDetailsCubit>()
|
||||||
.repository
|
.repository
|
||||||
|
@ -76,7 +68,6 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
rebootAfterUpgrade = switched;
|
rebootAfterUpgrade = switched;
|
||||||
didSomethingChange = true;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
title: Text('server.reboot_after_upgrade'.tr()),
|
title: Text('server.reboot_after_upgrade'.tr()),
|
||||||
|
@ -91,14 +82,9 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
||||||
serverDetailsState.serverTimezone.toString(),
|
serverDetailsState.serverTimezone.toString(),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (didSomethingChange == false) {
|
context.read<JobsCubit>().addUniqueJob(
|
||||||
context.read<JobsCubit>().addJob(
|
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
||||||
RebuildServerJob(title: 'jobs.upgrade_server'.tr()),
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
didSomethingChange = true;
|
|
||||||
});
|
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
materialRoute(
|
materialRoute(
|
||||||
const SelectTimezone(),
|
const SelectTimezone(),
|
||||||
|
|
Loading…
Reference in a new issue