mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 10:07:51 -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/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(
|
||||||
@@ -107,7 +113,7 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
|
|||||||
val != MatchingAlgorithm.none.value;
|
val != MatchingAlgorithm.none.value;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
items: MatchingAlgorithm.values
|
items: selectableMatchingAlgorithmValues
|
||||||
.map(
|
.map(
|
||||||
(algo) => DropdownMenuItem<int?>(
|
(algo) => DropdownMenuItem<int?>(
|
||||||
child: Text(
|
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 {
|
void _onSubmit() async {
|
||||||
if (_formKey.currentState?.saveAndValidate() ?? false) {
|
if (_formKey.currentState?.saveAndValidate() ?? false) {
|
||||||
try {
|
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_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);
|
||||||
@@ -257,98 +259,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: (_) => 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'],
|
"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,
|
||||||
@@ -133,7 +133,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,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ abstract class Label extends Equatable implements Comparable {
|
|||||||
Label copyWith({
|
Label copyWith({
|
||||||
int? id,
|
int? id,
|
||||||
String? name,
|
String? name,
|
||||||
String match,
|
String? match,
|
||||||
MatchingAlgorithm? matchingAlgorithm,
|
MatchingAlgorithm? matchingAlgorithm,
|
||||||
bool? isInsensitive,
|
bool? isInsensitive,
|
||||||
int? documentCount,
|
int? documentCount,
|
||||||
|
|||||||
Reference in New Issue
Block a user