Skip to content

Commit cfcc2c0

Browse files
authored
Merge pull request #332 from ioet/329-isse-reload-entries-after-clock-in
closes #329 reload entries after clock-in closes #274 sets the right project id on time-clock screen closes #327 modal is closed after updating the information closes #325 adds a wildcard to query the entries report closes #323 sets the activity to blank on time-clock screen
2 parents 6725a5f + 10e7694 commit cfcc2c0

File tree

12 files changed

+55
-8
lines changed

12 files changed

+55
-8
lines changed

src/app/modules/reports/components/time-range-form/time-range-form.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class TimeRangeFormComponent {
2323
onSubmit() {
2424
this.store.dispatch(new entryActions.LoadEntriesByTimeRange({
2525
start_date: this.startDate.value,
26-
end_date: this.endDate.value
26+
end_date: this.endDate.value,
27+
user_id: '*',
2728
}));
2829
}
2930
}

src/app/modules/reports/components/time-range-form/time-range.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ describe('Reports Page', () => {
6767
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntriesByTimeRange({
6868
start_date: startDateValue,
6969
end_date: endDateValue,
70+
user_id: '*',
7071
}));
7172
});
7273

src/app/modules/time-clock/components/entry-fields/entry-fields.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<span class="input-group-text span-width">Activity</span>
55
</div>
66
<select id="activitiesSelect" (blur)="onSubmit()" class="form-control" formControlName="activity_id">
7+
<option value="-1"></option>
78
<option *ngFor="let activity of activities" value="{{activity.id}}">{{ activity.name }}</option>
89
</select>
910
</div>

src/app/modules/time-clock/components/entry-fields/entry-fields.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class EntryFieldsComponent implements OnInit {
2929
this.entryForm = this.formBuilder.group({
3030
description: '',
3131
uri: '',
32-
activity_id: ''
32+
activity_id: '-1'
3333
});
3434
}
3535

@@ -38,8 +38,11 @@ export class EntryFieldsComponent implements OnInit {
3838
const activities$ = this.store.pipe(select(allActivities));
3939
activities$.subscribe((response) => {
4040
this.activities = response;
41+
this.loadActiveEntry();
4142
});
43+
}
4244

45+
loadActiveEntry() {
4346
const activeEntry$ = this.store.pipe(select(getActiveTimeEntry));
4447
activeEntry$.subscribe((response) => {
4548
if (response) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export class ProjectListHoverComponent implements OnInit {
3131
const projects$ = this.store.pipe(select(getProjects));
3232
projects$.subscribe((projects) => {
3333
this.listProjects = projects;
34+
this.loadActiveTimeEntry();
3435
});
35-
this.loadActiveTimeEntry();
3636
}
3737

3838
private loadActiveTimeEntry() {
@@ -61,5 +61,6 @@ export class ProjectListHoverComponent implements OnInit {
6161
const newEntry = { project_id: selectedProject, start_date: new Date().toISOString() };
6262
this.store.dispatch(new entryActions.CreateEntry(newEntry));
6363
}
64+
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1 ));
6465
}
6566
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface TimeEntriesTimeRange {
22
start_date: Date;
33
end_date: Date;
4+
user_id: string;
45
}

src/app/modules/time-clock/services/entry.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('EntryService', () => {
9292
const startDateValue = new Date();
9393
const endDateValue = new Date();
9494
const pipe: DatePipe = new DatePipe('en');
95-
const timeRange: TimeEntriesTimeRange = {start_date: startDateValue, end_date: endDateValue};
95+
const timeRange: TimeEntriesTimeRange = {start_date: startDateValue, end_date: endDateValue, user_id: '*'};
9696

9797
service.loadEntriesByTimeRange(timeRange).subscribe();
9898

src/app/modules/time-clock/services/entry.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export class EntryService {
5555
{
5656
params: {
5757
start_date: this.datePipe.transform(range.start_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT),
58-
end_date: this.datePipe.transform(range.end_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT)
58+
end_date: this.datePipe.transform(range.end_date, EntryService.TIME_ENTRIES_DATE_TIME_FORMAT),
59+
user_id: range.user_id
5960
}
6061
}
6162
);

src/app/modules/time-clock/store/entry.effects.spec.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,27 @@ describe('TimeEntryActionEffects', () => {
3434
expect(effects).toBeTruthy();
3535
});
3636

37+
it('returns an action with type LOAD_ENTRIES_SUMMARY_SUCCESS when the service returns a value', () => {
38+
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_SUMMARY});
39+
const serviceSpy = spyOn(service, 'summary');
40+
serviceSpy.and.returnValue(of({}));
41+
42+
effects.loadEntriesSummary$.subscribe(action => {
43+
expect(action.type).toEqual(EntryActionTypes.LOAD_ENTRIES_SUMMARY_SUCCESS);
44+
});
45+
});
46+
47+
it('returns an action with type LOAD_ENTRIES_SUMMARY_FAIL when the service fails', () => {
48+
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_SUMMARY});
49+
spyOn(service, 'summary').and.returnValue(throwError('any error'));
50+
51+
effects.loadEntriesSummary$.subscribe(action => {
52+
expect(action.type).toEqual(EntryActionTypes.LOAD_ENTRIES_SUMMARY_FAIL);
53+
});
54+
});
55+
3756
it('When the service returns a value, then LOAD_ENTRIES_BY_TIME_RANGE_SUCCESS should be triggered', () => {
38-
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date()};
57+
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date(), user_id: '*' };
3958
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE, timeRange});
4059
const serviceSpy = spyOn(service, 'loadEntriesByTimeRange');
4160
serviceSpy.and.returnValue(of([]));
@@ -47,7 +66,7 @@ describe('TimeEntryActionEffects', () => {
4766
});
4867

4968
it('When the service fails, then LOAD_ENTRIES_BY_TIME_RANGE_FAIL should be triggered', async () => {
50-
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date()};
69+
const timeRange: TimeEntriesTimeRange = {start_date: new Date(), end_date: new Date(), user_id: '*'};
5170
actions$ = of({type: EntryActionTypes.LOAD_ENTRIES_BY_TIME_RANGE, timeRange});
5271
spyOn(service, 'loadEntriesByTimeRange').and.returnValue(throwError('any error'));
5372

src/app/modules/time-clock/store/entry.reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
153153
const entryList = [...state.entryList];
154154
const index = entryList.findIndex((entry) => entry.id === action.payload.id);
155155
entryList[index] = action.payload;
156-
entryList.sort((a, b) => b.start_date.getTime() - a.start_date.getTime());
156+
entryList.sort((a, b) => new Date(b.start_date).getTime() - new Date(a.start_date).getTime());
157157
return {
158158
...state,
159159
isLoading: false,

0 commit comments

Comments
 (0)