mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
Move DiskStatus to the server volume cubit
This commit is contained in:
parent
61d049118f
commit
641e329725
|
@ -31,7 +31,7 @@ class BlocAndProviderConfig extends StatelessWidget {
|
|||
final recoveryKeyCubit = RecoveryKeyCubit(serverInstallationCubit);
|
||||
final apiDevicesCubit = ApiDevicesCubit(serverInstallationCubit);
|
||||
final apiVolumesCubit = ApiProviderVolumeCubit(serverInstallationCubit);
|
||||
final apiServerVolumesCubit = ApiServerVolumeCubit(serverInstallationCubit);
|
||||
final apiServerVolumesCubit = ApiServerVolumeCubit(serverInstallationCubit, apiVolumesCubit);
|
||||
final serverJobsCubit = ServerJobsCubit(serverInstallationCubit);
|
||||
final serverDetailsCubit = ServerDetailsCubit(serverInstallationCubit);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_pro
|
|||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||
|
||||
part 'provider_volume_state.dart';
|
||||
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/provider_volumes/provider_volume_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||
import 'package:selfprivacy/logic/models/json/server_disk_volume.dart';
|
||||
|
||||
part 'server_volume_state.dart';
|
||||
|
||||
class ApiServerVolumeCubit
|
||||
extends ServerInstallationDependendCubit<ApiServerVolumeState> {
|
||||
ApiServerVolumeCubit(final ServerInstallationCubit serverInstallationCubit)
|
||||
: super(serverInstallationCubit, const ApiServerVolumeState.initial());
|
||||
ApiServerVolumeCubit(
|
||||
final ServerInstallationCubit serverInstallationCubit, this.providerVolumeCubit,
|
||||
) : super(serverInstallationCubit, ApiServerVolumeState.initial()) {
|
||||
_providerVolumeSubscription =
|
||||
providerVolumeCubit.stream.listen(checkProviderVolumes);
|
||||
}
|
||||
|
||||
final ServerApi serverApi = ServerApi();
|
||||
|
||||
|
@ -19,6 +27,21 @@ class ApiServerVolumeCubit
|
|||
}
|
||||
}
|
||||
|
||||
late StreamSubscription<ApiProviderVolumeState> _providerVolumeSubscription;
|
||||
final ApiProviderVolumeCubit providerVolumeCubit;
|
||||
|
||||
void checkProviderVolumes(final ApiProviderVolumeState state) {
|
||||
emit(
|
||||
ApiServerVolumeState(
|
||||
this.state._volumes,
|
||||
this.state.status,
|
||||
this.state.usesBinds,
|
||||
DiskStatus.fromVolumes(this.state._volumes, state.volumes),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Future<void> _refetch() async {
|
||||
final volumes = await serverApi.getServerDiskVolumes();
|
||||
final usesBinds = await serverApi.isUsingBinds();
|
||||
|
@ -28,11 +51,27 @@ class ApiServerVolumeCubit
|
|||
status = LoadingStatus.success;
|
||||
}
|
||||
|
||||
emit(ApiServerVolumeState(volumes, status, usesBinds));
|
||||
emit(
|
||||
ApiServerVolumeState(
|
||||
volumes,
|
||||
status,
|
||||
usesBinds,
|
||||
DiskStatus.fromVolumes(
|
||||
volumes,
|
||||
providerVolumeCubit.state.volumes,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void clear() {
|
||||
emit(const ApiServerVolumeState.initial());
|
||||
emit(ApiServerVolumeState.initial());
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_providerVolumeSubscription.cancel();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,26 +5,33 @@ class ApiServerVolumeState extends ServerInstallationDependendState {
|
|||
this._volumes,
|
||||
this.status,
|
||||
this.usesBinds,
|
||||
this._diskStatus,
|
||||
);
|
||||
|
||||
const ApiServerVolumeState.initial()
|
||||
: this(const [], LoadingStatus.uninitialized, null);
|
||||
ApiServerVolumeState.initial()
|
||||
: this(const [], LoadingStatus.uninitialized, null, DiskStatus());
|
||||
|
||||
final List<ServerDiskVolume> _volumes;
|
||||
final DiskStatus _diskStatus;
|
||||
final bool? usesBinds;
|
||||
final LoadingStatus status;
|
||||
|
||||
List<ServerDiskVolume> get volumes => _volumes;
|
||||
List<DiskVolume> get volumes => _diskStatus.diskVolumes;
|
||||
DiskStatus get diskStatus => _diskStatus;
|
||||
|
||||
DiskVolume getVolume(final String volumeName) => volumes.firstWhere((final volume) => volume.name == volumeName, orElse: () => DiskVolume());
|
||||
|
||||
ApiServerVolumeState copyWith({
|
||||
final List<ServerDiskVolume>? volumes,
|
||||
final LoadingStatus? status,
|
||||
final bool? usesBinds,
|
||||
final DiskStatus? diskStatus,
|
||||
}) =>
|
||||
ApiServerVolumeState(
|
||||
volumes ?? _volumes,
|
||||
status ?? this.status,
|
||||
usesBinds ?? this.usesBinds,
|
||||
diskStatus ?? _diskStatus,
|
||||
);
|
||||
|
||||
@override
|
||||
|
|
|
@ -2,7 +2,6 @@ import 'package:easy_localization/easy_localization.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:ionicons/ionicons.dart';
|
||||
import 'package:selfprivacy/config/brand_theme.dart';
|
||||
import 'package:selfprivacy/logic/cubit/provider_volumes/provider_volume_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/services/services_cubit.dart';
|
||||
|
@ -12,7 +11,6 @@ import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
|||
import 'package:selfprivacy/ui/pages/devices/devices.dart';
|
||||
import 'package:selfprivacy/ui/pages/recovery_key/recovery_key.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/data_migration.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/ui/pages/setup/initializing.dart';
|
||||
import 'package:selfprivacy/ui/pages/onboarding/onboarding.dart';
|
||||
import 'package:selfprivacy/ui/pages/root_route.dart';
|
||||
|
@ -53,10 +51,7 @@ class MorePage extends StatelessWidget {
|
|||
title: 'providers.storage.start_migration_button'.tr(),
|
||||
iconData: Icons.drive_file_move_outline,
|
||||
goTo: DataMigrationPage(
|
||||
diskStatus: DiskStatus.fromVolumes(
|
||||
context.read<ApiServerVolumeCubit>().state.volumes,
|
||||
context.read<ApiProviderVolumeCubit>().state.volumes,
|
||||
),
|
||||
diskStatus: context.watch<ApiServerVolumeCubit>().state.diskStatus,
|
||||
services: context
|
||||
.read<ServicesCubit>()
|
||||
.state
|
||||
|
|
|
@ -3,12 +3,9 @@ import 'package:flutter/material.dart';
|
|||
import 'package:selfprivacy/config/brand_theme.dart';
|
||||
import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/dns_records/dns_records_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/provider_volumes/provider_volume_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/providers/providers_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/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/models/json/server_disk_volume.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
||||
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
||||
|
@ -16,7 +13,6 @@ import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
|||
import 'package:selfprivacy/ui/pages/backup_details/backup_details.dart';
|
||||
import 'package:selfprivacy/ui/pages/dns_details/dns_details.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_details/server_details_screen.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||
|
||||
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
@ -38,11 +34,7 @@ class _ProvidersPageState extends State<ProvidersPage> {
|
|||
final DnsRecordsStatus dnsStatus =
|
||||
context.watch<DnsRecordsCubit>().state.dnsState;
|
||||
|
||||
final List<ServerDiskVolume> serverVolumes =
|
||||
context.watch<ApiServerVolumeCubit>().state.volumes;
|
||||
final List<ServerVolume> providerVolumes =
|
||||
context.watch<ApiProviderVolumeCubit>().state.volumes;
|
||||
final diskStatus = DiskStatus.fromVolumes(serverVolumes, providerVolumes);
|
||||
final diskStatus = context.watch<ApiServerVolumeCubit>().state.diskStatus;
|
||||
|
||||
final ServerInstallationState appConfig =
|
||||
context.watch<ServerInstallationCubit>().state;
|
||||
|
|
|
@ -4,7 +4,6 @@ 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/hetzner_metrics/hetzner_metrics_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/provider_volumes/provider_volume_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';
|
||||
|
@ -19,7 +18,6 @@ import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
|||
import 'package:selfprivacy/ui/components/switch_block/switch_bloc.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/storage_card.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_details/time_zone/lang.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/utils/extensions/duration.dart';
|
||||
import 'package:selfprivacy/utils/named_font_weight.dart';
|
||||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||
|
@ -83,10 +81,7 @@ class _ServerDetailsScreenState extends State<ServerDetailsScreen>
|
|||
heroSubtitle: 'providers.server.bottom_sheet.1'.tr(),
|
||||
children: [
|
||||
StorageCard(
|
||||
diskStatus: DiskStatus.fromVolumes(
|
||||
context.read<ApiServerVolumeCubit>().state.volumes,
|
||||
context.read<ApiProviderVolumeCubit>().state.volumes,
|
||||
),
|
||||
diskStatus: context.watch<ApiServerVolumeCubit>().state.diskStatus,
|
||||
),
|
||||
const Divider(height: 32),
|
||||
Text(
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'package:selfprivacy/logic/models/service.dart';
|
|||
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
||||
import 'package:selfprivacy/ui/components/info_box/info_box.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/server_storage_list_item.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/service_migration_list_item.dart';
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'package:selfprivacy/logic/cubit/provider_volumes/provider_volume_cubit.d
|
|||
import 'package:selfprivacy/logic/models/disk_size.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/filled_button.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||
|
||||
class ExtendingVolumePage extends StatefulWidget {
|
||||
const ExtendingVolumePage({
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_button/outlined_button.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/extending_volume.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/server_storage_list_item.dart';
|
||||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_linear_indicator/brand_linear_indicator.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||
|
||||
class ServerStorageListItem extends StatelessWidget {
|
||||
const ServerStorageListItem({
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:selfprivacy/logic/models/service.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||
|
||||
class ServiceMigrationListItem extends StatelessWidget {
|
||||
const ServiceMigrationListItem({
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||
import 'package:selfprivacy/logic/cubit/providers/providers_cubit.dart';
|
||||
import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/disk_status.dart';
|
||||
import 'package:selfprivacy/logic/models/disk_status.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/server_storage.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/server_storage_list_item.dart';
|
||||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||
|
|
|
@ -117,6 +117,10 @@ class _ServicePageState extends State<ServicePage> {
|
|||
'services.service_page.move'.tr(),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
// subtitle: Text(
|
||||
// 'Uses ${service.storageUsage.used} on ${context.read<ApiServerVolumeCubit>().state.totalStorage}',
|
||||
// style: Theme.of(context).textTheme.bodyMedium,
|
||||
// ),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue