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