From eca14593f8d620d69feae710b6a01ae21312da33 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 7 Oct 2019 09:23:01 +0300 Subject: [PATCH] Settings --- lib/data/models/client_model.g.dart | 4 +- lib/redux/company/company_state.dart | 12 ++++ lib/redux/company/company_state.g.dart | 87 +++++++++++++++++++++++- lib/redux/settings/settings_actions.dart | 15 +--- lib/redux/ui/ui_reducer.dart | 17 +++-- lib/ui/settings/company_details_vm.dart | 3 +- lib/ui/settings/localization_vm.dart | 3 +- lib/ui/settings/settings_list_vm.dart | 2 +- lib/ui/settings/user_details_vm.dart | 3 +- 9 files changed, 113 insertions(+), 33 deletions(-) diff --git a/lib/data/models/client_model.g.dart b/lib/data/models/client_model.g.dart index 59636ca1d..ca22aca64 100644 --- a/lib/data/models/client_model.g.dart +++ b/lib/data/models/client_model.g.dart @@ -208,7 +208,7 @@ class _$ClientEntitySerializer implements StructuredSerializer { ]; if (object.groupId != null) { result - ..add('group_id') + ..add('group_setting_id') ..add(serializers.serialize(object.groupId, specifiedType: const FullType(String))); } @@ -310,7 +310,7 @@ class _$ClientEntitySerializer implements StructuredSerializer { iterator.moveNext(); final dynamic value = iterator.current; switch (key) { - case 'group_id': + case 'group_setting_id': result.groupId = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; diff --git a/lib/redux/company/company_state.dart b/lib/redux/company/company_state.dart index 406aa1260..29de4f525 100644 --- a/lib/redux/company/company_state.dart +++ b/lib/redux/company/company_state.dart @@ -95,6 +95,9 @@ abstract class SettingsUIState extends Object {UserCompanyEntity userCompany, ClientEntity client, GroupEntity group, + UserCompanyEntity origUserCompany, + ClientEntity origClient, + GroupEntity origGroup, String section}) { return _$SettingsUIState._( userCompany: userCompany ?? UserCompanyEntity(), @@ -103,6 +106,9 @@ abstract class SettingsUIState extends Object entityType: client != null ? EntityType.client : group != null ? EntityType.group : EntityType.company, + origClient: origClient ?? ClientEntity(), + origGroup: origGroup ?? GroupEntity(), + origUserCompany: origUserCompany ?? UserCompanyEntity(), isChanged: false, updatedAt: 0, section: section ?? kSettingsCompanyDetails, @@ -113,10 +119,16 @@ abstract class SettingsUIState extends Object UserCompanyEntity get userCompany; + UserCompanyEntity get origUserCompany; + ClientEntity get client; + ClientEntity get origClient; + GroupEntity get group; + GroupEntity get origGroup; + EntityType get entityType; bool get isChanged; diff --git a/lib/redux/company/company_state.g.dart b/lib/redux/company/company_state.g.dart index 19692e945..10ba68796 100644 --- a/lib/redux/company/company_state.g.dart +++ b/lib/redux/company/company_state.g.dart @@ -154,12 +154,21 @@ class _$SettingsUIStateSerializer 'userCompany', serializers.serialize(object.userCompany, specifiedType: const FullType(UserCompanyEntity)), + 'origUserCompany', + serializers.serialize(object.origUserCompany, + specifiedType: const FullType(UserCompanyEntity)), 'client', serializers.serialize(object.client, specifiedType: const FullType(ClientEntity)), + 'origClient', + serializers.serialize(object.origClient, + specifiedType: const FullType(ClientEntity)), 'group', serializers.serialize(object.group, specifiedType: const FullType(GroupEntity)), + 'origGroup', + serializers.serialize(object.origGroup, + specifiedType: const FullType(GroupEntity)), 'entityType', serializers.serialize(object.entityType, specifiedType: const FullType(EntityType)), @@ -194,14 +203,27 @@ class _$SettingsUIStateSerializer specifiedType: const FullType(UserCompanyEntity)) as UserCompanyEntity); break; + case 'origUserCompany': + result.origUserCompany.replace(serializers.deserialize(value, + specifiedType: const FullType(UserCompanyEntity)) + as UserCompanyEntity); + break; case 'client': result.client.replace(serializers.deserialize(value, specifiedType: const FullType(ClientEntity)) as ClientEntity); break; + case 'origClient': + result.origClient.replace(serializers.deserialize(value, + specifiedType: const FullType(ClientEntity)) as ClientEntity); + break; case 'group': result.group.replace(serializers.deserialize(value, specifiedType: const FullType(GroupEntity)) as GroupEntity); break; + case 'origGroup': + result.origGroup.replace(serializers.deserialize(value, + specifiedType: const FullType(GroupEntity)) as GroupEntity); + break; case 'entityType': result.entityType = serializers.deserialize(value, specifiedType: const FullType(EntityType)) as EntityType; @@ -566,10 +588,16 @@ class _$SettingsUIState extends SettingsUIState { @override final UserCompanyEntity userCompany; @override + final UserCompanyEntity origUserCompany; + @override final ClientEntity client; @override + final ClientEntity origClient; + @override final GroupEntity group; @override + final GroupEntity origGroup; + @override final EntityType entityType; @override final bool isChanged; @@ -583,8 +611,11 @@ class _$SettingsUIState extends SettingsUIState { _$SettingsUIState._( {this.userCompany, + this.origUserCompany, this.client, + this.origClient, this.group, + this.origGroup, this.entityType, this.isChanged, this.updatedAt, @@ -593,12 +624,21 @@ class _$SettingsUIState extends SettingsUIState { if (userCompany == null) { throw new BuiltValueNullFieldError('SettingsUIState', 'userCompany'); } + if (origUserCompany == null) { + throw new BuiltValueNullFieldError('SettingsUIState', 'origUserCompany'); + } if (client == null) { throw new BuiltValueNullFieldError('SettingsUIState', 'client'); } + if (origClient == null) { + throw new BuiltValueNullFieldError('SettingsUIState', 'origClient'); + } if (group == null) { throw new BuiltValueNullFieldError('SettingsUIState', 'group'); } + if (origGroup == null) { + throw new BuiltValueNullFieldError('SettingsUIState', 'origGroup'); + } if (entityType == null) { throw new BuiltValueNullFieldError('SettingsUIState', 'entityType'); } @@ -626,8 +666,11 @@ class _$SettingsUIState extends SettingsUIState { if (identical(other, this)) return true; return other is SettingsUIState && userCompany == other.userCompany && + origUserCompany == other.origUserCompany && client == other.client && + origClient == other.origClient && group == other.group && + origGroup == other.origGroup && entityType == other.entityType && isChanged == other.isChanged && updatedAt == other.updatedAt && @@ -640,8 +683,16 @@ class _$SettingsUIState extends SettingsUIState { $jc( $jc( $jc( - $jc($jc($jc(0, userCompany.hashCode), client.hashCode), - group.hashCode), + $jc( + $jc( + $jc( + $jc( + $jc($jc(0, userCompany.hashCode), + origUserCompany.hashCode), + client.hashCode), + origClient.hashCode), + group.hashCode), + origGroup.hashCode), entityType.hashCode), isChanged.hashCode), updatedAt.hashCode), @@ -652,8 +703,11 @@ class _$SettingsUIState extends SettingsUIState { String toString() { return (newBuiltValueToStringHelper('SettingsUIState') ..add('userCompany', userCompany) + ..add('origUserCompany', origUserCompany) ..add('client', client) + ..add('origClient', origClient) ..add('group', group) + ..add('origGroup', origGroup) ..add('entityType', entityType) ..add('isChanged', isChanged) ..add('updatedAt', updatedAt) @@ -672,15 +726,32 @@ class SettingsUIStateBuilder set userCompany(UserCompanyEntityBuilder userCompany) => _$this._userCompany = userCompany; + UserCompanyEntityBuilder _origUserCompany; + UserCompanyEntityBuilder get origUserCompany => + _$this._origUserCompany ??= new UserCompanyEntityBuilder(); + set origUserCompany(UserCompanyEntityBuilder origUserCompany) => + _$this._origUserCompany = origUserCompany; + ClientEntityBuilder _client; ClientEntityBuilder get client => _$this._client ??= new ClientEntityBuilder(); set client(ClientEntityBuilder client) => _$this._client = client; + ClientEntityBuilder _origClient; + ClientEntityBuilder get origClient => + _$this._origClient ??= new ClientEntityBuilder(); + set origClient(ClientEntityBuilder origClient) => + _$this._origClient = origClient; + GroupEntityBuilder _group; GroupEntityBuilder get group => _$this._group ??= new GroupEntityBuilder(); set group(GroupEntityBuilder group) => _$this._group = group; + GroupEntityBuilder _origGroup; + GroupEntityBuilder get origGroup => + _$this._origGroup ??= new GroupEntityBuilder(); + set origGroup(GroupEntityBuilder origGroup) => _$this._origGroup = origGroup; + EntityType _entityType; EntityType get entityType => _$this._entityType; set entityType(EntityType entityType) => _$this._entityType = entityType; @@ -702,8 +773,11 @@ class SettingsUIStateBuilder SettingsUIStateBuilder get _$this { if (_$v != null) { _userCompany = _$v.userCompany?.toBuilder(); + _origUserCompany = _$v.origUserCompany?.toBuilder(); _client = _$v.client?.toBuilder(); + _origClient = _$v.origClient?.toBuilder(); _group = _$v.group?.toBuilder(); + _origGroup = _$v.origGroup?.toBuilder(); _entityType = _$v.entityType; _isChanged = _$v.isChanged; _updatedAt = _$v.updatedAt; @@ -733,8 +807,11 @@ class SettingsUIStateBuilder _$result = _$v ?? new _$SettingsUIState._( userCompany: userCompany.build(), + origUserCompany: origUserCompany.build(), client: client.build(), + origClient: origClient.build(), group: group.build(), + origGroup: origGroup.build(), entityType: entityType, isChanged: isChanged, updatedAt: updatedAt, @@ -744,10 +821,16 @@ class SettingsUIStateBuilder try { _$failedField = 'userCompany'; userCompany.build(); + _$failedField = 'origUserCompany'; + origUserCompany.build(); _$failedField = 'client'; client.build(); + _$failedField = 'origClient'; + origClient.build(); _$failedField = 'group'; group.build(); + _$failedField = 'origGroup'; + origGroup.build(); } catch (e) { throw new BuiltValueNestedFieldError( 'SettingsUIState', _$failedField, e.toString()); diff --git a/lib/redux/settings/settings_actions.dart b/lib/redux/settings/settings_actions.dart index 9d93db1d4..879a5e115 100644 --- a/lib/redux/settings/settings_actions.dart +++ b/lib/redux/settings/settings_actions.dart @@ -24,20 +24,9 @@ class ViewSettings implements PersistUI { final String section; } -class ClearSettingsFilter { - ClearSettingsFilter({@required this.userCompany}); - final UserCompanyEntity userCompany; -} +class ClearSettingsFilter {} -class ResetCompany { - ResetCompany({@required this.company}); - final CompanyEntity company; -} - -class ResetUser { - ResetUser({@required this.user}); - final UserEntity user; -} +class ResetSettings {} class UpdateCompany { UpdateCompany({@required this.company}); diff --git a/lib/redux/ui/ui_reducer.dart b/lib/redux/ui/ui_reducer.dart index e7d799e9e..342f15b7d 100644 --- a/lib/redux/ui/ui_reducer.dart +++ b/lib/redux/ui/ui_reducer.dart @@ -172,14 +172,17 @@ int selectCompanyReducer(int selectedCompanyIndex, SelectCompany action) { Reducer settingsUIReducer = combineReducers([ TypedReducer((state, action) { return state.rebuild((b) => b - ..userCompany.replace(action.userCompany ?? state.userCompany) + ..userCompany.replace(state.origUserCompany) ..entityType = EntityType.company); }), TypedReducer((state, action) { return state.rebuild((b) => b ..userCompany.replace(action.userCompany ?? state.userCompany) + ..origUserCompany.replace(action.userCompany ?? state.origUserCompany) ..group.replace(action.group ?? state.group) + ..origGroup.replace(action.group ?? state.origGroup) ..client.replace(action.client ?? state.client) + ..origClient.replace(action.client ?? state.origClient) ..entityType = action.client != null ? EntityType.client : action.group != null ? EntityType.group : state.entityType); @@ -210,15 +213,11 @@ Reducer settingsUIReducer = combineReducers([ ..userCompany.user.replace(action.user) ..isChanged = true); }), - TypedReducer((state, action) { + TypedReducer((state, action) { return state.rebuild((b) => b - ..userCompany.company.replace(action.company) - ..isChanged = false - ..updatedAt = DateTime.now().millisecondsSinceEpoch); - }), - TypedReducer((state, action) { - return state.rebuild((b) => b - ..userCompany.user.replace(action.user) + ..userCompany.replace(state.origUserCompany) + ..group.replace(state.origGroup) + ..client.replace(state.origClient) ..isChanged = false ..updatedAt = DateTime.now().millisecondsSinceEpoch); }), diff --git a/lib/ui/settings/company_details_vm.dart b/lib/ui/settings/company_details_vm.dart index e8e1e37d1..4459985d0 100644 --- a/lib/ui/settings/company_details_vm.dart +++ b/lib/ui/settings/company_details_vm.dart @@ -50,8 +50,7 @@ class CompanyDetailsVM { store.dispatch(UpdateSettings(settings: settings)), onCompanyChanged: (company) => store.dispatch(UpdateCompany(company: company)), - onCancelPressed: (context) => - store.dispatch(ResetCompany(company: state.selectedCompany)), + onCancelPressed: (context) => store.dispatch(ResetSettings()), onSavePressed: (context) { final completer = snackBarCompleter( context, AppLocalization.of(context).savedSettings); diff --git a/lib/ui/settings/localization_vm.dart b/lib/ui/settings/localization_vm.dart index e5e1aad63..a1c9edac2 100644 --- a/lib/ui/settings/localization_vm.dart +++ b/lib/ui/settings/localization_vm.dart @@ -46,8 +46,7 @@ class LocalizationSettingsVM { onChanged: (settings) { store.dispatch(UpdateSettings(settings: settings)); }, - onCancelPressed: (context) => - store.dispatch(ResetCompany(company: state.selectedCompany)), + onCancelPressed: (context) => store.dispatch(ResetSettings()), onSavePressed: (context) { final completer = snackBarCompleter( context, AppLocalization.of(context).savedSettings); diff --git a/lib/ui/settings/settings_list_vm.dart b/lib/ui/settings/settings_list_vm.dart index 2e3b23702..26bcfac4a 100644 --- a/lib/ui/settings/settings_list_vm.dart +++ b/lib/ui/settings/settings_list_vm.dart @@ -44,7 +44,7 @@ class SettingsListVM { userCompany: state.userCompany)); }, onClearSettingsFilterPressed: () => - store.dispatch(ClearSettingsFilter(userCompany: state.userCompany)), + store.dispatch(ClearSettingsFilter()), onViewClientPressed: (context) => store.dispatch( ViewClient(context: context, clientId: settingsUIState.client.id)), onViewGroupPressed: (context) => store.dispatch( diff --git a/lib/ui/settings/user_details_vm.dart b/lib/ui/settings/user_details_vm.dart index c92c0c6f3..8a0f5f949 100644 --- a/lib/ui/settings/user_details_vm.dart +++ b/lib/ui/settings/user_details_vm.dart @@ -43,8 +43,7 @@ class UserDetailsVM { state: state, user: state.uiState.settingsUIState.userCompany.user, onChanged: (user) => store.dispatch(UpdateUser(user: user)), - onCancelPressed: (context) => - store.dispatch(ResetUser(user: state.user)), + onCancelPressed: (context) => store.dispatch(ResetSettings()), onSavePressed: (context) { final completer = snackBarCompleter( context, AppLocalization.of(context).savedSettings);