mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-27 03:06:41 +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 {
|
||||
final GraphQLClient client = await getClient();
|
||||
final input = Input$MigrateToBindsInput(
|
||||
|
@ -70,9 +73,16 @@ mixin VolumeApi on ApiMap {
|
|||
final variables = Variables$Mutation$MigrateToBinds(input: input);
|
||||
final migrateMutation =
|
||||
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) {
|
||||
print(e);
|
||||
}
|
||||
|
||||
return jobUid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,7 @@ class ServerJobsCubit
|
|||
ServerJobsCubit(final ServerInstallationCubit serverInstallationCubit)
|
||||
: super(
|
||||
serverInstallationCubit,
|
||||
const ServerJobsState(
|
||||
serverJobList: [],
|
||||
),
|
||||
const ServerJobsState(),
|
||||
);
|
||||
|
||||
Timer? timer;
|
||||
|
@ -24,9 +22,7 @@ class ServerJobsCubit
|
|||
@override
|
||||
void clear() async {
|
||||
emit(
|
||||
const ServerJobsState(
|
||||
serverJobList: [],
|
||||
),
|
||||
const ServerJobsState(),
|
||||
);
|
||||
if (timer != null && timer!.isActive) {
|
||||
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 {
|
||||
final List<ServerJob> jobs = await api.getServerJobs();
|
||||
emit(
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
part of 'server_jobs_cubit.dart';
|
||||
|
||||
class ServerJobsState extends ServerInstallationDependendState {
|
||||
const ServerJobsState({this.serverJobList = const []});
|
||||
const ServerJobsState({
|
||||
this.serverJobList = const [],
|
||||
this.migrationJobUid,
|
||||
});
|
||||
final List<ServerJob> serverJobList;
|
||||
final String? migrationJobUid;
|
||||
|
||||
@override
|
||||
List<Object?> get props => serverJobList;
|
||||
List<Object?> get props => [migrationJobUid, ...serverJobList];
|
||||
|
||||
ServerJobsState copyWith({
|
||||
final List<ServerJob>? serverJobList,
|
||||
final String? migrationJobUid,
|
||||
}) =>
|
||||
ServerJobsState(
|
||||
serverJobList: serverJobList ?? this.serverJobList,
|
||||
migrationJobUid: migrationJobUid ?? this.migrationJobUid,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:easy_localization/easy_localization.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/service.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/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/pages/server_storage/binds_migration/migration_process_page.dart';
|
||||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||
|
||||
class DataToBindsMigrationPage extends StatefulWidget {
|
||||
const DataToBindsMigrationPage({
|
||||
|
@ -158,7 +161,10 @@ class _DataToBindsMigrationPageState extends State<DataToBindsMigrationPage> {
|
|||
FilledButton(
|
||||
title: 'providers.storage.start_migration_button'.tr(),
|
||||
onPressed: () {
|
||||
// TODO: Implement migration
|
||||
context.read<ServerJobsCubit>().migrateToBinds(serviceToDisk);
|
||||
Navigator.of(context).push(
|
||||
materialRoute(const MigrationProcessPage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
|
|
|
@ -10,12 +10,9 @@ import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
|||
|
||||
class MigrationProcessPage extends StatefulWidget {
|
||||
const MigrationProcessPage({
|
||||
required this.jobUid,
|
||||
final super.key,
|
||||
});
|
||||
|
||||
final String jobUid;
|
||||
|
||||
@override
|
||||
State<MigrationProcessPage> createState() => _MigrationProcessPageState();
|
||||
}
|
||||
|
@ -28,22 +25,25 @@ class _MigrationProcessPageState extends State<MigrationProcessPage> {
|
|||
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
ServerJob? job;
|
||||
String? subtitle = '';
|
||||
double value = 0.0;
|
||||
List<Widget> children = [];
|
||||
|
||||
final serverJobsState = context.watch<ServerJobsCubit>().state;
|
||||
final ServerJob job = serverJobsState.serverJobList.firstWhere(
|
||||
(final ServerJob job) => job.uid == widget.jobUid,
|
||||
);
|
||||
final double value = job.progress == null ? 0.0 : job.progress! / 100;
|
||||
return BrandHeroScreen(
|
||||
hasBackButton: false,
|
||||
heroTitle: 'providers.storage.migration_process'.tr(),
|
||||
heroSubtitle: job.statusText,
|
||||
children: [
|
||||
BrandLinearIndicator(
|
||||
value: value,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
|
||||
height: 4.0,
|
||||
),
|
||||
if (serverJobsState.migrationJobUid != null) {
|
||||
job = context.read<ServerJobsCubit>().getServerJobByUid(
|
||||
serverJobsState.migrationJobUid!,
|
||||
);
|
||||
}
|
||||
|
||||
if (job == null) {
|
||||
subtitle = 'basis.loading'.tr();
|
||||
} else {
|
||||
value = job.progress == null ? 0.0 : job.progress! / 100;
|
||||
subtitle = job.statusText;
|
||||
children = [
|
||||
...children,
|
||||
const SizedBox(height: 16),
|
||||
if (job.finishedAt != null)
|
||||
Text(
|
||||
|
@ -60,7 +60,21 @@ class _MigrationProcessPageState extends State<MigrationProcessPage> {
|
|||
(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