mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-14 16:12:20 -06:00
Merge pull request #180 from losiu97/fix/add-match-none
BUGFIX add MATCH_NONE to tag matching options
This commit is contained in:
@@ -19,6 +19,8 @@ String translateMatchingAlgorithmDescription(
|
|||||||
return S.of(context)!.documentContainsAWordSimilarToThisWord;
|
return S.of(context)!.documentContainsAWordSimilarToThisWord;
|
||||||
case MatchingAlgorithm.auto:
|
case MatchingAlgorithm.auto:
|
||||||
return S.of(context)!.learnMatchingAutomatically;
|
return S.of(context)!.learnMatchingAutomatically;
|
||||||
|
case MatchingAlgorithm.none:
|
||||||
|
return S.of(context)!.disableMatching;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,5 +41,7 @@ String translateMatchingAlgorithmName(
|
|||||||
return S.of(context)!.fuzzy;
|
return S.of(context)!.fuzzy;
|
||||||
case MatchingAlgorithm.auto:
|
case MatchingAlgorithm.auto:
|
||||||
return S.of(context)!.auto;
|
return S.of(context)!.auto;
|
||||||
|
case MatchingAlgorithm.none:
|
||||||
|
return S.of(context)!.none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||||
|
|
||||||
import 'package:paperless_api/paperless_api.dart';
|
import 'package:paperless_api/paperless_api.dart';
|
||||||
import 'package:paperless_mobile/core/translation/matching_algorithm_localization_mapper.dart';
|
import 'package:paperless_mobile/core/translation/matching_algorithm_localization_mapper.dart';
|
||||||
import 'package:paperless_mobile/core/type/types.dart';
|
import 'package:paperless_mobile/core/type/types.dart';
|
||||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||||
|
import 'package:paperless_mobile/features/home/view/model/api_version.dart';
|
||||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||||
@@ -57,13 +59,17 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_enableMatchFormField = (widget.initialValue?.matchingAlgorithm ??
|
var matchingAlgorithm = (widget.initialValue?.matchingAlgorithm ??
|
||||||
MatchingAlgorithm.defaultValue) !=
|
MatchingAlgorithm.defaultValue);
|
||||||
MatchingAlgorithm.auto;
|
_enableMatchFormField = matchingAlgorithm != MatchingAlgorithm.auto &&
|
||||||
|
matchingAlgorithm != MatchingAlgorithm.none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
List<MatchingAlgorithm> selectableMatchingAlgorithmValues =
|
||||||
|
getSelectableMatchingAlgorithmValues(
|
||||||
|
context.watch<ApiVersion>().hasMultiUserSupport);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
floatingActionButton: FloatingActionButton.extended(
|
floatingActionButton: FloatingActionButton.extended(
|
||||||
@@ -103,10 +109,11 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
|
|||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_errors = {};
|
_errors = {};
|
||||||
_enableMatchFormField = val != MatchingAlgorithm.auto.value;
|
_enableMatchFormField = val != MatchingAlgorithm.auto.value &&
|
||||||
|
val != MatchingAlgorithm.none.value;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
items: MatchingAlgorithm.values
|
items: selectableMatchingAlgorithmValues
|
||||||
.map(
|
.map(
|
||||||
(algo) => DropdownMenuItem<int?>(
|
(algo) => DropdownMenuItem<int?>(
|
||||||
child: Text(
|
child: Text(
|
||||||
@@ -139,6 +146,18 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<MatchingAlgorithm> getSelectableMatchingAlgorithmValues(
|
||||||
|
bool hasMultiUserSupport) {
|
||||||
|
var selectableMatchingAlgorithmValues = MatchingAlgorithm.values;
|
||||||
|
if (!hasMultiUserSupport) {
|
||||||
|
selectableMatchingAlgorithmValues = selectableMatchingAlgorithmValues
|
||||||
|
.where((matchingAlgorithm) =>
|
||||||
|
matchingAlgorithm != MatchingAlgorithm.none)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
return selectableMatchingAlgorithmValues;
|
||||||
|
}
|
||||||
|
|
||||||
void _onSubmit() async {
|
void _onSubmit() async {
|
||||||
if (_formKey.currentState?.saveAndValidate() ?? false) {
|
if (_formKey.currentState?.saveAndValidate() ?? false) {
|
||||||
try {
|
try {
|
||||||
@@ -146,11 +165,6 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
|
|||||||
...widget.initialValue?.toJson() ?? {},
|
...widget.initialValue?.toJson() ?? {},
|
||||||
..._formKey.currentState!.value
|
..._formKey.currentState!.value
|
||||||
};
|
};
|
||||||
if (mergedJson[Label.matchingAlgorithmKey] ==
|
|
||||||
MatchingAlgorithm.auto.value) {
|
|
||||||
// If auto is selected, the match will be removed.
|
|
||||||
mergedJson[Label.matchKey] = '';
|
|
||||||
}
|
|
||||||
final parsed = widget.fromJsonT(mergedJson);
|
final parsed = widget.fromJsonT(mergedJson);
|
||||||
final createdLabel = await widget.submitButtonConfig.onSubmit(parsed);
|
final createdLabel = await widget.submitButtonConfig.onSubmit(parsed);
|
||||||
Navigator.pop(context, createdLabel);
|
Navigator.pop(context, createdLabel);
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ import 'package:paperless_mobile/features/edit_label/view/impl/edit_corresponden
|
|||||||
import 'package:paperless_mobile/features/edit_label/view/impl/edit_document_type_page.dart';
|
import 'package:paperless_mobile/features/edit_label/view/impl/edit_document_type_page.dart';
|
||||||
import 'package:paperless_mobile/features/edit_label/view/impl/edit_storage_path_page.dart';
|
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/edit_label/view/impl/edit_tag_page.dart';
|
||||||
|
import 'package:paperless_mobile/features/home/view/model/api_version.dart';
|
||||||
import 'package:paperless_mobile/features/labels/cubit/label_cubit.dart';
|
import 'package:paperless_mobile/features/labels/cubit/label_cubit.dart';
|
||||||
import 'package:paperless_mobile/features/labels/view/widgets/label_tab_view.dart';
|
import 'package:paperless_mobile/features/labels/view/widgets/label_tab_view.dart';
|
||||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class LabelsPage extends StatefulWidget {
|
class LabelsPage extends StatefulWidget {
|
||||||
const LabelsPage({Key? key}) : super(key: key);
|
const LabelsPage({Key? key}) : super(key: key);
|
||||||
@@ -267,98 +269,70 @@ class _LabelsPageState extends State<LabelsPage> with SingleTickerProviderStateM
|
|||||||
void _openEditCorrespondentPage(Correspondent correspondent) {
|
void _openEditCorrespondentPage(Correspondent correspondent) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
_buildLabelPageRoute(EditCorrespondentPage(correspondent: correspondent)),
|
||||||
builder: (_) => RepositoryProvider.value(
|
|
||||||
value: context.read<LabelRepository>(),
|
|
||||||
child: EditCorrespondentPage(correspondent: correspondent),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openEditDocumentTypePage(DocumentType docType) {
|
void _openEditDocumentTypePage(DocumentType docType) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
_buildLabelPageRoute(EditDocumentTypePage(documentType: docType)),
|
||||||
builder: (_) => RepositoryProvider.value(
|
|
||||||
value: context.read<LabelRepository>(),
|
|
||||||
child: EditDocumentTypePage(documentType: docType),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openEditTagPage(Tag tag) {
|
void _openEditTagPage(Tag tag) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
_buildLabelPageRoute(EditTagPage(tag: tag)),
|
||||||
builder: (_) => RepositoryProvider.value(
|
|
||||||
value: context.read<LabelRepository>(),
|
|
||||||
child: EditTagPage(tag: tag),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openEditStoragePathPage(StoragePath path) {
|
void _openEditStoragePathPage(StoragePath path) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
_buildLabelPageRoute(EditStoragePathPage(
|
||||||
builder: (_) => RepositoryProvider.value(
|
storagePath: path,
|
||||||
value: context.read<LabelRepository>(),
|
)),
|
||||||
child: EditStoragePathPage(
|
|
||||||
storagePath: path,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openAddCorrespondentPage() {
|
void _openAddCorrespondentPage() {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
_buildLabelPageRoute(const AddCorrespondentPage()),
|
||||||
builder: (_) => RepositoryProvider.value(
|
|
||||||
value: context.read<LabelRepository>(),
|
|
||||||
child: const AddCorrespondentPage(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openAddDocumentTypePage() {
|
void _openAddDocumentTypePage() {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
_buildLabelPageRoute(const AddDocumentTypePage()),
|
||||||
builder: (_) => RepositoryProvider.value(
|
|
||||||
value: context.read<LabelRepository>(),
|
|
||||||
child: const AddDocumentTypePage(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openAddTagPage() {
|
void _openAddTagPage() {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
_buildLabelPageRoute(const AddTagPage()),
|
||||||
builder: (_) => RepositoryProvider.value(
|
|
||||||
value: context.read<LabelRepository>(),
|
|
||||||
child: const AddTagPage(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openAddStoragePathPage() {
|
void _openAddStoragePathPage() {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
_buildLabelPageRoute(const AddStoragePathPage()),
|
||||||
builder: (_) => RepositoryProvider.value(
|
);
|
||||||
value: context.read<LabelRepository>(),
|
}
|
||||||
child: const AddStoragePathPage(),
|
|
||||||
),
|
MaterialPageRoute<dynamic> _buildLabelPageRoute(Widget page) {
|
||||||
),
|
return MaterialPageRoute(
|
||||||
|
builder: (_) => MultiProvider(
|
||||||
|
providers: [
|
||||||
|
Provider.value(value: context.read<LabelRepository>()),
|
||||||
|
Provider.value(value: context.read<ApiVersion>())
|
||||||
|
],
|
||||||
|
child: page
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class LocalMockApiServer {
|
|||||||
"name": body?['name'],
|
"name": body?['name'],
|
||||||
"color": body?['color'],
|
"color": body?['color'],
|
||||||
"text_color": "#000000",
|
"text_color": "#000000",
|
||||||
"match": "",
|
"match": body?['match'],
|
||||||
"matching_algorithm": body?['matching_algorithm'],
|
"matching_algorithm": body?['matching_algorithm'],
|
||||||
"is_insensitive": body?['is_insensitive'],
|
"is_insensitive": body?['is_insensitive'],
|
||||||
"is_inbox_tag": false,
|
"is_inbox_tag": false,
|
||||||
@@ -129,7 +129,7 @@ class LocalMockApiServer {
|
|||||||
"name": body?['name'],
|
"name": body?['name'],
|
||||||
"color": body?['color'],
|
"color": body?['color'],
|
||||||
"text_color": "#000000",
|
"text_color": "#000000",
|
||||||
"match": "",
|
"match": body?['match'],
|
||||||
"matching_algorithm": body?['matching_algorithm'],
|
"matching_algorithm": body?['matching_algorithm'],
|
||||||
"is_insensitive": body?['is_insensitive'],
|
"is_insensitive": body?['is_insensitive'],
|
||||||
"is_inbox_tag": false,
|
"is_inbox_tag": false,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ dependencies:
|
|||||||
logging: ^1.1.1
|
logging: ^1.1.1
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
http: ^1.0.0
|
http: ^0.13.4
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ abstract class Label extends Equatable implements Comparable {
|
|||||||
final int? id;
|
final int? id;
|
||||||
final String name;
|
final String name;
|
||||||
final String? slug;
|
final String? slug;
|
||||||
final String? match;
|
final String match;
|
||||||
final MatchingAlgorithm matchingAlgorithm;
|
final MatchingAlgorithm matchingAlgorithm;
|
||||||
final bool? isInsensitive;
|
final bool? isInsensitive;
|
||||||
final int? documentCount;
|
final int? documentCount;
|
||||||
@@ -26,7 +26,7 @@ abstract class Label extends Equatable implements Comparable {
|
|||||||
this.id,
|
this.id,
|
||||||
required this.name,
|
required this.name,
|
||||||
this.matchingAlgorithm = MatchingAlgorithm.defaultValue,
|
this.matchingAlgorithm = MatchingAlgorithm.defaultValue,
|
||||||
this.match,
|
this.match = "",
|
||||||
this.isInsensitive = true,
|
this.isInsensitive = true,
|
||||||
this.documentCount,
|
this.documentCount,
|
||||||
this.slug,
|
this.slug,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:json_annotation/json_annotation.dart';
|
|||||||
|
|
||||||
@JsonEnum(valueField: 'value')
|
@JsonEnum(valueField: 'value')
|
||||||
enum MatchingAlgorithm {
|
enum MatchingAlgorithm {
|
||||||
|
none(0, "None: Disable matching"),
|
||||||
anyWord(1, "Any: Match one of the following words"),
|
anyWord(1, "Any: Match one of the following words"),
|
||||||
allWords(2, "All: Match all of the following words"),
|
allWords(2, "All: Match all of the following words"),
|
||||||
exactMatch(3, "Exact: Match the following string"),
|
exactMatch(3, "Exact: Match the following string"),
|
||||||
|
|||||||
Reference in New Issue
Block a user