2023-02-24 16:45:32 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2021-01-14 18:45:10 +00:00
|
|
|
import 'package:cubit_form/cubit_form.dart';
|
2022-03-03 17:38:30 +00:00
|
|
|
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';
|
2022-09-08 15:13:18 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/forms/user/ssh_form_cubit.dart';
|
2022-05-17 13:31:34 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2022-05-04 16:58:47 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
2021-01-14 18:45:10 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
|
2022-08-30 03:09:09 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
2020-12-03 16:52:53 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
2021-08-29 15:02:51 +00:00
|
|
|
import 'package:selfprivacy/logic/models/job.dart';
|
2022-05-14 02:54:40 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
2023-03-27 17:02:44 +00:00
|
|
|
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';
|
2020-12-03 16:52:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart';
|
2020-12-03 16:52:53 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
2022-09-14 16:45:50 +00:00
|
|
|
import 'package:selfprivacy/ui/components/info_box/info_box.dart';
|
2022-09-18 13:24:17 +00:00
|
|
|
import 'package:selfprivacy/ui/components/list_tiles/list_tile_on_surface_variant.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
2023-02-24 16:45:32 +00:00
|
|
|
import 'package:selfprivacy/ui/router/router.dart';
|
2023-02-23 14:49:14 +00:00
|
|
|
import 'package:selfprivacy/utils/breakpoints.dart';
|
2021-03-26 13:38:39 +00:00
|
|
|
import 'package:selfprivacy/utils/ui_helpers.dart';
|
2020-12-03 16:52:53 +00:00
|
|
|
|
2022-03-03 17:38:30 +00:00
|
|
|
part 'empty.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
part 'new_user.dart';
|
|
|
|
part 'user.dart';
|
2022-03-03 17:38:30 +00:00
|
|
|
part 'user_details.dart';
|
2022-09-18 20:25:26 +00:00
|
|
|
part 'reset_password.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
|
2023-03-22 11:38:18 +00:00
|
|
|
@RoutePage()
|
2020-12-03 16:52:53 +00:00
|
|
|
class UsersPage extends StatelessWidget {
|
2022-10-26 16:26:09 +00:00
|
|
|
const UsersPage({super.key});
|
2020-12-03 16:52:53 +00:00
|
|
|
|
|
|
|
@override
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget build(final BuildContext context) {
|
|
|
|
final bool isReady = context.watch<ServerInstallationCubit>().state
|
2022-05-17 13:31:34 +00:00
|
|
|
is ServerInstallationFinished;
|
2021-01-06 17:35:57 +00:00
|
|
|
Widget child;
|
|
|
|
|
|
|
|
if (!isReady) {
|
|
|
|
child = isNotReady();
|
|
|
|
} else {
|
2022-03-23 14:07:52 +00:00
|
|
|
child = BlocBuilder<UsersCubit, UsersState>(
|
2022-06-05 22:40:34 +00:00
|
|
|
builder: (final BuildContext context, final UsersState state) {
|
2022-09-05 10:51:01 +00:00
|
|
|
final List<User> users = state.users
|
|
|
|
.where((final user) => user.type != UserType.root)
|
|
|
|
.toList();
|
|
|
|
// final List<User> users = [];
|
|
|
|
users.sort(
|
|
|
|
(final User a, final User b) =>
|
|
|
|
a.login.toLowerCase().compareTo(b.login.toLowerCase()),
|
|
|
|
);
|
2022-03-23 14:07:52 +00:00
|
|
|
|
2022-09-05 10:51:01 +00:00
|
|
|
if (users.isEmpty) {
|
|
|
|
if (state.isLoading) {
|
|
|
|
return const Center(
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return RefreshIndicator(
|
|
|
|
onRefresh: () async {
|
2023-03-27 17:29:02 +00:00
|
|
|
await context.read<UsersCubit>().refresh();
|
2022-09-05 10:51:01 +00:00
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
_CouldNotLoadUsers(
|
|
|
|
text: 'users.could_not_fetch_description'.tr(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 18),
|
|
|
|
BrandOutlinedButton(
|
|
|
|
onPressed: () {
|
|
|
|
context.read<UsersCubit>().refresh();
|
|
|
|
},
|
|
|
|
title: 'users.refresh_users'.tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-03-23 14:07:52 +00:00
|
|
|
return RefreshIndicator(
|
|
|
|
onRefresh: () async {
|
2023-03-27 17:29:02 +00:00
|
|
|
await context.read<UsersCubit>().refresh();
|
2022-03-23 14:07:52 +00:00
|
|
|
},
|
2023-02-24 16:45:32 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
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],
|
|
|
|
isRootUser: 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(
|
2023-02-23 14:49:14 +00:00
|
|
|
appBar: Breakpoints.small.isActive(context)
|
|
|
|
? PreferredSize(
|
|
|
|
preferredSize: const Size.fromHeight(52),
|
|
|
|
child: BrandHeader(
|
|
|
|
title: 'basis.users'.tr(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
2021-01-06 17:35:57 +00:00
|
|
|
body: child,
|
2020-12-03 16:52:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
Widget isNotReady() => Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
child: NotReadyCard(),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
|
|
|
child: Center(
|
|
|
|
child: _NoUsers(
|
|
|
|
text: 'users.not_ready'.tr(),
|
|
|
|
),
|
2020-12-03 16:52:53 +00:00
|
|
|
),
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
2020-12-03 16:52:53 +00:00
|
|
|
}
|