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
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,25 @@ describe('DetailsFieldsComponent', () => {
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
});

it('when the current entry is not running, then the end hour input should be rendered', () => {
it('when the current entry is not running, then the end date and end hour inputs should be rendered', () => {
component.goingToWorkOnThis = false;
fixture.detectChanges();

const endDateInput = fixture.debugElement.nativeElement.querySelector('#end_date');
const endHourInput = fixture.debugElement.nativeElement.querySelector('#end_hour');

expect(endDateInput).toBeDefined();
expect(endHourInput).toBeDefined();
});

it('when the current entry is running, then the end hour input should not be rendered', () => {
it('when the current entry is running, then the end date and end hour inputs should not be rendered', () => {
component.goingToWorkOnThis = true;
fixture.detectChanges();

const endDateInput = fixture.debugElement.nativeElement.querySelector('#end_date');
const endHourInput = fixture.debugElement.nativeElement.querySelector('#end_hour');

expect(endDateInput).toBeNull();
expect(endHourInput).toBeNull();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ import { ProjectSelectedEvent } from './project-selected-event';
import { get } from 'lodash';
import { DATE_FORMAT } from 'src/environments/environment';


type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
@Component({
selector: 'app-details-fields',
templateUrl: './details-fields.component.html',
styleUrls: ['./details-fields.component.scss'],
})
export class DetailsFieldsComponent implements OnChanges, OnInit {

keyword = 'search_field';
@Input() entryToEdit: Entry;
@Input() canMarkEntryAsWIP: boolean;
Expand All @@ -43,8 +41,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
goingToWorkOnThis = false;
shouldRestartEntry = false;

constructor(private formBuilder: FormBuilder, private store: Store<Merged>,
private actionsSubject$: ActionsSubject, private toastrService: ToastrService) {
constructor(
private formBuilder: FormBuilder,
private store: Store<Merged>,
private actionsSubject$: ActionsSubject,
private toastrService: ToastrService
) {
this.entryForm = this.formBuilder.group({
project_id: ['', Validators.required],
project_name: ['', Validators.required],
Expand All @@ -66,11 +68,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
if (projects) {
this.listProjects = [];
projects.forEach((project) => {
const projectWithSearchField = {...project};
projectWithSearchField.search_field = `${project.customer_name} - ${project.name}`;
this.listProjects.push(projectWithSearchField);
}
);
const projectWithSearchField = { ...project };
projectWithSearchField.search_field = `${project.customer_name} - ${project.name}`;
this.listProjects.push(projectWithSearchField);
});
}
});

Expand All @@ -95,31 +96,32 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
}
});

this.actionsSubject$.pipe(
filter((action: any) => (
action.type === EntryActionTypes.CREATE_ENTRY_SUCCESS ||
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS
))
).subscribe(() => {
this.cleanForm();
});
this.actionsSubject$
.pipe(
filter(
(action: any) =>
action.type === EntryActionTypes.CREATE_ENTRY_SUCCESS ||
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS
)
)
.subscribe(() => {
this.cleanForm();
});
}

onClearedComponent(event) {
this.entryForm.patchValue(
{
project_id: '',
project_name: '',
});
this.entryForm.patchValue({
project_id: '',
project_name: '',
});
}

onSelectedProject(item) {
this.projectSelected.emit({ projectId : item.id});
this.entryForm.patchValue(
{
project_id: item.id,
project_name: item.search_field,
});
this.projectSelected.emit({ projectId: item.id });
this.entryForm.patchValue({
project_id: item.id,
project_name: item.search_field,
});
}

ngOnChanges(): void {
Expand Down Expand Up @@ -197,7 +199,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
this.closeModal?.nativeElement?.click();
}

dateToSubmit(date, hour){
dateToSubmit(date, hour) {
const entryFormDate = this.entryForm.value[date];
const updatedHour = this.entryForm.value[hour];
const initialDate = this.entryToEdit[date];
Expand Down Expand Up @@ -246,7 +248,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
onGoingToWorkOnThisChange(event: any) {
this.goingToWorkOnThis = event.currentTarget.checked;
if (!this.goingToWorkOnThis) {
this.entryForm.patchValue({ end_hour: formatDate(new Date(), 'HH:mm:ss', 'en') });
this.entryForm.patchValue({
end_date: formatDate(get(this.entryToEdit, 'start_date', ''), DATE_FORMAT, 'en'),
end_hour: formatDate(get(this.entryToEdit, 'start_date', '00:00'), 'HH:mm', 'en'),
});
}
this.shouldRestartEntry = !this.entryToEdit?.running && this.goingToWorkOnThis;
}
Expand Down