mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-27 11:16:45 +00:00
Implement migrate to binds logic
This commit is contained in:
parent
5ca4ee27e3
commit
39358a827f
|
@ -57,7 +57,10 @@ mixin VolumeApi on ApiMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> migrateToBinds(final Map<String, String> serviceToDisk) async {
|
Future<String?> migrateToBinds(
|
||||||
|
final Map<String, String> serviceToDisk,
|
||||||
|
) async {
|
||||||
|
String? jobUid;
|
||||||
try {
|
try {
|
||||||
final GraphQLClient client = await getClient();
|
final GraphQLClient client = await getClient();
|
||||||
final input = Input$MigrateToBindsInput(
|
final input = Input$MigrateToBindsInput(
|
||||||
|
@ -70,9 +73,16 @@ mixin VolumeApi on ApiMap {
|
||||||
final variables = Variables$Mutation$MigrateToBinds(input: input);
|
final variables = Variables$Mutation$MigrateToBinds(input: input);
|
||||||
final migrateMutation =
|
final migrateMutation =
|
||||||
Options$Mutation$MigrateToBinds(variables: variables);
|
Options$Mutation$MigrateToBinds(variables: variables);
|
||||||
await client.mutate$MigrateToBinds(migrateMutation);
|
final QueryResult<Mutation$MigrateToBinds> result =
|
||||||
|
await client.mutate$MigrateToBinds(
|
||||||
|
migrateMutation,
|
||||||
|
);
|
||||||
|
|
||||||
|
jobUid = result.parsedData!.migrateToBinds.job!.uid;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return jobUid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,7 @@ class ServerJobsCubit
|
||||||
ServerJobsCubit(final ServerInstallationCubit serverInstallationCubit)
|
ServerJobsCubit(final ServerInstallationCubit serverInstallationCubit)
|
||||||
: super(
|
: super(
|
||||||
serverInstallationCubit,
|
serverInstallationCubit,
|
||||||
const ServerJobsState(
|
const ServerJobsState(),
|
||||||
serverJobList: [],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Timer? timer;
|
Timer? timer;
|
||||||
|
@ -24,9 +22,7 @@ class ServerJobsCubit
|
||||||
@override
|
@override
|
||||||
void clear() async {
|
void clear() async {
|
||||||
emit(
|
emit(
|
||||||
const ServerJobsState(
|
const ServerJobsState(),
|
||||||
serverJobList: [],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
if (timer != null && timer!.isActive) {
|
if (timer != null && timer!.isActive) {
|
||||||
timer!.cancel();
|
timer!.cancel();
|
||||||
|
@ -47,6 +43,29 @@ class ServerJobsCubit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> migrateToBinds(final Map<String, String> serviceToDisk) async {
|
||||||
|
final String? jobUid = await api.migrateToBinds(serviceToDisk);
|
||||||
|
emit(
|
||||||
|
ServerJobsState(
|
||||||
|
migrationJobUid: jobUid,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerJob? getServerJobByUid(final String uid) {
|
||||||
|
ServerJob? job;
|
||||||
|
|
||||||
|
try {
|
||||||
|
job = state.serverJobList.firstWhere(
|
||||||
|
(final ServerJob job) => job.uid == uid,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return job;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> reload({final bool useTimer = false}) async {
|
Future<void> reload({final bool useTimer = false}) async {
|
||||||
final List<ServerJob> jobs = await api.getServerJobs();
|
final List<ServerJob> jobs = await api.getServerJobs();
|
||||||
emit(
|
emit(
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
part of 'server_jobs_cubit.dart';
|
part of 'server_jobs_cubit.dart';
|
||||||
|
|
||||||
class ServerJobsState extends ServerInstallationDependendState {
|
class ServerJobsState extends ServerInstallationDependendState {
|
||||||
const ServerJobsState({this.serverJobList = const []});
|
const ServerJobsState({
|
||||||
|
this.serverJobList = const [],
|
||||||
|
this.migrationJobUid,
|
||||||
|
});
|
||||||
final List<ServerJob> serverJobList;
|
final List<ServerJob> serverJobList;
|
||||||
|
final String? migrationJobUid;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => serverJobList;
|
List<Object?> get props => [migrationJobUid, ...serverJobList];
|
||||||
|
|
||||||
ServerJobsState copyWith({
|
ServerJobsState copyWith({
|
||||||
final List<ServerJob>? serverJobList,
|
final List<ServerJob>? serverJobList,
|
||||||
|
final String? migrationJobUid,
|
||||||
}) =>
|
}) =>
|
||||||
ServerJobsState(
|
ServerJobsState(
|
||||||
serverJobList: serverJobList ?? this.serverJobList,
|
serverJobList: serverJobList ?? this.serverJobList,
|
||||||
|
migrationJobUid: migrationJobUid ?? this.migrationJobUid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:selfprivacy/logic/cubit/server_jobs/server_jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/disk_size.dart';
|
import 'package:selfprivacy/logic/models/disk_size.dart';
|
||||||
import 'package:selfprivacy/logic/models/service.dart';
|
import 'package:selfprivacy/logic/models/service.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
||||||
|
@ -8,6 +9,8 @@ import 'package:selfprivacy/ui/components/info_box/info_box.dart';
|
||||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||||
import 'package:selfprivacy/ui/components/storage_list_items/server_storage_list_item.dart';
|
import 'package:selfprivacy/ui/components/storage_list_items/server_storage_list_item.dart';
|
||||||
import 'package:selfprivacy/ui/components/storage_list_items/service_migration_list_item.dart';
|
import 'package:selfprivacy/ui/components/storage_list_items/service_migration_list_item.dart';
|
||||||
|
import 'package:selfprivacy/ui/pages/server_storage/binds_migration/migration_process_page.dart';
|
||||||
|
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||||
|
|
||||||
class DataToBindsMigrationPage extends StatefulWidget {
|
class DataToBindsMigrationPage extends StatefulWidget {
|
||||||
const DataToBindsMigrationPage({
|
const DataToBindsMigrationPage({
|
||||||
|
@ -158,7 +161,10 @@ class _DataToBindsMigrationPageState extends State<DataToBindsMigrationPage> {
|
||||||
FilledButton(
|
FilledButton(
|
||||||
title: 'providers.storage.start_migration_button'.tr(),
|
title: 'providers.storage.start_migration_button'.tr(),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// TODO: Implement migration
|
context.read<ServerJobsCubit>().migrateToBinds(serviceToDisk);
|
||||||
|
Navigator.of(context).push(
|
||||||
|
materialRoute(const MigrationProcessPage()),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 32),
|
const SizedBox(height: 32),
|
||||||
|
|
|
@ -10,12 +10,9 @@ import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||||
|
|
||||||
class MigrationProcessPage extends StatefulWidget {
|
class MigrationProcessPage extends StatefulWidget {
|
||||||
const MigrationProcessPage({
|
const MigrationProcessPage({
|
||||||
required this.jobUid,
|
|
||||||
final super.key,
|
final super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String jobUid;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MigrationProcessPage> createState() => _MigrationProcessPageState();
|
State<MigrationProcessPage> createState() => _MigrationProcessPageState();
|
||||||
}
|
}
|
||||||
|
@ -28,22 +25,25 @@ class _MigrationProcessPageState extends State<MigrationProcessPage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(final BuildContext context) {
|
Widget build(final BuildContext context) {
|
||||||
|
ServerJob? job;
|
||||||
|
String? subtitle = '';
|
||||||
|
double value = 0.0;
|
||||||
|
List<Widget> children = [];
|
||||||
|
|
||||||
final serverJobsState = context.watch<ServerJobsCubit>().state;
|
final serverJobsState = context.watch<ServerJobsCubit>().state;
|
||||||
final ServerJob job = serverJobsState.serverJobList.firstWhere(
|
if (serverJobsState.migrationJobUid != null) {
|
||||||
(final ServerJob job) => job.uid == widget.jobUid,
|
job = context.read<ServerJobsCubit>().getServerJobByUid(
|
||||||
);
|
serverJobsState.migrationJobUid!,
|
||||||
final double value = job.progress == null ? 0.0 : job.progress! / 100;
|
);
|
||||||
return BrandHeroScreen(
|
}
|
||||||
hasBackButton: false,
|
|
||||||
heroTitle: 'providers.storage.migration_process'.tr(),
|
if (job == null) {
|
||||||
heroSubtitle: job.statusText,
|
subtitle = 'basis.loading'.tr();
|
||||||
children: [
|
} else {
|
||||||
BrandLinearIndicator(
|
value = job.progress == null ? 0.0 : job.progress! / 100;
|
||||||
value: value,
|
subtitle = job.statusText;
|
||||||
color: Theme.of(context).colorScheme.primary,
|
children = [
|
||||||
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
|
...children,
|
||||||
height: 4.0,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
if (job.finishedAt != null)
|
if (job.finishedAt != null)
|
||||||
Text(
|
Text(
|
||||||
|
@ -60,7 +60,21 @@ class _MigrationProcessPageState extends State<MigrationProcessPage> {
|
||||||
(final predicate) => false,
|
(final predicate) => false,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return BrandHeroScreen(
|
||||||
|
hasBackButton: false,
|
||||||
|
heroTitle: 'providers.storage.migration_process'.tr(),
|
||||||
|
heroSubtitle: subtitle,
|
||||||
|
children: [
|
||||||
|
BrandLinearIndicator(
|
||||||
|
value: value,
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
|
||||||
|
height: 4.0,
|
||||||
|
),
|
||||||
|
...children,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue