From 3eac70a4e604d1ad8102dd2ec46fade625eecd72 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 9 Aug 2023 19:08:35 +0300 Subject: [PATCH] Improve documents --- lib/redux/document/document_reducer.dart | 14 +++ lib/ui/app/list_filter.dart | 122 ++++++++++++----------- lib/ui/document/document_screen.dart | 11 +- 3 files changed, 82 insertions(+), 65 deletions(-) diff --git a/lib/redux/document/document_reducer.dart b/lib/redux/document/document_reducer.dart index 5651092ab..7eee18f39 100644 --- a/lib/redux/document/document_reducer.dart +++ b/lib/redux/document/document_reducer.dart @@ -23,6 +23,7 @@ final forceSelectedReducer = combineReducers([ TypedReducer((completer, action) => true), TypedReducer((completer, action) => false), TypedReducer((completer, action) => false), + TypedReducer((completer, action) => false), TypedReducer((completer, action) => false), TypedReducer((completer, action) => false), TypedReducer((completer, action) => false), @@ -43,6 +44,7 @@ Reducer selectedIdReducer = combineReducers([ TypedReducer((selectedId, action) => ''), TypedReducer((selectedId, action) => ''), TypedReducer((selectedId, action) => ''), + TypedReducer((selectedId, action) => ''), TypedReducer((selectedId, action) => ''), TypedReducer((selectedId, action) => ''), TypedReducer((selectedId, action) => ''), @@ -68,6 +70,7 @@ DocumentEntity _updateEditing(DocumentEntity document, dynamic action) { final documentListReducer = combineReducers([ TypedReducer(_sortDocuments), TypedReducer(_filterDocumentsByState), + TypedReducer(_filterDocumentsByStatus), TypedReducer(_filterDocuments), TypedReducer( _filterDocumentsByCustom1), @@ -125,6 +128,17 @@ ListUIState _filterDocumentsByState( } } +ListUIState _filterDocumentsByStatus( + ListUIState documentListState, FilterDocumentsByStatus action) { + if (documentListState.statusFilters.contains(action.status)) { + return documentListState + .rebuild((b) => b..statusFilters.remove(action.status)); + } else { + return documentListState + .rebuild((b) => b..statusFilters.add(action.status)); + } +} + ListUIState _filterDocuments( ListUIState documentListState, FilterDocuments action) { return documentListState.rebuild((b) => b diff --git a/lib/ui/app/list_filter.dart b/lib/ui/app/list_filter.dart index e932bb555..8eeec34f4 100644 --- a/lib/ui/app/list_filter.dart +++ b/lib/ui/app/list_filter.dart @@ -142,69 +142,71 @@ class _ListFilterState extends State { ), ), ), - if (isDesktop(context) && - !isDashboardOrSettings && - widget.onSelectedState != null) ...[ - SizedBox(width: 8), - Flexible( - child: DropDownMultiSelect( - onChanged: (List selected) { - final stateFilters = state + if (isDesktop(context) && !isDashboardOrSettings) ...[ + if (widget.onSelectedState != null) ...[ + SizedBox(width: 8), + Flexible( + child: DropDownMultiSelect( + onChanged: (List selected) { + final stateFilters = state + .getListState(widget.entityType) + .stateFilters + .toList(); + + final added = selected + .where((dynamic e) => !stateFilters.contains(e)); + final removed = stateFilters + .where((dynamic e) => !selected.contains(e)); + + for (var state in added) { + widget.onSelectedState(state, true); + } + for (var state in removed) { + widget.onSelectedState(state, false); + } + }, + options: EntityState.values.toList(), + decoration: InputDecoration( + border: OutlineInputBorder(borderSide: BorderSide()), + enabledBorder: state.prefState.enableDarkMode + ? null + : OutlineInputBorder( + borderSide: BorderSide(color: Colors.white)), + isDense: true, + contentPadding: + EdgeInsets.symmetric(vertical: 13, horizontal: 10), + ), + selectedValues: state .getListState(widget.entityType) .stateFilters - .toList(); - - final added = - selected.where((dynamic e) => !stateFilters.contains(e)); - final removed = - stateFilters.where((dynamic e) => !selected.contains(e)); - - for (var state in added) { - widget.onSelectedState(state, true); - } - for (var state in removed) { - widget.onSelectedState(state, false); - } - }, - options: EntityState.values.toList(), - decoration: InputDecoration( - border: OutlineInputBorder(borderSide: BorderSide()), - enabledBorder: state.prefState.enableDarkMode - ? null - : OutlineInputBorder( - borderSide: BorderSide(color: Colors.white)), - isDense: true, - contentPadding: - EdgeInsets.symmetric(vertical: 13, horizontal: 10), - ), - selectedValues: - state.getListState(widget.entityType).stateFilters.toList(), - whenEmpty: localization.all, - menuItembuilder: (dynamic value) { - final state = value as EntityState; - return Text( - localization.lookup(state.name), - overflow: TextOverflow.clip, - maxLines: 1, - ); - }, - childBuilder: (selected) { - return Align( - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 10), - child: Text( - selected.isNotEmpty - ? selected - .map((dynamic value) => localization - .lookup((value as EntityState).name)) - .join(', ') - : localization.all, - style: TextStyle(fontSize: 15), + .toList(), + whenEmpty: localization.all, + menuItembuilder: (dynamic value) { + final state = value as EntityState; + return Text( + localization.lookup(state.name), + overflow: TextOverflow.clip, + maxLines: 1, + ); + }, + childBuilder: (selected) { + return Align( + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 10), + child: Text( + selected.isNotEmpty + ? selected + .map((dynamic value) => localization + .lookup((value as EntityState).name)) + .join(', ') + : localization.all, + style: TextStyle(fontSize: 15), + ), ), - ), - alignment: Alignment.centerLeft); - }), - ), + alignment: Alignment.centerLeft); + }), + ), + ], if (widget.statuses != null) ...[ SizedBox(width: 8), Flexible( diff --git a/lib/ui/document/document_screen.dart b/lib/ui/document/document_screen.dart index b6e9b7836..cad791133 100644 --- a/lib/ui/document/document_screen.dart +++ b/lib/ui/document/document_screen.dart @@ -7,6 +7,7 @@ import 'package:invoiceninja_flutter/constants.dart'; // Project imports: import 'package:invoiceninja_flutter/data/models/models.dart'; +import 'package:invoiceninja_flutter/data/models/static/document_status_model.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/document/document_actions.dart'; @@ -36,27 +37,27 @@ class DocumentScreen extends StatelessWidget { final localization = AppLocalization.of(context); final statuses = [ - InvoiceStatusEntity().rebuild( + DocumentStatusEntity().rebuild( (b) => b ..id = kDocumentStatusPublic ..name = localization.public, ), - InvoiceStatusEntity().rebuild( + DocumentStatusEntity().rebuild( (b) => b ..id = kDocumentStatusPrivate ..name = localization.private, ), - InvoiceStatusEntity().rebuild( + DocumentStatusEntity().rebuild( (b) => b ..id = kDocumentStatusImage ..name = localization.image, ), - InvoiceStatusEntity().rebuild( + DocumentStatusEntity().rebuild( (b) => b ..id = kDocumentStatusPDF ..name = localization.pdf, ), - InvoiceStatusEntity().rebuild( + DocumentStatusEntity().rebuild( (b) => b ..id = kDocumentStatusOther ..name = localization.other,