diff --git a/lib/data/models/company_model.dart b/lib/data/models/company_model.dart index cf5be7e47..493045277 100644 --- a/lib/data/models/company_model.dart +++ b/lib/data/models/company_model.dart @@ -1011,6 +1011,8 @@ abstract class UserSettingsEntity period: DashboardUISettings.PERIOD_CURRENT, ), ]), + dashboardFieldsPerRowMobile: 1, + dashboardFieldsPerRowDesktop: 2, ); } @@ -1039,6 +1041,12 @@ abstract class UserSettingsEntity @BuiltValueField(wireName: 'dashboard_fields') BuiltList get dashboardFields; + @BuiltValueField(wireName: 'dashboard_fields_per_row_mobile') + int get dashboardFieldsPerRowMobile; + + @BuiltValueField(wireName: 'dashboard_fields_per_row_desktop') + int get dashboardFieldsPerRowDesktop; + List getTableColumns(EntityType entityType) { if (tableColumns != null && tableColumns.containsKey('$entityType')) { return tableColumns['$entityType'].toList(); @@ -1063,6 +1071,8 @@ abstract class UserSettingsEntity period: DashboardUISettings.PERIOD_CURRENT, ), ])) + ..dashboardFieldsPerRowMobile = 1 + ..dashboardFieldsPerRowDesktop = 2 ..includeDeletedClients = false; static Serializer get serializer => diff --git a/lib/data/models/company_model.g.dart b/lib/data/models/company_model.g.dart index dbaf11450..d3d5067de 100644 --- a/lib/data/models/company_model.g.dart +++ b/lib/data/models/company_model.g.dart @@ -1186,6 +1186,12 @@ class _$UserSettingsEntitySerializer serializers.serialize(object.dashboardFields, specifiedType: const FullType( BuiltList, const [const FullType(DashboardField)])), + 'dashboard_fields_per_row_mobile', + serializers.serialize(object.dashboardFieldsPerRowMobile, + specifiedType: const FullType(int)), + 'dashboard_fields_per_row_desktop', + serializers.serialize(object.dashboardFieldsPerRowDesktop, + specifiedType: const FullType(int)), ]; Object value; value = object.accentColor; @@ -1242,6 +1248,14 @@ class _$UserSettingsEntitySerializer BuiltList, const [const FullType(DashboardField)])) as BuiltList); break; + case 'dashboard_fields_per_row_mobile': + result.dashboardFieldsPerRowMobile = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'dashboard_fields_per_row_desktop': + result.dashboardFieldsPerRowDesktop = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; } } @@ -3623,6 +3637,10 @@ class _$UserSettingsEntity extends UserSettingsEntity { final bool includeDeletedClients; @override final BuiltList dashboardFields; + @override + final int dashboardFieldsPerRowMobile; + @override + final int dashboardFieldsPerRowDesktop; factory _$UserSettingsEntity( [void Function(UserSettingsEntityBuilder) updates]) => @@ -3634,7 +3652,9 @@ class _$UserSettingsEntity extends UserSettingsEntity { this.reportSettings, this.numberYearsActive, this.includeDeletedClients, - this.dashboardFields}) + this.dashboardFields, + this.dashboardFieldsPerRowMobile, + this.dashboardFieldsPerRowDesktop}) : super._() { BuiltValueNullFieldError.checkNotNull( tableColumns, 'UserSettingsEntity', 'tableColumns'); @@ -3646,6 +3666,10 @@ class _$UserSettingsEntity extends UserSettingsEntity { includeDeletedClients, 'UserSettingsEntity', 'includeDeletedClients'); BuiltValueNullFieldError.checkNotNull( dashboardFields, 'UserSettingsEntity', 'dashboardFields'); + BuiltValueNullFieldError.checkNotNull(dashboardFieldsPerRowMobile, + 'UserSettingsEntity', 'dashboardFieldsPerRowMobile'); + BuiltValueNullFieldError.checkNotNull(dashboardFieldsPerRowDesktop, + 'UserSettingsEntity', 'dashboardFieldsPerRowDesktop'); } @override @@ -3666,7 +3690,9 @@ class _$UserSettingsEntity extends UserSettingsEntity { reportSettings == other.reportSettings && numberYearsActive == other.numberYearsActive && includeDeletedClients == other.includeDeletedClients && - dashboardFields == other.dashboardFields; + dashboardFields == other.dashboardFields && + dashboardFieldsPerRowMobile == other.dashboardFieldsPerRowMobile && + dashboardFieldsPerRowDesktop == other.dashboardFieldsPerRowDesktop; } int __hashCode; @@ -3675,11 +3701,17 @@ class _$UserSettingsEntity extends UserSettingsEntity { return __hashCode ??= $jf($jc( $jc( $jc( - $jc($jc($jc(0, accentColor.hashCode), tableColumns.hashCode), - reportSettings.hashCode), - numberYearsActive.hashCode), - includeDeletedClients.hashCode), - dashboardFields.hashCode)); + $jc( + $jc( + $jc( + $jc($jc(0, accentColor.hashCode), + tableColumns.hashCode), + reportSettings.hashCode), + numberYearsActive.hashCode), + includeDeletedClients.hashCode), + dashboardFields.hashCode), + dashboardFieldsPerRowMobile.hashCode), + dashboardFieldsPerRowDesktop.hashCode)); } @override @@ -3690,7 +3722,9 @@ class _$UserSettingsEntity extends UserSettingsEntity { ..add('reportSettings', reportSettings) ..add('numberYearsActive', numberYearsActive) ..add('includeDeletedClients', includeDeletedClients) - ..add('dashboardFields', dashboardFields)) + ..add('dashboardFields', dashboardFields) + ..add('dashboardFieldsPerRowMobile', dashboardFieldsPerRowMobile) + ..add('dashboardFieldsPerRowDesktop', dashboardFieldsPerRowDesktop)) .toString(); } } @@ -3731,6 +3765,16 @@ class UserSettingsEntityBuilder set dashboardFields(ListBuilder dashboardFields) => _$this._dashboardFields = dashboardFields; + int _dashboardFieldsPerRowMobile; + int get dashboardFieldsPerRowMobile => _$this._dashboardFieldsPerRowMobile; + set dashboardFieldsPerRowMobile(int dashboardFieldsPerRowMobile) => + _$this._dashboardFieldsPerRowMobile = dashboardFieldsPerRowMobile; + + int _dashboardFieldsPerRowDesktop; + int get dashboardFieldsPerRowDesktop => _$this._dashboardFieldsPerRowDesktop; + set dashboardFieldsPerRowDesktop(int dashboardFieldsPerRowDesktop) => + _$this._dashboardFieldsPerRowDesktop = dashboardFieldsPerRowDesktop; + UserSettingsEntityBuilder() { UserSettingsEntity._initializeBuilder(this); } @@ -3744,6 +3788,8 @@ class UserSettingsEntityBuilder _numberYearsActive = $v.numberYearsActive; _includeDeletedClients = $v.includeDeletedClients; _dashboardFields = $v.dashboardFields.toBuilder(); + _dashboardFieldsPerRowMobile = $v.dashboardFieldsPerRowMobile; + _dashboardFieldsPerRowDesktop = $v.dashboardFieldsPerRowDesktop; _$v = null; } return this; @@ -3775,7 +3821,17 @@ class UserSettingsEntityBuilder includeDeletedClients, 'UserSettingsEntity', 'includeDeletedClients'), - dashboardFields: dashboardFields.build()); + dashboardFields: dashboardFields.build(), + dashboardFieldsPerRowMobile: + BuiltValueNullFieldError.checkNotNull( + dashboardFieldsPerRowMobile, + 'UserSettingsEntity', + 'dashboardFieldsPerRowMobile'), + dashboardFieldsPerRowDesktop: + BuiltValueNullFieldError.checkNotNull( + dashboardFieldsPerRowDesktop, + 'UserSettingsEntity', + 'dashboardFieldsPerRowDesktop')); } catch (_) { String _$failedField; try { diff --git a/lib/redux/company/company_reducer.dart b/lib/redux/company/company_reducer.dart index b8789ec64..51bf53d2e 100644 --- a/lib/redux/company/company_reducer.dart +++ b/lib/redux/company/company_reducer.dart @@ -143,6 +143,21 @@ Reducer userCompanyEntityReducer = combineReducers([ (userCompany, action) => userCompany.rebuild( (b) => b..settings.dashboardFields.replace(action.dashboardFields)), ), + TypedReducer( + (userCompany, action) { + if (action.numberFieldsPerRowDesktop != null) { + return userCompany.rebuild((b) => b + ..settings.dashboardFieldsPerRowDesktop = + action.numberFieldsPerRowDesktop); + } else if (action.numberFieldsPerRowDesktop != null) { + return userCompany.rebuild((b) => b + ..settings.dashboardFieldsPerRowMobile = + action.numberFieldsPerRowMobile); + } + + return userCompany; + }, + ), ]); UserCompanyEntity loadCompanySuccessReducer( diff --git a/lib/redux/dashboard/dashboard_actions.dart b/lib/redux/dashboard/dashboard_actions.dart index 969dbdb2a..b78a6d022 100644 --- a/lib/redux/dashboard/dashboard_actions.dart +++ b/lib/redux/dashboard/dashboard_actions.dart @@ -22,7 +22,6 @@ class UpdateDashboardSettings implements PersistUI { this.currencyId, this.includeTaxes, this.groupBy, - this.numberFieldsPerRow, }); DashboardSettings settings; @@ -30,7 +29,6 @@ class UpdateDashboardSettings implements PersistUI { String currencyId; bool includeTaxes; String groupBy; - final int numberFieldsPerRow; } class UpdateDashboardFields implements PersistUI { @@ -41,6 +39,16 @@ class UpdateDashboardFields implements PersistUI { BuiltList dashboardFields; } +class UpdateDashboardFieldSettingss implements PersistUI { + UpdateDashboardFieldSettingss({ + this.numberFieldsPerRowMobile, + this.numberFieldsPerRowDesktop, + }); + + final int numberFieldsPerRowMobile; + final int numberFieldsPerRowDesktop; +} + class UpdateDashboardSelection implements PersistUI { UpdateDashboardSelection({ this.entityType, diff --git a/lib/redux/dashboard/dashboard_reducer.dart b/lib/redux/dashboard/dashboard_reducer.dart index 5c94355ed..91097a1f3 100644 --- a/lib/redux/dashboard/dashboard_reducer.dart +++ b/lib/redux/dashboard/dashboard_reducer.dart @@ -65,9 +65,6 @@ DashboardUISettings dashboardSettingsReducer( return state.rebuild((b) => b..currencyId = action.currencyId); } else if (action.groupBy != null) { return state.rebuild((b) => b..groupBy = action.groupBy); - } 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 85d94b5b4..6a9d3eb06 100644 --- a/lib/redux/dashboard/dashboard_state.dart +++ b/lib/redux/dashboard/dashboard_state.dart @@ -56,7 +56,6 @@ abstract class DashboardUISettings currencyId: kCurrencyAll, includeTaxes: true, groupBy: kReportGroupDay, - numberFieldsPerRow: 2, ); } @@ -108,8 +107,6 @@ abstract class DashboardUISettings String get groupBy; - int get numberFieldsPerRow; - bool matchesCurrency(String match) { if (currencyId == null || currencyId.isEmpty || @@ -141,9 +138,8 @@ abstract class DashboardUISettings } // ignore: unused_element - static void _initializeBuilder(DashboardUISettingsBuilder builder) => builder - ..groupBy = kReportGroupDay - ..numberFieldsPerRow = 2; + static void _initializeBuilder(DashboardUISettingsBuilder builder) => + builder..groupBy = kReportGroupDay; static Serializer get serializer => _$dashboardUISettingsSerializer; diff --git a/lib/redux/dashboard/dashboard_state.g.dart b/lib/redux/dashboard/dashboard_state.g.dart index 579de2508..7adf9544f 100644 --- a/lib/redux/dashboard/dashboard_state.g.dart +++ b/lib/redux/dashboard/dashboard_state.g.dart @@ -128,9 +128,6 @@ class _$DashboardUISettingsSerializer 'groupBy', serializers.serialize(object.groupBy, specifiedType: const FullType(String)), - 'numberFieldsPerRow', - serializers.serialize(object.numberFieldsPerRow, - specifiedType: const FullType(int)), ]; return result; @@ -193,10 +190,6 @@ class _$DashboardUISettingsSerializer result.groupBy = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; - case 'numberFieldsPerRow': - result.numberFieldsPerRow = serializers.deserialize(value, - specifiedType: const FullType(int)) as int; - break; } } @@ -378,8 +371,6 @@ class _$DashboardUISettings extends DashboardUISettings { final bool includeTaxes; @override final String groupBy; - @override - final int numberFieldsPerRow; factory _$DashboardUISettings( [void Function(DashboardUISettingsBuilder) updates]) => @@ -396,8 +387,7 @@ class _$DashboardUISettings extends DashboardUISettings { this.offset, this.currencyId, this.includeTaxes, - this.groupBy, - this.numberFieldsPerRow}) + this.groupBy}) : super._() { BuiltValueNullFieldError.checkNotNull( dateRange, 'DashboardUISettings', 'dateRange'); @@ -421,8 +411,6 @@ class _$DashboardUISettings extends DashboardUISettings { includeTaxes, 'DashboardUISettings', 'includeTaxes'); BuiltValueNullFieldError.checkNotNull( groupBy, 'DashboardUISettings', 'groupBy'); - BuiltValueNullFieldError.checkNotNull( - numberFieldsPerRow, 'DashboardUISettings', 'numberFieldsPerRow'); } @override @@ -448,8 +436,7 @@ class _$DashboardUISettings extends DashboardUISettings { offset == other.offset && currencyId == other.currencyId && includeTaxes == other.includeTaxes && - groupBy == other.groupBy && - numberFieldsPerRow == other.numberFieldsPerRow; + groupBy == other.groupBy; } int __hashCode; @@ -464,19 +451,17 @@ class _$DashboardUISettings extends DashboardUISettings { $jc( $jc( $jc( - $jc( - $jc($jc(0, dateRange.hashCode), - customStartDate.hashCode), - customEndDate.hashCode), - enableComparison.hashCode), - compareDateRange.hashCode), - compareCustomStartDate.hashCode), - compareCustomEndDate.hashCode), - offset.hashCode), - currencyId.hashCode), - includeTaxes.hashCode), - groupBy.hashCode), - numberFieldsPerRow.hashCode)); + $jc($jc(0, dateRange.hashCode), + customStartDate.hashCode), + customEndDate.hashCode), + enableComparison.hashCode), + compareDateRange.hashCode), + compareCustomStartDate.hashCode), + compareCustomEndDate.hashCode), + offset.hashCode), + currencyId.hashCode), + includeTaxes.hashCode), + groupBy.hashCode)); } @override @@ -492,8 +477,7 @@ class _$DashboardUISettings extends DashboardUISettings { ..add('offset', offset) ..add('currencyId', currencyId) ..add('includeTaxes', includeTaxes) - ..add('groupBy', groupBy) - ..add('numberFieldsPerRow', numberFieldsPerRow)) + ..add('groupBy', groupBy)) .toString(); } } @@ -552,11 +536,6 @@ class DashboardUISettingsBuilder String get groupBy => _$this._groupBy; set groupBy(String groupBy) => _$this._groupBy = groupBy; - int _numberFieldsPerRow; - int get numberFieldsPerRow => _$this._numberFieldsPerRow; - set numberFieldsPerRow(int numberFieldsPerRow) => - _$this._numberFieldsPerRow = numberFieldsPerRow; - DashboardUISettingsBuilder() { DashboardUISettings._initializeBuilder(this); } @@ -575,7 +554,6 @@ class DashboardUISettingsBuilder _currencyId = $v.currencyId; _includeTaxes = $v.includeTaxes; _groupBy = $v.groupBy; - _numberFieldsPerRow = $v.numberFieldsPerRow; _$v = null; } return this; @@ -615,8 +593,7 @@ class DashboardUISettingsBuilder offset: BuiltValueNullFieldError.checkNotNull(offset, 'DashboardUISettings', 'offset'), currencyId: BuiltValueNullFieldError.checkNotNull(currencyId, 'DashboardUISettings', 'currencyId'), includeTaxes: BuiltValueNullFieldError.checkNotNull(includeTaxes, 'DashboardUISettings', 'includeTaxes'), - groupBy: BuiltValueNullFieldError.checkNotNull(groupBy, 'DashboardUISettings', 'groupBy'), - numberFieldsPerRow: BuiltValueNullFieldError.checkNotNull(numberFieldsPerRow, 'DashboardUISettings', 'numberFieldsPerRow')); + groupBy: BuiltValueNullFieldError.checkNotNull(groupBy, 'DashboardUISettings', 'groupBy')); replace(_$result); return _$result; } diff --git a/lib/ui/dashboard/dashboard_panels.dart b/lib/ui/dashboard/dashboard_panels.dart index 1c8584464..8acf29619 100644 --- a/lib/ui/dashboard/dashboard_panels.dart +++ b/lib/ui/dashboard/dashboard_panels.dart @@ -326,6 +326,7 @@ class DashboardPanels extends StatelessWidget { final company = state.company; final localization = AppLocalization.of(context); final settings = viewModel.dashboardUIState.settings; + final userCompanySettings = state.userCompany.settings; final runningTasks = _runningTasks(context); if (!state.staticState.isLoaded) { @@ -572,7 +573,10 @@ class DashboardPanels extends StatelessWidget { Padding( padding: const EdgeInsets.symmetric(horizontal: 12), child: StaggeredGrid.count( - crossAxisCount: settings.numberFieldsPerRow, + crossAxisCount: isMobile(context) + ? userCompanySettings.dashboardFieldsPerRowMobile + : userCompanySettings + .dashboardFieldsPerRowDesktop, crossAxisSpacing: 8, mainAxisSpacing: 12, children: state.userCompany.settings.dashboardFields @@ -982,7 +986,7 @@ class __DashboardSettingsState extends State<_DashboardSettings> { final groupMap = state.groupState.map; final company = state.company; final settings = state.dashboardUIState.settings; - final dashboardFields = state.userCompany.settings.dashboardFields; + final userCompanySettings = state.userCompany.settings; final hasMultipleCurrencies = memoizedHasMultipleCurrencies(company, clientMap, groupMap); @@ -1140,7 +1144,8 @@ class __DashboardSettingsState extends State<_DashboardSettings> { setState(() {}); }, children: [ - for (var dashboardField in dashboardFields) + for (var dashboardField + in userCompanySettings.dashboardFields) ListTile( key: ValueKey( '__${dashboardField.field}_${dashboardField.period}_'), @@ -1151,7 +1156,8 @@ class __DashboardSettingsState extends State<_DashboardSettings> { icon: Icon(Icons.close), onPressed: () { store.dispatch(UpdateDashboardFields( - dashboardFields: dashboardFields + dashboardFields: userCompanySettings + .dashboardFields .rebuild((b) => b..remove(dashboardField)))); setState(() {}); }, @@ -1171,10 +1177,17 @@ class __DashboardSettingsState extends State<_DashboardSettings> { SizedBox(height: 16), AppDropdownButton( labelText: localization.fieldsPerRow, - value: settings.numberFieldsPerRow, + value: isMobile(context) + ? userCompanySettings.dashboardFieldsPerRowMobile + : userCompanySettings.dashboardFieldsPerRowDesktop, onChanged: (dynamic value) { - store.dispatch( - UpdateDashboardSettings(numberFieldsPerRow: value)); + if (isMobile(context)) { + store.dispatch(UpdateDashboardFieldSettingss( + numberFieldsPerRowMobile: value)); + } else { + store.dispatch(UpdateDashboardFieldSettingss( + numberFieldsPerRowDesktop: value)); + } setState(() {}); }, items: List.generate(8, (i) => i + 1)