Move history to activity

This commit is contained in:
Hillel Coren 2021-09-23 13:33:03 +03:00
parent 5b1c901a20
commit 48788a207b
7 changed files with 128 additions and 167 deletions

View File

@ -632,6 +632,9 @@ abstract class ActivityEntity
@BuiltValueField(wireName: 'token_id')
String get tokenId;
@nullable
InvoiceHistoryEntity get history;
EntityType get entityType {
if ([
kActivityCreateClient,

View File

@ -609,6 +609,13 @@ class _$ActivityEntitySerializer
..add(serializers.serialize(value,
specifiedType: const FullType(String)));
}
value = object.history;
if (value != null) {
result
..add('history')
..add(serializers.serialize(value,
specifiedType: const FullType(InvoiceHistoryEntity)));
}
return result;
}
@ -700,6 +707,11 @@ class _$ActivityEntitySerializer
result.tokenId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
break;
case 'history':
result.history.replace(serializers.deserialize(value,
specifiedType: const FullType(InvoiceHistoryEntity))
as InvoiceHistoryEntity);
break;
}
}
@ -1028,6 +1040,8 @@ class _$ActivityEntity extends ActivityEntity {
final String vendorId;
@override
final String tokenId;
@override
final InvoiceHistoryEntity history;
factory _$ActivityEntity([void Function(ActivityEntityBuilder) updates]) =>
(new ActivityEntityBuilder()..update(updates)).build();
@ -1051,7 +1065,8 @@ class _$ActivityEntity extends ActivityEntity {
this.taskId,
this.projectId,
this.vendorId,
this.tokenId})
this.tokenId,
this.history})
: super._() {
BuiltValueNullFieldError.checkNotNull(notes, 'ActivityEntity', 'notes');
BuiltValueNullFieldError.checkNotNull(key, 'ActivityEntity', 'key');
@ -1092,7 +1107,8 @@ class _$ActivityEntity extends ActivityEntity {
taskId == other.taskId &&
projectId == other.projectId &&
vendorId == other.vendorId &&
tokenId == other.tokenId;
tokenId == other.tokenId &&
history == other.history;
}
int __hashCode;
@ -1116,33 +1132,26 @@ class _$ActivityEntity extends ActivityEntity {
$jc(
$jc(
$jc(
$jc(
0,
notes
.hashCode),
key
.hashCode),
activityTypeId
.hashCode),
clientId
.hashCode),
userId
.hashCode),
invoiceId.hashCode),
recurringInvoiceId
.hashCode),
quoteId.hashCode),
paymentId.hashCode),
creditId.hashCode),
updatedAt.hashCode),
expenseId.hashCode),
isSystem.hashCode),
ip.hashCode),
contactId.hashCode),
taskId.hashCode),
projectId.hashCode),
vendorId.hashCode),
tokenId.hashCode));
$jc($jc(0, notes.hashCode),
key.hashCode),
activityTypeId.hashCode),
clientId.hashCode),
userId.hashCode),
invoiceId.hashCode),
recurringInvoiceId.hashCode),
quoteId.hashCode),
paymentId.hashCode),
creditId.hashCode),
updatedAt.hashCode),
expenseId.hashCode),
isSystem.hashCode),
ip.hashCode),
contactId.hashCode),
taskId.hashCode),
projectId.hashCode),
vendorId.hashCode),
tokenId.hashCode),
history.hashCode));
}
@override
@ -1166,7 +1175,8 @@ class _$ActivityEntity extends ActivityEntity {
..add('taskId', taskId)
..add('projectId', projectId)
..add('vendorId', vendorId)
..add('tokenId', tokenId))
..add('tokenId', tokenId)
..add('history', history))
.toString();
}
}
@ -1253,6 +1263,11 @@ class ActivityEntityBuilder
String get tokenId => _$this._tokenId;
set tokenId(String tokenId) => _$this._tokenId = tokenId;
InvoiceHistoryEntityBuilder _history;
InvoiceHistoryEntityBuilder get history =>
_$this._history ??= new InvoiceHistoryEntityBuilder();
set history(InvoiceHistoryEntityBuilder history) => _$this._history = history;
ActivityEntityBuilder();
ActivityEntityBuilder get _$this {
@ -1277,6 +1292,7 @@ class ActivityEntityBuilder
_projectId = $v.projectId;
_vendorId = $v.vendorId;
_tokenId = $v.tokenId;
_history = $v.history?.toBuilder();
_$v = null;
}
return this;
@ -1295,32 +1311,46 @@ class ActivityEntityBuilder
@override
_$ActivityEntity build() {
final _$result = _$v ??
new _$ActivityEntity._(
notes: BuiltValueNullFieldError.checkNotNull(
notes, 'ActivityEntity', 'notes'),
key: BuiltValueNullFieldError.checkNotNull(
key, 'ActivityEntity', 'key'),
activityTypeId: BuiltValueNullFieldError.checkNotNull(
activityTypeId, 'ActivityEntity', 'activityTypeId'),
clientId: clientId,
userId: BuiltValueNullFieldError.checkNotNull(
userId, 'ActivityEntity', 'userId'),
invoiceId: invoiceId,
recurringInvoiceId: recurringInvoiceId,
quoteId: quoteId,
paymentId: paymentId,
creditId: creditId,
updatedAt: BuiltValueNullFieldError.checkNotNull(
updatedAt, 'ActivityEntity', 'updatedAt'),
expenseId: expenseId,
isSystem: isSystem,
ip: ip,
contactId: contactId,
taskId: taskId,
projectId: projectId,
vendorId: vendorId,
tokenId: tokenId);
_$ActivityEntity _$result;
try {
_$result = _$v ??
new _$ActivityEntity._(
notes: BuiltValueNullFieldError.checkNotNull(
notes, 'ActivityEntity', 'notes'),
key: BuiltValueNullFieldError.checkNotNull(
key, 'ActivityEntity', 'key'),
activityTypeId: BuiltValueNullFieldError.checkNotNull(
activityTypeId, 'ActivityEntity', 'activityTypeId'),
clientId: clientId,
userId: BuiltValueNullFieldError.checkNotNull(
userId, 'ActivityEntity', 'userId'),
invoiceId: invoiceId,
recurringInvoiceId: recurringInvoiceId,
quoteId: quoteId,
paymentId: paymentId,
creditId: creditId,
updatedAt: BuiltValueNullFieldError.checkNotNull(
updatedAt, 'ActivityEntity', 'updatedAt'),
expenseId: expenseId,
isSystem: isSystem,
ip: ip,
contactId: contactId,
taskId: taskId,
projectId: projectId,
vendorId: vendorId,
tokenId: tokenId,
history: _history?.build());
} catch (_) {
String _$failedField;
try {
_$failedField = 'history';
_history?.build();
} catch (e) {
throw new BuiltValueNestedFieldError(
'ActivityEntity', _$failedField, e.toString());
}
rethrow;
}
replace(_$result);
return _$result;
}

View File

@ -185,7 +185,6 @@ abstract class InvoiceEntity extends Object
subscriptionId: '',
recurringDates: BuiltList<InvoiceScheduleEntity>(),
lineItems: BuiltList<InvoiceItemEntity>(),
history: BuiltList<InvoiceHistoryEntity>(),
usesInclusiveTaxes: company?.settings?.enableInclusiveTaxes ?? false,
documents: BuiltList<DocumentEntity>(),
activities: BuiltList<ActivityEntity>(),
@ -461,9 +460,6 @@ abstract class InvoiceEntity extends Object
BuiltList<ActivityEntity> get activities;
@nullable
BuiltList<InvoiceHistoryEntity> get history;
bool get isApproved => statusId == kQuoteStatusApproved;
bool get hasClient => '${clientId ?? ''}'.isNotEmpty;
@ -480,6 +476,11 @@ abstract class InvoiceEntity extends Object
@nullable
int get loadedAt;
List<InvoiceHistoryEntity> get history => activities
.where((activity) => activity.history != null)
.map((activity) => activity.history)
.toList();
bool get isLoaded => loadedAt != null && loadedAt > 0;
bool get isStale {
@ -1517,7 +1518,6 @@ abstract class InvoiceHistoryEntity
htmlBackup: '',
createdAt: 0,
activityId: '',
activity: ActivityEntity(),
amount: 0,
);
}
@ -1530,8 +1530,6 @@ abstract class InvoiceHistoryEntity
String get id;
ActivityEntity get activity;
@BuiltValueField(wireName: 'activity_id')
String get activityId;

View File

@ -367,14 +367,6 @@ class _$InvoiceEntitySerializer implements StructuredSerializer<InvoiceEntity> {
specifiedType: const FullType(
BuiltList, const [const FullType(InvoiceScheduleEntity)])));
}
value = object.history;
if (value != null) {
result
..add('history')
..add(serializers.serialize(value,
specifiedType: const FullType(
BuiltList, const [const FullType(InvoiceHistoryEntity)])));
}
value = object.loadedAt;
if (value != null) {
result
@ -677,12 +669,6 @@ class _$InvoiceEntitySerializer implements StructuredSerializer<InvoiceEntity> {
BuiltList, const [const FullType(ActivityEntity)]))
as BuiltList<Object>);
break;
case 'history':
result.history.replace(serializers.deserialize(value,
specifiedType: const FullType(
BuiltList, const [const FullType(InvoiceHistoryEntity)]))
as BuiltList<Object>);
break;
case 'loadedAt':
result.loadedAt = serializers.deserialize(value,
specifiedType: const FullType(int)) as int;
@ -1157,9 +1143,6 @@ class _$InvoiceHistoryEntitySerializer
final result = <Object>[
'id',
serializers.serialize(object.id, specifiedType: const FullType(String)),
'activity',
serializers.serialize(object.activity,
specifiedType: const FullType(ActivityEntity)),
'activity_id',
serializers.serialize(object.activityId,
specifiedType: const FullType(String)),
@ -1193,10 +1176,6 @@ class _$InvoiceHistoryEntitySerializer
result.id = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
break;
case 'activity':
result.activity.replace(serializers.deserialize(value,
specifiedType: const FullType(ActivityEntity)) as ActivityEntity);
break;
case 'activity_id':
result.activityId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
@ -1525,8 +1504,6 @@ class _$InvoiceEntity extends InvoiceEntity {
@override
final BuiltList<ActivityEntity> activities;
@override
final BuiltList<InvoiceHistoryEntity> history;
@override
final int loadedAt;
@override
final bool isChanged;
@ -1610,7 +1587,6 @@ class _$InvoiceEntity extends InvoiceEntity {
this.invitations,
this.documents,
this.activities,
this.history,
this.loadedAt,
this.isChanged,
this.createdAt,
@ -1787,7 +1763,6 @@ class _$InvoiceEntity extends InvoiceEntity {
invitations == other.invitations &&
documents == other.documents &&
activities == other.activities &&
history == other.history &&
loadedAt == other.loadedAt &&
isChanged == other.isChanged &&
createdAt == other.createdAt &&
@ -1821,16 +1796,16 @@ class _$InvoiceEntity extends InvoiceEntity {
$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($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, amount.hashCode), balance.hashCode), paidToDate.hashCode), clientId.hashCode), subscriptionId.hashCode), statusId.hashCode), number.hashCode), discount.hashCode), poNumber.hashCode), date.hashCode), dueDate.hashCode), publicNotes.hashCode), privateNotes.hashCode), terms.hashCode), footer.hashCode), designId.hashCode), usesInclusiveTaxes.hashCode), taxName1.hashCode), taxRate1.hashCode), taxName2.hashCode), taxRate2.hashCode), taxName3.hashCode), taxRate3.hashCode), isAmountDiscount.hashCode), partial.hashCode), taxAmount.hashCode), partialDueDate.hashCode), autoBill.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), customSurcharge1.hashCode), customSurcharge2.hashCode), customSurcharge3.hashCode), customSurcharge4.hashCode), customTaxes1.hashCode), customTaxes2.hashCode), customTaxes3.hashCode), customTaxes4.hashCode), exchangeRate.hashCode), reminder1Sent.hashCode), reminder2Sent.hashCode), reminder3Sent.hashCode), reminderLastSent.hashCode), frequencyId.hashCode), lastSentDate.hashCode), nextSendDate.hashCode), remainingCycles.hashCode), dueDateDays.hashCode), invoiceId.hashCode),
recurringId.hashCode),
autoBillEnabled.hashCode),
filename.hashCode),
recurringDates.hashCode),
lineItems.hashCode),
invitations.hashCode),
documents.hashCode),
activities.hashCode),
history.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($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, amount.hashCode), balance.hashCode), paidToDate.hashCode), clientId.hashCode), subscriptionId.hashCode), statusId.hashCode), number.hashCode), discount.hashCode), poNumber.hashCode), date.hashCode), dueDate.hashCode), publicNotes.hashCode), privateNotes.hashCode), terms.hashCode), footer.hashCode), designId.hashCode), usesInclusiveTaxes.hashCode), taxName1.hashCode), taxRate1.hashCode), taxName2.hashCode), taxRate2.hashCode), taxName3.hashCode), taxRate3.hashCode), isAmountDiscount.hashCode), partial.hashCode), taxAmount.hashCode), partialDueDate.hashCode), autoBill.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), customSurcharge1.hashCode), customSurcharge2.hashCode), customSurcharge3.hashCode), customSurcharge4.hashCode), customTaxes1.hashCode), customTaxes2.hashCode), customTaxes3.hashCode), customTaxes4.hashCode), exchangeRate.hashCode), reminder1Sent.hashCode), reminder2Sent.hashCode), reminder3Sent.hashCode), reminderLastSent.hashCode), frequencyId.hashCode), lastSentDate.hashCode), nextSendDate.hashCode), remainingCycles.hashCode), dueDateDays.hashCode),
invoiceId.hashCode),
recurringId.hashCode),
autoBillEnabled.hashCode),
filename.hashCode),
recurringDates.hashCode),
lineItems.hashCode),
invitations.hashCode),
documents.hashCode),
activities.hashCode),
loadedAt.hashCode),
isChanged.hashCode),
createdAt.hashCode),
@ -1905,7 +1880,6 @@ class _$InvoiceEntity extends InvoiceEntity {
..add('invitations', invitations)
..add('documents', documents)
..add('activities', activities)
..add('history', history)
..add('loadedAt', loadedAt)
..add('isChanged', isChanged)
..add('createdAt', createdAt)
@ -2184,12 +2158,6 @@ class InvoiceEntityBuilder
set activities(ListBuilder<ActivityEntity> activities) =>
_$this._activities = activities;
ListBuilder<InvoiceHistoryEntity> _history;
ListBuilder<InvoiceHistoryEntity> get history =>
_$this._history ??= new ListBuilder<InvoiceHistoryEntity>();
set history(ListBuilder<InvoiceHistoryEntity> history) =>
_$this._history = history;
int _loadedAt;
int get loadedAt => _$this._loadedAt;
set loadedAt(int loadedAt) => _$this._loadedAt = loadedAt;
@ -2298,7 +2266,6 @@ class InvoiceEntityBuilder
_invitations = $v.invitations.toBuilder();
_documents = $v.documents.toBuilder();
_activities = $v.activities.toBuilder();
_history = $v.history?.toBuilder();
_loadedAt = $v.loadedAt;
_isChanged = $v.isChanged;
_createdAt = $v.createdAt;
@ -2398,7 +2365,6 @@ class InvoiceEntityBuilder
invitations: invitations.build(),
documents: documents.build(),
activities: activities.build(),
history: _history?.build(),
loadedAt: loadedAt,
isChanged: isChanged,
createdAt: BuiltValueNullFieldError.checkNotNull(createdAt, 'InvoiceEntity', 'createdAt'),
@ -2422,8 +2388,6 @@ class InvoiceEntityBuilder
documents.build();
_$failedField = 'activities';
activities.build();
_$failedField = 'history';
_history?.build();
} catch (e) {
throw new BuiltValueNestedFieldError(
'InvoiceEntity', _$failedField, e.toString());
@ -3211,8 +3175,6 @@ class _$InvoiceHistoryEntity extends InvoiceHistoryEntity {
@override
final String id;
@override
final ActivityEntity activity;
@override
final String activityId;
@override
final String htmlBackup;
@ -3226,16 +3188,9 @@ class _$InvoiceHistoryEntity extends InvoiceHistoryEntity {
(new InvoiceHistoryEntityBuilder()..update(updates)).build();
_$InvoiceHistoryEntity._(
{this.id,
this.activity,
this.activityId,
this.htmlBackup,
this.createdAt,
this.amount})
{this.id, this.activityId, this.htmlBackup, this.createdAt, this.amount})
: super._() {
BuiltValueNullFieldError.checkNotNull(id, 'InvoiceHistoryEntity', 'id');
BuiltValueNullFieldError.checkNotNull(
activity, 'InvoiceHistoryEntity', 'activity');
BuiltValueNullFieldError.checkNotNull(
activityId, 'InvoiceHistoryEntity', 'activityId');
BuiltValueNullFieldError.checkNotNull(
@ -3260,7 +3215,6 @@ class _$InvoiceHistoryEntity extends InvoiceHistoryEntity {
if (identical(other, this)) return true;
return other is InvoiceHistoryEntity &&
id == other.id &&
activity == other.activity &&
activityId == other.activityId &&
htmlBackup == other.htmlBackup &&
createdAt == other.createdAt &&
@ -3272,9 +3226,7 @@ class _$InvoiceHistoryEntity extends InvoiceHistoryEntity {
int get hashCode {
return __hashCode ??= $jf($jc(
$jc(
$jc(
$jc($jc($jc(0, id.hashCode), activity.hashCode),
activityId.hashCode),
$jc($jc($jc(0, id.hashCode), activityId.hashCode),
htmlBackup.hashCode),
createdAt.hashCode),
amount.hashCode));
@ -3284,7 +3236,6 @@ class _$InvoiceHistoryEntity extends InvoiceHistoryEntity {
String toString() {
return (newBuiltValueToStringHelper('InvoiceHistoryEntity')
..add('id', id)
..add('activity', activity)
..add('activityId', activityId)
..add('htmlBackup', htmlBackup)
..add('createdAt', createdAt)
@ -3301,11 +3252,6 @@ class InvoiceHistoryEntityBuilder
String get id => _$this._id;
set id(String id) => _$this._id = id;
ActivityEntityBuilder _activity;
ActivityEntityBuilder get activity =>
_$this._activity ??= new ActivityEntityBuilder();
set activity(ActivityEntityBuilder activity) => _$this._activity = activity;
String _activityId;
String get activityId => _$this._activityId;
set activityId(String activityId) => _$this._activityId = activityId;
@ -3328,7 +3274,6 @@ class InvoiceHistoryEntityBuilder
final $v = _$v;
if ($v != null) {
_id = $v.id;
_activity = $v.activity.toBuilder();
_activityId = $v.activityId;
_htmlBackup = $v.htmlBackup;
_createdAt = $v.createdAt;
@ -3351,32 +3296,18 @@ class InvoiceHistoryEntityBuilder
@override
_$InvoiceHistoryEntity build() {
_$InvoiceHistoryEntity _$result;
try {
_$result = _$v ??
new _$InvoiceHistoryEntity._(
id: BuiltValueNullFieldError.checkNotNull(
id, 'InvoiceHistoryEntity', 'id'),
activity: activity.build(),
activityId: BuiltValueNullFieldError.checkNotNull(
activityId, 'InvoiceHistoryEntity', 'activityId'),
htmlBackup: BuiltValueNullFieldError.checkNotNull(
htmlBackup, 'InvoiceHistoryEntity', 'htmlBackup'),
createdAt: BuiltValueNullFieldError.checkNotNull(
createdAt, 'InvoiceHistoryEntity', 'createdAt'),
amount: BuiltValueNullFieldError.checkNotNull(
amount, 'InvoiceHistoryEntity', 'amount'));
} catch (_) {
String _$failedField;
try {
_$failedField = 'activity';
activity.build();
} catch (e) {
throw new BuiltValueNestedFieldError(
'InvoiceHistoryEntity', _$failedField, e.toString());
}
rethrow;
}
final _$result = _$v ??
new _$InvoiceHistoryEntity._(
id: BuiltValueNullFieldError.checkNotNull(
id, 'InvoiceHistoryEntity', 'id'),
activityId: BuiltValueNullFieldError.checkNotNull(
activityId, 'InvoiceHistoryEntity', 'activityId'),
htmlBackup: BuiltValueNullFieldError.checkNotNull(
htmlBackup, 'InvoiceHistoryEntity', 'htmlBackup'),
createdAt: BuiltValueNullFieldError.checkNotNull(
createdAt, 'InvoiceHistoryEntity', 'createdAt'),
amount: BuiltValueNullFieldError.checkNotNull(
amount, 'InvoiceHistoryEntity', 'amount'));
replace(_$result);
return _$result;
}

View File

@ -458,10 +458,6 @@ Serializers _$serializers = (new Serializers().toBuilder()
..addBuilderFactory(
const FullType(BuiltList, const [const FullType(ActivityEntity)]),
() => new ListBuilder<ActivityEntity>())
..addBuilderFactory(
const FullType(
BuiltList, const [const FullType(InvoiceHistoryEntity)]),
() => new ListBuilder<InvoiceHistoryEntity>())
..addBuilderFactory(
const FullType(BuiltList, const [const FullType(LanguageEntity)]),
() => new ListBuilder<LanguageEntity>())

View File

@ -20,7 +20,7 @@ class InvoiceRepository {
Future<InvoiceEntity> loadItem(
Credentials credentials, String entityId) async {
final dynamic response = await webClient.get(
'${credentials.url}/invoices/$entityId?include=history,activities',
'${credentials.url}/invoices/$entityId?include=activities.history',
credentials.token);
final InvoiceItemResponse invoiceResponse = await compute<dynamic, dynamic>(
@ -67,12 +67,12 @@ class InvoiceRepository {
if (invoice.isNew) {
response = await webClient.post(
credentials.url + '/invoices?include=history,activities',
credentials.url + '/invoices?include=activities.history',
credentials.token,
data: json.encode(data));
} else {
final url =
'${credentials.url}/invoices/${invoice.id}?include=history,activities';
'${credentials.url}/invoices/${invoice.id}?include=activities.history';
response =
await webClient.put(url, credentials.token, data: json.encode(data));
}

View File

@ -35,14 +35,17 @@ class _InvoiceViewHistoryState extends State<InvoiceViewHistory> {
return LoadingIndicator();
}
final historyList = invoice.history.toList();
historyList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
final activityList = invoice.activities
.where((activity) => activity.history != null)
.toList();
activityList.sort((a, b) => b.updatedAt.compareTo(a.updatedAt));
return ScrollableListViewBuilder(
padding: const EdgeInsets.symmetric(vertical: 16),
itemBuilder: (BuildContext context, index) {
final history = historyList[index];
final user = viewModel.state.userState.get(history.activity.userId);
final activity = activityList[index];
final history = activity.history;
final user = viewModel.state.userState.get(activity.userId);
return ListTile(
title: Text(