Skip to content

Commit 0fbd41b

Browse files
authored
Merge 73e73f4 into 3f884a7
2 parents 3f884a7 + 73e73f4 commit 0fbd41b

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

src/app/modules/reports/components/time-entries-table/time-entries-table.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="row scroll-table mt-5 ml-0">
2-
<app-search-user [users]="users" (selectedUserId)="user($event)"></app-search-user>
2+
<app-search-user [users]="users" (selectedUserId)="user($event)"></app-search-user>
33

44
<table class="table table-striped mb-0" datatable [dtTrigger]="dtTrigger" [dtOptions]="dtOptions" *ngIf="(reportDataSource$ | async) as dataSource">
55
<thead class="thead-blue">
@@ -57,3 +57,4 @@
5757
</tbody>
5858
</table>
5959
</div>
60+
<div class="alert alert-dark mt-3">Total: {{this.resultSum.hours}} hours, {{this.resultSum.minutes}} minutes</div>

src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SubstractDatePipe } from 'src/app/modules/shared/pipes/substract-date/s
77
import { getReportDataSource } from 'src/app/modules/time-clock/store/entry.selectors';
88
import { EntryState } from '../../../time-clock/store/entry.reducer';
99
import { TimeEntriesTableComponent } from './time-entries-table.component';
10+
import { TotalHours } from '../../models/total-hours-report';
1011
import { ActionsSubject } from '@ngrx/store';
1112
import { UserActionTypes } from 'src/app/modules/users/store';
1213

@@ -32,6 +33,31 @@ describe('Reports Page', () => {
3233
project_name: 'Time-Tracker',
3334
};
3435

36+
const timeEntryList: Entry[] = [
37+
{
38+
id: '123',
39+
start_date: new Date('2022-04-24T11:30:00Z'),
40+
end_date: new Date('2022-04-24T14:30:00Z'),
41+
activity_id: '123',
42+
technologies: ['react', 'redux'],
43+
description: 'any comment',
44+
uri: 'custom uri',
45+
project_id: '123',
46+
project_name: 'Time-Tracker',
47+
},
48+
{
49+
id: '456',
50+
start_date: new Date('2022-04-25T12:40:00Z'),
51+
end_date: new Date('2022-04-25T13:00:00Z'),
52+
activity_id: '123',
53+
technologies: ['react', 'redux'],
54+
description: 'any comment',
55+
uri: 'custom uri',
56+
project_id: '123',
57+
project_name: 'Time-Tracker',
58+
}
59+
];
60+
3561
const state: EntryState = {
3662
active: timeEntry,
3763
isLoading: false,
@@ -175,6 +201,11 @@ describe('Reports Page', () => {
175201

176202
expect(component.users).toEqual(usersArray);
177203
});
204+
205+
it('The sum of the data dates is equal to {"hours": 3, "minutes":20,"seconds":0}', () => {
206+
let {hours,minutes,seconds}: TotalHours = component.sumDates(timeEntryList);
207+
expect({hours, minutes, seconds}).toEqual({hours:3,minutes:20,seconds:0});
208+
});
178209

179210
afterEach(() => {
180211
fixture.destroy();

src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Entry } from 'src/app/modules/shared/models';
99
import { DataSource } from 'src/app/modules/shared/models/data-source.model';
1010
import { EntryState } from '../../../time-clock/store/entry.reducer';
1111
import { getReportDataSource } from '../../../time-clock/store/entry.selectors';
12+
import { TotalHours } from '../../models/total-hours-report';
1213
import { User } from 'src/app/modules/users/models/users';
1314
import { LoadUsers, UserActionTypes } from 'src/app/modules/users/store/user.actions';
1415
import { ParseDateTimeOffset } from '../../../shared/formatters/parse-date-time-offset/parse-date-time-offset';
@@ -67,6 +68,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
6768
isLoading$: Observable<boolean>;
6869
reportDataSource$: Observable<DataSource<Entry>>;
6970
rerenderTableSubscription: Subscription;
71+
resultSum: TotalHours;
7072
dateTimeOffset: ParseDateTimeOffset;
7173

7274
constructor(private store: Store<EntryState>, private actionsSubject$: ActionsSubject, private storeUser: Store<User> ) {
@@ -85,6 +87,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
8587

8688
ngOnInit(): void {
8789
this.rerenderTableSubscription = this.reportDataSource$.subscribe((ds) => {
90+
this.sumDates(ds.data);
8891
this.rerenderDataTable();
8992
});
9093
this.uploadUsers();
@@ -124,6 +127,26 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
124127
const durationColumnIndex = 3;
125128
return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated;
126129
}
130+
131+
sumDates(arrayData: Entry[]): TotalHours{
132+
this.resultSum = new TotalHours();
133+
let arrayDurations= new Array();
134+
arrayData.forEach(entry =>{
135+
let start = moment(entry.end_date).diff(moment(entry.start_date));
136+
arrayDurations.push(moment.utc(start).format("HH:mm:ss"));
137+
});
138+
139+
let totalDurations = arrayDurations.slice(1)
140+
.reduce((prev, cur) => {
141+
return prev.add(cur);
142+
},
143+
moment.duration(arrayDurations[0]));
144+
let daysInHours = totalDurations.days() * 24;
145+
this.resultSum.hours=totalDurations.hours() + daysInHours;
146+
this.resultSum.minutes = totalDurations.minutes();
147+
this.resultSum.seconds = totalDurations.seconds();
148+
return this.resultSum;
149+
}
127150

128151
user(userId: string){
129152
this.selectedUserId.emit(userId);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export class TotalHours {
2+
3+
hours: number;
4+
minutes: number;
5+
seconds: number;
6+
7+
constructor() {
8+
this.hours = 0;
9+
this.minutes = 0;
10+
this.seconds = 0;
11+
}
12+
}

0 commit comments

Comments
 (0)