mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-07 20:07:48 -06:00
fix: Add providers to bulk edit routes
This commit is contained in:
@@ -10,6 +10,9 @@ import 'package:paperless_mobile/core/database/tables/local_user_app_state.dart'
|
||||
import 'package:paperless_mobile/core/notifier/document_changed_notifier.dart';
|
||||
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
||||
import 'package:paperless_mobile/core/repository/user_repository.dart';
|
||||
import 'package:paperless_mobile/features/document_bulk_action/cubit/document_bulk_action_cubit.dart';
|
||||
import 'package:paperless_mobile/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_label_page.dart';
|
||||
import 'package:paperless_mobile/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_tags_widget.dart';
|
||||
import 'package:paperless_mobile/features/document_search/cubit/document_search_cubit.dart';
|
||||
import 'package:paperless_mobile/features/document_search/view/document_search_page.dart';
|
||||
import 'package:paperless_mobile/features/home/view/model/api_version.dart';
|
||||
@@ -20,6 +23,7 @@ import 'package:paperless_mobile/features/saved_view/cubit/saved_view_cubit.dart
|
||||
import 'package:paperless_mobile/features/saved_view/view/add_saved_view_page.dart';
|
||||
import 'package:paperless_mobile/features/saved_view_details/cubit/saved_view_details_cubit.dart';
|
||||
import 'package:paperless_mobile/features/saved_view_details/view/saved_view_details_page.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
import 'package:paperless_mobile/routes/document_details_route.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -161,3 +165,167 @@ Future<void> pushLinkedDocumentsView(BuildContext context, {required DocumentFil
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pushBulkEditCorrespondentRoute(
|
||||
BuildContext context, {
|
||||
required List<DocumentModel> selection,
|
||||
}) {
|
||||
return Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MultiProvider(
|
||||
providers: [
|
||||
..._getRequiredBulkEditProviders(context),
|
||||
],
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: selection,
|
||||
),
|
||||
child: BlocBuilder<DocumentBulkActionCubit, DocumentBulkActionState>(
|
||||
builder: (context, state) {
|
||||
return FullscreenBulkEditLabelPage(
|
||||
options: state.correspondents,
|
||||
selection: state.selection,
|
||||
labelMapper: (document) => document.correspondent,
|
||||
leadingIcon: const Icon(Icons.person_outline),
|
||||
hintText: S.of(context)!.startTyping,
|
||||
onSubmit: context.read<DocumentBulkActionCubit>().bulkModifyCorrespondent,
|
||||
assignMessageBuilder: (int count, String name) {
|
||||
return S.of(context)!.bulkEditCorrespondentAssignMessage(
|
||||
name,
|
||||
count,
|
||||
);
|
||||
},
|
||||
removeMessageBuilder: (int count) {
|
||||
return S.of(context)!.bulkEditCorrespondentRemoveMessage(count);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pushBulkEditStoragePathRoute(
|
||||
BuildContext context, {
|
||||
required List<DocumentModel> selection,
|
||||
}) {
|
||||
return Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MultiProvider(
|
||||
providers: [
|
||||
..._getRequiredBulkEditProviders(context),
|
||||
],
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: selection,
|
||||
),
|
||||
child: BlocBuilder<DocumentBulkActionCubit, DocumentBulkActionState>(
|
||||
builder: (context, state) {
|
||||
return FullscreenBulkEditLabelPage(
|
||||
options: state.storagePaths,
|
||||
selection: state.selection,
|
||||
labelMapper: (document) => document.storagePath,
|
||||
leadingIcon: const Icon(Icons.folder_outlined),
|
||||
hintText: S.of(context)!.startTyping,
|
||||
onSubmit: context.read<DocumentBulkActionCubit>().bulkModifyStoragePath,
|
||||
assignMessageBuilder: (int count, String name) {
|
||||
return S.of(context)!.bulkEditStoragePathAssignMessage(
|
||||
count,
|
||||
name,
|
||||
);
|
||||
},
|
||||
removeMessageBuilder: (int count) {
|
||||
return S.of(context)!.bulkEditStoragePathRemoveMessage(count);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pushBulkEditTagsRoute(
|
||||
BuildContext context, {
|
||||
required List<DocumentModel> selection,
|
||||
}) {
|
||||
return Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MultiProvider(
|
||||
providers: [
|
||||
..._getRequiredBulkEditProviders(context),
|
||||
],
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: selection,
|
||||
),
|
||||
child: Builder(builder: (context) {
|
||||
return const FullscreenBulkEditTagsWidget();
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pushBulkEditDocumentTypeRoute(BuildContext context,
|
||||
{required List<DocumentModel> selection}) {
|
||||
return Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MultiProvider(
|
||||
providers: [
|
||||
..._getRequiredBulkEditProviders(context),
|
||||
],
|
||||
builder: (_, __) => BlocProvider(
|
||||
create: (_) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: selection,
|
||||
),
|
||||
child: BlocBuilder<DocumentBulkActionCubit, DocumentBulkActionState>(
|
||||
builder: (context, state) {
|
||||
return FullscreenBulkEditLabelPage(
|
||||
options: state.documentTypes,
|
||||
selection: state.selection,
|
||||
labelMapper: (document) => document.documentType,
|
||||
leadingIcon: const Icon(Icons.description_outlined),
|
||||
hintText: S.of(context)!.startTyping,
|
||||
onSubmit: context.read<DocumentBulkActionCubit>().bulkModifyDocumentType,
|
||||
assignMessageBuilder: (int count, String name) {
|
||||
return S.of(context)!.bulkEditDocumentTypeAssignMessage(
|
||||
count,
|
||||
name,
|
||||
);
|
||||
},
|
||||
removeMessageBuilder: (int count) {
|
||||
return S.of(context)!.bulkEditDocumentTypeRemoveMessage(count);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Provider> _getRequiredBulkEditProviders(BuildContext context) {
|
||||
return [
|
||||
Provider.value(value: context.read<PaperlessDocumentsApi>()),
|
||||
Provider.value(value: context.read<LabelRepository>()),
|
||||
Provider.value(value: context.read<DocumentChangedNotifier>()),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ class AppDrawer extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
top: true,
|
||||
child: Drawer(
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
@@ -83,8 +83,7 @@ class DocumentsState extends DocumentPagingState {
|
||||
);
|
||||
}
|
||||
|
||||
factory DocumentsState.fromJson(Map<String, dynamic> json) =>
|
||||
_$DocumentsStateFromJson(json);
|
||||
factory DocumentsState.fromJson(Map<String, dynamic> json) => _$DocumentsStateFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$DocumentsStateToJson(this);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class _DocumentsPageState extends State<DocumentsPage> with SingleTickerProvider
|
||||
},
|
||||
builder: (context, connectivityState) {
|
||||
return SafeArea(
|
||||
top: context.read<DocumentsCubit>().state.selection.isEmpty,
|
||||
top: context.watch<DocumentsCubit>().state.selection.isEmpty,
|
||||
child: Scaffold(
|
||||
drawer: const AppDrawer(),
|
||||
floatingActionButton: BlocBuilder<DocumentsCubit, DocumentsState>(
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/navigation/push_routes.dart';
|
||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/document_bulk_action/cubit/document_bulk_action_cubit.dart';
|
||||
import 'package:paperless_mobile/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_label_page.dart';
|
||||
import 'package:paperless_mobile/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_tags_widget.dart';
|
||||
import 'package:paperless_mobile/features/documents/cubit/documents_cubit.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/selection/bulk_delete_confirmation_dialog.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
@@ -35,15 +33,12 @@ class DocumentSelectionSliverAppBar extends StatelessWidget {
|
||||
onPressed: () async {
|
||||
final shouldDelete = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
BulkDeleteConfirmationDialog(state: state),
|
||||
builder: (context) => BulkDeleteConfirmationDialog(state: state),
|
||||
) ??
|
||||
false;
|
||||
if (shouldDelete) {
|
||||
try {
|
||||
await context
|
||||
.read<DocumentsCubit>()
|
||||
.bulkDelete(state.selection);
|
||||
await context.read<DocumentsCubit>().bulkDelete(state.selection);
|
||||
showSnackBar(
|
||||
context,
|
||||
S.of(context)!.documentsSuccessfullyDeleted,
|
||||
@@ -66,140 +61,22 @@ class DocumentSelectionSliverAppBar extends StatelessWidget {
|
||||
ActionChip(
|
||||
label: Text(S.of(context)!.correspondent),
|
||||
avatar: const Icon(Icons.edit),
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BlocProvider(
|
||||
create: (context) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: state.selection,
|
||||
),
|
||||
child: BlocBuilder<DocumentBulkActionCubit,
|
||||
DocumentBulkActionState>(
|
||||
builder: (context, state) {
|
||||
return FullscreenBulkEditLabelPage(
|
||||
options: state.correspondents,
|
||||
selection: state.selection,
|
||||
labelMapper: (document) => document.correspondent,
|
||||
leadingIcon: const Icon(Icons.person_outline),
|
||||
hintText: S.of(context)!.startTyping,
|
||||
onSubmit: context
|
||||
.read<DocumentBulkActionCubit>()
|
||||
.bulkModifyCorrespondent,
|
||||
assignMessageBuilder: (int count, String name) {
|
||||
return S
|
||||
.of(context)!
|
||||
.bulkEditCorrespondentAssignMessage(
|
||||
name,
|
||||
count,
|
||||
);
|
||||
},
|
||||
removeMessageBuilder: (int count) {
|
||||
return S
|
||||
.of(context)!
|
||||
.bulkEditCorrespondentRemoveMessage(count);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
onPressed: () {
|
||||
pushBulkEditCorrespondentRoute(context, selection: state.selection);
|
||||
},
|
||||
).paddedOnly(left: 8, right: 4),
|
||||
ActionChip(
|
||||
label: Text(S.of(context)!.documentType),
|
||||
avatar: const Icon(Icons.edit),
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BlocProvider(
|
||||
create: (context) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: state.selection,
|
||||
),
|
||||
child: BlocBuilder<DocumentBulkActionCubit,
|
||||
DocumentBulkActionState>(
|
||||
builder: (context, state) {
|
||||
return FullscreenBulkEditLabelPage(
|
||||
options: state.documentTypes,
|
||||
selection: state.selection,
|
||||
labelMapper: (document) => document.documentType,
|
||||
leadingIcon:
|
||||
const Icon(Icons.description_outlined),
|
||||
hintText: S.of(context)!.startTyping,
|
||||
onSubmit: context
|
||||
.read<DocumentBulkActionCubit>()
|
||||
.bulkModifyDocumentType,
|
||||
assignMessageBuilder: (int count, String name) {
|
||||
return S
|
||||
.of(context)!
|
||||
.bulkEditDocumentTypeAssignMessage(
|
||||
count,
|
||||
name,
|
||||
);
|
||||
},
|
||||
removeMessageBuilder: (int count) {
|
||||
return S
|
||||
.of(context)!
|
||||
.bulkEditDocumentTypeRemoveMessage(count);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
pushBulkEditDocumentTypeRoute(context, selection: state.selection);
|
||||
},
|
||||
).paddedOnly(left: 8, right: 4),
|
||||
ActionChip(
|
||||
label: Text(S.of(context)!.storagePath),
|
||||
avatar: const Icon(Icons.edit),
|
||||
onPressed: () async {
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BlocProvider(
|
||||
create: (context) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: state.selection,
|
||||
),
|
||||
child: BlocBuilder<DocumentBulkActionCubit,
|
||||
DocumentBulkActionState>(
|
||||
builder: (context, state) {
|
||||
return FullscreenBulkEditLabelPage(
|
||||
options: state.storagePaths,
|
||||
selection: state.selection,
|
||||
labelMapper: (document) => document.storagePath,
|
||||
leadingIcon: const Icon(Icons.folder_outlined),
|
||||
hintText: S.of(context)!.startTyping,
|
||||
onSubmit: context
|
||||
.read<DocumentBulkActionCubit>()
|
||||
.bulkModifyStoragePath,
|
||||
assignMessageBuilder: (int count, String name) {
|
||||
return S
|
||||
.of(context)!
|
||||
.bulkEditStoragePathAssignMessage(
|
||||
count,
|
||||
name,
|
||||
);
|
||||
},
|
||||
removeMessageBuilder: (int count) {
|
||||
return S
|
||||
.of(context)!
|
||||
.bulkEditStoragePathRemoveMessage(count);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
pushBulkEditStoragePathRoute(context, selection: state.selection);
|
||||
},
|
||||
).paddedOnly(left: 8, right: 4),
|
||||
_buildBulkEditTagsChip(context).paddedOnly(left: 4, right: 4),
|
||||
@@ -215,21 +92,7 @@ class DocumentSelectionSliverAppBar extends StatelessWidget {
|
||||
label: Text(S.of(context)!.tags),
|
||||
avatar: const Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BlocProvider(
|
||||
create: (context) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: state.selection,
|
||||
),
|
||||
child: Builder(builder: (context) {
|
||||
return const FullscreenBulkEditTagsWidget();
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
pushBulkEditTagsRoute(context, selection: state.selection);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -109,13 +109,16 @@ class HomeRoute extends StatelessWidget {
|
||||
providers: [
|
||||
ProxyProvider3<PaperlessDocumentsApi, DocumentChangedNotifier, LabelRepository,
|
||||
DocumentsCubit>(
|
||||
update: (context, docApi, notifier, labelRepo, previous) => DocumentsCubit(
|
||||
docApi,
|
||||
notifier,
|
||||
labelRepo,
|
||||
Hive.box<LocalUserAppState>(HiveBoxes.localUserAppState)
|
||||
.get(currentLocalUserId)!,
|
||||
)..reload(),
|
||||
update: (context, docApi, notifier, labelRepo, previous) {
|
||||
print("UPDATED DOCUMENT CUBIT"); //TODO: REMOVE
|
||||
return DocumentsCubit(
|
||||
docApi,
|
||||
notifier,
|
||||
labelRepo,
|
||||
Hive.box<LocalUserAppState>(HiveBoxes.localUserAppState)
|
||||
.get(currentLocalUserId)!,
|
||||
)..reload();
|
||||
},
|
||||
),
|
||||
Provider(create: (context) => DocumentScannerCubit()),
|
||||
ProxyProvider4<PaperlessDocumentsApi, PaperlessServerStatsApi, LabelRepository,
|
||||
|
||||
Reference in New Issue
Block a user