diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.html b/src/app/modules/shared/components/details-fields/details-fields.component.html index 7c27d169a..05f2ae3de 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.html +++ b/src/app/modules/shared/components/details-fields/details-fields.component.html @@ -1,31 +1,42 @@
- Project + Project
+
Activity
+
@@ -53,19 +64,21 @@ class="form-control" aria-label="Small" aria-describedby="inputGroup-sizing-sm" - [class.is-invalid]="start_date.invalid && start_date.touched || hoursValidation" + [class.is-invalid]="start_date.invalid && start_date.touched" required />
Start/Hour
@@ -88,20 +101,24 @@ End/Hour
- +
@@ -109,8 +126,8 @@
diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts index a17b1a0d2..c67f9bfce 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.spec.ts @@ -140,6 +140,8 @@ describe('DetailsFieldsComponent', () => { }); it('should emit ngOnChange with new data', () => { + const childComponent = jasmine.createSpyObj('ChildComponent', ['closeModal']); + component.closeModal = childComponent; const formValue = { project_id: '', activity_id: '', @@ -157,6 +159,8 @@ describe('DetailsFieldsComponent', () => { }); it('should call createError ', () => { + const childComponent = jasmine.createSpyObj('ChildComponent', ['closeModal']); + component.closeModal = childComponent; mockEntriesCreateErrorSelector = store.overrideSelector(getCreateError, false); spyOn(store, 'dispatch'); component.ngOnInit(); @@ -164,6 +168,8 @@ describe('DetailsFieldsComponent', () => { }); it('should call updateError ', () => { + const childComponent = jasmine.createSpyObj('ChildComponent', ['closeModal']); + component.closeModal = childComponent; mockEntriesUpdateErrorSelector = store.overrideSelector(getUpdateError, false); spyOn(store, 'dispatch'); component.ngOnInit(); @@ -172,44 +178,25 @@ describe('DetailsFieldsComponent', () => { it('should emit saveEntry event', () => { spyOn(component.saveEntry, 'emit'); - component.onSubmit(); - const data = { + component.entryForm.setValue({ project_id: '', activity_id: '', - technologies: [], - description: '', - start_date: 'T00:00', - end_date: 'T00:00', uri: '', - }; - expect(component.saveEntry.emit).toHaveBeenCalledWith(data); - }); - - it('should emit saveEntry without project and activite fields event', () => { - spyOn(component.saveEntry, 'emit'); - component.entryForm.setValue({ - project_id: 'id', - activity_id: 'fc5fab41-a21e-4155-9d05-511b956ebd05', - uri: '', - start_date: '', - end_date: '', + start_date: '2020-02-05', + end_date: '2020-02-05', start_hour: '00:00', - end_hour: '00:00', + end_hour: '00:01', description: '', technology: '', }); - component.activities = [ - { 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', + project_id: '', + activity_id: '', technologies: [], description: '', - start_date: 'T00:00', - end_date: 'T00:00', + start_date: '2020-02-05T00:00', + end_date: '2020-02-05T00:01', uri: '', }; expect(component.saveEntry.emit).toHaveBeenCalledWith(data); diff --git a/src/app/modules/shared/components/details-fields/details-fields.component.ts b/src/app/modules/shared/components/details-fields/details-fields.component.ts index e37be1849..ed4474b29 100644 --- a/src/app/modules/shared/components/details-fields/details-fields.component.ts +++ b/src/app/modules/shared/components/details-fields/details-fields.component.ts @@ -22,7 +22,8 @@ import * as projectActions from '../../../customer-management/components/project import { EntryState } from '../../../time-clock/store/entry.reducer'; import * as entryActions from '../../../time-clock/store/entry.actions'; import { getUpdateError, getCreateError } from 'src/app/modules/time-clock/store/entry.selectors'; - +import $ from 'jquery'; +import 'bootstrap'; type Merged = TechnologyState & ProjectState & ActivityState & EntryState; @Component({ @@ -35,7 +36,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { @Input() formType: string; @Output() saveEntry = new EventEmitter(); @ViewChild('closeModal') closeModal: ElementRef; - @ViewChild('list') list: ElementRef; entryForm: FormGroup; selectedTechnologies: string[] = []; isLoading = false; @@ -43,14 +43,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { activities: Activity[] = []; keyword = 'name'; showlist: boolean; - hoursValidation: boolean; + errorDate: boolean; constructor(private formBuilder: FormBuilder, private store: Store, private renderer: Renderer2) { - this.renderer.listen('window', 'click', (e: Event) => { - if (this.showlist && !this.list.nativeElement.contains(e.target)) { - this.showlist = false; - } - }); this.entryForm = this.formBuilder.group({ project_id: '', activity_id: '', @@ -62,10 +57,10 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { uri: '', technology: '', }); + $('[data-toggle="tooltip"]').tooltip(); } ngOnInit(): void { - this.store.dispatch(new projectActions.LoadProjects()); const projects$ = this.store.pipe(select(getProjects)); projects$.subscribe((response) => { @@ -95,7 +90,6 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { } ngOnChanges(): void { - this.hoursValidation = false; if (this.entryToEdit) { this.selectedTechnologies = this.entryToEdit.technologies; this.entryForm.setValue({ @@ -110,21 +104,25 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { technology: '', }); } else { - this.selectedTechnologies = []; - this.entryForm.setValue({ - project_id: '', - activity_id: '', - description: '', - start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'), - start_hour: '00:00', - end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'), - end_hour: '00:00', - uri: '', - technology: '', - }); + this.cleanForm(); } } + cleanForm() { + this.selectedTechnologies = []; + this.entryForm.setValue({ + project_id: '', + activity_id: '', + description: '', + start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'), + start_hour: '00:00', + end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'), + end_hour: '00:00', + uri: '', + technology: '', + }); + } + onTechnologiesUpdated($event: string[]) { this.selectedTechnologies = $event; } @@ -153,8 +151,14 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { } closeEntryModal() { + this.close(); + this.closeModal.nativeElement.click(); + } + + close() { this.entryForm.reset(); - this.closeModal?.nativeElement?.click(); + this.errorDate = false; + this.cleanForm(); } onSubmit() { @@ -167,6 +171,12 @@ export class DetailsFieldsComponent implements OnChanges, OnInit { end_date: `${this.entryForm.value.end_date}T${this.entryForm.value.end_hour}`, uri: this.entryForm.value.uri, }; - this.saveEntry.emit(entry); + + if (new Date(entry.start_date) < new Date(entry.end_date)) { + this.errorDate = false; + this.saveEntry.emit(entry); + } else { + this.errorDate = true; + } } } diff --git a/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts b/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts index 6e5718f1a..1a7be9cdd 100644 --- a/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts +++ b/src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.spec.ts @@ -73,5 +73,4 @@ describe('ProjectListHoverComponent', () => { expect(store.dispatch).toHaveBeenCalledWith(jasmine.any(UpdateActiveEntry)); }); - }); diff --git a/src/app/modules/time-entries/pages/time-entries.component.spec.ts b/src/app/modules/time-entries/pages/time-entries.component.spec.ts index 0beabdd18..668a76d61 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.spec.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.spec.ts @@ -127,7 +127,7 @@ describe('TimeEntriesComponent', () => { }; mockEntriesSelector = store.overrideSelector(allEntries, [newEntry]); component.ngOnInit(); - expect(component.dataByMonth.length).toEqual(1); + expect(component.dataByMonth.length).toEqual(0); })); it('should call dataByMonth without new date in ngOnInit()', async(() => { diff --git a/src/app/modules/time-entries/pages/time-entries.component.ts b/src/app/modules/time-entries/pages/time-entries.component.ts index c11b46674..0ac26563f 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.ts @@ -26,7 +26,7 @@ export class TimeEntriesComponent implements OnInit { dataByMonth$.subscribe((response) => { this.entryList = response; this.dataByMonth = this.entryList.reduce((acc: any, entry: any) => { - if (new Date(entry.start_date).getMonth() === new Date().getMonth()) { + if (new Date(entry.start_date).getMonth() === new Date().getMonth() && entry.end_date) { const item = { ...entry }; return [...acc, item]; }