Merge pull request #180 from losiu97/fix/add-match-none

BUGFIX add MATCH_NONE to tag matching options
This commit is contained in:
Anton Stubenbord
2023-06-02 15:04:12 +02:00
committed by GitHub
7 changed files with 58 additions and 65 deletions

View File

@@ -19,6 +19,8 @@ String translateMatchingAlgorithmDescription(
return S.of(context)!.documentContainsAWordSimilarToThisWord;
case MatchingAlgorithm.auto:
return S.of(context)!.learnMatchingAutomatically;
case MatchingAlgorithm.none:
return S.of(context)!.disableMatching;
}
}
@@ -39,5 +41,7 @@ String translateMatchingAlgorithmName(
return S.of(context)!.fuzzy;
case MatchingAlgorithm.auto:
return S.of(context)!.auto;
case MatchingAlgorithm.none:
return S.of(context)!.none;
}
}

View File

@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/translation/matching_algorithm_localization_mapper.dart';
import 'package:paperless_mobile/core/type/types.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/helpers/message_helpers.dart';
@@ -57,13 +59,17 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
@override
void initState() {
super.initState();
_enableMatchFormField = (widget.initialValue?.matchingAlgorithm ??
MatchingAlgorithm.defaultValue) !=
MatchingAlgorithm.auto;
var matchingAlgorithm = (widget.initialValue?.matchingAlgorithm ??
MatchingAlgorithm.defaultValue);
_enableMatchFormField = matchingAlgorithm != MatchingAlgorithm.auto &&
matchingAlgorithm != MatchingAlgorithm.none;
}
@override
Widget build(BuildContext context) {
List<MatchingAlgorithm> selectableMatchingAlgorithmValues =
getSelectableMatchingAlgorithmValues(
context.watch<ApiVersion>().hasMultiUserSupport);
return Scaffold(
resizeToAvoidBottomInset: false,
floatingActionButton: FloatingActionButton.extended(
@@ -103,10 +109,11 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
onChanged: (val) {
setState(() {
_errors = {};
_enableMatchFormField = val != MatchingAlgorithm.auto.value;
_enableMatchFormField = val != MatchingAlgorithm.auto.value &&
val != MatchingAlgorithm.none.value;
});
},
items: MatchingAlgorithm.values
items: selectableMatchingAlgorithmValues
.map(
(algo) => DropdownMenuItem<int?>(
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 {
if (_formKey.currentState?.saveAndValidate() ?? false) {
try {
@@ -146,11 +165,6 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
...widget.initialValue?.toJson() ?? {},
..._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 createdLabel = await widget.submitButtonConfig.onSubmit(parsed);
Navigator.pop(context, createdLabel);

View File

@@ -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_storage_path_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/view/widgets/label_tab_view.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:provider/provider.dart';
class LabelsPage extends StatefulWidget {
const LabelsPage({Key? key}) : super(key: key);
@@ -267,98 +269,70 @@ class _LabelsPageState extends State<LabelsPage> with SingleTickerProviderStateM
void _openEditCorrespondentPage(Correspondent correspondent) {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => RepositoryProvider.value(
value: context.read<LabelRepository>(),
child: EditCorrespondentPage(correspondent: correspondent),
),
),
_buildLabelPageRoute(EditCorrespondentPage(correspondent: correspondent)),
);
}
void _openEditDocumentTypePage(DocumentType docType) {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => RepositoryProvider.value(
value: context.read<LabelRepository>(),
child: EditDocumentTypePage(documentType: docType),
),
),
_buildLabelPageRoute(EditDocumentTypePage(documentType: docType)),
);
}
void _openEditTagPage(Tag tag) {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => RepositoryProvider.value(
value: context.read<LabelRepository>(),
child: EditTagPage(tag: tag),
),
),
_buildLabelPageRoute(EditTagPage(tag: tag)),
);
}
void _openEditStoragePathPage(StoragePath path) {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => RepositoryProvider.value(
value: context.read<LabelRepository>(),
child: EditStoragePathPage(
storagePath: path,
),
),
),
_buildLabelPageRoute(EditStoragePathPage(
storagePath: path,
)),
);
}
void _openAddCorrespondentPage() {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => RepositoryProvider.value(
value: context.read<LabelRepository>(),
child: const AddCorrespondentPage(),
),
),
_buildLabelPageRoute(const AddCorrespondentPage()),
);
}
void _openAddDocumentTypePage() {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => RepositoryProvider.value(
value: context.read<LabelRepository>(),
child: const AddDocumentTypePage(),
),
),
_buildLabelPageRoute(const AddDocumentTypePage()),
);
}
void _openAddTagPage() {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => RepositoryProvider.value(
value: context.read<LabelRepository>(),
child: const AddTagPage(),
),
),
_buildLabelPageRoute(const AddTagPage()),
);
}
void _openAddStoragePathPage() {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => RepositoryProvider.value(
value: context.read<LabelRepository>(),
child: const AddStoragePathPage(),
),
),
_buildLabelPageRoute(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
)
);
}
}