Skip to content

Commit

Permalink
feat: Add statistics card on landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
astubenbord committed Aug 1, 2023
1 parent f3e660e commit 53a01ae
Show file tree
Hide file tree
Showing 21 changed files with 469 additions and 78 deletions.
1 change: 1 addition & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
project_id: "568557"
files: [
{
"source" : "/lib/l10n/intl_en.arb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,21 +341,14 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
document: state.document,
enabled: isConnected,
),
// //TODO: Enable again, need new pdf viewer package...
// IconButton(
// tooltip: S.of(context)!.previewTooltip,
// icon: const Icon(Icons.visibility),
// onPressed:
// (isConnected) ? () => _onOpen(state.document) : null,
// ).paddedOnly(right: 4.0),
IconButton(
tooltip: S.of(context)!.openInSystemViewer,
icon: const Icon(Icons.open_in_new),
onPressed: isConnected ? _onOpenFileInSystemViewer : null,
).paddedOnly(right: 4.0),
DocumentShareButton(document: state.document),
IconButton(
tooltip: S.of(context)!.print, //TODO: INTL
tooltip: S.of(context)!.print,
onPressed: () =>
context.read<DocumentDetailsCubit>().printDocument(),
icon: const Icon(Icons.print),
Expand Down
13 changes: 4 additions & 9 deletions lib/features/home/view/scaffold_with_navigation_bar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -46,33 +45,29 @@ class ScaffoldWithNavigationBarState extends State<ScaffoldWithNavigationBar> {
if (widget.authenticatedUser.canViewDocuments) {
widget.navigationShell.goBranch(index);
} else {
showSnackBar(context,
"You do not have the required permissions to access this page.");
showSnackBar(context, S.of(context)!.missingPermissions);
}
break;
case _scannerIndex:
if (widget.authenticatedUser.canCreateDocuments) {
widget.navigationShell.goBranch(index);
} else {
showSnackBar(context,
"You do not have the required permissions to access this page.");
showSnackBar(context, S.of(context)!.missingPermissions);
}
break;
case _labelsIndex:
if (widget.authenticatedUser.canViewAnyLabel) {
widget.navigationShell.goBranch(index);
} else {
showSnackBar(context,
"You do not have the required permissions to access this page.");
showSnackBar(context, S.of(context)!.missingPermissions);
}
break;
case _inboxIndex:
if (widget.authenticatedUser.canViewDocuments &&
widget.authenticatedUser.canViewTags) {
widget.navigationShell.goBranch(index);
} else {
showSnackBar(context,
"You do not have the required permissions to access this page.");
showSnackBar(context, S.of(context)!.missingPermissions);
}
break;
default:
Expand Down
1 change: 0 additions & 1 deletion lib/features/inbox/cubit/inbox_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class InboxCubit extends HydratedCubit<InboxState>
Future<void> initialize() async {
await refreshItemsInInboxCount(false);
await loadInbox();
super.initialize();
}

Future<void> refreshItemsInInboxCount([bool shouldLoadInbox = true]) async {
Expand Down
4 changes: 4 additions & 0 deletions lib/features/inbox/view/pages/inbox_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ class _InboxPageState extends State<InboxPage>
}

Future<bool> _onItemDismissed(DocumentModel doc) async {
if (!context.read<LocalUserAccount>().paperlessUser.canEditDocuments) {
showSnackBar(context, S.of(context)!.missingPermissions);
return false;
}
try {
final removedTags = await context.read<InboxCubit>().removeFromInbox(doc);
showSnackBar(
Expand Down
135 changes: 127 additions & 8 deletions lib/features/landing/view/landing_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/database/tables/local_user_account.dart';
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
import 'package:paperless_mobile/features/app_drawer/view/app_drawer.dart';
import 'package:paperless_mobile/features/document_search/view/sliver_search_bar.dart';
import 'package:paperless_mobile/features/landing/view/widgets/expansion_card.dart';
import 'package:paperless_mobile/features/landing/view/widgets/mime_types_pie_chart.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:paperless_mobile/routes/routes.dart';
import 'package:paperless_mobile/routes/typed/branches/documents_route.dart';
import 'package:paperless_mobile/routes/typed/branches/inbox_route.dart';
import 'package:fl_chart/fl_chart.dart';

class LandingPage extends StatefulWidget {
const LandingPage({super.key});
Expand All @@ -14,6 +25,7 @@ class _LandingPageState extends State<LandingPage> {
final _searchBarHandle = SliverOverlapAbsorberHandle();
@override
Widget build(BuildContext context) {
final currentUser = context.watch<LocalUserAccount>().paperlessUser;
return SafeArea(
child: Scaffold(
drawer: const AppDrawer(),
Expand All @@ -29,19 +41,126 @@ class _LandingPageState extends State<LandingPage> {
],
body: CustomScrollView(
slivers: [
SliverPadding(
padding: const EdgeInsets.all(16),
sliver: SliverToBoxAdapter(
child: Text(
"Welcome!",
style: Theme.of(context).textTheme.titleLarge,
),
),
SliverToBoxAdapter(
child: Text(
"Welcome to Paperless Mobile, ${currentUser.fullName ?? currentUser.username}!",
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
.displaySmall
?.copyWith(fontSize: 28),
).padded(24),
),
SliverToBoxAdapter(child: _buildStatisticsCard(context)),
],
),
),
),
);
}

Widget _buildStatisticsCard(BuildContext context) {
return FutureBuilder<PaperlessServerStatisticsModel>(
future: context.read<PaperlessServerStatsApi>().getServerStatistics(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Card(
margin: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Statistics", //TODO: INTL
style: Theme.of(context).textTheme.titleLarge,
),
const Padding(
padding: EdgeInsets.all(16.0),
child: Center(child: CircularProgressIndicator()),
),
],
).padded(16),
);
}
final stats = snapshot.data!;
return ExpansionCard(
title: Text(
"Statistics", //TODO: INTL
style: Theme.of(context).textTheme.titleLarge,
),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Card(
color: Theme.of(context).colorScheme.surfaceVariant,
child: ListTile(
shape: Theme.of(context).cardTheme.shape,
titleTextStyle: Theme.of(context).textTheme.labelLarge,
title: Text("Documents in inbox:"),
onTap: () {
InboxRoute().go(context);
},
trailing: Chip(
padding: EdgeInsets.symmetric(
horizontal: 4,
vertical: 2,
),
labelPadding: EdgeInsets.symmetric(horizontal: 4),
label: Text(
stats.documentsInInbox.toString(),
),
),
),
),
Card(
color: Theme.of(context).colorScheme.surfaceVariant,
child: ListTile(
shape: Theme.of(context).cardTheme.shape,
titleTextStyle: Theme.of(context).textTheme.labelLarge,
title: Text("Total documents:"),
onTap: () {
DocumentsRoute().go(context);
},
trailing: Chip(
padding: EdgeInsets.symmetric(
horizontal: 4,
vertical: 2,
),
labelPadding: EdgeInsets.symmetric(horizontal: 4),
label: Text(
stats.documentsTotal.toString(),
),
),
),
),
Card(
color: Theme.of(context).colorScheme.surfaceVariant,
child: ListTile(
shape: Theme.of(context).cardTheme.shape,
titleTextStyle: Theme.of(context).textTheme.labelLarge,
title: Text("Total characters:"),
trailing: Chip(
padding: const EdgeInsets.symmetric(
horizontal: 4,
vertical: 2,
),
labelPadding: EdgeInsets.symmetric(horizontal: 4),
label: Text(
stats.totalChars.toString(),
),
),
),
),
AspectRatio(
aspectRatio: 1.3,
child: SizedBox(
width: 300,
child: MimeTypesPieChart(statistics: stats),
),
),
],
).padded(16),
);
},
);
}
}
33 changes: 33 additions & 0 deletions lib/features/landing/view/widgets/expansion_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:paperless_mobile/extensions/flutter_extensions.dart';

class ExpansionCard extends StatelessWidget {
final Widget title;
final Widget content;

const ExpansionCard({super.key, required this.title, required this.content});

@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.all(16),
child: Theme(
data: Theme.of(context).copyWith(
dividerColor: Colors.transparent,
expansionTileTheme: ExpansionTileThemeData(
shape: Theme.of(context).cardTheme.shape,
collapsedShape: Theme.of(context).cardTheme.shape,
),
listTileTheme: ListTileThemeData(
shape: Theme.of(context).cardTheme.shape,
),
),
child: ExpansionTile(
initiallyExpanded: true,
title: title,
children: [content],
),
),
);
}
}
Loading

0 comments on commit 53a01ae

Please sign in to comment.