Skip to content

Commit 89740ad

Browse files
committed
fix: #395 Make the activity required when clocking-out
1 parent 8afbfe7 commit 89740ad

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

src/app/modules/time-clock/components/entry-fields/entry-fields.component.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,39 @@
33
<div class="input-group-prepend">
44
<span class="input-group-text span-width">Activity</span>
55
</div>
6-
<select id="activitiesSelect" (blur)="onSubmit()" class="form-control" formControlName="activity_id">
6+
<select
7+
id="activitiesSelect"
8+
(blur)="onSubmit()"
9+
class="form-control"
10+
formControlName="activity_id"
11+
[class.is-invalid]="activity_id.invalid && activity_id.touched"
12+
required
13+
>
714
<option value="-1"></option>
8-
<option *ngFor="let activity of activities" value="{{activity.id}}">{{ activity.name }}</option>
15+
<option *ngFor="let activity of activities" value="{{ activity.id }}">{{ activity.name }}</option>
916
</select>
1017
</div>
1118
<div class="input-group input-group-sm mb-3">
1219
<div class="input-group-prepend">
1320
<span class="input-group-text span-width">Ticket URI</span>
1421
</div>
15-
<input (blur)="onSubmit()" type="text" id="uri" formControlName="uri" class="form-control" aria-label="Small"
16-
aria-describedby="inputGroup-sizing-sm"/>
22+
<input
23+
(blur)="onSubmit()"
24+
type="text"
25+
id="uri"
26+
formControlName="uri"
27+
class="form-control"
28+
aria-label="Small"
29+
aria-describedby="inputGroup-sizing-sm"
30+
/>
1731
</div>
18-
<app-technologies (technologyAdded)="onTechnologyAdded($event)"
19-
(technologyRemoved)="onTechnologyRemoved($event)"
20-
[selectedTechnologies]="selectedTechnologies">
32+
<app-technologies
33+
(technologyAdded)="onTechnologyAdded($event)"
34+
(technologyRemoved)="onTechnologyRemoved($event)"
35+
[selectedTechnologies]="selectedTechnologies"
36+
>
2137
</app-technologies>
2238

23-
2439
<div class="input-group input-group-sm mb-3">
2540
<div class="input-group-prepend">
2641
<span class="input-group-text span-width">Description</span>
@@ -31,8 +46,8 @@
3146
formControlName="description"
3247
class="form-control"
3348
id="NotesTextarea"
34-
rows="2">
49+
rows="2"
50+
>
3551
</textarea>
3652
</div>
37-
3853
</form>

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export class EntryFieldsComponent implements OnInit {
5858
});
5959
}
6060

61+
get activity_id() {
62+
return this.entryForm.get('activity_id');
63+
}
64+
6165
setDataToUpdate(entryData: NewEntry) {
6266
if (entryData) {
6367
this.entryForm.patchValue({

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ describe('TimeClockComponent', () => {
8181
it('clockOut dispatch a StopTimeEntryRunning action', () => {
8282
spyOn(store, 'dispatch');
8383

84-
component.clockOut();
85-
84+
component.stopEntry();
8685
expect(store.dispatch).toHaveBeenCalledWith(new StopTimeEntryRunning('id'));
8786
});
8887
});

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ import { getActiveTimeEntry } from './../store/entry.selectors';
22
import { StopTimeEntryRunning } from './../store/entry.actions';
33
import { Entry } from './../../shared/models/entry.model';
44
import { Store, select } from '@ngrx/store';
5-
import { Component, OnInit } from '@angular/core';
5+
import { Component, OnInit, ViewChild } from '@angular/core';
66
import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service';
77
import { Subscription } from 'rxjs';
8+
import { EntryFieldsComponent } from '../components/entry-fields/entry-fields.component';
89

910
@Component({
1011
selector: 'app-time-clock',
1112
templateUrl: './time-clock.component.html',
1213
styleUrls: ['./time-clock.component.scss'],
1314
})
1415
export class TimeClockComponent implements OnInit {
16+
@ViewChild(EntryFieldsComponent)
17+
entryFieldsComponent: EntryFieldsComponent;
1518
username: string;
1619
areFieldsVisible = false;
1720
activeTimeEntry: Entry;
1821
actionsSubscription: Subscription;
1922

20-
constructor(private azureAdB2CService: AzureAdB2CService, private store: Store<Entry>) {
21-
}
23+
constructor(private azureAdB2CService: AzureAdB2CService, private store: Store<Entry>) {}
2224

2325
ngOnInit() {
2426
this.username = this.azureAdB2CService.isLogin() ? this.azureAdB2CService.getName() : '';
@@ -32,8 +34,16 @@ export class TimeClockComponent implements OnInit {
3234
});
3335
}
3436

35-
clockOut() {
37+
stopEntry() {
3638
this.store.dispatch(new StopTimeEntryRunning(this.activeTimeEntry.id));
3739
this.areFieldsVisible = false;
3840
}
41+
42+
clockOut() {
43+
if (this.entryFieldsComponent.entryForm.valid) {
44+
this.stopEntry();
45+
} else {
46+
this.entryFieldsComponent.entryForm.get('activity_id').markAsTouched();
47+
}
48+
}
3949
}

0 commit comments

Comments
 (0)