2021-05-25 21:53:54 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-07-29 05:24:42 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2021-06-20 21:08:52 +00:00
|
|
|
import 'package:selfprivacy/config/brand_theme.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/config/get_it_config.dart';
|
2022-08-30 03:09:09 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
|
2022-05-18 09:07:14 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2022-08-30 03:09:09 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_jobs/server_jobs_cubit.dart';
|
2021-12-06 18:31:19 +00:00
|
|
|
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
2021-05-25 21:53:54 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_cards/brand_cards.dart';
|
2021-07-29 05:24:42 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_loader/brand_loader.dart';
|
2021-05-25 21:53:54 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
2022-08-26 02:34:25 +00:00
|
|
|
import 'package:selfprivacy/ui/components/jobs_content/server_job_card.dart';
|
2021-05-25 21:53:54 +00:00
|
|
|
|
|
|
|
class JobsContent extends StatelessWidget {
|
2022-06-05 22:40:34 +00:00
|
|
|
const JobsContent({final super.key});
|
2021-05-25 21:53:54 +00:00
|
|
|
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) => BlocBuilder<JobsCubit, JobsState>(
|
2022-06-05 22:40:34 +00:00
|
|
|
builder: (final context, final state) {
|
|
|
|
late List<Widget> widgets;
|
|
|
|
final ServerInstallationState installationState =
|
|
|
|
context.read<ServerInstallationCubit>().state;
|
|
|
|
if (state is JobsStateEmpty) {
|
2022-05-18 09:07:14 +00:00
|
|
|
widgets = [
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(height: 80),
|
2022-06-05 22:40:34 +00:00
|
|
|
Center(child: BrandText.body1('jobs.empty'.tr())),
|
2022-05-18 09:07:14 +00:00
|
|
|
];
|
2022-06-05 22:40:34 +00:00
|
|
|
|
|
|
|
if (installationState is ServerInstallationFinished) {
|
|
|
|
widgets = [
|
|
|
|
...widgets,
|
|
|
|
const SizedBox(height: 80),
|
|
|
|
BrandButton.rised(
|
|
|
|
onPressed: () => context.read<JobsCubit>().upgradeServer(),
|
|
|
|
text: 'jobs.upgradeServer'.tr(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
BrandButton.text(
|
|
|
|
onPressed: () {
|
|
|
|
final NavigationService nav = getIt<NavigationService>();
|
|
|
|
nav.showPopUpDialog(
|
|
|
|
BrandAlert(
|
|
|
|
title: 'jobs.rebootServer'.tr(),
|
|
|
|
contentText: 'modals.3'.tr(),
|
|
|
|
actions: [
|
|
|
|
ActionButton(
|
|
|
|
text: 'basis.cancel'.tr(),
|
|
|
|
),
|
|
|
|
ActionButton(
|
|
|
|
onPressed: () =>
|
|
|
|
{context.read<JobsCubit>().rebootServer()},
|
|
|
|
text: 'modals.9'.tr(),
|
|
|
|
)
|
|
|
|
],
|
2021-05-25 21:53:54 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
title: 'jobs.rebootServer'.tr(),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
} else if (state is JobsStateLoading) {
|
|
|
|
widgets = [
|
|
|
|
const SizedBox(height: 80),
|
|
|
|
BrandLoader.horizontal(),
|
|
|
|
];
|
|
|
|
} else if (state is JobsStateWithJobs) {
|
|
|
|
widgets = [
|
2022-08-24 05:35:49 +00:00
|
|
|
...state.clientJobList
|
2022-06-05 22:40:34 +00:00
|
|
|
.map(
|
|
|
|
(final j) => Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: BrandCards.small(
|
|
|
|
child: Text(j.title),
|
2021-07-29 05:24:42 +00:00
|
|
|
),
|
2021-05-25 21:53:54 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
const SizedBox(width: 10),
|
|
|
|
ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary:
|
|
|
|
Theme.of(context).colorScheme.errorContainer,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () =>
|
|
|
|
context.read<JobsCubit>().removeJob(j.id),
|
|
|
|
child: Text(
|
|
|
|
'basis.remove'.tr(),
|
2022-06-05 19:36:32 +00:00
|
|
|
style: TextStyle(
|
2022-06-05 22:40:34 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.onErrorContainer,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
BrandButton.rised(
|
|
|
|
onPressed: () => context.read<JobsCubit>().applyAll(),
|
|
|
|
text: 'jobs.start'.tr(),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
return ListView(
|
|
|
|
padding: paddingH15V0,
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 15),
|
|
|
|
Center(
|
|
|
|
child: BrandText.h2(
|
|
|
|
'jobs.title'.tr(),
|
|
|
|
),
|
2021-07-29 05:24:42 +00:00
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
const SizedBox(height: 20),
|
2022-08-26 02:34:25 +00:00
|
|
|
...widgets,
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
const Divider(),
|
|
|
|
const SizedBox(height: 8),
|
2022-08-30 03:09:09 +00:00
|
|
|
...context.read<ServerJobsCubit>().state.serverJobList.map(
|
|
|
|
(final job) => ServerJobCard(
|
|
|
|
serverJob: job,
|
|
|
|
),
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2021-05-25 21:53:54 +00:00
|
|
|
}
|