Skip to content

Commit 14782f7

Browse files
authored
Merge pull request #258 from ioet/fix-messages
fix: #259 fix messages and save activity on time-clock
2 parents c62d436 + 7263e03 commit 14782f7

File tree

14 files changed

+103
-131
lines changed

14 files changed

+103
-131
lines changed

package-lock.json

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

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Project</span>
55
</div>
66
<select
7-
[class.is-invalid]="project.invalid && project.touched"
7+
[class.is-invalid]="project_id.invalid && project_id.touched"
88
required
9-
id="activity"
9+
id="project_id"
1010
class="form-control"
11-
formControlName="project"
11+
formControlName="project_id"
1212
>
13-
<option *ngFor="let project of listProjects">{{ project.name }}</option>
13+
<option *ngFor="let project of listProjects" value="{{project.id}}">{{ project.name }}</option>
1414
</select>
1515
</div>
1616
<div class="input-group input-group-sm mb-3">
1717
<div class="input-group-prepend">
1818
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Activity</span>
1919
</div>
2020
<select
21-
[class.is-invalid]="activity.invalid && activity.touched"
21+
[class.is-invalid]="activity_id.invalid && activity_id.touched"
2222
required
23-
id="activity"
23+
id="activity_id"
2424
class="form-control"
25-
formControlName="activity"
25+
formControlName="activity_id"
2626
>
27-
<option *ngFor="let activity of activities">{{ activity.name }}</option>
27+
<option *ngFor="let activity of activities" value="{{activity.id}}">{{ activity.name }}</option>
2828
</select>
2929
</div>
3030

@@ -109,7 +109,7 @@
109109
<textarea formControlName="description" class="form-control" id="NotesTextarea" rows="3"></textarea>
110110
</div>
111111
<div class="modal-footer">
112-
<button type="submit" class="btn btn-primary" [disabled]="!entryForm.valid">Save</button>
112+
<button type="submit" class="btn btn-primary">Save</button>
113113
<button #closeModal type="button" class="btn btn-secondary" data-dismiss="modal">
114114
Close
115115
</button>

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

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ describe('DetailsFieldsComponent', () => {
4848
};
4949

5050
const initialData = {
51-
project: '',
52-
activity: '',
51+
project_id: '',
52+
activity_id: '',
5353
uri: '',
5454
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
5555
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
@@ -75,7 +75,6 @@ describe('DetailsFieldsComponent', () => {
7575
beforeEach(() => {
7676
fixture = TestBed.createComponent(DetailsFieldsComponent);
7777
component = fixture.componentInstance;
78-
fixture.detectChanges();
7978
});
8079

8180
it('should create', () => {
@@ -100,8 +99,8 @@ describe('DetailsFieldsComponent', () => {
10099
description: '',
101100
};
102101
const formValue = {
103-
project: 'name',
104-
activity: 'abc',
102+
project_id: 'id',
103+
activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd05',
105104
uri: 'ticketUri',
106105
start_date: '2020-02-05',
107106
end_date: '2020-02-05',
@@ -117,16 +116,16 @@ describe('DetailsFieldsComponent', () => {
117116

118117
it('should emit ngOnChange with new data', () => {
119118
const entryToEdit = {
120-
project_id: 'abc',
119+
project_id: '',
121120
activity_id: '',
122121
uri: 'ticketUri',
123122
start_date: null,
124123
end_date: null,
125124
description: '',
126125
};
127126
const formValue = {
128-
project: '',
129-
activity: '',
127+
project_id: '',
128+
activity_id: '',
130129
uri: 'ticketUri',
131130
start_date: '',
132131
end_date: '',
@@ -142,8 +141,8 @@ describe('DetailsFieldsComponent', () => {
142141

143142
it('should emit ngOnChange with new data', () => {
144143
const formValue = {
145-
project: '',
146-
activity: '',
144+
project_id: '',
145+
activity_id: '',
147146
uri: '',
148147
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
149148
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
@@ -157,27 +156,8 @@ describe('DetailsFieldsComponent', () => {
157156
expect(component.entryForm.value).toEqual(formValue);
158157
});
159158

160-
it('should dispatch FindTechnology action #getTechnologies', () => {
161-
const value = 'java';
162-
spyOn(store, 'dispatch');
163-
length = value.length;
164-
component.getTechnologies(value);
165-
166-
expect(component.showlist).toBe(true);
167-
expect(store.dispatch).toHaveBeenCalledWith(new actions.FindTechnology(value));
168-
});
169-
170-
it('should NOT dispatch FindTechnology action #getTechnologies', () => {
171-
const value = 'j';
172-
spyOn(store, 'dispatch');
173-
length = value.length;
174-
component.getTechnologies(value);
175-
176-
expect(store.dispatch).not.toHaveBeenCalledWith(new actions.FindTechnology(value));
177-
});
178-
179159
it('should call createError ', () => {
180-
mockEntriesUpdateErrorSelector = store.overrideSelector(getCreateError, false);
160+
mockEntriesCreateErrorSelector = store.overrideSelector(getCreateError, false);
181161
spyOn(store, 'dispatch');
182162
component.ngOnInit();
183163
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CleanEntryCreateError(null));
@@ -194,8 +174,8 @@ describe('DetailsFieldsComponent', () => {
194174
spyOn(component.saveEntry, 'emit');
195175
component.onSubmit();
196176
const data = {
197-
project_id: null,
198-
activity_id: null,
177+
project_id: '',
178+
activity_id: '',
199179
technologies: [],
200180
description: '',
201181
start_date: 'T00:00',
@@ -208,8 +188,8 @@ describe('DetailsFieldsComponent', () => {
208188
it('should emit saveEntry without project and activite fields event', () => {
209189
spyOn(component.saveEntry, 'emit');
210190
component.entryForm.setValue({
211-
project: 'name',
212-
activity: 'activity1',
191+
project_id: 'id',
192+
activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd05',
213193
uri: '',
214194
start_date: '',
215195
end_date: '',
@@ -222,6 +202,7 @@ describe('DetailsFieldsComponent', () => {
222202
{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', tenant_id: 'ioet', name: 'activity1', description: '' },
223203
];
224204
component.onSubmit();
205+
fixture.detectChanges();
225206
const data = {
226207
project_id: 'id',
227208
activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd05',

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

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ import {
1111
} from '@angular/core';
1212
import { FormBuilder, FormGroup } from '@angular/forms';
1313
import { Store, select } from '@ngrx/store';
14-
import * as actions from '../../store/technology.actions';
1514
import { formatDate } from '@angular/common';
1615

17-
import { allTechnologies } from '../../store/technology.selectors';
18-
import { Technology, Project, Activity } from '../../models';
19-
16+
import { Project, Activity } from '../../models';
2017
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
2118
import { TechnologyState } from '../../store/technology.reducers';
2219
import { LoadActivities, ActivityState, allActivities } from '../../../activities-management/store';
@@ -40,7 +37,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4037
@ViewChild('closeModal') closeModal: ElementRef;
4138
@ViewChild('list') list: ElementRef;
4239
entryForm: FormGroup;
43-
technology: Technology;
4440
selectedTechnologies: string[] = [];
4541
isLoading = false;
4642
listProjects: Project[] = [];
@@ -56,8 +52,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
5652
}
5753
});
5854
this.entryForm = this.formBuilder.group({
59-
project: '',
60-
activity: '',
55+
project_id: '',
56+
activity_id: '',
6157
description: '',
6258
start_date: '',
6359
end_date: '',
@@ -69,11 +65,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
6965
}
7066

7167
ngOnInit(): void {
72-
const technologies$ = this.store.pipe(select(allTechnologies));
73-
technologies$.subscribe((response) => {
74-
this.isLoading = response.isLoading;
75-
this.technology = response.technologyList;
76-
});
7768

7869
this.store.dispatch(new projectActions.LoadProjects());
7970
const projects$ = this.store.pipe(select(getProjects));
@@ -90,15 +81,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
9081
const updateError$ = this.store.pipe(select(getUpdateError));
9182
updateError$.subscribe((updateError) => {
9283
if (updateError != null && !updateError) {
93-
this.closeEntryModal();
9484
this.store.dispatch(new entryActions.CleanEntryUpdateError(null));
85+
this.closeEntryModal();
9586
}
9687
});
9788
const createError$ = this.store.pipe(select(getCreateError));
9889
createError$.subscribe((createError) => {
9990
if (createError != null && !createError) {
100-
this.closeEntryModal();
10191
this.store.dispatch(new entryActions.CleanEntryCreateError(null));
92+
this.closeEntryModal();
10293
}
10394
});
10495
}
@@ -107,11 +98,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
10798
this.hoursValidation = false;
10899
if (this.entryToEdit) {
109100
this.selectedTechnologies = this.entryToEdit.technologies;
110-
const project = this.listProjects.find((p) => p.id === this.entryToEdit.project_id);
111-
const activity = this.activities.find((a) => a.id === this.entryToEdit.activity_id);
112101
this.entryForm.setValue({
113-
project: project ? project.name : '',
114-
activity: activity ? activity.name : '',
102+
project_id: this.entryToEdit.project_id,
103+
activity_id: this.entryToEdit.activity_id,
115104
description: this.entryToEdit.description,
116105
start_date: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'yyyy-MM-dd', 'en') : '',
117106
start_hour: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'HH:mm', 'en') : '00:00',
@@ -123,8 +112,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
123112
} else {
124113
this.selectedTechnologies = [];
125114
this.entryForm.setValue({
126-
project: '',
127-
activity: '',
115+
project_id: '',
116+
activity_id: '',
128117
description: '',
129118
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
130119
start_hour: '00:00',
@@ -136,22 +125,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
136125
}
137126
}
138127

139-
getTechnologies(value) {
140-
if (value.length >= 2) {
141-
this.showlist = true;
142-
this.store.dispatch(new actions.FindTechnology(value));
143-
}
144-
}
145-
146128
onTechnologiesUpdated($event: string[]) {
147129
this.selectedTechnologies = $event;
148130
}
149131

150-
get project() {
151-
return this.entryForm.get('project');
132+
get project_id() {
133+
return this.entryForm.get('project_id');
152134
}
153-
get activity() {
154-
return this.entryForm.get('activity');
135+
get activity_id() {
136+
return this.entryForm.get('activity_id');
155137
}
156138

157139
get start_date() {
@@ -176,12 +158,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
176158
}
177159

178160
onSubmit() {
179-
const activity = this.activities.find((a) => a.name === this.entryForm.value.activity);
180-
const project = this.listProjects.find((p) => p.name === this.entryForm.value.project);
181161
const entry = {
182-
project_id: project ? project.id : null,
183-
activity_id: activity ? activity.id : null,
184-
technologies: this.selectedTechnologies,
162+
project_id: this.entryForm.value.project_id,
163+
activity_id: this.entryForm.value.activity_id,
164+
technologies: this.selectedTechnologies ? this.selectedTechnologies : [],
185165
description: this.entryForm.value.description,
186166
start_date: `${this.entryForm.value.start_date}T${this.entryForm.value.start_hour}`,
187167
end_date: `${this.entryForm.value.end_date}T${this.entryForm.value.end_hour}`,

0 commit comments

Comments
 (0)