mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 02:07:57 -06:00
feat: Further migrations to go_router, add onclick to document previews
This commit is contained in:
@@ -17,4 +17,6 @@ class R {
|
||||
static const inbox = "inbox";
|
||||
static const documentPreview = "documentPreview";
|
||||
static const settings = "settings";
|
||||
static const linkedDocuments = "linkedDocuments";
|
||||
static const bulkEditDocuments = "bulkEditDocuments";
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:paperless_api/paperless_api.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_details/cubit/document_details_cubit.dart';
|
||||
import 'package:paperless_mobile/features/document_details/view/pages/document_details_page.dart';
|
||||
import 'package:paperless_mobile/features/document_edit/cubit/document_edit_cubit.dart';
|
||||
import 'package:paperless_mobile/features/document_edit/view/document_edit_page.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/pages/document_view.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/pages/documents_page.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
import 'package:paperless_mobile/routes/navigation_keys.dart';
|
||||
import 'package:paperless_mobile/routes/routes.dart';
|
||||
|
||||
@@ -37,7 +37,11 @@ class DocumentsBranch extends StatefulShellBranchData {
|
||||
TypedGoRoute<DocumentPreviewRoute>(
|
||||
path: "preview",
|
||||
name: R.documentPreview,
|
||||
)
|
||||
),
|
||||
TypedGoRoute<BulkEditDocumentsRoute>(
|
||||
path: "bulk-edit",
|
||||
name: R.bulkEditDocuments,
|
||||
),
|
||||
],
|
||||
)
|
||||
class DocumentsRoute extends GoRouteData {
|
||||
@@ -101,13 +105,115 @@ class EditDocumentRoute extends GoRouteData {
|
||||
}
|
||||
|
||||
class DocumentPreviewRoute extends GoRouteData {
|
||||
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;
|
||||
|
||||
final DocumentModel $extra;
|
||||
const DocumentPreviewRoute(this.$extra);
|
||||
final String? title;
|
||||
|
||||
const DocumentPreviewRoute({
|
||||
required this.$extra,
|
||||
this.title,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return DocumentView(
|
||||
documentBytes: context.read<PaperlessDocumentsApi>().download($extra),
|
||||
title: title ?? $extra.title,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class BulkEditExtraWrapper {
|
||||
final List<DocumentModel> selection;
|
||||
final LabelType type;
|
||||
|
||||
const BulkEditExtraWrapper(this.selection, this.type);
|
||||
}
|
||||
|
||||
class BulkEditDocumentsRoute extends GoRouteData {
|
||||
/// Selection
|
||||
final BulkEditExtraWrapper $extra;
|
||||
BulkEditDocumentsRoute(this.$extra);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return BlocProvider(
|
||||
create: (_) => DocumentBulkActionCubit(
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
selection: $extra.selection,
|
||||
),
|
||||
child: BlocBuilder<DocumentBulkActionCubit, DocumentBulkActionState>(
|
||||
builder: (context, state) {
|
||||
return switch ($extra.type) {
|
||||
LabelType.tag => const FullscreenBulkEditTagsWidget(),
|
||||
_ => FullscreenBulkEditLabelPage(
|
||||
options: switch ($extra.type) {
|
||||
LabelType.correspondent => state.correspondents,
|
||||
LabelType.documentType => state.documentTypes,
|
||||
LabelType.storagePath => state.storagePaths,
|
||||
_ => throw Exception("Parameter not allowed here."),
|
||||
},
|
||||
selection: state.selection,
|
||||
labelMapper: (document) {
|
||||
return switch ($extra.type) {
|
||||
LabelType.correspondent => document.correspondent,
|
||||
LabelType.documentType => document.documentType,
|
||||
LabelType.storagePath => document.storagePath,
|
||||
_ => throw Exception("Parameter not allowed here."),
|
||||
};
|
||||
},
|
||||
leadingIcon: switch ($extra.type) {
|
||||
LabelType.correspondent => const Icon(Icons.person_outline),
|
||||
LabelType.documentType =>
|
||||
const Icon(Icons.description_outlined),
|
||||
LabelType.storagePath => const Icon(Icons.folder_outlined),
|
||||
_ => throw Exception("Parameter not allowed here."),
|
||||
},
|
||||
hintText: S.of(context)!.startTyping,
|
||||
onSubmit: switch ($extra.type) {
|
||||
LabelType.correspondent => context
|
||||
.read<DocumentBulkActionCubit>()
|
||||
.bulkModifyCorrespondent,
|
||||
LabelType.documentType => context
|
||||
.read<DocumentBulkActionCubit>()
|
||||
.bulkModifyDocumentType,
|
||||
LabelType.storagePath => context
|
||||
.read<DocumentBulkActionCubit>()
|
||||
.bulkModifyStoragePath,
|
||||
_ => throw Exception("Parameter not allowed here."),
|
||||
},
|
||||
assignMessageBuilder: (int count, String name) {
|
||||
return switch ($extra.type) {
|
||||
LabelType.correspondent => S
|
||||
.of(context)!
|
||||
.bulkEditCorrespondentAssignMessage(name, count),
|
||||
LabelType.documentType => S
|
||||
.of(context)!
|
||||
.bulkEditDocumentTypeAssignMessage(count, name),
|
||||
LabelType.storagePath => S
|
||||
.of(context)!
|
||||
.bulkEditDocumentTypeAssignMessage(count, name),
|
||||
_ => throw Exception("Parameter not allowed here."),
|
||||
};
|
||||
},
|
||||
removeMessageBuilder: (int count) {
|
||||
return switch ($extra.type) {
|
||||
LabelType.correspondent =>
|
||||
S.of(context)!.bulkEditCorrespondentRemoveMessage(count),
|
||||
LabelType.documentType =>
|
||||
S.of(context)!.bulkEditDocumentTypeRemoveMessage(count),
|
||||
LabelType.storagePath =>
|
||||
S.of(context)!.bulkEditStoragePathRemoveMessage(count),
|
||||
_ => throw Exception("Parameter not allowed here."),
|
||||
};
|
||||
},
|
||||
),
|
||||
};
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/widgets.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/features/edit_label/view/impl/add_correspondent_page.dart';
|
||||
@@ -10,6 +11,8 @@ import 'package:paperless_mobile/features/edit_label/view/impl/edit_document_typ
|
||||
import 'package:paperless_mobile/features/edit_label/view/impl/edit_storage_path_page.dart';
|
||||
import 'package:paperless_mobile/features/edit_label/view/impl/edit_tag_page.dart';
|
||||
import 'package:paperless_mobile/features/labels/view/pages/labels_page.dart';
|
||||
import 'package:paperless_mobile/features/linked_documents/cubit/linked_documents_cubit.dart';
|
||||
import 'package:paperless_mobile/features/linked_documents/view/linked_documents_page.dart';
|
||||
import 'package:paperless_mobile/routes/navigation_keys.dart';
|
||||
import 'package:paperless_mobile/routes/routes.dart';
|
||||
|
||||
@@ -32,6 +35,10 @@ class LabelsBranch extends StatefulShellBranchData {
|
||||
path: "create",
|
||||
name: R.createLabel,
|
||||
),
|
||||
TypedGoRoute<LinkedDocumentsRoute>(
|
||||
path: "linked-documents",
|
||||
name: R.linkedDocuments,
|
||||
),
|
||||
],
|
||||
)
|
||||
class LabelsRoute extends GoRouteData {
|
||||
@@ -59,26 +66,42 @@ class EditLabelRoute extends GoRouteData {
|
||||
}
|
||||
}
|
||||
|
||||
class CreateLabelRoute<T extends Label> extends GoRouteData {
|
||||
class CreateLabelRoute extends GoRouteData {
|
||||
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;
|
||||
|
||||
final LabelType $extra;
|
||||
final String? name;
|
||||
|
||||
CreateLabelRoute({
|
||||
CreateLabelRoute(
|
||||
this.$extra, {
|
||||
this.name,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
if (T is Correspondent) {
|
||||
return AddCorrespondentPage(initialName: name);
|
||||
} else if (T is DocumentType) {
|
||||
return AddDocumentTypePage(initialName: name);
|
||||
} else if (T is Tag) {
|
||||
return AddTagPage(initialName: name);
|
||||
} else if (T is StoragePath) {
|
||||
return AddStoragePathPage(initialName: name);
|
||||
}
|
||||
throw ArgumentError();
|
||||
return switch ($extra) {
|
||||
LabelType.correspondent => AddCorrespondentPage(initialName: name),
|
||||
LabelType.documentType => AddDocumentTypePage(initialName: name),
|
||||
LabelType.tag => AddTagPage(initialName: name),
|
||||
LabelType.storagePath => AddStoragePathPage(initialName: name),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class LinkedDocumentsRoute extends GoRouteData {
|
||||
static final GlobalKey<NavigatorState> $parentNavigatorKey = rootNavigatorKey;
|
||||
final DocumentFilter $extra;
|
||||
|
||||
const LinkedDocumentsRoute(this.$extra);
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return BlocProvider(
|
||||
create: (context) => LinkedDocumentsCubit(
|
||||
$extra,
|
||||
context.read(),
|
||||
context.read(),
|
||||
context.read(),
|
||||
),
|
||||
child: const LinkedDocumentsPage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user