selfprivacy.org.app/lib/ui/pages/users/users.dart

157 lines
6.2 KiB
Dart
Raw Normal View History

import 'package:auto_route/auto_route.dart';
2021-01-14 18:45:10 +00:00
import 'package:cubit_form/cubit_form.dart';
import 'package:easy_localization/easy_localization.dart';
2020-12-03 16:52:53 +00:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/config/brand_theme.dart';
import 'package:selfprivacy/config/get_it_config.dart';
import 'package:selfprivacy/logic/bloc/outdated_server_checker/outdated_server_checker_bloc.dart';
import 'package:selfprivacy/logic/bloc/users/users_bloc.dart';
2024-01-31 05:14:23 +00:00
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
2024-01-31 05:14:23 +00:00
import 'package:selfprivacy/logic/cubit/forms/user/ssh_form_cubit.dart';
2021-01-14 18:45:10 +00:00
import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
2024-03-09 16:30:43 +00:00
import 'package:selfprivacy/logic/cubit/server_detailed_info/server_detailed_info_cubit.dart';
2024-01-31 05:14:23 +00:00
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
import 'package:selfprivacy/logic/models/hive/user.dart';
2024-01-31 05:14:23 +00:00
import 'package:selfprivacy/logic/models/job.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/buttons/brand_button.dart';
import 'package:selfprivacy/ui/components/buttons/outlined_button.dart';
2023-04-05 10:33:53 +00:00
import 'package:selfprivacy/ui/components/cards/filled_card.dart';
import 'package:selfprivacy/ui/components/info_box/info_box.dart';
import 'package:selfprivacy/ui/components/list_tiles/list_tile_on_surface_variant.dart';
import 'package:selfprivacy/ui/components/server_outdated_card/server_outdated_card.dart';
2024-01-31 05:14:23 +00:00
import 'package:selfprivacy/ui/helpers/empty_page_placeholder.dart';
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
import 'package:selfprivacy/ui/router/router.dart';
import 'package:selfprivacy/utils/breakpoints.dart';
import 'package:selfprivacy/utils/platform_adapter.dart';
2021-03-26 13:38:39 +00:00
import 'package:selfprivacy/utils/ui_helpers.dart';
2020-12-03 16:52:53 +00:00
2021-01-06 17:35:57 +00:00
part 'new_user.dart';
2024-01-31 05:14:23 +00:00
part 'reset_password.dart';
2021-01-06 17:35:57 +00:00
part 'user.dart';
part 'user_details.dart';
2021-01-06 17:35:57 +00:00
@RoutePage()
2020-12-03 16:52:53 +00:00
class UsersPage extends StatelessWidget {
const UsersPage({super.key});
2020-12-03 16:52:53 +00:00
@override
Widget build(final BuildContext context) {
final bool isReady = context.watch<ServerInstallationCubit>().state
is ServerInstallationFinished;
2021-01-06 17:35:57 +00:00
Widget child;
final OutdatedServerCheckerState outdatedServerCheckerState =
context.watch<OutdatedServerCheckerBloc>().state;
2021-01-06 17:35:57 +00:00
if (!isReady) {
child = EmptyPagePlaceholder(
showReadyCard: true,
title: 'users.nobody_here'.tr(),
description: 'basis.please_connect'.tr(),
iconData: BrandIcons.users,
);
2021-01-06 17:35:57 +00:00
} else {
child = BlocBuilder<UsersBloc, UsersState>(
builder: (final BuildContext context, final UsersState state) {
final users = state.orderedUsers;
if (users.isEmpty) {
if (state is UsersRefreshing) {
return const Center(
child: CircularProgressIndicator.adaptive(),
);
}
return RefreshIndicator(
onRefresh: () async {
await context.read<UsersBloc>().refresh();
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
EmptyPagePlaceholder(
title: 'users.could_not_fetch_users'.tr(),
description: 'users.could_not_fetch_description'.tr(),
iconData: BrandIcons.users,
),
const SizedBox(height: 18),
BrandOutlinedButton(
onPressed: () {
context.read<UsersBloc>().refresh();
},
title: 'users.refresh_users'.tr(),
),
],
),
),
),
);
}
2022-03-23 14:07:52 +00:00
return RefreshIndicator(
onRefresh: () async {
await context.read<UsersBloc>().refresh();
2022-03-23 14:07:52 +00:00
},
child: Column(
children: [
if (outdatedServerCheckerState
is OutdatedServerCheckerOutdated) ...[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: ServerOutdatedCard(
requiredVersion:
outdatedServerCheckerState.requiredVersion.toString(),
currentVersion:
outdatedServerCheckerState.currentVersion.toString(),
),
),
],
Padding(
padding: const EdgeInsets.all(8.0),
child: FilledButton.tonal(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.person_add_outlined),
const SizedBox(width: 8),
Text('users.new_user'.tr()),
],
),
onPressed: () {
context.pushRoute(const NewUserRoute());
},
),
),
Expanded(
child: ListView.builder(
itemCount: users.length,
itemBuilder:
(final BuildContext context, final int index) => _User(
user: users[index],
isPrimaryUser: users[index].type == UserType.primary,
),
),
),
],
2022-03-23 14:07:52 +00:00
),
);
},
);
2021-01-06 17:35:57 +00:00
}
2020-12-03 16:52:53 +00:00
return Scaffold(
appBar: Breakpoints.small.isActive(context)
? BrandHeader(
title: 'basis.users'.tr(),
)
: null,
2021-01-06 17:35:57 +00:00
body: child,
2020-12-03 16:52:53 +00:00
);
}
}