@@ -8,17 +8,19 @@ import { Project } from 'src/app/modules/shared/models';
88import * as actions from '../../../customer-management/components/projects/components/store/project.actions' ;
99import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer' ;
1010import * as entryActions from '../../store/entry.actions' ;
11+
1112import {
1213 getIsLoading ,
1314 getProjects ,
1415 getRecentProjects ,
1516} from './../../../customer-management/components/projects/components/store/project.selectors' ;
1617import { EntryActionTypes } from './../../store/entry.actions' ;
17- import { getActiveTimeEntry } from './../../store/entry.selectors' ;
18+ import { getActiveTimeEntry , getTimeEntriesDataSource } from './../../store/entry.selectors' ;
1819import { Activity , } from '../../../shared/models' ;
1920import { LoadActivities } from './../../../activities-management/store/activity-management.actions' ;
2021import { allActivities } from 'src/app/modules/activities-management/store/activity-management.selectors' ;
2122import { head } from 'lodash' ;
23+ import { Entry } from '../../../shared/models' ;
2224
2325@Component ( {
2426 selector : 'app-project-list-hover' ,
@@ -39,6 +41,7 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
3941 recentProjectsSubscription : Subscription ;
4042 activeEntrySubscription : Subscription ;
4143 loadActivitiesSubscription : Subscription ;
44+ canMarkEntryAsWIP = true ;
4245
4346 constructor (
4447 private formBuilder : FormBuilder ,
@@ -113,13 +116,24 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
113116 technologies : [ ] ,
114117 activity_id : head ( this . activities ) . id ,
115118 } ;
119+ this . store . pipe ( select ( getTimeEntriesDataSource ) ) . subscribe ( ds => {
120+ this . canMarkEntryAsWIP = ! this . isThereAnEntryRunning ( ds . data ) ;
121+ } ) ;
116122 this . store . dispatch ( new entryActions . ClockIn ( entry ) ) ;
117123 this . projectsForm . setValue ( { project_id : `${ customerName } - ${ name } ` } ) ;
118124 setTimeout ( ( ) => {
119125 this . store . dispatch ( new actions . LoadRecentProjects ( ) ) ;
120126 } , 2000 ) ;
121127 }
122128
129+ getEntryRunning ( entries : Entry [ ] ) {
130+ const runningEntry : Entry = entries . find ( entry => entry . running === true ) ;
131+ return runningEntry ;
132+ }
133+ isThereAnEntryRunning ( entries : Entry [ ] ) {
134+ return ! ! this . getEntryRunning ( entries ) ;
135+ }
136+
123137 updateProject ( selectedProject ) {
124138 const entry = { id : this . activeEntry . id , project_id : selectedProject } ;
125139 this . store . dispatch ( new entryActions . UpdateEntryRunning ( entry ) ) ;
0 commit comments