mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-11 00:07:59 -06:00
feat: Migrate to go_router
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'paperless_server_exception.g.dart';
|
||||
part 'paperless_server_message_exception.g.dart';
|
||||
|
||||
@JsonSerializable(createToJson: false)
|
||||
class PaperlessServerMessageException implements Exception {
|
||||
@@ -13,5 +13,5 @@ class PaperlessServerMessageException implements Exception {
|
||||
}
|
||||
|
||||
factory PaperlessServerMessageException.fromJson(Map<String, dynamic> json) =>
|
||||
_$PaperlessServerExceptionFromJson(json);
|
||||
_$PaperlessServerMessageExceptionFromJson(json);
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/src/converters/local_date_time_json_converter.dart';
|
||||
import 'package:paperless_api/src/models/labels/label_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/matching_algorithm.dart';
|
||||
|
||||
part 'correspondent_model.g.dart';
|
||||
|
||||
@LocalDateTimeJsonConverter()
|
||||
@JsonSerializable(includeIfNull: false, fieldRename: FieldRename.snake)
|
||||
class Correspondent extends Label {
|
||||
final DateTime? lastCorrespondence;
|
||||
|
||||
const Correspondent({
|
||||
this.lastCorrespondence,
|
||||
required super.name,
|
||||
super.id,
|
||||
super.slug,
|
||||
super.match,
|
||||
super.matchingAlgorithm,
|
||||
super.isInsensitive,
|
||||
super.documentCount,
|
||||
super.owner,
|
||||
super.userCanChange,
|
||||
});
|
||||
|
||||
factory Correspondent.fromJson(Map<String, dynamic> json) =>
|
||||
_$CorrespondentFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$CorrespondentToJson(this);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@override
|
||||
Correspondent copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? slug,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
DateTime? lastCorrespondence,
|
||||
}) {
|
||||
return Correspondent(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
documentCount: documentCount ?? documentCount,
|
||||
isInsensitive: isInsensitive ?? isInsensitive,
|
||||
match: match ?? this.match,
|
||||
matchingAlgorithm: matchingAlgorithm ?? this.matchingAlgorithm,
|
||||
slug: slug ?? this.slug,
|
||||
lastCorrespondence: lastCorrespondence ?? this.lastCorrespondence,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get queryEndpoint => 'correspondents';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
isInsensitive,
|
||||
documentCount,
|
||||
lastCorrespondence,
|
||||
matchingAlgorithm,
|
||||
match,
|
||||
];
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/src/models/labels/label_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/matching_algorithm.dart';
|
||||
part 'document_type_model.g.dart';
|
||||
|
||||
@JsonSerializable(includeIfNull: false, fieldRename: FieldRename.snake)
|
||||
class DocumentType extends Label {
|
||||
const DocumentType({
|
||||
super.id,
|
||||
required super.name,
|
||||
super.slug,
|
||||
super.match,
|
||||
super.matchingAlgorithm,
|
||||
super.isInsensitive,
|
||||
super.documentCount,
|
||||
super.owner,
|
||||
super.userCanChange,
|
||||
});
|
||||
|
||||
factory DocumentType.fromJson(Map<String, dynamic> json) => _$DocumentTypeFromJson(json);
|
||||
|
||||
@override
|
||||
String get queryEndpoint => 'document_types';
|
||||
|
||||
@override
|
||||
DocumentType copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
String? slug,
|
||||
}) {
|
||||
return DocumentType(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
match: match ?? this.match,
|
||||
matchingAlgorithm: matchingAlgorithm ?? this.matchingAlgorithm,
|
||||
isInsensitive: isInsensitive ?? this.isInsensitive,
|
||||
documentCount: documentCount ?? this.documentCount,
|
||||
slug: slug ?? this.slug,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$DocumentTypeToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
isInsensitive,
|
||||
documentCount,
|
||||
matchingAlgorithm,
|
||||
match,
|
||||
];
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/src/converters/hex_color_json_converter.dart';
|
||||
import 'package:paperless_api/src/converters/local_date_time_json_converter.dart';
|
||||
import 'package:paperless_api/src/models/labels/matching_algorithm.dart';
|
||||
|
||||
abstract class Label extends Equatable implements Comparable {
|
||||
part 'label_model.g.dart';
|
||||
|
||||
sealed class Label extends Equatable implements Comparable {
|
||||
static const idKey = "id";
|
||||
static const nameKey = "name";
|
||||
static const slugKey = "slug";
|
||||
@@ -56,3 +63,278 @@ abstract class Label extends Equatable implements Comparable {
|
||||
|
||||
Map<String, dynamic> toJson();
|
||||
}
|
||||
|
||||
@LocalDateTimeJsonConverter()
|
||||
@JsonSerializable(includeIfNull: false, fieldRename: FieldRename.snake)
|
||||
class Correspondent extends Label {
|
||||
final DateTime? lastCorrespondence;
|
||||
|
||||
const Correspondent({
|
||||
this.lastCorrespondence,
|
||||
required super.name,
|
||||
super.id,
|
||||
super.slug,
|
||||
super.match,
|
||||
super.matchingAlgorithm,
|
||||
super.isInsensitive,
|
||||
super.documentCount,
|
||||
super.owner,
|
||||
super.userCanChange,
|
||||
});
|
||||
|
||||
factory Correspondent.fromJson(Map<String, dynamic> json) =>
|
||||
_$CorrespondentFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$CorrespondentToJson(this);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@override
|
||||
Correspondent copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? slug,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
DateTime? lastCorrespondence,
|
||||
}) {
|
||||
return Correspondent(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
documentCount: documentCount ?? documentCount,
|
||||
isInsensitive: isInsensitive ?? isInsensitive,
|
||||
match: match ?? this.match,
|
||||
matchingAlgorithm: matchingAlgorithm ?? this.matchingAlgorithm,
|
||||
slug: slug ?? this.slug,
|
||||
lastCorrespondence: lastCorrespondence ?? this.lastCorrespondence,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get queryEndpoint => 'correspondents';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
isInsensitive,
|
||||
documentCount,
|
||||
lastCorrespondence,
|
||||
matchingAlgorithm,
|
||||
match,
|
||||
];
|
||||
}
|
||||
|
||||
@JsonSerializable(includeIfNull: false, fieldRename: FieldRename.snake)
|
||||
class DocumentType extends Label {
|
||||
const DocumentType({
|
||||
super.id,
|
||||
required super.name,
|
||||
super.slug,
|
||||
super.match,
|
||||
super.matchingAlgorithm,
|
||||
super.isInsensitive,
|
||||
super.documentCount,
|
||||
super.owner,
|
||||
super.userCanChange,
|
||||
});
|
||||
|
||||
factory DocumentType.fromJson(Map<String, dynamic> json) =>
|
||||
_$DocumentTypeFromJson(json);
|
||||
|
||||
@override
|
||||
String get queryEndpoint => 'document_types';
|
||||
|
||||
@override
|
||||
DocumentType copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
String? slug,
|
||||
}) {
|
||||
return DocumentType(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
match: match ?? this.match,
|
||||
matchingAlgorithm: matchingAlgorithm ?? this.matchingAlgorithm,
|
||||
isInsensitive: isInsensitive ?? this.isInsensitive,
|
||||
documentCount: documentCount ?? this.documentCount,
|
||||
slug: slug ?? this.slug,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$DocumentTypeToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
isInsensitive,
|
||||
documentCount,
|
||||
matchingAlgorithm,
|
||||
match,
|
||||
];
|
||||
}
|
||||
|
||||
@JsonSerializable(includeIfNull: false, fieldRename: FieldRename.snake)
|
||||
class StoragePath extends Label {
|
||||
static const pathKey = 'path';
|
||||
final String path;
|
||||
|
||||
const StoragePath({
|
||||
super.id,
|
||||
required super.name,
|
||||
required this.path,
|
||||
super.slug,
|
||||
super.match,
|
||||
super.matchingAlgorithm,
|
||||
super.isInsensitive,
|
||||
super.documentCount,
|
||||
super.owner,
|
||||
super.userCanChange,
|
||||
});
|
||||
|
||||
factory StoragePath.fromJson(Map<String, dynamic> json) =>
|
||||
_$StoragePathFromJson(json);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@override
|
||||
StoragePath copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? slug,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
String? path,
|
||||
}) {
|
||||
return StoragePath(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
documentCount: documentCount ?? documentCount,
|
||||
isInsensitive: isInsensitive ?? isInsensitive,
|
||||
path: path ?? this.path,
|
||||
match: match ?? this.match,
|
||||
matchingAlgorithm: matchingAlgorithm ?? this.matchingAlgorithm,
|
||||
slug: slug ?? this.slug,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get queryEndpoint => 'storage_paths';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
isInsensitive,
|
||||
documentCount,
|
||||
path,
|
||||
matchingAlgorithm,
|
||||
match,
|
||||
];
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$StoragePathToJson(this);
|
||||
}
|
||||
|
||||
@HexColorJsonConverter()
|
||||
@JsonSerializable(
|
||||
fieldRename: FieldRename.snake,
|
||||
explicitToJson: true,
|
||||
)
|
||||
class Tag extends Label {
|
||||
static const colorKey = 'color';
|
||||
static const isInboxTagKey = 'is_inbox_tag';
|
||||
static const textColorKey = 'text_color';
|
||||
static const legacyColourKey = 'colour';
|
||||
final Color? textColor;
|
||||
final Color? color;
|
||||
|
||||
final bool isInboxTag;
|
||||
|
||||
const Tag({
|
||||
super.id,
|
||||
required super.name,
|
||||
super.documentCount,
|
||||
super.isInsensitive,
|
||||
super.match,
|
||||
super.matchingAlgorithm = MatchingAlgorithm.defaultValue,
|
||||
super.slug,
|
||||
this.color,
|
||||
this.textColor,
|
||||
this.isInboxTag = false,
|
||||
super.owner,
|
||||
super.userCanChange,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
|
||||
@override
|
||||
Tag copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
String? slug,
|
||||
Color? color,
|
||||
Color? textColor,
|
||||
bool? isInboxTag,
|
||||
}) {
|
||||
return Tag(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
match: match ?? this.match,
|
||||
matchingAlgorithm: matchingAlgorithm ?? this.matchingAlgorithm,
|
||||
isInsensitive: isInsensitive ?? this.isInsensitive,
|
||||
documentCount: documentCount ?? this.documentCount,
|
||||
slug: slug ?? this.slug,
|
||||
color: color ?? this.color,
|
||||
textColor: textColor ?? this.textColor,
|
||||
isInboxTag: isInboxTag ?? this.isInboxTag,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get queryEndpoint => 'tags';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
isInsensitive,
|
||||
documentCount,
|
||||
matchingAlgorithm,
|
||||
color,
|
||||
textColor,
|
||||
isInboxTag,
|
||||
match,
|
||||
];
|
||||
|
||||
factory Tag.fromJson(Map<String, dynamic> json) => _$TagFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$TagToJson(this);
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/src/models/labels/label_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/matching_algorithm.dart';
|
||||
part 'storage_path_model.g.dart';
|
||||
|
||||
@JsonSerializable(includeIfNull: false, fieldRename: FieldRename.snake)
|
||||
class StoragePath extends Label {
|
||||
static const pathKey = 'path';
|
||||
final String path;
|
||||
|
||||
const StoragePath({
|
||||
super.id,
|
||||
required super.name,
|
||||
required this.path,
|
||||
super.slug,
|
||||
super.match,
|
||||
super.matchingAlgorithm,
|
||||
super.isInsensitive,
|
||||
super.documentCount,
|
||||
super.owner,
|
||||
super.userCanChange,
|
||||
});
|
||||
|
||||
factory StoragePath.fromJson(Map<String, dynamic> json) => _$StoragePathFromJson(json);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@override
|
||||
StoragePath copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? slug,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
String? path,
|
||||
}) {
|
||||
return StoragePath(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
documentCount: documentCount ?? documentCount,
|
||||
isInsensitive: isInsensitive ?? isInsensitive,
|
||||
path: path ?? this.path,
|
||||
match: match ?? this.match,
|
||||
matchingAlgorithm: matchingAlgorithm ?? this.matchingAlgorithm,
|
||||
slug: slug ?? this.slug,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get queryEndpoint => 'storage_paths';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
isInsensitive,
|
||||
documentCount,
|
||||
path,
|
||||
matchingAlgorithm,
|
||||
match,
|
||||
];
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$StoragePathToJson(this);
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/src/converters/hex_color_json_converter.dart';
|
||||
import 'package:paperless_api/src/models/labels/label_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/matching_algorithm.dart';
|
||||
|
||||
part 'tag_model.g.dart';
|
||||
|
||||
@HexColorJsonConverter()
|
||||
@JsonSerializable(
|
||||
fieldRename: FieldRename.snake,
|
||||
explicitToJson: true,
|
||||
)
|
||||
class Tag extends Label {
|
||||
static const colorKey = 'color';
|
||||
static const isInboxTagKey = 'is_inbox_tag';
|
||||
static const textColorKey = 'text_color';
|
||||
static const legacyColourKey = 'colour';
|
||||
final Color? textColor;
|
||||
final Color? color;
|
||||
|
||||
final bool isInboxTag;
|
||||
|
||||
const Tag({
|
||||
super.id,
|
||||
required super.name,
|
||||
super.documentCount,
|
||||
super.isInsensitive,
|
||||
super.match,
|
||||
super.matchingAlgorithm = MatchingAlgorithm.defaultValue,
|
||||
super.slug,
|
||||
this.color,
|
||||
this.textColor,
|
||||
this.isInboxTag = false,
|
||||
super.owner,
|
||||
super.userCanChange,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() => name;
|
||||
|
||||
@override
|
||||
Tag copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
String? slug,
|
||||
Color? color,
|
||||
Color? textColor,
|
||||
bool? isInboxTag,
|
||||
}) {
|
||||
return Tag(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
match: match ?? this.match,
|
||||
matchingAlgorithm: matchingAlgorithm ?? this.matchingAlgorithm,
|
||||
isInsensitive: isInsensitive ?? this.isInsensitive,
|
||||
documentCount: documentCount ?? this.documentCount,
|
||||
slug: slug ?? this.slug,
|
||||
color: color ?? this.color,
|
||||
textColor: textColor ?? this.textColor,
|
||||
isInboxTag: isInboxTag ?? this.isInboxTag,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get queryEndpoint => 'tags';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
name,
|
||||
slug,
|
||||
isInsensitive,
|
||||
documentCount,
|
||||
matchingAlgorithm,
|
||||
color,
|
||||
textColor,
|
||||
isInboxTag,
|
||||
match,
|
||||
];
|
||||
|
||||
factory Tag.fromJson(Map<String, dynamic> json) => _$TagFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$TagToJson(this);
|
||||
}
|
||||
@@ -5,12 +5,8 @@ export 'document_model.dart';
|
||||
export 'field_suggestions.dart';
|
||||
export 'filter_rule_model.dart';
|
||||
export 'group_model.dart';
|
||||
export 'labels/correspondent_model.dart';
|
||||
export 'labels/document_type_model.dart';
|
||||
export 'labels/label_model.dart';
|
||||
export 'labels/matching_algorithm.dart';
|
||||
export 'labels/storage_path_model.dart';
|
||||
export 'labels/tag_model.dart';
|
||||
export 'paged_search_result.dart';
|
||||
export 'paperless_api_exception.dart';
|
||||
export 'paperless_server_information_model.dart';
|
||||
|
||||
@@ -81,4 +81,10 @@ extension UserPermissionExtension on UserModel {
|
||||
hasPermission(PermissionAction.add, PermissionTarget.storagePath);
|
||||
bool get canCreateSavedViews =>
|
||||
hasPermission(PermissionAction.add, PermissionTarget.savedView);
|
||||
|
||||
bool get canViewAnyLabel =>
|
||||
canViewCorrespondents ||
|
||||
canViewDocumentTypes ||
|
||||
canViewTags ||
|
||||
canViewStoragePaths;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:paperless_api/src/models/labels/correspondent_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/document_type_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/storage_path_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/tag_model.dart';
|
||||
|
||||
import 'package:paperless_api/src/models/models.dart';
|
||||
|
||||
///
|
||||
/// Provides basic CRUD operations for labels, including:
|
||||
|
||||
@@ -3,10 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:paperless_api/src/extensions/dio_exception_extension.dart';
|
||||
import 'package:paperless_api/src/models/labels/correspondent_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/document_type_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/storage_path_model.dart';
|
||||
import 'package:paperless_api/src/models/labels/tag_model.dart';
|
||||
import 'package:paperless_api/src/models/models.dart';
|
||||
import 'package:paperless_api/src/models/paperless_api_exception.dart';
|
||||
import 'package:paperless_api/src/modules/labels_api/paperless_labels_api.dart';
|
||||
import 'package:paperless_api/src/request_utils.dart';
|
||||
|
||||
Reference in New Issue
Block a user