Further migrations to route based navigation, improved saved view logic

This commit is contained in:
Anton Stubenbord
2023-09-12 01:03:01 +02:00
parent 8e5eb5a6c6
commit 2e8144700f
28 changed files with 878 additions and 550 deletions

View File

@@ -63,6 +63,9 @@ class DocumentFilter extends Equatable {
@HiveField(13)
final int? moreLike;
@HiveField(14)
final int? selectedView;
const DocumentFilter({
this.documentType = const IdQueryParameter.unset(),
this.correspondent = const IdQueryParameter.unset(),
@@ -78,6 +81,7 @@ class DocumentFilter extends Equatable {
this.created = const UnsetDateRangeQuery(),
this.modified = const UnsetDateRangeQuery(),
this.moreLike,
this.selectedView,
});
bool get forceExtendedQuery {
@@ -143,6 +147,7 @@ class DocumentFilter extends Equatable {
DateRangeQuery? modified,
TextQuery? query,
int? Function()? moreLike,
int? Function()? selectedView,
}) {
final newFilter = DocumentFilter(
pageSize: pageSize ?? this.pageSize,
@@ -159,6 +164,7 @@ class DocumentFilter extends Equatable {
created: created ?? this.created,
modified: modified ?? this.modified,
moreLike: moreLike != null ? moreLike.call() : this.moreLike,
selectedView: selectedView != null ? selectedView.call() : this.selectedView,
);
if (query?.queryType != QueryType.extended &&
newFilter.forceExtendedQuery) {
@@ -244,6 +250,8 @@ class DocumentFilter extends Equatable {
created,
modified,
query,
moreLike,
selectedView,
];
factory DocumentFilter.fromJson(Map<String, dynamic> json) =>

View File

@@ -8,8 +8,12 @@ class PaperlessServerMessageException implements Exception {
PaperlessServerMessageException(this.detail);
static bool canParse(Map<String, dynamic> json) {
return json.containsKey('detail') && json.length == 1;
static bool canParse(dynamic json) {
if (json is Map<String, dynamic>) {
return json.containsKey('detail') && json.length == 1;
} else {
return false;
}
}
factory PaperlessServerMessageException.fromJson(Map<String, dynamic> json) =>

View File

@@ -54,5 +54,18 @@ enum ErrorCode {
unsupportedFileFormat,
missingClientCertificate,
acknowledgeTasksError,
correspondentDeleteFailed, documentTypeDeleteFailed, tagDeleteFailed, correspondentUpdateFailed, documentTypeUpdateFailed, tagUpdateFailed, storagePathDeleteFailed, storagePathUpdateFailed, serverInformationLoadFailed, serverStatisticsLoadFailed, uiSettingsLoadFailed, loadTasksError, userNotFound;
correspondentDeleteFailed,
documentTypeDeleteFailed,
tagDeleteFailed,
correspondentUpdateFailed,
documentTypeUpdateFailed,
tagUpdateFailed,
storagePathDeleteFailed,
storagePathUpdateFailed,
serverInformationLoadFailed,
serverStatisticsLoadFailed,
uiSettingsLoadFailed,
loadTasksError,
userNotFound,
updateSavedViewError;
}

View File

@@ -87,4 +87,6 @@ extension UserPermissionExtension on UserModel {
canViewDocumentTypes ||
canViewTags ||
canViewStoragePaths;
bool get canViewInbox => canViewTags && canViewDocuments;
}

View File

@@ -50,11 +50,32 @@ class SavedView with EquatableMixin {
Map<String, dynamic> toJson() => _$SavedViewToJson(this);
SavedView copyWith({
int? id,
String? name,
bool? showOnDashboard,
bool? showInSidebar,
SortField? sortField,
bool? sortReverse,
List<FilterRule>? filterRules,
}) {
return SavedView(
id: id ?? this.id,
name: name ?? this.name,
showOnDashboard: showOnDashboard ?? this.showOnDashboard,
showInSidebar: showInSidebar ?? this.showInSidebar,
sortField: sortField ?? this.sortField,
sortReverse: sortReverse ?? this.sortReverse,
filterRules: filterRules ?? this.filterRules,
);
}
DocumentFilter toDocumentFilter() {
return filterRules.fold(
DocumentFilter(
sortOrder: sortReverse ? SortOrder.descending : SortOrder.ascending,
sortField: sortField,
selectedView: id,
),
(filter, filterRule) => filterRule.applyToFilter(filter),
);

View File

@@ -1,6 +1,6 @@
import 'package:dio/dio.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_api/src/extensions/dio_exception_extension.dart';
import 'package:paperless_api/src/modules/authentication_api/authentication_api.dart';
class PaperlessAuthenticationApiImpl implements PaperlessAuthenticationApi {
final Dio client;
@@ -20,10 +20,19 @@ class PaperlessAuthenticationApiImpl implements PaperlessAuthenticationApi {
"password": password,
},
options: Options(
validateStatus: (status) => status == 200,
followRedirects: false,
headers: {
"Accept": "application/json",
},
validateStatus: (status) {
return status! == 200;
},
),
);
return response.data['token'];
// } else if (response.statusCode == 302) {
// final redirectUrl = response.headers.value("location");
// return AuthenticationTemporaryRedirect(redirectUrl!);
} on DioException catch (exception) {
throw exception.unravel();
}

View File

@@ -6,4 +6,7 @@ abstract class PaperlessSavedViewsApi {
Future<SavedView> save(SavedView view);
Future<int> delete(SavedView view);
/// Since API V3
Future<SavedView> update(SavedView view);
}

View File

@@ -41,6 +41,22 @@ class PaperlessSavedViewsApiImpl implements PaperlessSavedViewsApi {
}
}
@override
Future<SavedView> update(SavedView view) async {
try {
final response = await _client.patch(
"/api/saved_views/${view.id}/",
data: view.toJson(),
options: Options(validateStatus: (status) => status == 200),
);
return SavedView.fromJson(response.data);
} on DioException catch (exception) {
throw exception.unravel(
orElse: const PaperlessApiException(ErrorCode.updateSavedViewError),
);
}
}
@override
Future<int> delete(SavedView view) async {
try {