mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-26 18:56:38 +00:00
Implement rebuild server job for settings page
This commit is contained in:
parent
fe95f5e5d3
commit
d6d7a0dcb6
|
@ -24,9 +24,7 @@ mixin ServerActionsApi on ApiMap {
|
|||
try {
|
||||
final GraphQLClient client = await getClient();
|
||||
return await _commonBoolRequest(
|
||||
() async {
|
||||
await client.mutate$RebootSystem();
|
||||
},
|
||||
() async => client.mutate$RebootSystem(),
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
@ -37,9 +35,7 @@ mixin ServerActionsApi on ApiMap {
|
|||
try {
|
||||
final GraphQLClient client = await getClient();
|
||||
return await _commonBoolRequest(
|
||||
() async {
|
||||
await client.mutate$PullRepositoryChanges();
|
||||
},
|
||||
() async => client.mutate$PullRepositoryChanges(),
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
@ -49,10 +45,8 @@ mixin ServerActionsApi on ApiMap {
|
|||
Future<bool> upgrade() async {
|
||||
try {
|
||||
final GraphQLClient client = await getClient();
|
||||
return await _commonBoolRequest(
|
||||
() async {
|
||||
await client.mutate$RunSystemUpgrade();
|
||||
},
|
||||
return _commonBoolRequest(
|
||||
() async => client.mutate$RunSystemUpgrade(),
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
|
|
@ -105,6 +105,7 @@ class JobsCubit extends Cubit<JobsState> {
|
|||
emit(JobsStateLoading());
|
||||
bool hasServiceJobs = false;
|
||||
for (final ClientJob job in jobs) {
|
||||
// TODO: Rewrite to polymorphism
|
||||
if (job is CreateUserJob) {
|
||||
await usersCubit.createUser(job.user);
|
||||
}
|
||||
|
@ -124,6 +125,9 @@ class JobsCubit extends Cubit<JobsState> {
|
|||
if (job is ResetUserPasswordJob) {
|
||||
await usersCubit.changeUserPassword(job.user, job.user.password!);
|
||||
}
|
||||
if (job is RebuildServerJob) {
|
||||
await upgradeServer();
|
||||
}
|
||||
}
|
||||
|
||||
await api.pullConfigurationUpdate();
|
||||
|
|
|
@ -20,6 +20,13 @@ class ClientJob extends Equatable {
|
|||
List<Object> get props => [id, title];
|
||||
}
|
||||
|
||||
class RebuildServerJob extends ClientJob {
|
||||
RebuildServerJob({
|
||||
required final super.title,
|
||||
final super.id,
|
||||
});
|
||||
}
|
||||
|
||||
class CreateUserJob extends ClientJob {
|
||||
CreateUserJob({
|
||||
required this.user,
|
||||
|
|
|
@ -3,11 +3,13 @@ import 'package:easy_localization/easy_localization.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:selfprivacy/config/brand_colors.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/hetzner_metrics/hetzner_metrics_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_detailed_info/server_detailed_info_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_volumes/server_volume_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/job.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/segmented_buttons.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_cards/filled_card.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
||||
|
|
|
@ -10,6 +10,7 @@ class _ServerSettings extends StatefulWidget {
|
|||
class _ServerSettingsState extends State<_ServerSettings> {
|
||||
bool? allowAutoUpgrade;
|
||||
bool? rebootAfterUpgrade;
|
||||
bool? didSomethingChange;
|
||||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
|
@ -24,11 +25,18 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
rebootAfterUpgrade = serverDetailsState.autoUpgradeSettings.allowReboot;
|
||||
}
|
||||
|
||||
didSomethingChange ??= false;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
value: allowAutoUpgrade ?? false,
|
||||
onChanged: (final switched) {
|
||||
if (didSomethingChange == false) {
|
||||
context.read<JobsCubit>().addJob(
|
||||
RebuildServerJob(title: 'jobs.upgradeServer'.tr()),
|
||||
);
|
||||
}
|
||||
context
|
||||
.read<ServerDetailsCubit>()
|
||||
.repository
|
||||
|
@ -40,6 +48,7 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
);
|
||||
setState(() {
|
||||
allowAutoUpgrade = switched;
|
||||
didSomethingChange = true;
|
||||
});
|
||||
},
|
||||
title: Text('providers.server.settings.allow_autoupgrade'.tr()),
|
||||
|
@ -51,6 +60,11 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
SwitchListTile(
|
||||
value: rebootAfterUpgrade ?? false,
|
||||
onChanged: (final switched) {
|
||||
if (didSomethingChange == false) {
|
||||
context.read<JobsCubit>().addJob(
|
||||
RebuildServerJob(title: 'jobs.upgradeServer'.tr()),
|
||||
);
|
||||
}
|
||||
context
|
||||
.read<ServerDetailsCubit>()
|
||||
.repository
|
||||
|
@ -62,6 +76,7 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
);
|
||||
setState(() {
|
||||
rebootAfterUpgrade = switched;
|
||||
didSomethingChange = true;
|
||||
});
|
||||
},
|
||||
title: Text('providers.server.settings.reboot_after_upgrade'.tr()),
|
||||
|
@ -76,6 +91,14 @@ class _ServerSettingsState extends State<_ServerSettings> {
|
|||
serverDetailsState.serverTimezone.toString(),
|
||||
),
|
||||
onTap: () {
|
||||
if (didSomethingChange == false) {
|
||||
context.read<JobsCubit>().addJob(
|
||||
RebuildServerJob(title: 'jobs.upgradeServer'.tr()),
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
didSomethingChange = true;
|
||||
});
|
||||
Navigator.of(context).push(
|
||||
materialRoute(
|
||||
const SelectTimezone(),
|
||||
|
|
Loading…
Reference in a new issue