Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: #99 fix messages
  • Loading branch information
enriquezrene authored and DiegoTinitana committed May 18, 2020
commit 7263e03b65d12fc30d31b7da74d3d2000fac909c
49 changes: 25 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Project</span>
</div>
<select
[class.is-invalid]="project.invalid && project.touched"
[class.is-invalid]="project_id.invalid && project_id.touched"
required
id="activity"
id="project_id"
class="form-control"
formControlName="project"
formControlName="project_id"
>
<option *ngFor="let project of listProjects">{{ project.name }}</option>
<option *ngFor="let project of listProjects" value="{{project.id}}">{{ project.name }}</option>
</select>
</div>
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Activity</span>
</div>
<select
[class.is-invalid]="activity.invalid && activity.touched"
[class.is-invalid]="activity_id.invalid && activity_id.touched"
required
id="activity"
id="activity_id"
class="form-control"
formControlName="activity"
formControlName="activity_id"
>
<option *ngFor="let activity of activities">{{ activity.name }}</option>
<option *ngFor="let activity of activities" value="{{activity.id}}">{{ activity.name }}</option>
</select>
</div>

Expand Down Expand Up @@ -109,7 +109,7 @@
<textarea formControlName="description" class="form-control" id="NotesTextarea" rows="3"></textarea>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" [disabled]="!entryForm.valid">Save</button>
<button type="submit" class="btn btn-primary">Save</button>
<button #closeModal type="button" class="btn btn-secondary" data-dismiss="modal">
Close
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ describe('DetailsFieldsComponent', () => {
};

const initialData = {
project: '',
activity: '',
project_id: '',
activity_id: '',
uri: '',
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
Expand All @@ -75,7 +75,6 @@ describe('DetailsFieldsComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(DetailsFieldsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
Expand All @@ -100,8 +99,8 @@ describe('DetailsFieldsComponent', () => {
description: '',
};
const formValue = {
project: 'name',
activity: 'abc',
project_id: 'id',
activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd05',
uri: 'ticketUri',
start_date: '2020-02-05',
end_date: '2020-02-05',
Expand All @@ -117,16 +116,16 @@ describe('DetailsFieldsComponent', () => {

it('should emit ngOnChange with new data', () => {
const entryToEdit = {
project_id: 'abc',
project_id: '',
activity_id: '',
uri: 'ticketUri',
start_date: null,
end_date: null,
description: '',
};
const formValue = {
project: '',
activity: '',
project_id: '',
activity_id: '',
uri: 'ticketUri',
start_date: '',
end_date: '',
Expand All @@ -142,8 +141,8 @@ describe('DetailsFieldsComponent', () => {

it('should emit ngOnChange with new data', () => {
const formValue = {
project: '',
activity: '',
project_id: '',
activity_id: '',
uri: '',
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
Expand All @@ -157,27 +156,8 @@ describe('DetailsFieldsComponent', () => {
expect(component.entryForm.value).toEqual(formValue);
});

it('should dispatch FindTechnology action #getTechnologies', () => {
const value = 'java';
spyOn(store, 'dispatch');
length = value.length;
component.getTechnologies(value);

expect(component.showlist).toBe(true);
expect(store.dispatch).toHaveBeenCalledWith(new actions.FindTechnology(value));
});

it('should NOT dispatch FindTechnology action #getTechnologies', () => {
const value = 'j';
spyOn(store, 'dispatch');
length = value.length;
component.getTechnologies(value);

expect(store.dispatch).not.toHaveBeenCalledWith(new actions.FindTechnology(value));
});

it('should call createError ', () => {
mockEntriesUpdateErrorSelector = store.overrideSelector(getCreateError, false);
mockEntriesCreateErrorSelector = store.overrideSelector(getCreateError, false);
spyOn(store, 'dispatch');
component.ngOnInit();
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CleanEntryCreateError(null));
Expand All @@ -194,8 +174,8 @@ describe('DetailsFieldsComponent', () => {
spyOn(component.saveEntry, 'emit');
component.onSubmit();
const data = {
project_id: null,
activity_id: null,
project_id: '',
activity_id: '',
technologies: [],
description: '',
start_date: 'T00:00',
Expand All @@ -208,8 +188,8 @@ describe('DetailsFieldsComponent', () => {
it('should emit saveEntry without project and activite fields event', () => {
spyOn(component.saveEntry, 'emit');
component.entryForm.setValue({
project: 'name',
activity: 'activity1',
project_id: 'id',
activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd05',
uri: '',
start_date: '',
end_date: '',
Expand All @@ -222,6 +202,7 @@ describe('DetailsFieldsComponent', () => {
{ id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', tenant_id: 'ioet', name: 'activity1', description: '' },
];
component.onSubmit();
fixture.detectChanges();
const data = {
project_id: 'id',
activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd05',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ import {
} from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Store, select } from '@ngrx/store';
import * as actions from '../../store/technology.actions';
import { formatDate } from '@angular/common';

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

import { Project, Activity } from '../../models';
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
import { TechnologyState } from '../../store/technology.reducers';
import { LoadActivities, ActivityState, allActivities } from '../../../activities-management/store';
Expand All @@ -40,7 +37,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
@ViewChild('closeModal') closeModal: ElementRef;
@ViewChild('list') list: ElementRef;
entryForm: FormGroup;
technology: Technology;
selectedTechnologies: string[] = [];
isLoading = false;
listProjects: Project[] = [];
Expand All @@ -56,8 +52,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
}
});
this.entryForm = this.formBuilder.group({
project: '',
activity: '',
project_id: '',
activity_id: '',
description: '',
start_date: '',
end_date: '',
Expand All @@ -69,11 +65,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
}

ngOnInit(): void {
const technologies$ = this.store.pipe(select(allTechnologies));
technologies$.subscribe((response) => {
this.isLoading = response.isLoading;
this.technology = response.technologyList;
});

this.store.dispatch(new projectActions.LoadProjects());
const projects$ = this.store.pipe(select(getProjects));
Expand All @@ -90,15 +81,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
const updateError$ = this.store.pipe(select(getUpdateError));
updateError$.subscribe((updateError) => {
if (updateError != null && !updateError) {
this.closeEntryModal();
this.store.dispatch(new entryActions.CleanEntryUpdateError(null));
this.closeEntryModal();
}
});
const createError$ = this.store.pipe(select(getCreateError));
createError$.subscribe((createError) => {
if (createError != null && !createError) {
this.closeEntryModal();
this.store.dispatch(new entryActions.CleanEntryCreateError(null));
this.closeEntryModal();
}
});
}
Expand All @@ -107,11 +98,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
this.hoursValidation = false;
if (this.entryToEdit) {
this.selectedTechnologies = this.entryToEdit.technologies;
const project = this.listProjects.find((p) => p.id === this.entryToEdit.project_id);
const activity = this.activities.find((a) => a.id === this.entryToEdit.activity_id);
this.entryForm.setValue({
project: project ? project.name : '',
activity: activity ? activity.name : '',
project_id: this.entryToEdit.project_id,
activity_id: this.entryToEdit.activity_id,
description: this.entryToEdit.description,
start_date: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'yyyy-MM-dd', 'en') : '',
start_hour: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'HH:mm', 'en') : '00:00',
Expand All @@ -123,8 +112,8 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
} else {
this.selectedTechnologies = [];
this.entryForm.setValue({
project: '',
activity: '',
project_id: '',
activity_id: '',
description: '',
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
start_hour: '00:00',
Expand All @@ -136,22 +125,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
}
}

getTechnologies(value) {
if (value.length >= 2) {
this.showlist = true;
this.store.dispatch(new actions.FindTechnology(value));
}
}

onTechnologiesUpdated($event: string[]) {
this.selectedTechnologies = $event;
}

get project() {
return this.entryForm.get('project');
get project_id() {
return this.entryForm.get('project_id');
}
get activity() {
return this.entryForm.get('activity');
get activity_id() {
return this.entryForm.get('activity_id');
}

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

onSubmit() {
const activity = this.activities.find((a) => a.name === this.entryForm.value.activity);
const project = this.listProjects.find((p) => p.name === this.entryForm.value.project);
const entry = {
project_id: project ? project.id : null,
activity_id: activity ? activity.id : null,
technologies: this.selectedTechnologies,
project_id: this.entryForm.value.project_id,
activity_id: this.entryForm.value.activity_id,
technologies: this.selectedTechnologies ? this.selectedTechnologies : [],
description: this.entryForm.value.description,
start_date: `${this.entryForm.value.start_date}T${this.entryForm.value.start_hour}`,
end_date: `${this.entryForm.value.end_date}T${this.entryForm.value.end_hour}`,
Expand Down
Loading