Skip to content

Commit 0582e87

Browse files
committed
fix: #172 Create-time-entries-manually fix view
1 parent 1dfee7f commit 0582e87

File tree

9 files changed

+30
-18
lines changed

9 files changed

+30
-18
lines changed

src/app/modules/shared/components/details-fields/details-fields.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div>
2-
<div *ngIf="formType === 'entries'" class="input-group input-group-sm mb-3 flex-nowrap">
2+
<div class="input-group input-group-sm mb-3 flex-nowrap">
33
<div class="input-group-prepend">
44
<span class="input-group-text span-width" id="inputGroup-sizing-sm">Project</span>
55
</div>

src/app/modules/shared/components/details-fields/details-fields.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
6868
const technologies$ = this.store.pipe(select(allTechnologies));
6969
technologies$.subscribe((response) => {
7070
this.isLoading = response.isLoading;
71-
const filteredItems = response.technologyList.items.filter(item => !this.selectedTechnology.includes(item.name));
71+
const filteredItems = response.technologyList.items.filter(
72+
(item) => !this.selectedTechnology.includes(item.name)
73+
);
7274
this.technology = { items: filteredItems };
7375
});
7476

@@ -87,7 +89,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
8789

8890
ngOnChanges(): void {
8991
if (this.entryToEdit) {
90-
this.selectedTechnology = this.entryToEdit.technologies;
92+
this.selectedTechnology = this.entryToEdit.technologies ? this.entryToEdit.technologies : [];
9193
this.project = this.listProjects.find((p) => p.id === this.entryToEdit.project_id);
9294
const activity = this.activities.find((a) => a.id === this.entryToEdit.activity_id);
9395
this.projectName = this.project.name;
@@ -145,6 +147,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
145147
uri: this.entryForm.value.uri,
146148
};
147149
this.saveEntry.emit(entry);
150+
this.ngOnChanges();
148151
this.closeModal.nativeElement.click();
149152
}
150153
}

src/app/modules/time-clock/pages/time-clock.component.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { ProjectListHoverComponent } from '../components';
1111
import { FilterProjectPipe } from '../../shared/pipes';
1212
import { AzureAdB2CService } from '../../login/services/azure.ad.b2c.service';
1313

14-
import { ActionsSubject } from '@ngrx/store';
15-
1614
describe('TimeClockComponent', () => {
1715
let component: TimeClockComponent;
1816
let fixture: ComponentFixture<TimeClockComponent>;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ describe('Actions for Entries', () => {
4646

4747
it('UpdateActiveEntrySuccess type is EntryActionTypes.UDPATE_ACTIVE_ENTRY_SUCCESS', () => {
4848
const updateActiveEntrySuccess = new actions.UpdateActiveEntrySuccess({
49-
project_id: '1',
50-
description: 'It is good for learning',
49+
id: '1',
50+
start_date: new Date(),
51+
end_date: new Date(),
52+
activity: '',
53+
technologies: ['abc', 'abc'],
5154
});
5255
expect(updateActiveEntrySuccess.type).toEqual(actions.EntryActionTypes.UPDATE_ACTIVE_ENTRY_SUCCESS);
5356
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class UpdateActiveEntry implements Action {
9797
export class UpdateActiveEntrySuccess implements Action {
9898
public readonly type = EntryActionTypes.UPDATE_ACTIVE_ENTRY_SUCCESS;
9999

100-
constructor(public payload: NewEntry) {}
100+
constructor(public payload: Entry) {}
101101
}
102102

103103
export class UpdateActiveEntryFail implements Action {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ describe('entryReducer', () => {
1111
technologies: ['angular', 'typescript'],
1212
};
1313

14+
const newEntry: Entry = {
15+
id: '1',
16+
start_date: new Date(),
17+
end_date: new Date(),
18+
activity: '',
19+
technologies: ['abc', 'abc'],
20+
};
21+
1422
it('on Default, ', () => {
1523
const action = new actions.DefaultEntry();
1624
const state = entryReducer(initialState, action);
@@ -124,7 +132,7 @@ describe('entryReducer', () => {
124132
isLoading: false,
125133
message: '',
126134
};
127-
const action = new actions.UpdateActiveEntrySuccess(entry);
135+
const action = new actions.UpdateActiveEntrySuccess(newEntry);
128136
const state = entryReducer(currentState, action);
129137

130138
expect(state.isLoading).toEqual(false);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
7272
return {
7373
...state,
7474
active: action.payload,
75-
entryList: [...state.entryList, action.payload],
75+
entryList: [action.payload, ...state.entryList],
7676
isLoading: false,
7777
message: 'You clocked-in successfully',
7878
};
@@ -120,11 +120,12 @@ export const entryReducer = (state: EntryState = initialState, action: EntryActi
120120
}
121121

122122
case EntryActionTypes.UPDATE_ACTIVE_ENTRY_SUCCESS: {
123-
const activeEntry = { ...state.active, ...action.payload };
124-
123+
const entryList = [...state.entryList];
124+
const index = entryList.findIndex((entry) => entry.id === action.payload.id);
125+
entryList[index] = action.payload;
125126
return {
126127
...state,
127-
active: activeEntry,
128+
entryList,
128129
isLoading: false,
129130
};
130131
}

src/app/modules/time-entries/pages/time-entries.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
>
3535
<td class="col-sm-3">{{ item.project_id }}</td>
3636
<td class="col-sm-3">{{ item.time }}</td>
37-
<td class="col-sm-3">{{ item.date }}</td>
37+
<td class="col-sm-3">{{ item.start_date | date:'dd/MM/yyyy' }}</td>
3838
<td class="col-sm-3 text-center">
3939
<button type="button" class="btn btn-sm btn-secondary"
4040
data-toggle="modal"

src/app/modules/time-entries/pages/time-entries.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class TimeEntriesComponent implements OnInit {
1616
entryId: string;
1717
entry: Entry;
1818
entryToDelete: Entry;
19-
dataByMonth: Entry[];
19+
dataByMonth = [];
2020
entryList: Entry[];
2121

2222
constructor(private store: Store<EntryState>) {}
@@ -33,10 +33,9 @@ export class TimeEntriesComponent implements OnInit {
3333
const startDate = moment(entry.start_date, 'YYYY-MM-DD HH:mm:ss');
3434
const endDate = moment(entry.end_date, 'YYYY-MM-DD HH:mm:ss');
3535
const duration: any = moment.duration(endDate.diff(startDate));
36-
time = `${duration._data.hours} hour and ${duration._data.minutes} minutes`;
36+
time = `${duration._data.hours} hh : ${duration._data.minutes} mm`;
3737
}
38-
const date = moment(entry.start_date).format('YYYY-MM-DD');
39-
const item = { ...entry, time, date };
38+
const item = { ...entry, time };
4039
return [...acc, item];
4140
}
4241
return [];

0 commit comments

Comments
 (0)