Skip to content

Commit e6e4e9a

Browse files
authored
Merge pull request #26 from ioet/Time-Clock-Timer-Component
Time clock timer component
2 parents 1e9d801 + ce0682b commit e6e4e9a

File tree

7 files changed

+162
-46
lines changed

7 files changed

+162
-46
lines changed

src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const routes: Routes = [
1515
];
1616

1717
@NgModule({
18-
imports: [RouterModule.forRoot(routes, { useHash: true })],
18+
imports: [RouterModule.forRoot(routes)],
1919
exports: [RouterModule]
2020
})
2121
export class AppRoutingModule { }
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
.content-ClockIn {
2-
padding: 2.1rem 1rem;
2+
padding: 2.1rem 1rem;
33
}
44

55
.timer {
6-
align-items: center;
7-
display: flex;
8-
height: 100%;
9-
justify-content: center;
10-
}
6+
align-items: center;
7+
display: flex;
8+
height: 100%;
9+
justify-content: center;
10+
}

src/app/components/options-sidebar/time-clock/time-clock.component.html

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
<div class="text-center mt-3">
2-
3-
<div *ngIf="showAlertEnterTecnology" class="alert alert-danger" role="alert">
4-
Field technology is requiered. Enter this field for clock out.
5-
</div>
6-
1+
<div class="text-center mt-5">
72
<div class="card">
83
<div class="card-header">
94
<div class="row">
@@ -17,22 +12,22 @@
1712
</div>
1813

1914
<div class="card-body">
20-
<p *ngIf="!isClockIn" class="card-title text-left"><strong>{{ username }}</strong> clocked <strong class="text-success">in</strong> at <strong>{{ clockInUsername }}</strong></p>
21-
<p *ngIf="isClockIn" class="card-title text-left"><strong>{{ username }}</strong> clocked <strong class="text-danger">out</strong> at <strong>{{ clockOutUsername }}</strong></p>
15+
<p *ngIf="!isClockIn" class="card-title text-left"><strong>{{ username }}</strong> clocked <strong class="text-success">in</strong> at <strong>{{ hour | number: '2.0-2' }}:{{ minute | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</strong></p>
16+
<p *ngIf="isClockIn" class="card-title text-left"><strong>{{ username }}</strong> clocked <strong class="text-danger">out</strong> at <strong>{{ hour | number: '2.0-2' }}:{{ minute | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</strong></p>
2217
<h6 class="text-left"><strong>Totals</strong></h6>
2318
<hr>
2419
<div class="row">
2520
<div class="col-4">
2621
<h6>Current</h6>
27-
<h3>{{ hour | number: '2.0-2' }}:{{ minute | number: '2.0-2' }}:{{ seconds | number: '2.0-2' }}</h3>
22+
<h3>{{ hourCounterRealTime | number: '2.0-2' }}:{{ minuteCounterRealTime | number: '2.0-2' }}:{{ secondsCounterRealTime | number: '2.0-2' }}</h3>
2823
</div>
2924
<div class="col-4">
3025
<h6>Day</h6>
31-
<h3>4:22</h3>
26+
<h3>00:00</h3>
3227
</div>
3328
<div class="col-4">
3429
<h6>Week</h6>
35-
<h3>14:00</h3>
30+
<h3>00:00</h3>
3631
</div>
3732
</div>
3833
<h6 class="text-left"><strong>Projects</strong></h6>
@@ -46,7 +41,7 @@ <h6 class="text-left"><strong>Projects</strong></h6>
4641
<app-project-list-hover [projects]="projects" (showFields)="setShowFields($event)"></app-project-list-hover>
4742
</ul>
4843
<br>
49-
<form *ngIf="!isClockIn || showFields">
44+
<form *ngIf="(!isClockIn || showFields) && !isHidenForm">
5045
<div class="form-group row">
5146
<label for="inputActivity" class="col-sm-2 col-form-label text-center"><strong>Activity</strong></label>
5247
<div class="col-sm-10">
@@ -62,19 +57,23 @@ <h6 class="text-left"><strong>Projects</strong></h6>
6257
<div class="form-group row">
6358
<label for="inputTechnology" class="col-sm-2 col-form-label text-center"><strong>Technology</strong></label>
6459
<div class="col-sm-10">
65-
<input #data type="text" (keyup)="enterTechnology(data.value)" class="form-control">
60+
<input *ngIf="!showAlertEnterTecnology" #data type="text" (keyup)="enterTechnology(data.value)" class="form-control">
61+
<input *ngIf="showAlertEnterTecnology" #data type="text" (keyup)="enterTechnology(data.value)" class="form-control border-danger">
62+
<div>
63+
<h6 *ngIf="showAlertEnterTecnology" class="text-danger text-left">Technology field is required. Enter this field to clock out.</h6>
64+
</div>
6665
</div>
6766
</div>
6867
</form>
6968
<hr>
7069
<div class="container">
7170
<div class="row">
72-
<div class="col text-left">
71+
<div class="col text-left" id="optionsContainer">
7372
<button class="btn btn-light btn-sm dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
7473
Options
7574
</button>
7675
</div>
77-
<div class="col text-right">
76+
<div class="col text-right" id="clockInOutContainer">
7877
<button *ngIf="isClockIn" class="btn btn-success btn-sm" type="button" (click)="employeClockIn()">Clock In</button>
7978
<button *ngIf="!isClockIn" class="btn btn-danger btn-sm" type="button" (click)="employeClockOut()">Clock Out</button>
8079
</div>

src/app/components/options-sidebar/time-clock/time-clock.component.spec.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
1+
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
22
import { By } from '@angular/platform-browser';
3-
import { DebugElement } from '@angular/core';
3+
import { DebugElement, Component } from '@angular/core';
44
import { TimeClockComponent } from './time-clock.component';
55
import { ProjectListHoverComponent } from '../../shared/project-list-hover/project-list-hover.component';
66

@@ -10,7 +10,6 @@ describe('TimeClockComponent', () => {
1010
let de: DebugElement;
1111

1212
function setup() {
13-
// tslint:disable-next-line: no-shadowed-variable
1413
const fixture = TestBed.createComponent(TimeClockComponent);
1514
const app = fixture.debugElement.componentInstance;
1615
return { fixture, app };
@@ -33,13 +32,12 @@ describe('TimeClockComponent', () => {
3332
expect(component).toBeTruthy();
3433
});
3534

36-
it('should have p tag as \'Dario clocked out at hh:mm:ss\'', async(() => {
37-
// tslint:disable-next-line: no-shadowed-variable
38-
const { app, fixture } = setup();
35+
it('should have p tag as \'Dario clocked out at 00:00:00\'', async(() => {
36+
const { fixture } = setup();
3937
fixture.detectChanges();
4038
const compile = fixture.debugElement.nativeElement;
4139
const ptag = compile.querySelector('p');
42-
expect(ptag.textContent).toBe('Dario clocked out at hh:mm:ss');
40+
expect(ptag.textContent).toBe('Dario clocked out at 00:00:00');
4341
}));
4442

4543
it('should set showfileds as true', () => {
@@ -63,4 +61,45 @@ describe('TimeClockComponent', () => {
6361
li.nativeElement.click();
6462
expect(component.setShowFields).toHaveBeenCalledWith(true);
6563
});
64+
65+
it('should have button text as Options', async(() => {
66+
const { fixture } = setup();
67+
fixture.detectChanges();
68+
const x = document.getElementById('optionsContainer');
69+
const ptag = x.querySelector('button');
70+
expect(ptag.textContent).toBe(' Options ');
71+
}));
72+
73+
it('should set Clock In', () => {
74+
const { fixture } = setup();
75+
fixture.detectChanges();
76+
const x = document.getElementById('clockInOutContainer');
77+
const ptag = x.querySelector('button');
78+
expect(ptag.textContent).toBe('Clock In');
79+
});
80+
81+
it('should setVartToEmpty called', () => {
82+
spyOn(component, 'setDefaultValuesToFields');
83+
component.setDefaultValuesToFields();
84+
expect(component.setDefaultValuesToFields).toHaveBeenCalled();
85+
});
86+
87+
it('should employeClockIn called', () => {
88+
spyOn(component, 'employeClockIn');
89+
component.employeClockIn();
90+
expect(component.employeClockIn).toHaveBeenCalled();
91+
});
92+
93+
it('should employeClockOut called', () => {
94+
spyOn(component, 'employeClockOut');
95+
component.employeClockOut();
96+
expect(component.employeClockOut).toHaveBeenCalled();
97+
});
98+
99+
it('should enterTechnolofy called', () => {
100+
spyOn(component, 'enterTechnology');
101+
component.enterTechnology('');
102+
expect(component.enterTechnology).toHaveBeenCalled();
103+
});
104+
66105
});

src/app/components/options-sidebar/time-clock/time-clock.component.ts

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,42 @@ export class TimeClockComponent implements OnInit {
1515
{ id: 'P4', name: 'Project 4' }
1616
];
1717

18+
currentDate: Date = new Date();
1819
username = 'Dario';
19-
clockInUsername = 'hh:mm:ss';
20-
clockOutUsername = 'hh:mm:ss';
2120
isClockIn: boolean;
2221
isEnterTechnology: boolean;
2322
showAlertEnterTecnology: boolean;
24-
23+
showFields: boolean;
24+
hourCounterRealTime: number;
25+
minuteCounterRealTime: number;
26+
secondsCounterRealTime: number;
2527
hour: number;
2628
minute: number;
2729
seconds: number;
28-
29-
showFields: boolean;
30+
interval;
31+
dataTechnology: string[] = new Array();
32+
execOnlyOneTimeCounter = false;
33+
execOnlyOneTimeClockIn = false;
34+
isClockInEnable = false;
35+
isHidenForm = true;
3036

3137
constructor() {
3238
this.isClockIn = true;
3339
this.isEnterTechnology = false;
40+
this.hourCounterRealTime = 0;
41+
this.minuteCounterRealTime = 0;
42+
this.secondsCounterRealTime = 0;
3443
this.hour = 0;
3544
this.minute = 0;
3645
this.seconds = 0;
3746
}
3847

3948
employeClockIn(): boolean {
49+
this.isClockInEnable = true;
4050
this.isClockIn = !this.isClockIn;
51+
this.isHidenForm = false;
52+
this.startTimer();
53+
this.setArrivalAndDepartureTimes();
4154
return this.isClockIn;
4255
}
4356

@@ -46,9 +59,9 @@ export class TimeClockComponent implements OnInit {
4659
this.isClockIn = false;
4760
this.showAlertEnterTecnology = true;
4861
} else {
49-
this.isClockIn = true;
50-
this.isEnterTechnology = false;
51-
this.showAlertEnterTecnology = false;
62+
this.setDefaultValuesToFields();
63+
this.pauseTimer();
64+
this.setArrivalAndDepartureTimes();
5265
}
5366
}
5467

@@ -61,10 +74,62 @@ export class TimeClockComponent implements OnInit {
6174
}
6275

6376
setShowFields(show: boolean) {
64-
this.isClockIn = false;
65-
this.showFields = show;
77+
this.isHidenForm = false;
78+
if ( this.isClockInEnable !== true ) {
79+
this.isClockIn = false;
80+
this.showFields = show;
81+
if ( !this.execOnlyOneTimeCounter ) {
82+
this.startTimer();
83+
this.execOnlyOneTimeCounter = true;
84+
}
85+
this.setArrivalAndDepartureTimes();
86+
}
87+
}
88+
89+
startTimer() {
90+
this.interval = setInterval(() => {
91+
this.timer();
92+
}, 1000 );
93+
}
94+
95+
pauseTimer() {
96+
clearInterval(this.interval);
97+
}
98+
99+
timer() {
100+
this.secondsCounterRealTime += 1;
101+
if ( this.secondsCounterRealTime === 59 ) {
102+
this.minuteCounterRealTime += 1;
103+
this.secondsCounterRealTime = 0;
104+
if ( this.minuteCounterRealTime === 59 ) {
105+
this.hourCounterRealTime += 1;
106+
this.minuteCounterRealTime = 0;
107+
}
108+
}
109+
}
110+
111+
setArrivalAndDepartureTimes() {
112+
if ( !this.execOnlyOneTimeClockIn ) {
113+
this.currentDate = new Date();
114+
this.hour = this.currentDate.getHours();
115+
this.minute = this.currentDate.getMinutes();
116+
this.seconds = this.currentDate.getSeconds();
117+
this.execOnlyOneTimeClockIn = true;
118+
}
119+
66120
}
67121

68-
ngOnInit(): void {}
122+
setDefaultValuesToFields() {
123+
this.isHidenForm = true;
124+
this.isClockIn = true;
125+
this.isEnterTechnology = false;
126+
this.showAlertEnterTecnology = false;
127+
this.execOnlyOneTimeClockIn = false;
128+
this.execOnlyOneTimeCounter = false;
129+
this.isClockInEnable = false;
130+
}
131+
132+
ngOnInit(): void {
133+
}
69134

70135
}

src/app/components/shared/clock/clock.component.spec.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { ClockComponent } from './clock.component';
4+
import { interval, timer } from 'rxjs';
45

56
describe('ClockComponent', () => {
67
let component: ClockComponent;
78
let fixture: ComponentFixture<ClockComponent>;
89

10+
function setup() {
11+
// tslint:disable-next-line: no-shadowed-variable
12+
const fixture = TestBed.createComponent(ClockComponent);
13+
const app = fixture.debugElement.componentInstance;
14+
return { fixture, app };
15+
}
916

1017
beforeEach(async(() => {
1118
TestBed.configureTestingModule({
@@ -25,13 +32,19 @@ describe('ClockComponent', () => {
2532
});
2633

2734
it('should show the current hour of day', () => {
28-
const currentHour = 11;
29-
expect(component.currentDate.getHours()).toEqual(currentHour);
35+
const currentDate: Date = new Date();
36+
expect(component.currentDate.getHours()).toEqual(currentDate.getHours());
3037
});
3138

3239
it('should show the current minutes of day', () => {
33-
const currenMinutes = 5;
34-
expect(component.currentDate.getMinutes()).toEqual(currenMinutes);
40+
const currentDate: Date = new Date();
41+
expect(component.currentDate.getMinutes()).toEqual(currentDate.getMinutes());
3542
});
3643

44+
it('should show the current seconds of day', () => {
45+
const currentDate: Date = new Date();
46+
expect(component.currentDate.getSeconds()).toEqual(currentDate.getSeconds());
47+
});
48+
49+
3750
});

src/app/components/shared/clock/clock.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ export class ClockComponent implements OnInit {
1515
displayTime: boolean;
1616

1717
constructor() {
18-
this.showClcok();
18+
this.showClock();
1919
this.displayTime = false;
2020
setTimeout(() => {
2121
this.displayTime = true;
2222
}, 3000);
2323
}
2424

25-
showClcok() {
25+
showClock() {
2626
const timenInterval = interval(1000);
2727
timenInterval.subscribe( (data) => {
2828
this.currentDate = new Date();

0 commit comments

Comments
 (0)