Skip to content

Commit 8c6a373

Browse files
authored
Merge pull request #251 from ioet/247-replace-technologies-component
fix: #247 replacing technnologies component in time-entries page
2 parents f27e7e1 + 6a08184 commit 8c6a373

File tree

3 files changed

+10
-92
lines changed

3 files changed

+10
-92
lines changed

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

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,11 @@
9898
aria-describedby="inputGroup-sizing-sm"
9999
/>
100100
</div>
101-
<div class="input-group input-group-sm">
102-
<div class="input-group-prepend">
103-
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Technology</span>
104-
</div>
105-
<input
106-
(keypress)="getTechnologies($event.target.value)"
107-
type="text"
108-
class="form-control"
109-
aria-label="Small"
110-
aria-describedby="inputGroup-sizing-sm"
111-
formControlName="technology"
112-
/>
113-
</div>
114101

115-
<div *ngIf="isLoading">LOADING...</div>
116-
<div #list *ngIf="technology && showlist" class="d-flex flex-column technology-content">
117-
<div
118-
*ngFor="let item of technology.items"
119-
(click)="setTechnology(item.name)"
120-
class="technology-list"
121-
[ngClass]="{ active: selectedTechnology.includes(item.name) }"
122-
>
123-
{{ item.name }}
124-
</div>
125-
</div>
126-
<div class="tags-content d-flex flex-wrap">
127-
<div *ngFor="let technology of selectedTechnology; let tagIndex = index" class="tag">
128-
<span class="mr-3">{{ technology }}</span>
129-
<i class="fas fa-times text-white" (click)="removeTag(tagIndex)"></i>
130-
</div>
131-
</div>
102+
<app-technologies (technologyAdded)="onTechnologiesUpdated($event)"
103+
(technologyRemoved)="onTechnologiesUpdated($event)"
104+
[selectedTechnologies]="selectedTechnologies">
105+
</app-technologies>
132106

133107
<div class="form-group text-left">
134108
<label for="NotesTextarea">Description</label>

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

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -176,51 +176,6 @@ describe('DetailsFieldsComponent', () => {
176176
expect(store.dispatch).not.toHaveBeenCalledWith(new actions.FindTechnology(value));
177177
});
178178

179-
it('should add a new tag #setTechnology', () => {
180-
const name = 'ngrx';
181-
component.selectedTechnology = ['java', 'javascript'];
182-
component.selectedTechnology.indexOf(name);
183-
length = component.selectedTechnology.length;
184-
component.setTechnology(name);
185-
expect(component.selectedTechnology.length).toBe(3);
186-
});
187-
188-
it('should NOT add a new tag #setTechnology', () => {
189-
const name = 'ngrx';
190-
component.selectedTechnology = [
191-
'java',
192-
'javascript',
193-
'angular',
194-
'angular-ui',
195-
'typescript',
196-
'scss',
197-
'bootstrap',
198-
'jasmine',
199-
'karme',
200-
'github',
201-
];
202-
component.selectedTechnology.indexOf(name);
203-
length = component.selectedTechnology.length;
204-
component.setTechnology(name);
205-
expect(component.selectedTechnology.length).toBe(10);
206-
});
207-
208-
it('should call the removeTag function #setTechnology', () => {
209-
const name = 'java';
210-
component.selectedTechnology = ['java', 'javascript'];
211-
const index = component.selectedTechnology.indexOf(name);
212-
spyOn(component, 'removeTag');
213-
component.setTechnology(name);
214-
expect(component.removeTag).toHaveBeenCalledWith(index);
215-
});
216-
217-
it('should call the removeTag() function #removeTag', () => {
218-
const index = 1;
219-
component.selectedTechnology = ['java', 'angular'];
220-
component.removeTag(index);
221-
expect(component.selectedTechnology.length).toBe(1);
222-
});
223-
224179
it('should call createError ', () => {
225180
mockEntriesUpdateErrorSelector = store.overrideSelector(getCreateError, false);
226181
spyOn(store, 'dispatch');

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
4141
@ViewChild('list') list: ElementRef;
4242
entryForm: FormGroup;
4343
technology: Technology;
44-
selectedTechnology: string[] = [];
44+
selectedTechnologies: string[] = [];
4545
isLoading = false;
4646
listProjects: Project[] = [];
4747
activities: Activity[] = [];
@@ -106,7 +106,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
106106
ngOnChanges(): void {
107107
this.hoursValidation = false;
108108
if (this.entryToEdit) {
109-
this.selectedTechnology = this.entryToEdit.technologies;
109+
this.selectedTechnologies = this.entryToEdit.technologies;
110110
const project = this.listProjects.find((p) => p.id === this.entryToEdit.project_id);
111111
const activity = this.activities.find((a) => a.id === this.entryToEdit.activity_id);
112112
this.entryForm.setValue({
@@ -121,7 +121,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
121121
technology: '',
122122
});
123123
} else {
124-
this.selectedTechnology = [];
124+
this.selectedTechnologies = [];
125125
this.entryForm.setValue({
126126
project: '',
127127
activity: '',
@@ -143,19 +143,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
143143
}
144144
}
145145

146-
setTechnology(name: string) {
147-
const index = this.selectedTechnology.indexOf(name);
148-
if (index > -1) {
149-
this.removeTag(index);
150-
} else if (this.selectedTechnology.length < 10) {
151-
this.selectedTechnology = [...this.selectedTechnology, name];
152-
}
153-
this.showlist = false;
154-
this.entryForm.get('technology').reset();
155-
}
156-
157-
removeTag(index) {
158-
this.selectedTechnology.splice(index, 1);
146+
onTechnologiesUpdated($event: string[]) {
147+
this.selectedTechnologies = $event;
159148
}
160149

161150
get project() {
@@ -192,7 +181,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
192181
const entry = {
193182
project_id: project ? project.id : null,
194183
activity_id: activity ? activity.id : null,
195-
technologies: this.selectedTechnology,
184+
technologies: this.selectedTechnologies,
196185
description: this.entryForm.value.description,
197186
start_date: `${this.entryForm.value.start_date}T${this.entryForm.value.start_hour}`,
198187
end_date: `${this.entryForm.value.end_date}T${this.entryForm.value.end_hour}`,

0 commit comments

Comments
 (0)