mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-11 18:39:45 +00:00
Move disk status converting to disk status constructor
This commit is contained in:
parent
a693f694ac
commit
88a1393a1d
|
@ -8,11 +8,7 @@ class ApiServerVolumeState extends ServerInstallationDependendState {
|
||||||
);
|
);
|
||||||
|
|
||||||
const ApiServerVolumeState.initial()
|
const ApiServerVolumeState.initial()
|
||||||
: this(
|
: this(const [], LoadingStatus.uninitialized, null);
|
||||||
const [],
|
|
||||||
LoadingStatus.uninitialized,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
final List<ServerDiskVolume> _volumes;
|
final List<ServerDiskVolume> _volumes;
|
||||||
final bool? usesBinds;
|
final bool? usesBinds;
|
||||||
|
|
|
@ -7,9 +7,6 @@ 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_installation/server_installation_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/provider_volumes/provider_volume_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/provider_volumes/provider_volume_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/disk_size.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/json/server_disk_volume.dart';
|
|
||||||
import 'package:selfprivacy/logic/models/provider.dart';
|
import 'package:selfprivacy/logic/models/provider.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
||||||
|
@ -78,7 +75,7 @@ class _ProvidersPageState extends State<ProvidersPage> {
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 30),
|
padding: const EdgeInsets.only(bottom: 30),
|
||||||
child: StorageCard(
|
child: StorageCard(
|
||||||
diskStatus: toDiskStatus(
|
diskStatus: DiskStatus.fromVolumes(
|
||||||
context.read<ApiServerVolumeCubit>().state.volumes,
|
context.read<ApiServerVolumeCubit>().state.volumes,
|
||||||
context.read<ApiProviderVolumeCubit>().state.volumes,
|
context.read<ApiProviderVolumeCubit>().state.volumes,
|
||||||
),
|
),
|
||||||
|
@ -104,60 +101,6 @@ class _ProvidersPageState extends State<ProvidersPage> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DiskStatus toDiskStatus(
|
|
||||||
final List<ServerDiskVolume> serverVolumes,
|
|
||||||
final List<ServerVolume> providerVolumes,
|
|
||||||
) {
|
|
||||||
final DiskStatus diskStatus = DiskStatus();
|
|
||||||
diskStatus.isDiskOkay = true;
|
|
||||||
|
|
||||||
if (providerVolumes.isEmpty || serverVolumes.isEmpty) {
|
|
||||||
diskStatus.isDiskOkay = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
diskStatus.diskVolumes = serverVolumes.map((
|
|
||||||
final ServerDiskVolume volume,
|
|
||||||
) {
|
|
||||||
final DiskVolume diskVolume = DiskVolume();
|
|
||||||
diskVolume.sizeUsed = DiskSize(
|
|
||||||
byte: volume.usedSpace == 'None' ? 0 : int.parse(volume.usedSpace),
|
|
||||||
);
|
|
||||||
diskVolume.sizeTotal = DiskSize(
|
|
||||||
byte: volume.totalSpace == 'None' ? 0 : int.parse(volume.totalSpace),
|
|
||||||
);
|
|
||||||
diskVolume.serverDiskVolume = volume;
|
|
||||||
|
|
||||||
for (final ServerVolume providerVolume in providerVolumes) {
|
|
||||||
if (providerVolume.linuxDevice == null ||
|
|
||||||
volume.model == null ||
|
|
||||||
volume.serial == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String deviceId = providerVolume.linuxDevice!.split('/').last;
|
|
||||||
if (deviceId.contains(volume.model!) &&
|
|
||||||
deviceId.contains(volume.serial!)) {
|
|
||||||
diskVolume.providerVolume = providerVolume;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
diskVolume.name = volume.name;
|
|
||||||
diskVolume.root = volume.root;
|
|
||||||
diskVolume.percentage =
|
|
||||||
volume.usedSpace != 'None' && volume.totalSpace != 'None'
|
|
||||||
? 1.0 / diskVolume.sizeTotal.byte * diskVolume.sizeUsed.byte
|
|
||||||
: 0.0;
|
|
||||||
if (diskVolume.percentage >= 0.8 ||
|
|
||||||
diskVolume.sizeTotal.asGb() - diskVolume.sizeUsed.asGb() <= 2.0) {
|
|
||||||
diskStatus.isDiskOkay = false;
|
|
||||||
}
|
|
||||||
return diskVolume;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
return diskStatus;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _Card extends StatelessWidget {
|
class _Card extends StatelessWidget {
|
||||||
|
|
|
@ -16,6 +16,62 @@ class DiskVolume {
|
||||||
}
|
}
|
||||||
|
|
||||||
class DiskStatus {
|
class DiskStatus {
|
||||||
|
DiskStatus() {
|
||||||
|
isDiskOkay = false;
|
||||||
|
diskVolumes = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
DiskStatus.fromVolumes(
|
||||||
|
final List<ServerDiskVolume> serverVolumes,
|
||||||
|
final List<ServerVolume> providerVolumes,
|
||||||
|
) {
|
||||||
|
isDiskOkay = true;
|
||||||
|
|
||||||
|
if (providerVolumes.isEmpty || serverVolumes.isEmpty) {
|
||||||
|
isDiskOkay = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
diskVolumes = serverVolumes.map((
|
||||||
|
final ServerDiskVolume volume,
|
||||||
|
) {
|
||||||
|
final DiskVolume diskVolume = DiskVolume();
|
||||||
|
diskVolume.sizeUsed = DiskSize(
|
||||||
|
byte: volume.usedSpace == 'None' ? 0 : int.parse(volume.usedSpace),
|
||||||
|
);
|
||||||
|
diskVolume.sizeTotal = DiskSize(
|
||||||
|
byte: volume.totalSpace == 'None' ? 0 : int.parse(volume.totalSpace),
|
||||||
|
);
|
||||||
|
diskVolume.serverDiskVolume = volume;
|
||||||
|
|
||||||
|
for (final ServerVolume providerVolume in providerVolumes) {
|
||||||
|
if (providerVolume.linuxDevice == null ||
|
||||||
|
volume.model == null ||
|
||||||
|
volume.serial == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String deviceId = providerVolume.linuxDevice!.split('/').last;
|
||||||
|
if (deviceId.contains(volume.model!) &&
|
||||||
|
deviceId.contains(volume.serial!)) {
|
||||||
|
diskVolume.providerVolume = providerVolume;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
diskVolume.name = volume.name;
|
||||||
|
diskVolume.root = volume.root;
|
||||||
|
diskVolume.percentage =
|
||||||
|
volume.usedSpace != 'None' && volume.totalSpace != 'None'
|
||||||
|
? 1.0 / diskVolume.sizeTotal.byte * diskVolume.sizeUsed.byte
|
||||||
|
: 0.0;
|
||||||
|
if (diskVolume.percentage >= 0.8 ||
|
||||||
|
diskVolume.sizeTotal.asGb() - diskVolume.sizeUsed.asGb() <= 2.0) {
|
||||||
|
isDiskOkay = false;
|
||||||
|
}
|
||||||
|
return diskVolume;
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
bool isDiskOkay = false;
|
bool isDiskOkay = false;
|
||||||
List<DiskVolume> diskVolumes = [];
|
List<DiskVolume> diskVolumes = [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue