Skip to content

Commit a991d68

Browse files
committed
fix: #285 display current working time in time-clock screen
1 parent 82042e7 commit a991d68

File tree

4 files changed

+72
-15
lines changed

4 files changed

+72
-15
lines changed
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<h6 class="text-left"><strong>Summary</strong></h6>
22
<hr />
33
<div class="row pb-4">
4-
<div class="col-4">
4+
<div class="col-3">
5+
<h6>Current</h6>
6+
<h3>{{ currentWorkingTime }}</h3>
7+
</div>
8+
<div class="col-3">
59
<h6>Day</h6>
6-
<h3>{{ timeEntriesSummary.day | timeDetails }}</h3>
10+
<h3>{{ timeEntriesSummary?.day | timeDetails }}</h3>
711
</div>
8-
<div class="col-4">
12+
<div class="col-3">
913
<h6>Week</h6>
10-
<h3>{{ timeEntriesSummary.week | timeDetails }}</h3>
14+
<h3>{{ timeEntriesSummary?.week | timeDetails }}</h3>
1115
</div>
12-
<div class="col-4">
16+
<div class="col-3">
1317
<h6>Month</h6>
14-
<h3>{{ timeEntriesSummary.month | timeDetails }}</h3>
18+
<h3>{{ timeEntriesSummary?.month | timeDetails }}</h3>
1519
</div>
1620
</div>
Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { SubstractDatePipe } from './../../../shared/pipes/substract-date/substract-date.pipe';
2+
import { EntryState } from './../../store/entry.reducer';
13
import { TimeDetailsPipe } from './../../pipes/time-details.pipe';
2-
import { provideMockStore } from '@ngrx/store/testing';
4+
import { provideMockStore, MockStore } from '@ngrx/store/testing';
35
import { TimeEntriesSummary } from './../../models/time.entry.summary';
46
import { TimeDetails } from './../../models/time.entry.summary';
57
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
@@ -9,15 +11,35 @@ import { TimeEntriesSummaryComponent } from './time-entries-summary.component';
911
describe('TimeEntriesSummaryComponent', () => {
1012
let component: TimeEntriesSummaryComponent;
1113
let fixture: ComponentFixture<TimeEntriesSummaryComponent>;
12-
14+
let store: MockStore<EntryState>;
1315

1416
const emptyTimeDetails: TimeDetails = { hours: '--:--', minutes: '--:--', seconds: '--:--' };
1517
const emptyTimeEntriesSummary: TimeEntriesSummary = { day: emptyTimeDetails, week: emptyTimeDetails, month: emptyTimeDetails };
1618

19+
const timeTwoHoursBehind = new Date();
20+
timeTwoHoursBehind.setHours(timeTwoHoursBehind.getHours() - 2);
21+
22+
const timeEntry = {
23+
id: '123',
24+
start_date: timeTwoHoursBehind,
25+
end_date: null,
26+
activity_id: '123',
27+
technologies: ['react', 'redux'],
28+
comments: 'any comment',
29+
uri: 'custom uri',
30+
project_id: '123'
31+
};
32+
1733
const state = {
18-
entries: {
19-
timeEntriesSummary: emptyTimeEntriesSummary
20-
},
34+
active: timeEntry,
35+
entryList: [timeEntry],
36+
entries: [timeEntry],
37+
isLoading: false,
38+
message: '',
39+
createError: false,
40+
updateError: false,
41+
timeEntriesSummary: emptyTimeEntriesSummary,
42+
entriesForReport: [timeEntry],
2143
};
2244

2345
beforeEach(async(() => {
@@ -27,15 +49,26 @@ describe('TimeEntriesSummaryComponent', () => {
2749
],
2850
})
2951
.compileComponents();
52+
store = TestBed.inject(MockStore);
3053
}));
3154

3255
beforeEach(() => {
3356
fixture = TestBed.createComponent(TimeEntriesSummaryComponent);
3457
component = fixture.componentInstance;
3558
fixture.detectChanges();
59+
store.setState(state);
3660
});
3761

3862
it('should create', () => {
3963
expect(component).toBeTruthy();
4064
});
65+
66+
it('dispatches two actions on ngOnInit', () => {
67+
spyOn(store, 'dispatch');
68+
69+
component.ngOnInit();
70+
71+
expect(store.dispatch).toHaveBeenCalledTimes(2);
72+
});
73+
4174
});

src/app/modules/time-clock/components/time-entries-summary/time-entries-summary.component.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { getEntriesSummary } from './../../store/entry.selectors';
1+
import { SubstractDatePipe } from './../../../shared/pipes/substract-date/substract-date.pipe';
2+
import { interval } from 'rxjs';
3+
import { Entry } from './../../../shared/models/entry.model';
4+
import { getEntriesSummary, getActiveTimeEntry } from './../../store/entry.selectors';
25
import { TimeEntriesSummary } from '../../models/time.entry.summary';
3-
import { LoadEntriesSummary } from './../../store/entry.actions';
6+
import { LoadEntriesSummary, LoadActiveEntry } from './../../store/entry.actions';
47
import { EntryState } from './../../store/entry.reducer';
58
import { Store, select } from '@ngrx/store';
69
import { Component, OnInit } from '@angular/core';
@@ -13,14 +16,31 @@ import { Component, OnInit } from '@angular/core';
1316
export class TimeEntriesSummaryComponent implements OnInit {
1417

1518
timeEntriesSummary: TimeEntriesSummary;
19+
currentWorkingTime: string;
1620

1721
constructor(private store: Store<EntryState>) { }
1822

1923
ngOnInit(): void {
24+
this.store.dispatch(new LoadActiveEntry());
25+
const activeTimeEntry$ = this.store.pipe(select(getActiveTimeEntry));
26+
activeTimeEntry$.subscribe((response) => {
27+
if (response) {
28+
const activeTimeEntry: Entry = response;
29+
const timenInterval = interval(1000);
30+
timenInterval.subscribe(() => {
31+
this.currentWorkingTime =
32+
new SubstractDatePipe()
33+
.transform(new Date(), new Date(activeTimeEntry.start_date));
34+
});
35+
}
36+
});
37+
2038
this.store.dispatch(new LoadEntriesSummary());
2139
const timeEntriesSummary$ = this.store.pipe(select(getEntriesSummary));
2240
timeEntriesSummary$.subscribe((response) => {
23-
this.timeEntriesSummary = response;
41+
if (response) {
42+
this.timeEntriesSummary = response;
43+
}
2444
});
2545
}
2646

src/app/modules/time-clock/pipes/time-details.pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Pipe, PipeTransform } from '@angular/core';
77
export class TimeDetailsPipe implements PipeTransform {
88

99
transform(value: TimeDetails): string {
10-
return `${this.formatAsTwoDigit(value.hours)}:${this.formatAsTwoDigit(value.minutes)}` ;
10+
return `${this.formatAsTwoDigit(value?.hours)}:${this.formatAsTwoDigit(value?.minutes)}` ;
1111
}
1212

1313
formatAsTwoDigit(time: string): string {

0 commit comments

Comments
 (0)