diff --git a/lib/data/models/client_model.dart b/lib/data/models/client_model.dart index aaf113311..1c80fa87c 100644 --- a/lib/data/models/client_model.dart +++ b/lib/data/models/client_model.dart @@ -8,6 +8,7 @@ import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/data/models/gateway_token_model.dart'; import 'package:invoiceninja_flutter/data/models/group_model.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; +import 'package:invoiceninja_flutter/data/models/system_log_model.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/static/static_state.dart'; import 'package:invoiceninja_flutter/utils/formatting.dart'; @@ -130,6 +131,7 @@ abstract class ClientEntity extends Object activities: BuiltList(), ledger: BuiltList(), gatewayTokens: BuiltList(), + systemLogs: BuiltList(), loadedAt: 0, updatedAt: 0, archivedAt: 0, @@ -270,6 +272,10 @@ abstract class ClientEntity extends Object BuiltList get documents; + @BuiltValueField(wireName: 'system_logs') + BuiltList get systemLogs; + + //String get last_login; //String get custom_messages; diff --git a/lib/data/models/client_model.g.dart b/lib/data/models/client_model.g.dart index a9b31662d..ed90a561c 100644 --- a/lib/data/models/client_model.g.dart +++ b/lib/data/models/client_model.g.dart @@ -226,6 +226,10 @@ class _$ClientEntitySerializer implements StructuredSerializer { serializers.serialize(object.documents, specifiedType: const FullType( BuiltList, const [const FullType(DocumentEntity)])), + 'system_logs', + serializers.serialize(object.systemLogs, + specifiedType: const FullType( + BuiltList, const [const FullType(SystemLogEntity)])), 'created_at', serializers.serialize(object.createdAt, specifiedType: const FullType(int)), @@ -444,6 +448,12 @@ class _$ClientEntitySerializer implements StructuredSerializer { BuiltList, const [const FullType(DocumentEntity)])) as BuiltList); break; + case 'system_logs': + result.systemLogs.replace(serializers.deserialize(value, + specifiedType: const FullType( + BuiltList, const [const FullType(SystemLogEntity)])) + as BuiltList); + break; case 'isChanged': result.isChanged = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; @@ -943,6 +953,8 @@ class _$ClientEntity extends ClientEntity { @override final BuiltList documents; @override + final BuiltList systemLogs; + @override final bool isChanged; @override final int createdAt; @@ -1001,6 +1013,7 @@ class _$ClientEntity extends ClientEntity { this.ledger, this.gatewayTokens, this.documents, + this.systemLogs, this.isChanged, this.createdAt, this.updatedAt, @@ -1121,6 +1134,9 @@ class _$ClientEntity extends ClientEntity { if (documents == null) { throw new BuiltValueNullFieldError('ClientEntity', 'documents'); } + if (systemLogs == null) { + throw new BuiltValueNullFieldError('ClientEntity', 'systemLogs'); + } if (createdAt == null) { throw new BuiltValueNullFieldError('ClientEntity', 'createdAt'); } @@ -1184,6 +1200,7 @@ class _$ClientEntity extends ClientEntity { ledger == other.ledger && gatewayTokens == other.gatewayTokens && documents == other.documents && + systemLogs == other.systemLogs && isChanged == other.isChanged && createdAt == other.createdAt && updatedAt == other.updatedAt && @@ -1215,18 +1232,18 @@ class _$ClientEntity extends ClientEntity { $jc( $jc( $jc( - $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, groupId.hashCode), loadedAt.hashCode), name.hashCode), displayName.hashCode), balance.hashCode), creditBalance.hashCode), paidToDate.hashCode), address1.hashCode), address2.hashCode), city.hashCode), state.hashCode), postalCode.hashCode), countryId.hashCode), phone.hashCode), privateNotes.hashCode), publicNotes.hashCode), website.hashCode), industryId.hashCode), sizeId.hashCode), vatNumber.hashCode), idNumber.hashCode), shippingAddress1.hashCode), shippingAddress2.hashCode), shippingCity.hashCode), shippingState.hashCode), shippingPostalCode.hashCode), shippingCountryId.hashCode), - settings.hashCode), - lastLogin.hashCode), - customValue1.hashCode), - customValue2.hashCode), - customValue3.hashCode), - customValue4.hashCode), - contacts.hashCode), - activities.hashCode), - ledger.hashCode), - gatewayTokens.hashCode), - documents.hashCode), + $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, groupId.hashCode), loadedAt.hashCode), name.hashCode), displayName.hashCode), balance.hashCode), creditBalance.hashCode), paidToDate.hashCode), address1.hashCode), address2.hashCode), city.hashCode), state.hashCode), postalCode.hashCode), countryId.hashCode), phone.hashCode), privateNotes.hashCode), publicNotes.hashCode), website.hashCode), industryId.hashCode), sizeId.hashCode), vatNumber.hashCode), idNumber.hashCode), shippingAddress1.hashCode), shippingAddress2.hashCode), shippingCity.hashCode), shippingState.hashCode), shippingPostalCode.hashCode), shippingCountryId.hashCode), settings.hashCode), + lastLogin.hashCode), + customValue1.hashCode), + customValue2.hashCode), + customValue3.hashCode), + customValue4.hashCode), + contacts.hashCode), + activities.hashCode), + ledger.hashCode), + gatewayTokens.hashCode), + documents.hashCode), + systemLogs.hashCode), isChanged.hashCode), createdAt.hashCode), updatedAt.hashCode), @@ -1278,6 +1295,7 @@ class _$ClientEntity extends ClientEntity { ..add('ledger', ledger) ..add('gatewayTokens', gatewayTokens) ..add('documents', documents) + ..add('systemLogs', systemLogs) ..add('isChanged', isChanged) ..add('createdAt', createdAt) ..add('updatedAt', updatedAt) @@ -1462,6 +1480,12 @@ class ClientEntityBuilder set documents(ListBuilder documents) => _$this._documents = documents; + ListBuilder _systemLogs; + ListBuilder get systemLogs => + _$this._systemLogs ??= new ListBuilder(); + set systemLogs(ListBuilder systemLogs) => + _$this._systemLogs = systemLogs; + bool _isChanged; bool get isChanged => _$this._isChanged; set isChanged(bool isChanged) => _$this._isChanged = isChanged; @@ -1538,6 +1562,7 @@ class ClientEntityBuilder _ledger = _$v.ledger?.toBuilder(); _gatewayTokens = _$v.gatewayTokens?.toBuilder(); _documents = _$v.documents?.toBuilder(); + _systemLogs = _$v.systemLogs?.toBuilder(); _isChanged = _$v.isChanged; _createdAt = _$v.createdAt; _updatedAt = _$v.updatedAt; @@ -1608,6 +1633,7 @@ class ClientEntityBuilder ledger: ledger.build(), gatewayTokens: gatewayTokens.build(), documents: documents.build(), + systemLogs: systemLogs.build(), isChanged: isChanged, createdAt: createdAt, updatedAt: updatedAt, @@ -1632,6 +1658,8 @@ class ClientEntityBuilder gatewayTokens.build(); _$failedField = 'documents'; documents.build(); + _$failedField = 'systemLogs'; + systemLogs.build(); } catch (e) { throw new BuiltValueNestedFieldError( 'ClientEntity', _$failedField, e.toString()); diff --git a/lib/data/models/serializers.dart b/lib/data/models/serializers.dart index b590a2823..fb8513f79 100644 --- a/lib/data/models/serializers.dart +++ b/lib/data/models/serializers.dart @@ -15,6 +15,7 @@ import 'package:invoiceninja_flutter/data/models/payment_model.dart'; import 'package:invoiceninja_flutter/data/models/account_model.dart'; import 'package:invoiceninja_flutter/data/models/payment_term_model.dart'; import 'package:invoiceninja_flutter/data/models/project_model.dart'; +import 'package:invoiceninja_flutter/data/models/system_log_model.dart'; import 'package:invoiceninja_flutter/data/models/task_model.dart'; import 'package:invoiceninja_flutter/data/models/tax_rate_model.dart'; import 'package:invoiceninja_flutter/data/models/vendor_model.dart'; @@ -143,6 +144,7 @@ part 'serializers.g.dart'; UserCompanyItemResponse, DesignPreviewRequest, HealthCheckResponse, + SystemLogEntity, ]) final Serializers serializers = (_$serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); diff --git a/lib/data/models/serializers.g.dart b/lib/data/models/serializers.g.dart index 4bf5a509c..cb90de5c1 100644 --- a/lib/data/models/serializers.g.dart +++ b/lib/data/models/serializers.g.dart @@ -138,6 +138,7 @@ Serializers _$serializers = (new Serializers().toBuilder() ..add(StaticDataEntity.serializer) ..add(StaticDataItemResponse.serializer) ..add(StaticState.serializer) + ..add(SystemLogEntity.serializer) ..add(TaskEntity.serializer) ..add(TaskItemResponse.serializer) ..add(TaskListResponse.serializer) @@ -201,6 +202,9 @@ Serializers _$serializers = (new Serializers().toBuilder() ..addBuilderFactory( const FullType(BuiltList, const [const FullType(DocumentEntity)]), () => new ListBuilder()) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(SystemLogEntity)]), + () => new ListBuilder()) ..addBuilderFactory( const FullType(BuiltList, const [const FullType(CountryEntity)]), () => new ListBuilder()) diff --git a/lib/data/models/system_log_model.dart b/lib/data/models/system_log_model.dart new file mode 100644 index 000000000..f7f06df61 --- /dev/null +++ b/lib/data/models/system_log_model.dart @@ -0,0 +1,53 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'system_log_model.g.dart'; + +abstract class SystemLogEntity implements Built { + factory SystemLogEntity() { + return _$SystemLogEntity._( + id: '', + clientId: '', + createdAt: 0, + companyId: '', + categoryId: 0, + eventId: 0, + log: '', + typeId: 0, + userId: '', + ); + } + + SystemLogEntity._(); + + @override + @memoized + int get hashCode; + + String get id; + + @BuiltValueField(wireName: 'company_id') + String get companyId; + + @BuiltValueField(wireName: 'user_id') + String get userId; + + @BuiltValueField(wireName: 'client_id') + String get clientId; + + @BuiltValueField(wireName: 'event_id') + int get eventId; + + @BuiltValueField(wireName: 'category_id') + int get categoryId; + + @BuiltValueField(wireName: 'type_id') + int get typeId; + + String get log; + + @BuiltValueField(wireName: 'created_at') + int get createdAt; + + static Serializer get serializer => _$systemLogEntitySerializer; +} diff --git a/lib/data/models/system_log_model.g.dart b/lib/data/models/system_log_model.g.dart new file mode 100644 index 000000000..a32778b3c --- /dev/null +++ b/lib/data/models/system_log_model.g.dart @@ -0,0 +1,316 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'system_log_model.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer _$systemLogEntitySerializer = + new _$SystemLogEntitySerializer(); + +class _$SystemLogEntitySerializer + implements StructuredSerializer { + @override + final Iterable types = const [SystemLogEntity, _$SystemLogEntity]; + @override + final String wireName = 'SystemLogEntity'; + + @override + Iterable serialize(Serializers serializers, SystemLogEntity object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(String)), + 'company_id', + serializers.serialize(object.companyId, + specifiedType: const FullType(String)), + 'user_id', + serializers.serialize(object.userId, + specifiedType: const FullType(String)), + 'client_id', + serializers.serialize(object.clientId, + specifiedType: const FullType(String)), + 'event_id', + serializers.serialize(object.eventId, specifiedType: const FullType(int)), + 'category_id', + serializers.serialize(object.categoryId, + specifiedType: const FullType(int)), + 'type_id', + serializers.serialize(object.typeId, specifiedType: const FullType(int)), + 'log', + serializers.serialize(object.log, specifiedType: const FullType(String)), + 'created_at', + serializers.serialize(object.createdAt, + specifiedType: const FullType(int)), + ]; + + return result; + } + + @override + SystemLogEntity deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new SystemLogEntityBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current as String; + iterator.moveNext(); + final dynamic value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'company_id': + result.companyId = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'user_id': + result.userId = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'client_id': + result.clientId = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'event_id': + result.eventId = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'category_id': + result.categoryId = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'type_id': + result.typeId = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + case 'log': + result.log = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; + case 'created_at': + result.createdAt = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; + } + } + + return result.build(); + } +} + +class _$SystemLogEntity extends SystemLogEntity { + @override + final String id; + @override + final String companyId; + @override + final String userId; + @override + final String clientId; + @override + final int eventId; + @override + final int categoryId; + @override + final int typeId; + @override + final String log; + @override + final int createdAt; + + factory _$SystemLogEntity([void Function(SystemLogEntityBuilder) updates]) => + (new SystemLogEntityBuilder()..update(updates)).build(); + + _$SystemLogEntity._( + {this.id, + this.companyId, + this.userId, + this.clientId, + this.eventId, + this.categoryId, + this.typeId, + this.log, + this.createdAt}) + : super._() { + if (id == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'id'); + } + if (companyId == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'companyId'); + } + if (userId == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'userId'); + } + if (clientId == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'clientId'); + } + if (eventId == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'eventId'); + } + if (categoryId == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'categoryId'); + } + if (typeId == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'typeId'); + } + if (log == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'log'); + } + if (createdAt == null) { + throw new BuiltValueNullFieldError('SystemLogEntity', 'createdAt'); + } + } + + @override + SystemLogEntity rebuild(void Function(SystemLogEntityBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + SystemLogEntityBuilder toBuilder() => + new SystemLogEntityBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is SystemLogEntity && + id == other.id && + companyId == other.companyId && + userId == other.userId && + clientId == other.clientId && + eventId == other.eventId && + categoryId == other.categoryId && + typeId == other.typeId && + log == other.log && + createdAt == other.createdAt; + } + + int __hashCode; + @override + int get hashCode { + return __hashCode ??= $jf($jc( + $jc( + $jc( + $jc( + $jc( + $jc( + $jc($jc($jc(0, id.hashCode), companyId.hashCode), + userId.hashCode), + clientId.hashCode), + eventId.hashCode), + categoryId.hashCode), + typeId.hashCode), + log.hashCode), + createdAt.hashCode)); + } + + @override + String toString() { + return (newBuiltValueToStringHelper('SystemLogEntity') + ..add('id', id) + ..add('companyId', companyId) + ..add('userId', userId) + ..add('clientId', clientId) + ..add('eventId', eventId) + ..add('categoryId', categoryId) + ..add('typeId', typeId) + ..add('log', log) + ..add('createdAt', createdAt)) + .toString(); + } +} + +class SystemLogEntityBuilder + implements Builder { + _$SystemLogEntity _$v; + + String _id; + String get id => _$this._id; + set id(String id) => _$this._id = id; + + String _companyId; + String get companyId => _$this._companyId; + set companyId(String companyId) => _$this._companyId = companyId; + + String _userId; + String get userId => _$this._userId; + set userId(String userId) => _$this._userId = userId; + + String _clientId; + String get clientId => _$this._clientId; + set clientId(String clientId) => _$this._clientId = clientId; + + int _eventId; + int get eventId => _$this._eventId; + set eventId(int eventId) => _$this._eventId = eventId; + + int _categoryId; + int get categoryId => _$this._categoryId; + set categoryId(int categoryId) => _$this._categoryId = categoryId; + + int _typeId; + int get typeId => _$this._typeId; + set typeId(int typeId) => _$this._typeId = typeId; + + String _log; + String get log => _$this._log; + set log(String log) => _$this._log = log; + + int _createdAt; + int get createdAt => _$this._createdAt; + set createdAt(int createdAt) => _$this._createdAt = createdAt; + + SystemLogEntityBuilder(); + + SystemLogEntityBuilder get _$this { + if (_$v != null) { + _id = _$v.id; + _companyId = _$v.companyId; + _userId = _$v.userId; + _clientId = _$v.clientId; + _eventId = _$v.eventId; + _categoryId = _$v.categoryId; + _typeId = _$v.typeId; + _log = _$v.log; + _createdAt = _$v.createdAt; + _$v = null; + } + return this; + } + + @override + void replace(SystemLogEntity other) { + if (other == null) { + throw new ArgumentError.notNull('other'); + } + _$v = other as _$SystemLogEntity; + } + + @override + void update(void Function(SystemLogEntityBuilder) updates) { + if (updates != null) updates(this); + } + + @override + _$SystemLogEntity build() { + final _$result = _$v ?? + new _$SystemLogEntity._( + id: id, + companyId: companyId, + userId: userId, + clientId: clientId, + eventId: eventId, + categoryId: categoryId, + typeId: typeId, + log: log, + createdAt: createdAt); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new diff --git a/lib/data/repositories/client_repository.dart b/lib/data/repositories/client_repository.dart index 9055b2008..d3c46058b 100644 --- a/lib/data/repositories/client_repository.dart +++ b/lib/data/repositories/client_repository.dart @@ -19,7 +19,7 @@ class ClientRepository { Future loadItem( Credentials credentials, String entityId) async { final String url = - '${credentials.url}/clients/$entityId?include=gateway_tokens,activities,ledger'; + '${credentials.url}/clients/$entityId?include=gateway_tokens,activities,ledger,system_logs'; final dynamic response = await webClient.get(url, credentials.token); @@ -44,8 +44,8 @@ class ClientRepository { Future> bulkAction( Credentials credentials, List ids, EntityAction action) async { - final url = - credentials.url + '/clients/bulk?include=gateway_tokens,activities'; + final url = credentials.url + + '/clients/bulk?include=gateway_tokens,activities,ledger,system_logs'; final dynamic response = await webClient.post(url, credentials.token, data: json.encode({'ids': ids, 'action': action.toApiParam()})); @@ -63,12 +63,13 @@ class ClientRepository { if (client.isNew) { response = await webClient.post( - credentials.url + '/clients?include=gateway_tokens,activities', + credentials.url + + '/clients?include=gateway_tokens,activities,ledger,system_logs', credentials.token, data: json.encode(data)); } else { final url = credentials.url + - '/clients/${client.id}?include=gateway_tokens,activities'; + '/clients/${client.id}?include=gateway_tokens,activities,ledger,system_logs'; response = await webClient.put(url, credentials.token, data: json.encode(data)); } diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index 529b753e0..83c860f2b 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -637,6 +637,7 @@ abstract class AppState implements Built { //return 'gatewayId: ${companyGatewayState.map[companyGatewayUIState.selectedId].gatewayId}'; //return 'Language Id: ${company.settings.languageId}'; //return 'Rates: ${staticState.currencyMap.keys.map((key) => 'Rate: ${staticState.currencyMap[key].exchangeRate}').join(',')}'; + return 'LOG: ${clientState.map[clientUIState.selectedId]?.systemLogs ?? ''}'; return '\n\nURL: ${authState.url}\nRoute: ${uiState.currentRoute}\nPrev: ${uiState.previousRoute}\nIs Loaded: ${isLoaded ? 'Yes' : 'No'}\nis Large: ${(company?.isLarge ?? false) ? 'Yes' : 'No'}\nCompany: $companyUpdated${userCompanyState.isStale ? ' [S]' : ''}\nStatic: $staticUpdated${staticState.isStale ? ' [S]' : ''}\n'; } }