@@ -5,6 +5,7 @@ import { Component, OnInit } from '@angular/core';
5
5
templateUrl : './time-clock.component.html' ,
6
6
styleUrls : [ './time-clock.component.css' ]
7
7
} )
8
+
8
9
export class TimeClockComponent implements OnInit {
9
10
10
11
projects = [
@@ -14,22 +15,40 @@ export class TimeClockComponent implements OnInit {
14
15
{ id : 'P4' , name : 'Project 4' }
15
16
] ;
16
17
18
+ currentDate : Date = new Date ( ) ;
17
19
username = 'Dario' ;
18
- clockInUsername = 'hh:mm:ss' ;
19
- clockOutUsername = 'hh:mm:ss' ;
20
-
21
20
isClockIn : boolean ;
22
21
isEnterTechnology : boolean ;
23
22
showAlertEnterTecnology : boolean ;
24
23
showFields : boolean ;
24
+ hourCounterRealTime : number ;
25
+ minuteCounterRealTime : number ;
26
+ secondsCounterRealTime : number ;
27
+ hour : number ;
28
+ minute : number ;
29
+ seconds : number ;
30
+ interval ;
31
+ dataTechnology : string ;
32
+ execOnlyOneTimeCounter = 0 ;
33
+ execOnlyOneTimeClockIn = 0 ;
34
+ isClockInEnable = false ;
25
35
26
36
constructor ( ) {
27
37
this . isClockIn = true ;
28
38
this . isEnterTechnology = false ;
39
+ this . hourCounterRealTime = 0 ;
40
+ this . minuteCounterRealTime = 0 ;
41
+ this . secondsCounterRealTime = 0 ;
42
+ this . hour = 0 ;
43
+ this . minute = 0 ;
44
+ this . seconds = 0 ;
29
45
}
30
46
31
47
employeClockIn ( ) : boolean {
48
+ this . isClockInEnable = true ;
32
49
this . isClockIn = ! this . isClockIn ;
50
+ this . startTimer ( ) ;
51
+ this . setTimeToInOut ( ) ;
33
52
return this . isClockIn ;
34
53
}
35
54
@@ -38,13 +57,15 @@ export class TimeClockComponent implements OnInit {
38
57
this . isClockIn = false ;
39
58
this . showAlertEnterTecnology = true ;
40
59
} else {
41
- this . isClockIn = true ;
42
- this . isEnterTechnology = false ;
43
- this . showAlertEnterTecnology = false ;
60
+ this . setVarToEmpty ( ) ;
61
+ this . pauseTimer ( ) ;
62
+ this . setTimeToInOut ( ) ;
63
+
44
64
}
45
65
}
46
66
47
67
enterTechnology ( data : string ) {
68
+ this . dataTechnology = data ;
48
69
if ( data . length > 0 ) {
49
70
this . isEnterTechnology = true ;
50
71
} else {
@@ -53,9 +74,60 @@ export class TimeClockComponent implements OnInit {
53
74
}
54
75
55
76
setShowFields ( show : boolean ) {
56
- this . isClockIn = false ;
57
- this . showFields = show ;
77
+ if ( this . isClockInEnable !== true ) {
78
+ this . isClockIn = false ;
79
+ this . showFields = show ;
80
+ if ( this . execOnlyOneTimeCounter === 0 ) {
81
+ this . startTimer ( ) ;
82
+ this . execOnlyOneTimeCounter ++ ;
83
+ }
84
+ this . setTimeToInOut ( ) ;
85
+ }
86
+ }
87
+
88
+ startTimer ( ) {
89
+ this . interval = setInterval ( ( ) => {
90
+ this . timer ( ) ;
91
+ } , 1000 ) ;
92
+ }
93
+
94
+ pauseTimer ( ) {
95
+ clearInterval ( this . interval ) ;
96
+ }
97
+
98
+ timer ( ) {
99
+ this . secondsCounterRealTime += 1 ;
100
+ if ( this . secondsCounterRealTime === 59 ) {
101
+ this . minuteCounterRealTime += 1 ;
102
+ this . secondsCounterRealTime = 0 ;
103
+ if ( this . minuteCounterRealTime === 59 ) {
104
+ this . hourCounterRealTime += 1 ;
105
+ this . minuteCounterRealTime = 0 ;
106
+ }
107
+ }
108
+ }
109
+
110
+ setTimeToInOut ( ) {
111
+ if ( this . execOnlyOneTimeClockIn === 0 ) {
112
+ this . currentDate = new Date ( ) ;
113
+ this . hour = this . currentDate . getHours ( ) ;
114
+ this . minute = this . currentDate . getMinutes ( ) ;
115
+ this . seconds = this . currentDate . getSeconds ( ) ;
116
+ this . execOnlyOneTimeClockIn ++ ;
117
+ }
118
+
119
+ }
120
+
121
+ setVarToEmpty ( ) {
122
+ this . dataTechnology = '' ;
123
+ this . isClockIn = true ;
124
+ this . isEnterTechnology = false ;
125
+ this . showAlertEnterTecnology = false ;
126
+ this . execOnlyOneTimeClockIn = 0 ;
127
+ this . execOnlyOneTimeCounter = 0 ;
128
+ this . isClockInEnable = false ;
58
129
}
59
130
60
131
ngOnInit ( ) : void { }
132
+
61
133
}
0 commit comments