Skip to content

Commit 0775e94

Browse files
authored
Merge pull request #116 from ioet/85-list-activities-from-api
closes #85
2 parents 8bc8018 + ed8d476 commit 0775e94

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ <h6 class="text-left"><strong>Projects</strong></h6>
3636
<br />
3737
<form *ngIf="!isClockIn || showFields">
3838
<div class="form-group row">
39-
<label for="inputActivity" class="col-sm-2 col-form-label text-center"><strong>Activity</strong></label>
39+
<label for="activitiesSelect" class="col-sm-2 col-form-label text-center"><strong>Activity</strong></label>
4040
<div class="col-sm-10">
41-
<input type="text" class="form-control" />
41+
<select id="activitiesSelect" class="form-control">
42+
<option *ngFor="let activity of activities;">{{activity.name}}</option>
43+
</select>
4244
</div>
4345
</div>
4446
<div class="form-group row">
@@ -61,12 +63,7 @@ <h6 class="text-left"><strong>Projects</strong></h6>
6163
<button *ngIf="isClockIn" class="btn btn-primary" type="button" (click)="employeClockIn()">
6264
Clock In
6365
</button>
64-
<button
65-
*ngIf="!isClockIn"
66-
class="btn btn-primary"
67-
type="button"
68-
(click)="employeClockOut()"
69-
>
66+
<button *ngIf="!isClockIn" class="btn btn-primary" type="button" (click)="employeClockOut()">
7067
Clock Out
7168
</button>
7269
</div>

src/app/modules/time-clock/pages/time-clock.component.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LoadActivities } from '../../activities-management/store/activity-management.actions';
12
import { async, ComponentFixture, TestBed, inject } from '@angular/core/testing';
23
import { HttpClientTestingModule } from '@angular/common/http/testing';
34
import { provideMockStore, MockStore } from '@ngrx/store/testing';
@@ -49,6 +50,14 @@ describe('TimeClockComponent', () => {
4950
expect(component).toBeTruthy();
5051
});
5152

53+
it('onInit, LoadActivities action is dispatched', () => {
54+
spyOn(store, 'dispatch');
55+
56+
component.ngOnInit();
57+
58+
expect(store.dispatch).toHaveBeenCalledWith(new LoadActivities());
59+
});
60+
5261
it('Service injected via inject(...) and TestBed.get(...) should be the same instance', inject(
5362
[ProjectService],
5463
(injectService: ProjectService) => {

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { Store, select } from '@ngrx/store';
3+
4+
import { LoadActivities, ActivityState, allActivities } from '../../activities-management/store/';
5+
import { Activity } from 'src/app/modules/shared/models';
6+
27

38
@Component({
49
selector: 'app-time-clock',
@@ -25,7 +30,9 @@ export class TimeClockComponent implements OnInit {
2530
isClockInEnable = false;
2631
isHidenForm = true;
2732

28-
constructor() {
33+
activities: Activity[] = [];
34+
35+
constructor(private store: Store<ActivityState>) {
2936
this.isClockIn = true;
3037
this.isEnterTechnology = false;
3138
this.hourCounterRealTime = 0;
@@ -36,6 +43,14 @@ export class TimeClockComponent implements OnInit {
3643
this.seconds = 0;
3744
}
3845

46+
ngOnInit() {
47+
this.store.dispatch(new LoadActivities());
48+
const activities$ = this.store.pipe(select(allActivities));
49+
activities$.subscribe((response) => {
50+
this.activities = response;
51+
});
52+
}
53+
3954
employeClockIn(): boolean {
4055
this.isClockInEnable = true;
4156
this.isClockIn = !this.isClockIn;
@@ -119,5 +134,4 @@ export class TimeClockComponent implements OnInit {
119134
this.isClockInEnable = false;
120135
}
121136

122-
ngOnInit(): void {}
123137
}

0 commit comments

Comments
 (0)