mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-06 01:15:44 -06:00
BUGFIX conditional none matching algorithm based on API version
This commit is contained in:
@@ -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(
|
||||
@@ -107,7 +113,7 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
|
||||
val != MatchingAlgorithm.none.value;
|
||||
});
|
||||
},
|
||||
items: MatchingAlgorithm.values
|
||||
items: selectableMatchingAlgorithmValues
|
||||
.map(
|
||||
(algo) => DropdownMenuItem<int?>(
|
||||
child: Text(
|
||||
@@ -140,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 {
|
||||
|
||||
@@ -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);
|
||||
@@ -257,98 +259,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: (_) => MultiBlocProvider(
|
||||
providers: [
|
||||
Provider.value(value: context.read<LabelRepository>()),
|
||||
Provider.value(value: context.read<ApiVersion>())
|
||||
],
|
||||
child: page
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class LocalMockApiServer {
|
||||
"name": body?['name'],
|
||||
"color": body?['color'],
|
||||
"text_color": "#000000",
|
||||
"match": "",
|
||||
"match": body?['match'],
|
||||
"matching_algorithm": body?['matching_algorithm'],
|
||||
"is_insensitive": body?['is_insensitive'],
|
||||
"is_inbox_tag": false,
|
||||
@@ -133,7 +133,7 @@ class LocalMockApiServer {
|
||||
"name": body?['name'],
|
||||
"color": body?['color'],
|
||||
"text_color": "#000000",
|
||||
"match": "",
|
||||
"match": body?['match'],
|
||||
"matching_algorithm": body?['matching_algorithm'],
|
||||
"is_insensitive": body?['is_insensitive'],
|
||||
"is_inbox_tag": false,
|
||||
|
||||
@@ -37,7 +37,7 @@ abstract class Label extends Equatable implements Comparable {
|
||||
Label copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
String match,
|
||||
String? match,
|
||||
MatchingAlgorithm? matchingAlgorithm,
|
||||
bool? isInsensitive,
|
||||
int? documentCount,
|
||||
|
||||
Reference in New Issue
Block a user