From e3f2aad65ccdf6d3fbd1c61bef8bdd81f3ebe8da Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 12 Aug 2022 10:18:06 +0300 Subject: [PATCH] Dashboard overview --- lib/redux/dashboard/dashboard_actions.dart | 2 + lib/redux/dashboard/dashboard_reducer.dart | 3 + lib/redux/dashboard/dashboard_state.dart | 4 ++ lib/redux/dashboard/dashboard_state.g.dart | 56 ++++++++++++++----- lib/ui/dashboard/dashboard_panels.dart | 20 ++++++- lib/ui/invoice/edit/invoice_edit_desktop.dart | 6 +- lib/utils/i18n.dart | 5 ++ 7 files changed, 77 insertions(+), 19 deletions(-) diff --git a/lib/redux/dashboard/dashboard_actions.dart b/lib/redux/dashboard/dashboard_actions.dart index fbb09de01..efc381cce 100644 --- a/lib/redux/dashboard/dashboard_actions.dart +++ b/lib/redux/dashboard/dashboard_actions.dart @@ -25,6 +25,7 @@ class UpdateDashboardSettings implements PersistUI { this.showPreviousPeriod, this.showTotal, this.totalFields, + this.numberFieldsPerRow, }); DashboardSettings settings; @@ -36,6 +37,7 @@ class UpdateDashboardSettings implements PersistUI { bool showPreviousPeriod; bool showTotal; BuiltList totalFields; + final int numberFieldsPerRow; } class UpdateDashboardSelection implements PersistUI { diff --git a/lib/redux/dashboard/dashboard_reducer.dart b/lib/redux/dashboard/dashboard_reducer.dart index 1542897f4..c02e79ea0 100644 --- a/lib/redux/dashboard/dashboard_reducer.dart +++ b/lib/redux/dashboard/dashboard_reducer.dart @@ -75,6 +75,9 @@ DashboardUISettings dashboardSettingsReducer( return state.rebuild((b) => b..showTotal = action.showTotal); } else if (action.totalFields != null) { return state.rebuild((b) => b..totalFields.replace(action.totalFields)); + } else if (action.numberFieldsPerRow != null) { + return state + .rebuild((b) => b..numberFieldsPerRow = action.numberFieldsPerRow); } } else if (action is SelectCompany) { //return state.rebuild((b) => b..currencyId = action.company.currencyId); diff --git a/lib/redux/dashboard/dashboard_state.dart b/lib/redux/dashboard/dashboard_state.dart index 7a78c82ab..443272800 100644 --- a/lib/redux/dashboard/dashboard_state.dart +++ b/lib/redux/dashboard/dashboard_state.dart @@ -59,6 +59,7 @@ abstract class DashboardUISettings showCurrentPeriod: true, showPreviousPeriod: false, showTotal: true, + numberFieldsPerRow: 2, totalFields: BuiltList([ FIELD_COMPLETED_PAYMENTS, FIELD_OUTSTANDING_INVOICES, @@ -116,6 +117,8 @@ abstract class DashboardUISettings bool get showTotal; + int get numberFieldsPerRow; + BuiltList get totalFields; bool matchesCurrency(String match) { @@ -154,6 +157,7 @@ abstract class DashboardUISettings ..showTotal = true ..showPreviousPeriod = false ..showCurrentPeriod = true + ..numberFieldsPerRow = 2 ..totalFields.replace(BuiltList()); static Serializer get serializer => diff --git a/lib/redux/dashboard/dashboard_state.g.dart b/lib/redux/dashboard/dashboard_state.g.dart index 72bfa1244..f1bfef065 100644 --- a/lib/redux/dashboard/dashboard_state.g.dart +++ b/lib/redux/dashboard/dashboard_state.g.dart @@ -137,6 +137,9 @@ class _$DashboardUISettingsSerializer 'showTotal', serializers.serialize(object.showTotal, specifiedType: const FullType(bool)), + 'numberFieldsPerRow', + serializers.serialize(object.numberFieldsPerRow, + specifiedType: const FullType(int)), 'totalFields', serializers.serialize(object.totalFields, specifiedType: @@ -215,6 +218,10 @@ class _$DashboardUISettingsSerializer result.showTotal = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; break; + case 'numberFieldsPerRow': + result.numberFieldsPerRow = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; case 'totalFields': result.totalFields.replace(serializers.deserialize(value, specifiedType: @@ -409,6 +416,8 @@ class _$DashboardUISettings extends DashboardUISettings { @override final bool showTotal; @override + final int numberFieldsPerRow; + @override final BuiltList totalFields; factory _$DashboardUISettings( @@ -430,6 +439,7 @@ class _$DashboardUISettings extends DashboardUISettings { this.showCurrentPeriod, this.showPreviousPeriod, this.showTotal, + this.numberFieldsPerRow, this.totalFields}) : super._() { BuiltValueNullFieldError.checkNotNull( @@ -460,6 +470,8 @@ class _$DashboardUISettings extends DashboardUISettings { showPreviousPeriod, 'DashboardUISettings', 'showPreviousPeriod'); BuiltValueNullFieldError.checkNotNull( showTotal, 'DashboardUISettings', 'showTotal'); + BuiltValueNullFieldError.checkNotNull( + numberFieldsPerRow, 'DashboardUISettings', 'numberFieldsPerRow'); BuiltValueNullFieldError.checkNotNull( totalFields, 'DashboardUISettings', 'totalFields'); } @@ -491,6 +503,7 @@ class _$DashboardUISettings extends DashboardUISettings { showCurrentPeriod == other.showCurrentPeriod && showPreviousPeriod == other.showPreviousPeriod && showTotal == other.showTotal && + numberFieldsPerRow == other.numberFieldsPerRow && totalFields == other.totalFields; } @@ -512,23 +525,28 @@ class _$DashboardUISettings extends DashboardUISettings { $jc( $jc( $jc( - 0, - dateRange + $jc( + 0, + dateRange + .hashCode), + customStartDate .hashCode), - customStartDate + customEndDate .hashCode), - customEndDate.hashCode), - enableComparison.hashCode), - compareDateRange.hashCode), - compareCustomStartDate.hashCode), - compareCustomEndDate.hashCode), - offset.hashCode), - currencyId.hashCode), - includeTaxes.hashCode), - groupBy.hashCode), - showCurrentPeriod.hashCode), - showPreviousPeriod.hashCode), - showTotal.hashCode), + enableComparison + .hashCode), + compareDateRange.hashCode), + compareCustomStartDate + .hashCode), + compareCustomEndDate.hashCode), + offset.hashCode), + currencyId.hashCode), + includeTaxes.hashCode), + groupBy.hashCode), + showCurrentPeriod.hashCode), + showPreviousPeriod.hashCode), + showTotal.hashCode), + numberFieldsPerRow.hashCode), totalFields.hashCode)); } @@ -549,6 +567,7 @@ class _$DashboardUISettings extends DashboardUISettings { ..add('showCurrentPeriod', showCurrentPeriod) ..add('showPreviousPeriod', showPreviousPeriod) ..add('showTotal', showTotal) + ..add('numberFieldsPerRow', numberFieldsPerRow) ..add('totalFields', totalFields)) .toString(); } @@ -622,6 +641,11 @@ class DashboardUISettingsBuilder bool get showTotal => _$this._showTotal; set showTotal(bool showTotal) => _$this._showTotal = showTotal; + int _numberFieldsPerRow; + int get numberFieldsPerRow => _$this._numberFieldsPerRow; + set numberFieldsPerRow(int numberFieldsPerRow) => + _$this._numberFieldsPerRow = numberFieldsPerRow; + ListBuilder _totalFields; ListBuilder get totalFields => _$this._totalFields ??= new ListBuilder(); @@ -649,6 +673,7 @@ class DashboardUISettingsBuilder _showCurrentPeriod = $v.showCurrentPeriod; _showPreviousPeriod = $v.showPreviousPeriod; _showTotal = $v.showTotal; + _numberFieldsPerRow = $v.numberFieldsPerRow; _totalFields = $v.totalFields.toBuilder(); _$v = null; } @@ -693,6 +718,7 @@ class DashboardUISettingsBuilder showCurrentPeriod: BuiltValueNullFieldError.checkNotNull(showCurrentPeriod, 'DashboardUISettings', 'showCurrentPeriod'), showPreviousPeriod: BuiltValueNullFieldError.checkNotNull(showPreviousPeriod, 'DashboardUISettings', 'showPreviousPeriod'), showTotal: BuiltValueNullFieldError.checkNotNull(showTotal, 'DashboardUISettings', 'showTotal'), + numberFieldsPerRow: BuiltValueNullFieldError.checkNotNull(numberFieldsPerRow, 'DashboardUISettings', 'numberFieldsPerRow'), totalFields: totalFields.build()); } catch (_) { String _$failedField; diff --git a/lib/ui/dashboard/dashboard_panels.dart b/lib/ui/dashboard/dashboard_panels.dart index 7aa47317a..1307784f1 100644 --- a/lib/ui/dashboard/dashboard_panels.dart +++ b/lib/ui/dashboard/dashboard_panels.dart @@ -17,6 +17,7 @@ import 'package:invoiceninja_flutter/redux/task/task_actions.dart'; import 'package:invoiceninja_flutter/ui/app/actions_menu_button.dart'; import 'package:invoiceninja_flutter/ui/app/app_border.dart'; import 'package:invoiceninja_flutter/ui/app/form_card.dart'; +import 'package:invoiceninja_flutter/ui/app/forms/app_dropdown_button.dart'; import 'package:invoiceninja_flutter/ui/app/live_text.dart'; import 'package:invoiceninja_flutter/ui/app/review_app.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; @@ -680,7 +681,7 @@ class DashboardPanels extends StatelessWidget { Padding( padding: const EdgeInsets.symmetric(horizontal: 12), child: StaggeredGrid.count( - crossAxisCount: 2, + crossAxisCount: settings.numberFieldsPerRow, crossAxisSpacing: 8, mainAxisSpacing: 12, children: settings.totalFields.map((field) { @@ -1099,6 +1100,23 @@ class _DashboardTotalsSettingsState extends State<_DashboardTotalsSettings> { title: Text(localization.total), controlAffinity: ListTileControlAffinity.leading, ), + Padding( + padding: const EdgeInsets.only(left: 16, right: 24), + child: AppDropdownButton( + labelText: localization.fieldsPerRow, + value: settings.numberFieldsPerRow, + onChanged: (dynamic value) { + store.dispatch( + UpdateDashboardSettings(numberFieldsPerRow: value)); + setState(() {}); + }, + items: List.generate(8, (i) => i + 1) + .map((value) => DropdownMenuItem( + child: Text('$value'), + value: value, + )) + .toList()), + ) ], ); } diff --git a/lib/ui/invoice/edit/invoice_edit_desktop.dart b/lib/ui/invoice/edit/invoice_edit_desktop.dart index 4f2760b40..571af62c9 100644 --- a/lib/ui/invoice/edit/invoice_edit_desktop.dart +++ b/lib/ui/invoice/edit/invoice_edit_desktop.dart @@ -382,9 +382,9 @@ class InvoiceEditDesktopState extends State child: Text(localization.usePaymentTerms), value: 'terms', ), - DropdownMenuItem( - child: Text(localization.dueOnReceipt), - value: 'on_receipt', + DropdownMenuItem( + child: Text(localization.dueOnReceipt), + value: 'on_receipt', ), ...List.generate(31, (i) => i + 1) .map((value) => DropdownMenuItem( diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 22c689abc..90ed13d45 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -16,6 +16,7 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'fields_per_row': 'Fields Per Row', 'total_active_invoices': 'Active Invoices', 'total_outstanding_invoices': 'Outstanding Invoices', 'total_completed_payments': 'Completed Payments', @@ -85354,6 +85355,10 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]['total_invoice_paid_expenses'] ?? _localizedValues['en']['total_invoice_paid_expenses']; + String get fieldsPerRow => + _localizedValues[localeCode]['fields_per_row'] ?? + _localizedValues['en']['fields_per_row']; + // STARTER: lang field - do not remove comment String lookup(String key) {