From 1b63b65bc57388af9bd607e809b9f88670073deb Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 4 Apr 2023 15:57:37 +0300 Subject: [PATCH] Add total hours to projects --- lib/data/models/project_model.dart | 13 +++++++++++-- lib/data/models/project_model.g.dart | 21 +++++++++++++++++++++ lib/ui/project/project_presenter.dart | 6 +++++- lib/utils/i18n.dart | 5 +++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/data/models/project_model.dart b/lib/data/models/project_model.dart index 2335a6f5d..239b2e04e 100644 --- a/lib/data/models/project_model.dart +++ b/lib/data/models/project_model.dart @@ -66,6 +66,7 @@ class ProjectFields { static const String archivedAt = 'archived_at'; static const String isDeleted = 'is_deleted'; static const String documents = 'documents'; + static const String totalHours = 'total_hours'; } abstract class ProjectEntity extends Object @@ -99,6 +100,7 @@ abstract class ProjectEntity extends Object createdUserId: '', createdAt: 0, assignedUserId: user?.id ?? '', + totalHours: 0.0, documents: BuiltList(), ); } @@ -158,6 +160,9 @@ abstract class ProjectEntity extends Object String get number; + @BuiltValueField(wireName: 'current_hours') + double get totalHours; + BuiltList get documents; @override @@ -254,6 +259,9 @@ abstract class ProjectEntity extends Object case ProjectFields.budgetedHours: response = projectA.budgetedHours.compareTo(projectB.budgetedHours); break; + case ProjectFields.totalHours: + response = projectA.totalHours.compareTo(projectB.totalHours); + break; case EntityFields.state: final stateA = EntityState.valueOf(projectA.entityState) ?? EntityState.active; @@ -367,8 +375,9 @@ abstract class ProjectEntity extends Object FormatNumberType get listDisplayAmountType => FormatNumberType.money; // ignore: unused_element - static void _initializeBuilder(ProjectEntityBuilder builder) => - builder..color = ''; + static void _initializeBuilder(ProjectEntityBuilder builder) => builder + ..color = '' + ..totalHours = 0; static Serializer get serializer => _$projectEntitySerializer; } diff --git a/lib/data/models/project_model.g.dart b/lib/data/models/project_model.g.dart index b7ae889cd..ebbb0ecb5 100644 --- a/lib/data/models/project_model.g.dart +++ b/lib/data/models/project_model.g.dart @@ -156,6 +156,9 @@ class _$ProjectEntitySerializer implements StructuredSerializer { 'number', serializers.serialize(object.number, specifiedType: const FullType(String)), + 'current_hours', + serializers.serialize(object.totalHours, + specifiedType: const FullType(double)), 'documents', serializers.serialize(object.documents, specifiedType: const FullType( @@ -268,6 +271,10 @@ class _$ProjectEntitySerializer implements StructuredSerializer { result.number = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; + case 'current_hours': + result.totalHours = serializers.deserialize(value, + specifiedType: const FullType(double)) as double; + break; case 'documents': result.documents.replace(serializers.deserialize(value, specifiedType: const FullType( @@ -538,6 +545,8 @@ class _$ProjectEntity extends ProjectEntity { @override final String number; @override + final double totalHours; + @override final BuiltList documents; @override final bool isChanged; @@ -573,6 +582,7 @@ class _$ProjectEntity extends ProjectEntity { this.customValue3, this.customValue4, this.number, + this.totalHours, this.documents, this.isChanged, this.createdAt, @@ -605,6 +615,8 @@ class _$ProjectEntity extends ProjectEntity { BuiltValueNullFieldError.checkNotNull( customValue4, r'ProjectEntity', 'customValue4'); BuiltValueNullFieldError.checkNotNull(number, r'ProjectEntity', 'number'); + BuiltValueNullFieldError.checkNotNull( + totalHours, r'ProjectEntity', 'totalHours'); BuiltValueNullFieldError.checkNotNull( documents, r'ProjectEntity', 'documents'); BuiltValueNullFieldError.checkNotNull( @@ -640,6 +652,7 @@ class _$ProjectEntity extends ProjectEntity { customValue3 == other.customValue3 && customValue4 == other.customValue4 && number == other.number && + totalHours == other.totalHours && documents == other.documents && isChanged == other.isChanged && createdAt == other.createdAt && @@ -669,6 +682,7 @@ class _$ProjectEntity extends ProjectEntity { _$hash = $jc(_$hash, customValue3.hashCode); _$hash = $jc(_$hash, customValue4.hashCode); _$hash = $jc(_$hash, number.hashCode); + _$hash = $jc(_$hash, totalHours.hashCode); _$hash = $jc(_$hash, documents.hashCode); _$hash = $jc(_$hash, isChanged.hashCode); _$hash = $jc(_$hash, createdAt.hashCode); @@ -698,6 +712,7 @@ class _$ProjectEntity extends ProjectEntity { ..add('customValue3', customValue3) ..add('customValue4', customValue4) ..add('number', number) + ..add('totalHours', totalHours) ..add('documents', documents) ..add('isChanged', isChanged) ..add('createdAt', createdAt) @@ -768,6 +783,10 @@ class ProjectEntityBuilder String get number => _$this._number; set number(String number) => _$this._number = number; + double _totalHours; + double get totalHours => _$this._totalHours; + set totalHours(double totalHours) => _$this._totalHours = totalHours; + ListBuilder _documents; ListBuilder get documents => _$this._documents ??= new ListBuilder(); @@ -828,6 +847,7 @@ class ProjectEntityBuilder _customValue3 = $v.customValue3; _customValue4 = $v.customValue4; _number = $v.number; + _totalHours = $v.totalHours; _documents = $v.documents.toBuilder(); _isChanged = $v.isChanged; _createdAt = $v.createdAt; @@ -883,6 +903,7 @@ class ProjectEntityBuilder customValue3: BuiltValueNullFieldError.checkNotNull(customValue3, r'ProjectEntity', 'customValue3'), customValue4: BuiltValueNullFieldError.checkNotNull(customValue4, r'ProjectEntity', 'customValue4'), number: BuiltValueNullFieldError.checkNotNull(number, r'ProjectEntity', 'number'), + totalHours: BuiltValueNullFieldError.checkNotNull(totalHours, r'ProjectEntity', 'totalHours'), documents: documents.build(), isChanged: isChanged, createdAt: BuiltValueNullFieldError.checkNotNull(createdAt, r'ProjectEntity', 'createdAt'), diff --git a/lib/ui/project/project_presenter.dart b/lib/ui/project/project_presenter.dart index f58972456..7f4e44fcb 100644 --- a/lib/ui/project/project_presenter.dart +++ b/lib/ui/project/project_presenter.dart @@ -18,9 +18,10 @@ class ProjectPresenter extends EntityPresenter { ProjectFields.client, ProjectFields.taskRate, ProjectFields.dueDate, + ProjectFields.budgetedHours, + ProjectFields.totalHours, ProjectFields.publicNotes, ProjectFields.privateNotes, - ProjectFields.budgetedHours, EntityFields.state, ]; } @@ -79,6 +80,9 @@ class ProjectPresenter extends EntityPresenter { return Text(presentCustomField(context, project.customValue4)); case ProjectFields.documents: return Text('${project.documents.length}'); + case ProjectFields.totalHours: + return Text(formatNumber(project.totalHours, context, + formatNumberType: FormatNumberType.double)); } return super.getField(field: field, context: context); diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 82dafe47c..bd94a3ff8 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -16,6 +16,7 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'total_hours': 'Total Hours', 'date_picker_hint': 'Use +days to set the date in the future', 'browser_pdf_viewer': 'Use Browser PDF Viewer', 'browser_pdf_viewer_help': @@ -98285,6 +98286,10 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]['date_picker_hint'] ?? _localizedValues['en']['date_picker_hint']; + String get totalHours => + _localizedValues[localeCode]['total_hours'] ?? + _localizedValues['en']['total_hours']; + // STARTER: lang field - do not remove comment String lookup(String key) {