@@ -2,7 +2,7 @@ import { FeatureToggleGeneralService } from './../../../shared/feature-toggles/f
22import { ActivityManagementActionTypes } from './../../../activities-management/store/activity-management.actions' ;
33import { EntryActionTypes , LoadActiveEntry , UpdateCurrentOrLastEntry , UpdateEntry , UpdateEntryRunning } from './../../store/entry.actions' ;
44import { filter } from 'rxjs/operators' ;
5- import { Component , OnDestroy , OnInit } from '@angular/core' ;
5+ import { Component , OnDestroy , OnInit , ElementRef , ViewChild } from '@angular/core' ;
66import { FormBuilder , FormGroup } from '@angular/forms' ;
77import { Store , ActionsSubject , select } from '@ngrx/store' ;
88import { Activity , NewEntry } from '../../../shared/models' ;
@@ -19,6 +19,8 @@ import { DATE_FORMAT } from 'src/environments/environment';
1919import { Subscription , } from 'rxjs' ;
2020import { FeatureToggle } from './../../../../../environments/enum' ;
2121import { CookieService } from 'ngx-cookie-service' ;
22+ import { head } from 'lodash' ;
23+ import { __await } from 'tslib' ;
2224
2325type Merged = TechnologyState & ProjectState & ActivityState ;
2426
@@ -28,6 +30,9 @@ type Merged = TechnologyState & ProjectState & ActivityState;
2830 styleUrls : [ './entry-fields.component.scss' ] ,
2931} )
3032export class EntryFieldsComponent implements OnInit , OnDestroy {
33+
34+ @ViewChild ( 'autofocus' ) autofocus ! : ElementRef < HTMLSelectElement > ;
35+
3136 entryForm : FormGroup ;
3237 selectedTechnologies : string [ ] = [ ] ;
3338 activities : Activity [ ] = [ ] ;
@@ -46,7 +51,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
4651 private actionsSubject$ : ActionsSubject ,
4752 private toastrService : ToastrService ,
4853 private featureToggleGeneralService : FeatureToggleGeneralService ,
49- private cookiesService : CookieService
54+ private cookiesService : CookieService ,
5055 ) {
5156 this . entryForm = this . formBuilder . group ( {
5257 description : '' ,
@@ -60,7 +65,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
6065 ngOnInit ( ) : void {
6166 this . store . dispatch ( new LoadActivities ( ) ) ;
6267 this . store . dispatch ( new entryActions . LoadEntries ( new Date ( ) . getMonth ( ) + 1 , new Date ( ) . getFullYear ( ) ) ) ;
63- this . loadActivitiesSubscription = this . actionsSubject$
68+ this . loadActivitiesSubscription = this . actionsSubject$
6469 . pipe ( filter ( ( action : any ) => action . type === ActivityManagementActionTypes . LOAD_ACTIVITIES_SUCCESS ) )
6570 . subscribe ( ( action ) => {
6671 this . activities = action . payload . filter ( ( item ) => item . status !== 'inactive' ) ;
@@ -109,6 +114,7 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
109114 start_date : this . activeEntry . start_date ,
110115 start_hour : formatDate ( this . activeEntry . start_date , 'HH:mm' , 'en' ) ,
111116 } ;
117+ this . activateFocus ( ) ;
112118 } ) ;
113119 }
114120 get activity_id ( ) {
@@ -117,6 +123,13 @@ export class EntryFieldsComponent implements OnInit, OnDestroy {
117123 get start_hour ( ) {
118124 return this . entryForm . get ( 'start_hour' ) ;
119125 }
126+
127+ activateFocus ( ) {
128+ if ( ( this . activities . length > 0 ) && ( this . entryForm . value . activity_id === head ( this . activities ) . id ) ) {
129+ this . autofocus . nativeElement . focus ( ) ;
130+ }
131+ }
132+
120133 setDataToUpdate ( entryData : NewEntry ) {
121134 if ( entryData ) {
122135 this . entryForm . patchValue ( {
0 commit comments