Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,21 @@ describe('TimeEntriesComponent', () => {
expect(component.dataByMonth.length).toEqual(1);
}));

it('when saving time entries, the time entries should be queried', () => {
it('when create time entries, the time entries should be queried', () => {
const currentMonth = new Date().getMonth() + 1;
const entryToSave = {
entry: {
project_id: 'project-id',
end_date: new Date(),
start_date: new Date()
end_date: '2010-05-05T10:04',
start_date: null
}, shouldRestartEntry: false
};
component.activeTimeEntry = null;
spyOn(store, 'dispatch');
component.ngOnInit();

component.saveEntry(entryToSave);

expect(store.dispatch).toHaveBeenCalledWith(new entryActions.CreateEntry(entryToSave.entry));
expect(store.dispatch).toHaveBeenCalledWith(new entryActions.LoadEntries(currentMonth));
});

Expand Down
29 changes: 24 additions & 5 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { EntryActionTypes } from './../../time-clock/store/entry.actions';
import { filter } from 'rxjs/operators';
import { ToastrService } from 'ngx-toastr';
import { getActiveTimeEntry } from './../../time-clock/store/entry.selectors';
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Entry } from '../../shared/models';
import { EntryState } from '../../time-clock/store/entry.reducer';
import { allEntries } from '../../time-clock/store/entry.selectors';
import { select, Store } from '@ngrx/store';
import { select, Store, ActionsSubject } from '@ngrx/store';
import * as entryActions from '../../time-clock/store/entry.actions';
import { SaveEntryEvent } from '../../shared/components/details-fields/save-entry-event';
import { Subscription} from 'rxjs';

@Component({
selector: 'app-time-entries',
templateUrl: './time-entries.component.html',
styleUrls: ['./time-entries.component.scss'],
})
export class TimeEntriesComponent implements OnInit {
export class TimeEntriesComponent implements OnInit, OnDestroy {
entryId: string;
entry: Entry;
dataByMonth = [];
activeTimeEntry: Entry;
showModal = false;
message: string;
idToDelete: string;
entriesSubscription: Subscription;

constructor(private store: Store<EntryState>, private toastrService: ToastrService) {
constructor(private store: Store<EntryState>, private toastrService: ToastrService, private actionsSubject$: ActionsSubject) {
}

ngOnDestroy(): void {
this.entriesSubscription.unsubscribe();
}

ngOnInit(): void {
Expand All @@ -32,6 +40,18 @@ export class TimeEntriesComponent implements OnInit {
this.dataByMonth = response;
});
this.loadActiveEntry();

this.entriesSubscription = this.actionsSubject$.pipe(
filter((action: any) => (
action.type === EntryActionTypes.CREATE_ENTRY_SUCCESS ||
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS ||
action.type === EntryActionTypes.DELETE_ENTRY_SUCCESS
)
)
).subscribe((action) => {
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
});

}

newEntry() {
Expand All @@ -58,7 +78,6 @@ export class TimeEntriesComponent implements OnInit {
} else {
this.doSave(event);
}
this.store.dispatch(new entryActions.LoadEntries(new Date().getMonth() + 1));
}

doSave(event: SaveEntryEvent) {
Expand Down