Skip to content

Commit cb7f423

Browse files
committed
fix: #176 adding entries-summary
1 parent 9603281 commit cb7f423

14 files changed

+195
-21
lines changed

src/app/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import { EntryEffects } from './modules/time-clock/store/entry.effects';
5858
import { InjectTokenInterceptor } from './modules/shared/interceptors/inject.token.interceptor';
5959
import { SubstractDatePipe } from './modules/shared/pipes/substract-date/substract-date.pipe';
6060
import {TechnologiesComponent} from './modules/shared/components/technologies/technologies.component';
61+
import { TimeEntriesSummaryComponent } from './modules/time-clock/components/time-entries-summary/time-entries-summary.component';
62+
import { TimeDetailsPipe } from './modules/time-clock/pipes/time-details.pipe';
6163

6264
@NgModule({
6365
declarations: [
@@ -94,6 +96,8 @@ import {TechnologiesComponent} from './modules/shared/components/technologies/te
9496
EntryFieldsComponent,
9597
SubstractDatePipe,
9698
TechnologiesComponent,
99+
TimeEntriesSummaryComponent,
100+
TimeDetailsPipe,
97101
],
98102
imports: [
99103
CommonModule,

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

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<h6 class="text-left"><strong>Summary</strong></h6>
2+
<hr />
3+
<div class="row pb-4">
4+
<div class="col-4">
5+
<h6>Day</h6>
6+
<h3>{{ timeEntriesSummary.day | timeDetails }}</h3>
7+
</div>
8+
<div class="col-4">
9+
<h6>Week</h6>
10+
<h3>{{ timeEntriesSummary.week | timeDetails }}</h3>
11+
</div>
12+
<div class="col-4">
13+
<h6>Month</h6>
14+
<h3>{{ timeEntriesSummary.month | timeDetails }}</h3>
15+
</div>
16+
</div>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { TimeDetailsPipe } from './../../pipes/time-details.pipe';
2+
import { provideMockStore } from '@ngrx/store/testing';
3+
import { TimeEntriesSummary } from './../../models/time.entry.summary';
4+
import { TimeDetails } from './../../models/time.entry.summary';
5+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
6+
7+
import { TimeEntriesSummaryComponent } from './time-entries-summary.component';
8+
9+
describe('TimeEntriesSummaryComponent', () => {
10+
let component: TimeEntriesSummaryComponent;
11+
let fixture: ComponentFixture<TimeEntriesSummaryComponent>;
12+
13+
14+
const emptyTimeDetails: TimeDetails = { hours: '--:--', minutes: '--:--', seconds: '--:--' };
15+
const emptyTimeEntriesSummary: TimeEntriesSummary = { day: emptyTimeDetails, week: emptyTimeDetails, month: emptyTimeDetails };
16+
17+
const state = {
18+
entries: {
19+
timeEntriesSummary: emptyTimeEntriesSummary
20+
},
21+
};
22+
23+
beforeEach(async(() => {
24+
TestBed.configureTestingModule({
25+
declarations: [ TimeEntriesSummaryComponent, TimeDetailsPipe ],
26+
providers: [provideMockStore({ initialState: state })
27+
],
28+
})
29+
.compileComponents();
30+
}));
31+
32+
beforeEach(() => {
33+
fixture = TestBed.createComponent(TimeEntriesSummaryComponent);
34+
component = fixture.componentInstance;
35+
fixture.detectChanges();
36+
});
37+
38+
it('should create', () => {
39+
expect(component).toBeTruthy();
40+
});
41+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { getEntriesSummary } from './../../store/entry.selectors';
2+
import { TimeEntriesSummary } from '../../models/time.entry.summary';
3+
import { LoadEntriesSummary } from './../../store/entry.actions';
4+
import { EntryState } from './../../store/entry.reducer';
5+
import { Store, select } from '@ngrx/store';
6+
import { Component, OnInit } from '@angular/core';
7+
8+
@Component({
9+
selector: 'app-time-entries-summary',
10+
templateUrl: './time-entries-summary.component.html',
11+
styleUrls: ['./time-entries-summary.component.css']
12+
})
13+
export class TimeEntriesSummaryComponent implements OnInit {
14+
15+
timeEntriesSummary: TimeEntriesSummary;
16+
17+
constructor(private store: Store<EntryState>) { }
18+
19+
ngOnInit(): void {
20+
this.store.dispatch(new LoadEntriesSummary());
21+
const timeEntriesSummary$ = this.store.pipe(select(getEntriesSummary));
22+
timeEntriesSummary$.subscribe((response) => {
23+
this.timeEntriesSummary = response;
24+
});
25+
}
26+
27+
}

src/app/modules/time-clock/pages/time-clock.component.html

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
<h6 class="text-left"><strong>Summary</strong></h6>
2-
<hr />
3-
<div class="row pb-4">
4-
<div class="col-4">
5-
<h6>Day</h6>
6-
<h3>4:22</h3>
7-
</div>
8-
<div class="col-4">
9-
<h6>Week</h6>
10-
<h3>14:25</h3>
11-
</div>
12-
<div class="col-4">
13-
<h6>Month</h6>
14-
<h3>49:32</h3>
15-
</div>
16-
</div>
1+
<app-time-entries-summary></app-time-entries-summary>
2+
173
<div style="width: 60%;">
184

195
<div class="row pb-4">
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { TimeDetailsPipe } from './time-details.pipe';
2+
3+
describe('TimeDetailsPipe', () => {
4+
it('create an instance', () => {
5+
const pipe = new TimeDetailsPipe();
6+
expect(pipe).toBeTruthy();
7+
});
8+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { TimeDetails } from '../models/time.entry.summary';
2+
import { Pipe, PipeTransform } from '@angular/core';
3+
4+
@Pipe({
5+
name: 'timeDetails'
6+
})
7+
export class TimeDetailsPipe implements PipeTransform {
8+
9+
transform(value: TimeDetails): string {
10+
return `${this.formatAsTwoDigit(value.hours)}:${this.formatAsTwoDigit(value.minutes)}` ;
11+
}
12+
13+
formatAsTwoDigit(time: string): string {
14+
// tslint:disable-next-line:no-construct
15+
const stringLength = new String(time).length;
16+
const formattedTime = (stringLength === 1) ? `0${time}` : time;
17+
return formattedTime;
18+
}
19+
}

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TimeEntriesSummary } from './../models/time.entry.summary';
1+
import { TimeEntriesSummary } from '../models/time.entry.summary';
22
import { Injectable } from '@angular/core';
33
import { HttpClient } from '@angular/common/http';
44

src/app/modules/time-clock/store/entry.actions.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import { TimeEntriesSummary } from '../models/time.entry.summary';
12
import { Action } from '@ngrx/store';
23
import { NewEntry, Entry } from '../../shared/models';
34

45
export enum EntryActionTypes {
6+
LOAD_ENTRIES_SUMMARY = '[Entry] LOAD_ENTRIES_SUMMARY',
7+
LOAD_ENTRIES_SUMMARY_SUCCESS = '[Entry] LOAD_ENTRIES_SUMMARY_SUCCESS',
8+
LOAD_ENTRIES_SUMMARY_FAIL = '[Entry] LOAD_ENTRIES_SUMMARY_FAIL',
59
LOAD_ACTIVE_ENTRY = '[Entry] LOAD_ACTIVE_ENTRY',
610
LOAD_ACTIVE_ENTRY_SUCCESS = '[Entry] LOAD_ACTIVE_ENTRY_SUCCESS',
711
LOAD_ACTIVE_ENTRY_FAIL = '[Entry] LOAD_ACTIVE_ENTRY_FAIL',
@@ -25,6 +29,19 @@ export enum EntryActionTypes {
2529
CLEAN_ENTRY_UPDATE_ERROR = '[Entry] CLEAN_ENTRY_UPDATE_ERROR',
2630
}
2731

32+
export class LoadEntriesSummary implements Action {
33+
public readonly type = EntryActionTypes.LOAD_ENTRIES_SUMMARY;
34+
}
35+
36+
export class LoadEntriesSummarySuccess implements Action {
37+
readonly type = EntryActionTypes.LOAD_ENTRIES_SUMMARY_SUCCESS;
38+
constructor(readonly payload: TimeEntriesSummary) {}
39+
}
40+
41+
export class LoadEntriesSummaryFail implements Action {
42+
readonly type = EntryActionTypes.LOAD_ENTRIES_SUMMARY_FAIL;
43+
}
44+
2845
export class LoadActiveEntry implements Action {
2946
public readonly type = EntryActionTypes.LOAD_ACTIVE_ENTRY;
3047
}
@@ -137,6 +154,9 @@ export class DefaultEntry implements Action {
137154
}
138155

139156
export type EntryActions =
157+
| LoadEntriesSummary
158+
| LoadEntriesSummarySuccess
159+
| LoadEntriesSummaryFail
140160
| LoadActiveEntry
141161
| LoadActiveEntrySuccess
142162
| LoadActiveEntryFail

0 commit comments

Comments
 (0)