mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-18 04:12:41 -06:00
feat: Migrations, new saved views interface
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/search/document_filter_form.dart';
|
||||
import 'package:paperless_mobile/features/saved_view/cubit/saved_view_cubit.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
|
||||
const _fkName = 'name';
|
||||
const _fkShowOnDashboard = 'show_on_dashboard';
|
||||
const _fkShowInSidebar = 'show_in_sidebar';
|
||||
|
||||
class AddSavedViewPage extends StatefulWidget {
|
||||
final DocumentFilter? initialFilter;
|
||||
const AddSavedViewPage({
|
||||
@@ -17,12 +23,7 @@ class AddSavedViewPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AddSavedViewPageState extends State<AddSavedViewPage> {
|
||||
static const fkName = 'name';
|
||||
static const fkShowOnDashboard = 'show_on_dashboard';
|
||||
static const fkShowInSidebar = 'show_in_sidebar';
|
||||
|
||||
final _savedViewFormKey = GlobalKey<FormBuilderState>();
|
||||
final _filterFormKey = GlobalKey<FormBuilderState>();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -46,7 +47,7 @@ class _AddSavedViewPageState extends State<AddSavedViewPage> {
|
||||
child: Column(
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
name: _AddSavedViewPageState.fkName,
|
||||
name: _fkName,
|
||||
validator: (value) {
|
||||
if (value?.trim().isEmpty ?? true) {
|
||||
return S.of(context)!.thisFieldIsRequired;
|
||||
@@ -57,41 +58,53 @@ class _AddSavedViewPageState extends State<AddSavedViewPage> {
|
||||
label: Text(S.of(context)!.name),
|
||||
),
|
||||
),
|
||||
FormBuilderCheckbox(
|
||||
name: _AddSavedViewPageState.fkShowOnDashboard,
|
||||
FormBuilderField<bool>(
|
||||
name: _fkShowOnDashboard,
|
||||
initialValue: false,
|
||||
title: Text(S.of(context)!.showOnDashboard),
|
||||
builder: (field) {
|
||||
return CheckboxListTile(
|
||||
value: field.value,
|
||||
title: Text(S.of(context)!.showOnDashboard),
|
||||
onChanged: (value) => field.didChange(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
FormBuilderCheckbox(
|
||||
name: _AddSavedViewPageState.fkShowInSidebar,
|
||||
FormBuilderField<bool>(
|
||||
name: _fkShowInSidebar,
|
||||
initialValue: false,
|
||||
title: Text(S.of(context)!.showInSidebar),
|
||||
builder: (field) {
|
||||
return CheckboxListTile(
|
||||
value: field.value,
|
||||
title: Text(S.of(context)!.showInSidebar),
|
||||
onChanged: (value) => field.didChange(value),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onCreate(BuildContext context) {
|
||||
void _onCreate(BuildContext context) async {
|
||||
if (_savedViewFormKey.currentState?.saveAndValidate() ?? false) {
|
||||
// context.pop(
|
||||
// SavedView.fromDocumentFilter(
|
||||
// DocumentFilterForm.assembleFilter(
|
||||
// _filterFormKey,
|
||||
// widget.currentFilter,
|
||||
// ),
|
||||
// name: _savedViewFormKey.currentState?.value[fkName] as String,
|
||||
// showOnDashboard:
|
||||
// _savedViewFormKey.currentState?.value[fkShowOnDashboard] as bool,
|
||||
// showInSidebar:
|
||||
// _savedViewFormKey.currentState?.value[fkShowInSidebar] as bool,
|
||||
// ),
|
||||
// );
|
||||
final cubit = context.read<SavedViewCubit>();
|
||||
var savedView = SavedView.fromDocumentFilter(
|
||||
widget.initialFilter ?? const DocumentFilter(),
|
||||
name: _savedViewFormKey.currentState?.value[_fkName] as String,
|
||||
showOnDashboard:
|
||||
_savedViewFormKey.currentState?.value[_fkShowOnDashboard] as bool,
|
||||
showInSidebar:
|
||||
_savedViewFormKey.currentState?.value[_fkShowInSidebar] as bool,
|
||||
);
|
||||
final router = GoRouter.of(context);
|
||||
await cubit.add(
|
||||
savedView,
|
||||
);
|
||||
router.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user