mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 02:07:57 -06:00
feat: Add debug logs for label loading
This commit is contained in:
@@ -8,9 +8,7 @@ import 'package:paperless_mobile/core/repository/persistent_repository.dart';
|
|||||||
class LabelRepository extends PersistentRepository<LabelRepositoryState> {
|
class LabelRepository extends PersistentRepository<LabelRepositoryState> {
|
||||||
final PaperlessLabelsApi _api;
|
final PaperlessLabelsApi _api;
|
||||||
|
|
||||||
LabelRepository(this._api) : super(const LabelRepositoryState()) {
|
LabelRepository(this._api) : super(const LabelRepositoryState());
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> initialize() {
|
Future<void> initialize() {
|
||||||
debugPrint("Initializing labels...");
|
debugPrint("Initializing labels...");
|
||||||
@@ -19,7 +17,9 @@ class LabelRepository extends PersistentRepository<LabelRepositoryState> {
|
|||||||
findAllDocumentTypes(),
|
findAllDocumentTypes(),
|
||||||
findAllStoragePaths(),
|
findAllStoragePaths(),
|
||||||
findAllTags(),
|
findAllTags(),
|
||||||
]);
|
]).catchError((error) {
|
||||||
|
debugPrint(error.toString());
|
||||||
|
}, test: (error) => false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Tag> createTag(Tag object) async {
|
Future<Tag> createTag(Tag object) async {
|
||||||
@@ -87,11 +87,15 @@ class LabelRepository extends PersistentRepository<LabelRepositoryState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Iterable<Correspondent>> findAllCorrespondents([Iterable<int>? ids]) async {
|
Future<Iterable<Correspondent>> findAllCorrespondents([Iterable<int>? ids]) async {
|
||||||
|
debugPrint("Loading correspondents...");
|
||||||
final correspondents = await _api.getCorrespondents(ids);
|
final correspondents = await _api.getCorrespondents(ids);
|
||||||
final updatedState = {...state.correspondents}
|
debugPrint("${correspondents.length} correspondents successfully loaded.");
|
||||||
..addEntries(correspondents.map((e) => MapEntry(e.id!, e)));
|
final updatedState = {
|
||||||
|
...state.correspondents,
|
||||||
|
}..addAll({for (var element in correspondents) element.id!: element});
|
||||||
|
debugPrint("Pushing new correspondents state.");
|
||||||
emit(state.copyWith(correspondents: updatedState));
|
emit(state.copyWith(correspondents: updatedState));
|
||||||
|
debugPrint("New correspondents state pushed.");
|
||||||
return correspondents;
|
return correspondents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ class _DocumentMetaDataWidgetState extends State<DocumentMetaDataWidget> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<DocumentDetailsCubit, DocumentDetailsState>(
|
return BlocBuilder<DocumentDetailsCubit, DocumentDetailsState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
debugPrint("Building state...");
|
|
||||||
if (state.metaData == null) {
|
if (state.metaData == null) {
|
||||||
return const SliverToBoxAdapter(
|
return const SliverToBoxAdapter(
|
||||||
child: Center(
|
child: Center(
|
||||||
|
|||||||
@@ -65,7 +65,10 @@ class DocumentsState extends DocumentPagingState {
|
|||||||
documentTypes,
|
documentTypes,
|
||||||
tags,
|
tags,
|
||||||
storagePaths,
|
storagePaths,
|
||||||
...super.props,
|
super.filter,
|
||||||
|
super.hasLoaded,
|
||||||
|
super.isLoading,
|
||||||
|
super.value,
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -438,85 +438,122 @@ class _DocumentsPageState extends State<DocumentsPage> with SingleTickerProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _addTagToFilter(int tagId) {
|
void _addTagToFilter(int tagId) {
|
||||||
|
final cubit = context.read<DocumentsCubit>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final tagsQuery = context.read<DocumentsCubit>().state.filter.tags is IdsTagsQuery
|
cubit.state.filter.tags.maybeMap(
|
||||||
? context.read<DocumentsCubit>().state.filter.tags as IdsTagsQuery
|
ids: (state) {
|
||||||
: const IdsTagsQuery();
|
if (state.include.contains(tagId)) {
|
||||||
if (tagsQuery.include.contains(tagId)) {
|
cubit.updateCurrentFilter(
|
||||||
context.read<DocumentsCubit>().updateCurrentFilter(
|
|
||||||
(filter) => filter.copyWith(
|
(filter) => filter.copyWith(
|
||||||
tags: tagsQuery.copyWith(
|
tags: state.copyWith(
|
||||||
include: tagsQuery.include.whereNot((id) => id == tagId).toList(),
|
include: state.include.whereNot((element) => element == tagId).toList(),
|
||||||
exclude: tagsQuery.exclude.whereNot((id) => id == tagId).toList()),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else if (state.exclude.contains(tagId)) {
|
||||||
context.read<DocumentsCubit>().updateCurrentFilter(
|
cubit.updateCurrentFilter(
|
||||||
(filter) => filter.copyWith(
|
(filter) => filter.copyWith(
|
||||||
tags: tagsQuery.copyWith(include: [...tagsQuery.include, tagId]),
|
tags: state.copyWith(
|
||||||
|
exclude: state.exclude.whereNot((element) => element == tagId).toList(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
|
cubit.updateCurrentFilter(
|
||||||
|
(filter) => filter.copyWith(
|
||||||
|
tags: state.copyWith(include: [...state.include, tagId]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
orElse: () {
|
||||||
|
cubit.updateCurrentFilter(
|
||||||
|
(filter) => filter.copyWith(tags: TagsQuery.ids(include: [tagId])),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
} on PaperlessServerException catch (error, stackTrace) {
|
} on PaperlessServerException catch (error, stackTrace) {
|
||||||
showErrorMessage(context, error, stackTrace);
|
showErrorMessage(context, error, stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addCorrespondentToFilter(int? correspondentId) {
|
void _addCorrespondentToFilter(int? correspondentId) {
|
||||||
|
if (correspondentId == null) return;
|
||||||
final cubit = context.read<DocumentsCubit>();
|
final cubit = context.read<DocumentsCubit>();
|
||||||
try {
|
try {
|
||||||
final correspondent = cubit.state.filter.correspondent;
|
cubit.state.filter.correspondent.maybeWhen(
|
||||||
if (correspondent is SetIdQueryParameter) {
|
fromId: (id) {
|
||||||
if (correspondentId == null || correspondent.id == correspondentId) {
|
if (id == correspondentId) {
|
||||||
cubit.updateCurrentFilter(
|
cubit.updateCurrentFilter(
|
||||||
(filter) => filter.copyWith(correspondent: const IdQueryParameter.unset()),
|
(filter) => filter.copyWith(correspondent: const IdQueryParameter.unset()),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
cubit.updateCurrentFilter(
|
||||||
|
(filter) => filter.copyWith(correspondent: IdQueryParameter.fromId(correspondentId)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
orElse: () {
|
||||||
cubit.updateCurrentFilter(
|
cubit.updateCurrentFilter(
|
||||||
(filter) => filter.copyWith(correspondent: IdQueryParameter.fromId(correspondentId)),
|
(filter) => filter.copyWith(correspondent: IdQueryParameter.fromId(correspondentId)),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
}
|
);
|
||||||
} on PaperlessServerException catch (error, stackTrace) {
|
} on PaperlessServerException catch (error, stackTrace) {
|
||||||
showErrorMessage(context, error, stackTrace);
|
showErrorMessage(context, error, stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addDocumentTypeToFilter(int? documentTypeId) {
|
void _addDocumentTypeToFilter(int? documentTypeId) {
|
||||||
|
if (documentTypeId == null) return;
|
||||||
final cubit = context.read<DocumentsCubit>();
|
final cubit = context.read<DocumentsCubit>();
|
||||||
try {
|
try {
|
||||||
final documentType = cubit.state.filter.documentType;
|
cubit.state.filter.documentType.maybeWhen(
|
||||||
if (documentType is SetIdQueryParameter) {
|
fromId: (id) {
|
||||||
if (documentTypeId == null || documentType.id == documentTypeId) {
|
if (id == documentTypeId) {
|
||||||
cubit.updateCurrentFilter(
|
cubit.updateCurrentFilter(
|
||||||
(filter) => filter.copyWith(documentType: const IdQueryParameter.unset()),
|
(filter) => filter.copyWith(documentType: const IdQueryParameter.unset()),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
cubit.updateCurrentFilter(
|
||||||
|
(filter) => filter.copyWith(documentType: IdQueryParameter.fromId(documentTypeId)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
orElse: () {
|
||||||
cubit.updateCurrentFilter(
|
cubit.updateCurrentFilter(
|
||||||
(filter) => filter.copyWith(documentType: IdQueryParameter.fromId(documentTypeId)),
|
(filter) => filter.copyWith(documentType: IdQueryParameter.fromId(documentTypeId)),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
}
|
);
|
||||||
} on PaperlessServerException catch (error, stackTrace) {
|
} on PaperlessServerException catch (error, stackTrace) {
|
||||||
showErrorMessage(context, error, stackTrace);
|
showErrorMessage(context, error, stackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addStoragePathToFilter(int? pathId) {
|
void _addStoragePathToFilter(int? pathId) {
|
||||||
|
if (pathId == null) return;
|
||||||
final cubit = context.read<DocumentsCubit>();
|
final cubit = context.read<DocumentsCubit>();
|
||||||
try {
|
try {
|
||||||
final path = cubit.state.filter.documentType;
|
cubit.state.filter.storagePath.maybeWhen(
|
||||||
if (path is SetIdQueryParameter) {
|
fromId: (id) {
|
||||||
if (pathId == null || path.id == pathId) {
|
if (id == pathId) {
|
||||||
cubit.updateCurrentFilter(
|
cubit.updateCurrentFilter(
|
||||||
(filter) => filter.copyWith(storagePath: const IdQueryParameter.unset()),
|
(filter) => filter.copyWith(storagePath: const IdQueryParameter.unset()),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
cubit.updateCurrentFilter(
|
||||||
|
(filter) => filter.copyWith(storagePath: IdQueryParameter.fromId(pathId)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
orElse: () {
|
||||||
cubit.updateCurrentFilter(
|
cubit.updateCurrentFilter(
|
||||||
(filter) => filter.copyWith(storagePath: IdQueryParameter.fromId(pathId)),
|
(filter) => filter.copyWith(storagePath: IdQueryParameter.fromId(pathId)),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
}
|
);
|
||||||
} on PaperlessServerException catch (error, stackTrace) {
|
} on PaperlessServerException catch (error, stackTrace) {
|
||||||
showErrorMessage(context, error, stackTrace);
|
showErrorMessage(context, error, stackTrace);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
||||||
@@ -86,6 +87,8 @@ class DocumentListItem extends DocumentItem {
|
|||||||
const TextSpan(text: '\u30FB'),
|
const TextSpan(text: '\u30FB'),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: labels.documentTypes[document.documentType]?.name,
|
text: labels.documentTypes[document.documentType]?.name,
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () => onDocumentTypeSelected?.call(document.documentType),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
: null,
|
: null,
|
||||||
|
|||||||
@@ -219,8 +219,10 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
|
|||||||
];
|
];
|
||||||
final routes = <Widget>[
|
final routes = <Widget>[
|
||||||
const DocumentsPage(),
|
const DocumentsPage(),
|
||||||
if (LocalUserAccount.current.paperlessUser
|
if (LocalUserAccount.current.paperlessUser.hasPermission(
|
||||||
.hasPermission(PermissionAction.add, PermissionTarget.document))
|
PermissionAction.add,
|
||||||
|
PermissionTarget.document,
|
||||||
|
))
|
||||||
const ScannerPage(),
|
const ScannerPage(),
|
||||||
const LabelsPage(),
|
const LabelsPage(),
|
||||||
const InboxPage(),
|
const InboxPage(),
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class HomeRoute extends StatelessWidget {
|
|||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ProxyProvider<PaperlessLabelsApi, LabelRepository>(
|
ProxyProvider<PaperlessLabelsApi, LabelRepository>(
|
||||||
update: (context, value, previous) => LabelRepository(value),
|
update: (context, value, previous) => LabelRepository(value)..initialize(),
|
||||||
),
|
),
|
||||||
ProxyProvider<PaperlessSavedViewsApi, SavedViewRepository>(
|
ProxyProvider<PaperlessSavedViewsApi, SavedViewRepository>(
|
||||||
update: (context, value, previous) => SavedViewRepository(value)..initialize(),
|
update: (context, value, previous) => SavedViewRepository(value)..initialize(),
|
||||||
|
|||||||
@@ -44,13 +44,15 @@ mixin DocumentPagingBlocMixin<State extends DocumentPagingState> on BlocBase<Sta
|
|||||||
emit(state.copyWithPaged(isLoading: true));
|
emit(state.copyWithPaged(isLoading: true));
|
||||||
final result = await api.findAll(filter.copyWith(page: 1));
|
final result = await api.findAll(filter.copyWith(page: 1));
|
||||||
|
|
||||||
emit(state.copyWithPaged(
|
emit(
|
||||||
filter: filter,
|
state.copyWithPaged(
|
||||||
value: [result],
|
filter: filter,
|
||||||
hasLoaded: true,
|
value: [result],
|
||||||
));
|
hasLoaded: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
await onFilterUpdated(filter);
|
// await onFilterUpdated(filter);
|
||||||
emit(state.copyWithPaged(isLoading: false));
|
emit(state.copyWithPaged(isLoading: false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,13 @@ import 'package:collection/collection.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hive_flutter/adapters.dart';
|
import 'package:hive_flutter/adapters.dart';
|
||||||
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
|
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
|
||||||
import 'package:paperless_mobile/core/database/tables/global_settings.dart';
|
|
||||||
import 'package:paperless_mobile/core/database/tables/local_user_account.dart';
|
import 'package:paperless_mobile/core/database/tables/local_user_account.dart';
|
||||||
import 'package:paperless_mobile/features/home/view/model/api_version.dart';
|
import 'package:paperless_mobile/features/home/view/model/api_version.dart';
|
||||||
import 'package:paperless_mobile/features/login/cubit/authentication_cubit.dart';
|
import 'package:paperless_mobile/features/login/cubit/authentication_cubit.dart';
|
||||||
import 'package:paperless_mobile/features/login/model/login_form_credentials.dart';
|
import 'package:paperless_mobile/features/login/model/login_form_credentials.dart';
|
||||||
import 'package:paperless_mobile/features/login/view/login_page.dart';
|
import 'package:paperless_mobile/features/login/view/login_page.dart';
|
||||||
import 'package:paperless_mobile/features/settings/view/dialogs/switch_account_dialog.dart';
|
import 'package:paperless_mobile/features/settings/view/dialogs/switch_account_dialog.dart';
|
||||||
import 'package:paperless_mobile/features/settings/view/pages/switching_accounts_page.dart';
|
|
||||||
import 'package:paperless_mobile/features/settings/view/widgets/global_settings_builder.dart';
|
import 'package:paperless_mobile/features/settings/view/widgets/global_settings_builder.dart';
|
||||||
import 'package:paperless_mobile/features/settings/view/widgets/user_avatar.dart';
|
|
||||||
import 'package:paperless_mobile/features/users/view/widgets/user_account_list_tile.dart';
|
import 'package:paperless_mobile/features/users/view/widgets/user_account_list_tile.dart';
|
||||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -26,7 +23,7 @@ class ManageAccountsPage extends StatelessWidget {
|
|||||||
// This is one of the few places where the currentLoggedInUser can be null
|
// This is one of the few places where the currentLoggedInUser can be null
|
||||||
// (exactly after loggin out as the current user to be precise).
|
// (exactly after loggin out as the current user to be precise).
|
||||||
if (globalSettings.currentLoggedInUser == null) {
|
if (globalSettings.currentLoggedInUser == null) {
|
||||||
return SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
return ValueListenableBuilder(
|
return ValueListenableBuilder(
|
||||||
valueListenable: Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount).listenable(),
|
valueListenable: Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount).listenable(),
|
||||||
|
|||||||
Reference in New Issue
Block a user