Skip to content

Commit 4a69245

Browse files
author
Abigail Cabascango
committed
fix: TTA-206 implement functions tu validate a running activity in clockin function
1 parent c154edc commit 4a69245

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/app/modules/time-clock/components/project-list-hover/project-list-hover.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ import { Project } from 'src/app/modules/shared/models';
88
import * as actions from '../../../customer-management/components/projects/components/store/project.actions';
99
import { ProjectState } from '../../../customer-management/components/projects/components/store/project.reducer';
1010
import * as entryActions from '../../store/entry.actions';
11+
1112
import {
1213
getIsLoading,
1314
getProjects,
1415
getRecentProjects,
1516
} from './../../../customer-management/components/projects/components/store/project.selectors';
1617
import { EntryActionTypes } from './../../store/entry.actions';
17-
import { getActiveTimeEntry } from './../../store/entry.selectors';
18+
import { getActiveTimeEntry, getTimeEntriesDataSource } from './../../store/entry.selectors';
1819
import { Activity, } from '../../../shared/models';
1920
import { LoadActivities } from './../../../activities-management/store/activity-management.actions';
2021
import { allActivities } from 'src/app/modules/activities-management/store/activity-management.selectors';
2122
import { 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

Comments
 (0)