This commit is contained in:
Hillel Coren 2019-10-07 09:23:01 +03:00
parent cd8393c70d
commit eca14593f8
9 changed files with 113 additions and 33 deletions

View File

@ -208,7 +208,7 @@ class _$ClientEntitySerializer implements StructuredSerializer<ClientEntity> {
]; ];
if (object.groupId != null) { if (object.groupId != null) {
result result
..add('group_id') ..add('group_setting_id')
..add(serializers.serialize(object.groupId, ..add(serializers.serialize(object.groupId,
specifiedType: const FullType(String))); specifiedType: const FullType(String)));
} }
@ -310,7 +310,7 @@ class _$ClientEntitySerializer implements StructuredSerializer<ClientEntity> {
iterator.moveNext(); iterator.moveNext();
final dynamic value = iterator.current; final dynamic value = iterator.current;
switch (key) { switch (key) {
case 'group_id': case 'group_setting_id':
result.groupId = serializers.deserialize(value, result.groupId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String; specifiedType: const FullType(String)) as String;
break; break;

View File

@ -95,6 +95,9 @@ abstract class SettingsUIState extends Object
{UserCompanyEntity userCompany, {UserCompanyEntity userCompany,
ClientEntity client, ClientEntity client,
GroupEntity group, GroupEntity group,
UserCompanyEntity origUserCompany,
ClientEntity origClient,
GroupEntity origGroup,
String section}) { String section}) {
return _$SettingsUIState._( return _$SettingsUIState._(
userCompany: userCompany ?? UserCompanyEntity(), userCompany: userCompany ?? UserCompanyEntity(),
@ -103,6 +106,9 @@ abstract class SettingsUIState extends Object
entityType: client != null entityType: client != null
? EntityType.client ? EntityType.client
: group != null ? EntityType.group : EntityType.company, : group != null ? EntityType.group : EntityType.company,
origClient: origClient ?? ClientEntity(),
origGroup: origGroup ?? GroupEntity(),
origUserCompany: origUserCompany ?? UserCompanyEntity(),
isChanged: false, isChanged: false,
updatedAt: 0, updatedAt: 0,
section: section ?? kSettingsCompanyDetails, section: section ?? kSettingsCompanyDetails,
@ -113,10 +119,16 @@ abstract class SettingsUIState extends Object
UserCompanyEntity get userCompany; UserCompanyEntity get userCompany;
UserCompanyEntity get origUserCompany;
ClientEntity get client; ClientEntity get client;
ClientEntity get origClient;
GroupEntity get group; GroupEntity get group;
GroupEntity get origGroup;
EntityType get entityType; EntityType get entityType;
bool get isChanged; bool get isChanged;

View File

@ -154,12 +154,21 @@ class _$SettingsUIStateSerializer
'userCompany', 'userCompany',
serializers.serialize(object.userCompany, serializers.serialize(object.userCompany,
specifiedType: const FullType(UserCompanyEntity)), specifiedType: const FullType(UserCompanyEntity)),
'origUserCompany',
serializers.serialize(object.origUserCompany,
specifiedType: const FullType(UserCompanyEntity)),
'client', 'client',
serializers.serialize(object.client, serializers.serialize(object.client,
specifiedType: const FullType(ClientEntity)), specifiedType: const FullType(ClientEntity)),
'origClient',
serializers.serialize(object.origClient,
specifiedType: const FullType(ClientEntity)),
'group', 'group',
serializers.serialize(object.group, serializers.serialize(object.group,
specifiedType: const FullType(GroupEntity)), specifiedType: const FullType(GroupEntity)),
'origGroup',
serializers.serialize(object.origGroup,
specifiedType: const FullType(GroupEntity)),
'entityType', 'entityType',
serializers.serialize(object.entityType, serializers.serialize(object.entityType,
specifiedType: const FullType(EntityType)), specifiedType: const FullType(EntityType)),
@ -194,14 +203,27 @@ class _$SettingsUIStateSerializer
specifiedType: const FullType(UserCompanyEntity)) specifiedType: const FullType(UserCompanyEntity))
as UserCompanyEntity); as UserCompanyEntity);
break; break;
case 'origUserCompany':
result.origUserCompany.replace(serializers.deserialize(value,
specifiedType: const FullType(UserCompanyEntity))
as UserCompanyEntity);
break;
case 'client': case 'client':
result.client.replace(serializers.deserialize(value, result.client.replace(serializers.deserialize(value,
specifiedType: const FullType(ClientEntity)) as ClientEntity); specifiedType: const FullType(ClientEntity)) as ClientEntity);
break; break;
case 'origClient':
result.origClient.replace(serializers.deserialize(value,
specifiedType: const FullType(ClientEntity)) as ClientEntity);
break;
case 'group': case 'group':
result.group.replace(serializers.deserialize(value, result.group.replace(serializers.deserialize(value,
specifiedType: const FullType(GroupEntity)) as GroupEntity); specifiedType: const FullType(GroupEntity)) as GroupEntity);
break; break;
case 'origGroup':
result.origGroup.replace(serializers.deserialize(value,
specifiedType: const FullType(GroupEntity)) as GroupEntity);
break;
case 'entityType': case 'entityType':
result.entityType = serializers.deserialize(value, result.entityType = serializers.deserialize(value,
specifiedType: const FullType(EntityType)) as EntityType; specifiedType: const FullType(EntityType)) as EntityType;
@ -566,10 +588,16 @@ class _$SettingsUIState extends SettingsUIState {
@override @override
final UserCompanyEntity userCompany; final UserCompanyEntity userCompany;
@override @override
final UserCompanyEntity origUserCompany;
@override
final ClientEntity client; final ClientEntity client;
@override @override
final ClientEntity origClient;
@override
final GroupEntity group; final GroupEntity group;
@override @override
final GroupEntity origGroup;
@override
final EntityType entityType; final EntityType entityType;
@override @override
final bool isChanged; final bool isChanged;
@ -583,8 +611,11 @@ class _$SettingsUIState extends SettingsUIState {
_$SettingsUIState._( _$SettingsUIState._(
{this.userCompany, {this.userCompany,
this.origUserCompany,
this.client, this.client,
this.origClient,
this.group, this.group,
this.origGroup,
this.entityType, this.entityType,
this.isChanged, this.isChanged,
this.updatedAt, this.updatedAt,
@ -593,12 +624,21 @@ class _$SettingsUIState extends SettingsUIState {
if (userCompany == null) { if (userCompany == null) {
throw new BuiltValueNullFieldError('SettingsUIState', 'userCompany'); throw new BuiltValueNullFieldError('SettingsUIState', 'userCompany');
} }
if (origUserCompany == null) {
throw new BuiltValueNullFieldError('SettingsUIState', 'origUserCompany');
}
if (client == null) { if (client == null) {
throw new BuiltValueNullFieldError('SettingsUIState', 'client'); throw new BuiltValueNullFieldError('SettingsUIState', 'client');
} }
if (origClient == null) {
throw new BuiltValueNullFieldError('SettingsUIState', 'origClient');
}
if (group == null) { if (group == null) {
throw new BuiltValueNullFieldError('SettingsUIState', 'group'); throw new BuiltValueNullFieldError('SettingsUIState', 'group');
} }
if (origGroup == null) {
throw new BuiltValueNullFieldError('SettingsUIState', 'origGroup');
}
if (entityType == null) { if (entityType == null) {
throw new BuiltValueNullFieldError('SettingsUIState', 'entityType'); throw new BuiltValueNullFieldError('SettingsUIState', 'entityType');
} }
@ -626,8 +666,11 @@ class _$SettingsUIState extends SettingsUIState {
if (identical(other, this)) return true; if (identical(other, this)) return true;
return other is SettingsUIState && return other is SettingsUIState &&
userCompany == other.userCompany && userCompany == other.userCompany &&
origUserCompany == other.origUserCompany &&
client == other.client && client == other.client &&
origClient == other.origClient &&
group == other.group && group == other.group &&
origGroup == other.origGroup &&
entityType == other.entityType && entityType == other.entityType &&
isChanged == other.isChanged && isChanged == other.isChanged &&
updatedAt == other.updatedAt && updatedAt == other.updatedAt &&
@ -640,8 +683,16 @@ class _$SettingsUIState extends SettingsUIState {
$jc( $jc(
$jc( $jc(
$jc( $jc(
$jc($jc($jc(0, userCompany.hashCode), client.hashCode), $jc(
group.hashCode), $jc(
$jc(
$jc(
$jc($jc(0, userCompany.hashCode),
origUserCompany.hashCode),
client.hashCode),
origClient.hashCode),
group.hashCode),
origGroup.hashCode),
entityType.hashCode), entityType.hashCode),
isChanged.hashCode), isChanged.hashCode),
updatedAt.hashCode), updatedAt.hashCode),
@ -652,8 +703,11 @@ class _$SettingsUIState extends SettingsUIState {
String toString() { String toString() {
return (newBuiltValueToStringHelper('SettingsUIState') return (newBuiltValueToStringHelper('SettingsUIState')
..add('userCompany', userCompany) ..add('userCompany', userCompany)
..add('origUserCompany', origUserCompany)
..add('client', client) ..add('client', client)
..add('origClient', origClient)
..add('group', group) ..add('group', group)
..add('origGroup', origGroup)
..add('entityType', entityType) ..add('entityType', entityType)
..add('isChanged', isChanged) ..add('isChanged', isChanged)
..add('updatedAt', updatedAt) ..add('updatedAt', updatedAt)
@ -672,15 +726,32 @@ class SettingsUIStateBuilder
set userCompany(UserCompanyEntityBuilder userCompany) => set userCompany(UserCompanyEntityBuilder userCompany) =>
_$this._userCompany = userCompany; _$this._userCompany = userCompany;
UserCompanyEntityBuilder _origUserCompany;
UserCompanyEntityBuilder get origUserCompany =>
_$this._origUserCompany ??= new UserCompanyEntityBuilder();
set origUserCompany(UserCompanyEntityBuilder origUserCompany) =>
_$this._origUserCompany = origUserCompany;
ClientEntityBuilder _client; ClientEntityBuilder _client;
ClientEntityBuilder get client => ClientEntityBuilder get client =>
_$this._client ??= new ClientEntityBuilder(); _$this._client ??= new ClientEntityBuilder();
set client(ClientEntityBuilder client) => _$this._client = client; 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 _group;
GroupEntityBuilder get group => _$this._group ??= new GroupEntityBuilder(); GroupEntityBuilder get group => _$this._group ??= new GroupEntityBuilder();
set group(GroupEntityBuilder group) => _$this._group = group; 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 _entityType;
EntityType get entityType => _$this._entityType; EntityType get entityType => _$this._entityType;
set entityType(EntityType entityType) => _$this._entityType = entityType; set entityType(EntityType entityType) => _$this._entityType = entityType;
@ -702,8 +773,11 @@ class SettingsUIStateBuilder
SettingsUIStateBuilder get _$this { SettingsUIStateBuilder get _$this {
if (_$v != null) { if (_$v != null) {
_userCompany = _$v.userCompany?.toBuilder(); _userCompany = _$v.userCompany?.toBuilder();
_origUserCompany = _$v.origUserCompany?.toBuilder();
_client = _$v.client?.toBuilder(); _client = _$v.client?.toBuilder();
_origClient = _$v.origClient?.toBuilder();
_group = _$v.group?.toBuilder(); _group = _$v.group?.toBuilder();
_origGroup = _$v.origGroup?.toBuilder();
_entityType = _$v.entityType; _entityType = _$v.entityType;
_isChanged = _$v.isChanged; _isChanged = _$v.isChanged;
_updatedAt = _$v.updatedAt; _updatedAt = _$v.updatedAt;
@ -733,8 +807,11 @@ class SettingsUIStateBuilder
_$result = _$v ?? _$result = _$v ??
new _$SettingsUIState._( new _$SettingsUIState._(
userCompany: userCompany.build(), userCompany: userCompany.build(),
origUserCompany: origUserCompany.build(),
client: client.build(), client: client.build(),
origClient: origClient.build(),
group: group.build(), group: group.build(),
origGroup: origGroup.build(),
entityType: entityType, entityType: entityType,
isChanged: isChanged, isChanged: isChanged,
updatedAt: updatedAt, updatedAt: updatedAt,
@ -744,10 +821,16 @@ class SettingsUIStateBuilder
try { try {
_$failedField = 'userCompany'; _$failedField = 'userCompany';
userCompany.build(); userCompany.build();
_$failedField = 'origUserCompany';
origUserCompany.build();
_$failedField = 'client'; _$failedField = 'client';
client.build(); client.build();
_$failedField = 'origClient';
origClient.build();
_$failedField = 'group'; _$failedField = 'group';
group.build(); group.build();
_$failedField = 'origGroup';
origGroup.build();
} catch (e) { } catch (e) {
throw new BuiltValueNestedFieldError( throw new BuiltValueNestedFieldError(
'SettingsUIState', _$failedField, e.toString()); 'SettingsUIState', _$failedField, e.toString());

View File

@ -24,20 +24,9 @@ class ViewSettings implements PersistUI {
final String section; final String section;
} }
class ClearSettingsFilter { class ClearSettingsFilter {}
ClearSettingsFilter({@required this.userCompany});
final UserCompanyEntity userCompany;
}
class ResetCompany { class ResetSettings {}
ResetCompany({@required this.company});
final CompanyEntity company;
}
class ResetUser {
ResetUser({@required this.user});
final UserEntity user;
}
class UpdateCompany { class UpdateCompany {
UpdateCompany({@required this.company}); UpdateCompany({@required this.company});

View File

@ -172,14 +172,17 @@ int selectCompanyReducer(int selectedCompanyIndex, SelectCompany action) {
Reducer<SettingsUIState> settingsUIReducer = combineReducers([ Reducer<SettingsUIState> settingsUIReducer = combineReducers([
TypedReducer<SettingsUIState, ClearSettingsFilter>((state, action) { TypedReducer<SettingsUIState, ClearSettingsFilter>((state, action) {
return state.rebuild((b) => b return state.rebuild((b) => b
..userCompany.replace(action.userCompany ?? state.userCompany) ..userCompany.replace(state.origUserCompany)
..entityType = EntityType.company); ..entityType = EntityType.company);
}), }),
TypedReducer<SettingsUIState, ViewSettings>((state, action) { TypedReducer<SettingsUIState, ViewSettings>((state, action) {
return state.rebuild((b) => b return state.rebuild((b) => b
..userCompany.replace(action.userCompany ?? state.userCompany) ..userCompany.replace(action.userCompany ?? state.userCompany)
..origUserCompany.replace(action.userCompany ?? state.origUserCompany)
..group.replace(action.group ?? state.group) ..group.replace(action.group ?? state.group)
..origGroup.replace(action.group ?? state.origGroup)
..client.replace(action.client ?? state.client) ..client.replace(action.client ?? state.client)
..origClient.replace(action.client ?? state.origClient)
..entityType = action.client != null ..entityType = action.client != null
? EntityType.client ? EntityType.client
: action.group != null ? EntityType.group : state.entityType); : action.group != null ? EntityType.group : state.entityType);
@ -210,15 +213,11 @@ Reducer<SettingsUIState> settingsUIReducer = combineReducers([
..userCompany.user.replace(action.user) ..userCompany.user.replace(action.user)
..isChanged = true); ..isChanged = true);
}), }),
TypedReducer<SettingsUIState, ResetCompany>((state, action) { TypedReducer<SettingsUIState, ResetSettings>((state, action) {
return state.rebuild((b) => b return state.rebuild((b) => b
..userCompany.company.replace(action.company) ..userCompany.replace(state.origUserCompany)
..isChanged = false ..group.replace(state.origGroup)
..updatedAt = DateTime.now().millisecondsSinceEpoch); ..client.replace(state.origClient)
}),
TypedReducer<SettingsUIState, ResetUser>((state, action) {
return state.rebuild((b) => b
..userCompany.user.replace(action.user)
..isChanged = false ..isChanged = false
..updatedAt = DateTime.now().millisecondsSinceEpoch); ..updatedAt = DateTime.now().millisecondsSinceEpoch);
}), }),

View File

@ -50,8 +50,7 @@ class CompanyDetailsVM {
store.dispatch(UpdateSettings(settings: settings)), store.dispatch(UpdateSettings(settings: settings)),
onCompanyChanged: (company) => onCompanyChanged: (company) =>
store.dispatch(UpdateCompany(company: company)), store.dispatch(UpdateCompany(company: company)),
onCancelPressed: (context) => onCancelPressed: (context) => store.dispatch(ResetSettings()),
store.dispatch(ResetCompany(company: state.selectedCompany)),
onSavePressed: (context) { onSavePressed: (context) {
final completer = snackBarCompleter( final completer = snackBarCompleter(
context, AppLocalization.of(context).savedSettings); context, AppLocalization.of(context).savedSettings);

View File

@ -46,8 +46,7 @@ class LocalizationSettingsVM {
onChanged: (settings) { onChanged: (settings) {
store.dispatch(UpdateSettings(settings: settings)); store.dispatch(UpdateSettings(settings: settings));
}, },
onCancelPressed: (context) => onCancelPressed: (context) => store.dispatch(ResetSettings()),
store.dispatch(ResetCompany(company: state.selectedCompany)),
onSavePressed: (context) { onSavePressed: (context) {
final completer = snackBarCompleter( final completer = snackBarCompleter(
context, AppLocalization.of(context).savedSettings); context, AppLocalization.of(context).savedSettings);

View File

@ -44,7 +44,7 @@ class SettingsListVM {
userCompany: state.userCompany)); userCompany: state.userCompany));
}, },
onClearSettingsFilterPressed: () => onClearSettingsFilterPressed: () =>
store.dispatch(ClearSettingsFilter(userCompany: state.userCompany)), store.dispatch(ClearSettingsFilter()),
onViewClientPressed: (context) => store.dispatch( onViewClientPressed: (context) => store.dispatch(
ViewClient(context: context, clientId: settingsUIState.client.id)), ViewClient(context: context, clientId: settingsUIState.client.id)),
onViewGroupPressed: (context) => store.dispatch( onViewGroupPressed: (context) => store.dispatch(

View File

@ -43,8 +43,7 @@ class UserDetailsVM {
state: state, state: state,
user: state.uiState.settingsUIState.userCompany.user, user: state.uiState.settingsUIState.userCompany.user,
onChanged: (user) => store.dispatch(UpdateUser(user: user)), onChanged: (user) => store.dispatch(UpdateUser(user: user)),
onCancelPressed: (context) => onCancelPressed: (context) => store.dispatch(ResetSettings()),
store.dispatch(ResetUser(user: state.user)),
onSavePressed: (context) { onSavePressed: (context) {
final completer = snackBarCompleter( final completer = snackBarCompleter(
context, AppLocalization.of(context).savedSettings); context, AppLocalization.of(context).savedSettings);