Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -141,7 +141,8 @@
(technologyAdded)="onTechnologiesUpdated($event)"
(technologyRemoved)="onTechnologiesUpdated($event)"
[selectedTechnologies]="selectedTechnologies"
>
#technologies
>
</app-technologies>

<div class="form-group text-left">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ describe('DetailsFieldsComponent', () => {
});
});

it('on cleanFormWithSkipProject the project_id and project_name should be kept', () => {
const entryFormValueExpected = {
...formValues,
activity_id: '',
uri: '',
start_date: formatDate(new Date(), DATE_FORMAT, 'en'),
end_date: formatDate(new Date(), DATE_FORMAT, 'en'),
start_hour: '00:00',
end_hour: '00:00',
description: '',
technology: '',
};

component.entryForm.setValue(formValues);
component.cleanFormWithSkipProject();

expect(component.entryForm.value).toEqual(entryFormValueExpected);
});

it('should emit ngOnChange without data', () => {
component.entryToEdit = null;
component.ngOnChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { SaveEntryEvent } from './save-entry-event';
import { ProjectSelectedEvent } from './project-selected-event';
import { get } from 'lodash';
import { DATE_FORMAT } from 'src/environments/environment';
import { TechnologiesComponent } from '../technologies/technologies.component';

type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
@Component({
Expand All @@ -33,6 +34,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
@Output() saveEntry = new EventEmitter<SaveEntryEvent>();
@Output() projectSelected = new EventEmitter<ProjectSelectedEvent>();
@ViewChild('closeModal') closeModal: ElementRef;
@ViewChild('technologies', { static: true }) technologies: TechnologiesComponent;
entryForm: FormGroup;
selectedTechnologies: string[] = [];
isLoading = false;
Expand Down Expand Up @@ -151,11 +153,14 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
}
}

cleanForm() {
cleanForm(skipProject: boolean = false): void {
this.selectedTechnologies = [];
this.entryForm.setValue({
project_name: '',
project_id: '',
this.technologies.query = '';
const projectNameField = this.project_name.value;
const projectName = get(projectNameField, 'search_field', projectNameField);
this.entryForm.reset({
project_name: skipProject ? projectName : '',
project_id: skipProject ? this.project_id.value : '',
activity_id: '',
description: '',
start_date: formatDate(new Date(), DATE_FORMAT, 'en'),
Expand All @@ -167,6 +172,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
});
}

cleanFormWithSkipProject(): void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this function to cleanFieldsForm.

this.cleanForm(true);
}

onTechnologiesUpdated($event: string[]) {
this.selectedTechnologies = $event;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@
<div class="modal-content" cdkDrag (cdkDragEnded)="resetDraggablePosition($event)">
<div class="modal-header" cdkDragHandle>
<h5 class="modal-title">{{ entryId ? 'Edit Entry' : 'New Entry' }}</h5>
<button type="button" class="btn" (click)="detailsFields.cleanFormWithSkipProject()">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How work with #Id detailsFields?
I think this should be this.cleanFormWithSkipProject()

Copy link
Member Author

@LEON12699 LEON12699 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the #detailFields a local template variable associated with the app-details-fields component is created, this allows access to the functions and data of the app-details-fields component (child component) in this case when you click on the icon, the function cleanFormWithSkipProject() that is in the details-fields.component.ts is executed as it is not a function of the component time-entries.component.ts can not be accessed with this, but otherwise this.detailsFields.cleanFormWithSkipProject() can be used.

<i class="fa fa-undo" aria-hidden="true"></i>
</button>
</div>
<div class="modal-body">
<app-details-fields
[entryToEdit]="entry"
(saveEntry)="saveEntry($event)"
(projectSelected)="projectSelected($event)"
[canMarkEntryAsWIP]='canMarkEntryAsWIP'
#detailsFields
>
</app-details-fields>
</div>
Expand Down