Skip to content

Commit 974656b

Browse files
committed
fix: #99 fix messages
1 parent c62d436 commit 974656b

File tree

14 files changed

+273
-301
lines changed

14 files changed

+273
-301
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: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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', () => {
@@ -157,25 +156,6 @@ 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 ', () => {
180160
mockEntriesUpdateErrorSelector = store.overrideSelector(getCreateError, false);
181161
spyOn(store, 'dispatch');
@@ -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: 28 additions & 48 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));
@@ -87,31 +78,29 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
8778
this.activities = response;
8879
});
8980

90-
const updateError$ = this.store.pipe(select(getUpdateError));
91-
updateError$.subscribe((updateError) => {
92-
if (updateError != null && !updateError) {
93-
this.closeEntryModal();
94-
this.store.dispatch(new entryActions.CleanEntryUpdateError(null));
95-
}
96-
});
97-
const createError$ = this.store.pipe(select(getCreateError));
98-
createError$.subscribe((createError) => {
99-
if (createError != null && !createError) {
100-
this.closeEntryModal();
101-
this.store.dispatch(new entryActions.CleanEntryCreateError(null));
102-
}
103-
});
81+
// const updateError$ = this.store.pipe(select(getUpdateError));
82+
// updateError$.subscribe((updateError) => {
83+
// if (updateError != null && !updateError) {
84+
// this.closeEntryModal();
85+
// this.store.dispatch(new entryActions.CleanEntryUpdateError(null));
86+
// }
87+
// });
88+
// const createError$ = this.store.pipe(select(getCreateError));
89+
// createError$.subscribe((createError) => {
90+
// if (createError != null && !createError) {
91+
// this.closeEntryModal();
92+
// this.store.dispatch(new entryActions.CleanEntryCreateError(null));
93+
// }
94+
// });
10495
}
10596

10697
ngOnChanges(): void {
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}`,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
{{ item.name }}
2323
</div>
2424
</div>
25-
<div class="selected-technologies-container d-flex flex-wrap" *ngIf="selectedTechnologies.length">
25+
<div class="selected-technologies-container d-flex flex-wrap" *ngIf="selectedTechnologies?.length">
2626
<div *ngFor="let technology of selectedTechnologies; let tagIndex = index" class="selected-technology">
2727
<span class="mr-3">{{ technology }}</span>
2828
<i class="fas fa-times text-white" (click)="removeTechnology(tagIndex)"></i>
2929
</div>
3030
</div>
31-
<div class="form-group" *ngIf="selectedTechnologies.length === 0">
31+
<div class="form-group" *ngIf="selectedTechnologies === null || selectedTechnologies.length === 0">
3232
<!-- empty-space -->
3333
</div>
3434

src/app/modules/shared/models/entry.model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export interface Entry {
22
id: string;
33
start_date: Date;
44
end_date: Date;
5-
activity: string;
5+
activity_id?: string;
66
technologies: string[];
77
comments?: string;
88
uri?: string;
@@ -15,4 +15,5 @@ export interface NewEntry {
1515
description?: string;
1616
technologies?: string[];
1717
uri?: string;
18+
activity_id?: string;
1819
}

0 commit comments

Comments
 (0)