2022-07-31 23:10:37 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-09-18 16:06:17 +00:00
|
|
|
import 'package:flutter_svg/svg.dart';
|
2022-07-31 23:10:37 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2022-09-18 16:06:17 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/services/services_cubit.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/service.dart';
|
2022-08-24 05:35:49 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_button/outlined_button.dart';
|
2022-07-31 23:10:37 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
2022-09-16 11:28:17 +00:00
|
|
|
import 'package:selfprivacy/logic/models/disk_status.dart';
|
2022-08-03 02:25:33 +00:00
|
|
|
import 'package:selfprivacy/ui/pages/server_storage/extending_volume.dart';
|
2022-09-16 13:49:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/storage_list_items/server_storage_list_item.dart';
|
2022-08-03 02:25:33 +00:00
|
|
|
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
2022-07-31 23:10:37 +00:00
|
|
|
|
|
|
|
class ServerStoragePage extends StatefulWidget {
|
|
|
|
const ServerStoragePage({required this.diskStatus, final super.key});
|
|
|
|
|
|
|
|
final DiskStatus diskStatus;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<ServerStoragePage> createState() => _ServerStoragePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ServerStoragePageState extends State<ServerStoragePage> {
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final bool isReady = context.watch<ServerInstallationCubit>().state
|
|
|
|
is ServerInstallationFinished;
|
|
|
|
|
2022-09-18 16:06:17 +00:00
|
|
|
final List<Service> services =
|
|
|
|
context.watch<ServicesCubit>().state.services;
|
|
|
|
|
2022-07-31 23:10:37 +00:00
|
|
|
if (!isReady) {
|
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
2022-10-03 23:32:35 +00:00
|
|
|
heroTitle: 'storage.card_title'.tr(),
|
2022-07-31 23:10:37 +00:00
|
|
|
children: const [],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return BrandHeroScreen(
|
|
|
|
hasBackButton: true,
|
2022-10-03 23:32:35 +00:00
|
|
|
heroTitle: 'storage.card_title'.tr(),
|
2022-07-31 23:10:37 +00:00
|
|
|
children: [
|
2022-08-24 05:35:49 +00:00
|
|
|
// ...sections,
|
|
|
|
...widget.diskStatus.diskVolumes
|
|
|
|
.map(
|
|
|
|
(final volume) => Column(
|
2022-09-18 16:06:17 +00:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
2022-08-24 05:35:49 +00:00
|
|
|
children: [
|
|
|
|
ServerStorageSection(
|
|
|
|
volume: volume,
|
|
|
|
diskStatus: widget.diskStatus,
|
2022-09-18 16:06:17 +00:00
|
|
|
services: services
|
|
|
|
.where(
|
|
|
|
(final service) =>
|
|
|
|
service.storageUsage.volume == volume.name,
|
|
|
|
)
|
|
|
|
.toList(),
|
2022-08-24 05:35:49 +00:00
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
const Divider(),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
2022-07-31 23:10:37 +00:00
|
|
|
const SizedBox(height: 8),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-08-24 05:35:49 +00:00
|
|
|
|
|
|
|
class ServerStorageSection extends StatelessWidget {
|
|
|
|
const ServerStorageSection({
|
|
|
|
required this.volume,
|
|
|
|
required this.diskStatus,
|
2022-09-18 16:06:17 +00:00
|
|
|
required this.services,
|
2022-08-24 05:35:49 +00:00
|
|
|
final super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final DiskVolume volume;
|
|
|
|
final DiskStatus diskStatus;
|
2022-09-18 16:06:17 +00:00
|
|
|
final List<Service> services;
|
2022-08-24 05:35:49 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) => Column(
|
2022-09-18 16:06:17 +00:00
|
|
|
mainAxisSize: MainAxisSize.min,
|
2022-08-24 05:35:49 +00:00
|
|
|
children: [
|
|
|
|
ServerStorageListItem(
|
|
|
|
volume: volume,
|
|
|
|
),
|
2022-09-18 16:06:17 +00:00
|
|
|
const SizedBox(height: 16),
|
|
|
|
...services
|
|
|
|
.map(
|
|
|
|
(final service) => ServerConsumptionListTile(
|
|
|
|
service: service,
|
|
|
|
volume: volume,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
2022-08-24 05:35:49 +00:00
|
|
|
if (volume.isResizable) ...[
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
BrandOutlinedButton(
|
2022-10-03 23:32:35 +00:00
|
|
|
title: 'storage.extend_volume_button.title'.tr(),
|
2022-08-24 05:35:49 +00:00
|
|
|
onPressed: () => Navigator.of(context).push(
|
|
|
|
materialRoute(
|
|
|
|
ExtendingVolumePage(
|
|
|
|
diskVolumeToResize: volume,
|
|
|
|
diskStatus: diskStatus,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2022-09-18 16:06:17 +00:00
|
|
|
|
|
|
|
class ServerConsumptionListTile extends StatelessWidget {
|
|
|
|
const ServerConsumptionListTile({
|
|
|
|
required this.service,
|
|
|
|
required this.volume,
|
|
|
|
final super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final Service service;
|
|
|
|
final DiskVolume volume;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(final BuildContext context) => Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
child: ConsumptionListItem(
|
|
|
|
title: service.displayName,
|
|
|
|
icon: SvgPicture.string(
|
|
|
|
service.svgIcon,
|
|
|
|
width: 24.0,
|
|
|
|
height: 24.0,
|
|
|
|
color: Theme.of(context).colorScheme.onBackground,
|
|
|
|
),
|
|
|
|
rightSideText: service.storageUsage.used.toString(),
|
|
|
|
percentage: service.storageUsage.used.byte / volume.sizeTotal.byte,
|
|
|
|
color: volume.root
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Theme.of(context).colorScheme.secondary,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
|
|
|
|
dense: true,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|