Skip to content

Commit b0f2d63

Browse files
committed
fix: #172 Create-time-entries-manually
1 parent 9424000 commit b0f2d63

20 files changed

+561
-123
lines changed

package-lock.json

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"bootstrap": "^4.4.1",
2828
"jquery": "^3.5.0",
2929
"minimist": "^1.2.5",
30+
"moment": "^2.25.3",
3031
"msal": "^1.2.1",
3132
"ngx-pagination": "^5.0.0",
3233
"rxjs": "~6.5.4",

src/app/modules/shared/components/details-fields/details-fields.component.html

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<div class="ng-autocomplete">
77
<ng-autocomplete
88
class="autocomplete"
9+
910
[data]="listProjects && listProjects"
1011
[searchKeyword]="keyword"
1112
[itemTemplate]="itemTemplate"
@@ -24,23 +25,68 @@
2425
<div class="input-group-prepend">
2526
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Activity</span>
2627
</div>
27-
<select id="activitiesSelect" class="form-control">
28+
<select id="activitiesSelect" class="form-control" formControlName="activity">
2829
<option *ngFor="let activity of activities">{{ activity.name }}</option>
2930
</select>
3031
</div>
32+
3133
<div class="input-group input-group-sm mb-3">
3234
<div class="input-group-prepend">
33-
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Jira Ticket</span>
35+
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Ticket</span>
3436
</div>
3537
<input
36-
formControlName="ticket"
38+
formControlName="uri"
3739
type="text"
3840
class="form-control"
3941
aria-label="Small"
4042
aria-describedby="inputGroup-sizing-sm"
4143
/>
4244
</div>
4345

46+
<div class="input-group input-group-sm mb-3">
47+
<div class="input-group-prepend">
48+
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Start/Date</span>
49+
</div>
50+
<input
51+
formControlName="start_date"
52+
type="date"
53+
class="form-control"
54+
aria-label="Small"
55+
aria-describedby="inputGroup-sizing-sm"
56+
/>
57+
<div class="input-group-prepend">
58+
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Start/Hour</span>
59+
</div>
60+
<input
61+
formControlName="start_hour"
62+
type="text"
63+
class="form-control"
64+
aria-label="Small"
65+
aria-describedby="inputGroup-sizing-sm"
66+
/>
67+
</div>
68+
<div class="input-group input-group-sm mb-3">
69+
<div class="input-group-prepend">
70+
<span class="input-group-text span-width" id="inputGroup-sizing-sm">End/Date</span>
71+
</div>
72+
<input
73+
formControlName="end_date"
74+
type="date"
75+
class="form-control"
76+
aria-label="Small"
77+
aria-describedby="inputGroup-sizing-sm"
78+
/>
79+
<div class="input-group-prepend">
80+
<span class="input-group-text span-width" id="inputGroup-sizing-sm">End/Hour</span>
81+
</div>
82+
<input
83+
formControlName="end_hour"
84+
type="text"
85+
class="form-control"
86+
aria-label="Small"
87+
aria-describedby="inputGroup-sizing-sm"
88+
/>
89+
</div>
4490
<div class="input-group input-group-sm">
4591
<div class="input-group-prepend">
4692
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Technology</span>
@@ -73,8 +119,8 @@
73119
</div>
74120

75121
<div class="form-group text-left">
76-
<label for="NotesTextarea">Notes</label>
77-
<textarea formControlName="comments" class="form-control" id="NotesTextarea" rows="3"></textarea>
122+
<label for="NotesTextarea">Description</label>
123+
<textarea formControlName="description" class="form-control" id="NotesTextarea" rows="3"></textarea>
78124
</div>
79125
<div [ngClass]="{ hidden: formType !== 'entries' }" class="modal-footer">
80126
<button #closeModal type="button" class="btn close-button-style" data-dismiss="modal">

src/app/modules/shared/components/details-fields/details-fields.component.scss

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,24 @@
8989
}
9090
}
9191
}
92+
93+
input[type="date"]::-webkit-calendar-picker-indicator {
94+
position: absolute;
95+
top: 0;
96+
left: 0;
97+
right: 0;
98+
bottom: 0;
99+
width: auto;
100+
height: auto;
101+
color: transparent;
102+
background: transparent;
103+
-webkit-appearance: none;
104+
}
105+
106+
input[type="date"]::-webkit-inner-spin-button {
107+
-webkit-appearance: none;
108+
}
109+
110+
input[type="date"]::-webkit-clear-button {
111+
z-index: 1;
112+
}

src/app/modules/shared/components/details-fields/details-fields.component.spec.ts

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
22
import { provideMockStore, MockStore } from '@ngrx/store/testing';
33
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
4+
import { formatDate } from '@angular/common';
45

56
import { TechnologyState } from '../../store/technology.reducers';
67
import { allTechnologies } from '../../store/technology.selectors';
@@ -31,7 +32,7 @@ describe('DetailsFieldsComponent', () => {
3132
isLoading: false,
3233
},
3334
activities: {
34-
data: [{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', tenant_id: 'ioet', deleted: null, name: 'Training 2' }],
35+
data: [{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', tenant_id: 'ioet', deleted: null, name: 'abc' }],
3536
isLoading: false,
3637
message: 'Data fetch successfully!',
3738
activityIdToEdit: '',
@@ -41,15 +42,12 @@ describe('DetailsFieldsComponent', () => {
4142
const initialData = {
4243
project: '',
4344
activity: '',
44-
ticket: '',
45-
comments: '',
46-
};
47-
48-
const newData = {
49-
project: 'Ernst&Young',
50-
activity: 'development',
51-
ticket: 'WA-15',
52-
comments: 'No notes',
45+
uri: '',
46+
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
47+
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
48+
start_hour: '00:00',
49+
end_hour: '00:00',
50+
description: '',
5351
};
5452

5553
beforeEach(async(() => {
@@ -80,9 +78,53 @@ describe('DetailsFieldsComponent', () => {
8078
});
8179

8280
it('should emit ngOnChange with new data', () => {
83-
component.entryToEdit = newData;
81+
const entryToEdit = {
82+
project_id: 'id',
83+
activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd05',
84+
uri: 'ticketUri',
85+
start_date: '2020-02-05T14:36',
86+
end_date: '2020-02-05T15:36',
87+
start_hour: '14:36',
88+
end_hour: '15:36',
89+
description: '',
90+
};
91+
const formValue = {
92+
project: 'name',
93+
activity: 'abc',
94+
uri: 'ticketUri',
95+
start_date: '2020-02-05',
96+
end_date: '2020-02-05',
97+
start_hour: '14:36',
98+
end_hour: '15:36',
99+
description: '',
100+
};
101+
component.entryToEdit = entryToEdit;
102+
component.ngOnChanges();
103+
expect(component.entryForm.value).toEqual(formValue);
104+
});
105+
106+
it('should emit ngOnChange with new data', () => {
107+
const entryToEdit = {
108+
project_id: '',
109+
activity_id: '',
110+
uri: 'ticketUri',
111+
start_date: null,
112+
end_date: null,
113+
description: '',
114+
};
115+
const formValue = {
116+
project: '',
117+
activity: '',
118+
uri: 'ticketUri',
119+
start_date: '',
120+
end_date: '',
121+
start_hour: '00:00',
122+
end_hour: '00:00',
123+
description: '',
124+
};
125+
component.entryToEdit = entryToEdit;
84126
component.ngOnChanges();
85-
expect(component.entryForm.value).toEqual(newData);
127+
expect(component.entryForm.value).toEqual(formValue);
86128
});
87129

88130
it('should dispatch FindTechnology action #getTechnologies', () => {
@@ -152,6 +194,15 @@ describe('DetailsFieldsComponent', () => {
152194
it('should emit saveEntry event', () => {
153195
spyOn(component.saveEntry, 'emit');
154196
component.onSubmit();
155-
expect(component.saveEntry.emit).toHaveBeenCalledWith(initialData);
197+
const data = {
198+
project_id: undefined,
199+
activity_id: null,
200+
technologies: [],
201+
description: '',
202+
start_date: 'T00:00',
203+
end_date: 'T00:00',
204+
uri: '',
205+
};
206+
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
156207
});
157208
});

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import {
1212
import { FormBuilder, FormGroup } from '@angular/forms';
1313
import { Store, select } from '@ngrx/store';
1414
import * as actions from '../../store/technology.actions';
15+
import { formatDate } from '@angular/common';
1516

1617
import { allTechnologies } from '../../store/technology.selectors';
1718
import { Technology, Project, Activity } from '../../models';
1819

1920
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
2021
import { TechnologyState } from '../../store/technology.reducers';
2122
import { LoadActivities, ActivityState, allActivities } from '../../../activities-management/store';
22-
import { getCustomerProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
23+
import { getProjects } from '../../../customer-management/components/projects/components/store/project.selectors';
2324
import * as projectActions from '../../../customer-management/components/projects/components/store/project.actions';
2425

2526
type Merged = TechnologyState & ProjectState & ActivityState;
@@ -43,6 +44,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4344
activities: Activity[] = [];
4445
keyword = 'name';
4546
showlist: boolean;
47+
startDate;
4648

4749
constructor(private formBuilder: FormBuilder, private store: Store<Merged>, private renderer: Renderer2) {
4850
this.renderer.listen('window', 'click', (e: Event) => {
@@ -53,8 +55,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
5355
this.entryForm = this.formBuilder.group({
5456
project: '',
5557
activity: '',
56-
ticket: '',
57-
comments: '',
58+
description: '',
59+
start_date: '',
60+
end_date: '',
61+
start_hour: '00:00',
62+
end_hour: '00:00',
63+
uri: '',
5864
});
5965
}
6066

@@ -66,9 +72,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
6672
});
6773

6874
this.store.dispatch(new projectActions.LoadProjects());
69-
const projects$ = this.store.pipe(select(getCustomerProjects));
75+
const projects$ = this.store.pipe(select(getProjects));
7076
projects$.subscribe((response) => {
71-
this.listProjects = response.customerProjects;
77+
this.listProjects = response;
7278
});
7379

7480
this.store.dispatch(new LoadActivities());
@@ -81,12 +87,29 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
8187
ngOnChanges(): void {
8288
if (this.entryToEdit) {
8389
this.selectedTechnology = this.entryToEdit.technologies;
84-
90+
const project = this.listProjects.find((p) => p.id === this.entryToEdit.project_id);
91+
const activity = this.activities.find((a) => a.id === this.entryToEdit.activity_id);
92+
this.entryForm.setValue({
93+
project: project ? project.name : '',
94+
activity: activity ? activity.name : '',
95+
description: this.entryToEdit.description,
96+
start_date: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'yyyy-MM-dd', 'en') : '',
97+
start_hour: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'HH:mm', 'en') : '00:00',
98+
end_date: this.entryToEdit.end_date ? formatDate(this.entryToEdit.end_date, 'yyyy-MM-dd', 'en') : '',
99+
end_hour: this.entryToEdit.end_date ? formatDate(this.entryToEdit.end_date, 'HH:mm', 'en') : '00:00',
100+
uri: this.entryToEdit.uri,
101+
});
102+
} else {
103+
this.selectedTechnology = [];
85104
this.entryForm.setValue({
86-
project: this.entryToEdit.project,
87-
activity: this.entryToEdit.activity,
88-
ticket: this.entryToEdit.ticket,
89-
comments: this.entryToEdit.comments,
105+
project: '',
106+
activity: '',
107+
description: '',
108+
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
109+
start_hour: '00:00',
110+
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
111+
end_hour: '00:00',
112+
uri: '',
90113
});
91114
}
92115
}
@@ -112,7 +135,17 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
112135
}
113136

114137
onSubmit() {
115-
this.saveEntry.emit(this.entryForm.value);
138+
const activity = this.activities.find((a) => a.name === this.entryForm.value.activity);
139+
const entry = {
140+
project_id: this.entryForm.value.project.id,
141+
activity_id: activity ? activity.id : null,
142+
technologies: this.selectedTechnology,
143+
description: this.entryForm.value.description,
144+
start_date: `${this.entryForm.value.start_date}T${this.entryForm.value.start_hour}`,
145+
end_date: `${this.entryForm.value.end_date}T${this.entryForm.value.end_hour}`,
146+
uri: this.entryForm.value.uri,
147+
};
148+
this.saveEntry.emit(entry);
116149
this.closeModal.nativeElement.click();
117150
}
118151
}

src/app/modules/shared/components/modal/modal.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h5 class="modal-title" id="exampleModalLabel">Delete Project</h5>
1111
</div>
1212
<div class="modal-footer">
1313
<button #cancelDeleteModal type="button" class="btn cancel-button-style" data-dismiss="modal">Cancel</button>
14-
<button type="button" class="btn delete-button-style">Delete</button>
14+
<button type="button" class="btn delete-button-style" (click)="deleteAction()">Delete</button>
1515
</div>
1616
</div>
1717
</div>

0 commit comments

Comments
 (0)