Skip to content

Commit 3e2d97c

Browse files
committed
fix: #172 Create-time-entries-manually fix view
1 parent 26038ac commit 3e2d97c

File tree

9 files changed

+48
-87
lines changed

9 files changed

+48
-87
lines changed

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

Lines changed: 3 additions & 3 deletions
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>
@@ -126,10 +126,10 @@
126126
<textarea formControlName="description" class="form-control" id="NotesTextarea" rows="3"></textarea>
127127
</div>
128128
<div [ngClass]="{ hidden: formType !== 'entries' }" class="modal-footer">
129-
<button #closeModal type="button" class="btn close-button-style" data-dismiss="modal">
129+
<button #closeModal type="button" class="btn btn-secondary" data-dismiss="modal">
130130
Close
131131
</button>
132-
<button type="submit" class="btn save-button-style">Save changes</button>
132+
<button type="submit" class="btn btn-primary">Save changes</button>
133133
</div>
134134
</form>
135135
</div>

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,14 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
6262
start_hour: '00:00',
6363
end_hour: '00:00',
6464
uri: '',
65-
technology: '',
6665
});
6766
}
6867

6968
ngOnInit(): void {
7069
const technologies$ = this.store.pipe(select(allTechnologies));
7170
technologies$.subscribe((response) => {
7271
this.isLoading = response.isLoading;
73-
const filteredItems = response.technologyList.items.filter(item => !this.selectedTechnology.includes(item.name));
74-
this.technology = { items: filteredItems };
72+
this.technology = response.technologyList;
7573
});
7674

7775
this.store.dispatch(new projectActions.LoadProjects());
@@ -90,44 +88,30 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
9088
ngOnChanges(): void {
9189
if (this.entryToEdit) {
9290
this.selectedTechnology = this.entryToEdit.technologies;
93-
<<<<<<< HEAD
9491
this.project = this.listProjects.find((p) => p.id === this.entryToEdit.project_id);
9592
const activity = this.activities.find((a) => a.id === this.entryToEdit.activity_id);
9693
this.projectName = this.project.name;
9794
this.entryForm.setValue({
98-
=======
99-
const project = this.listProjects.find((p) => p.id === this.entryToEdit.project_id);
100-
const activity = this.activities.find((a) => a.id === this.entryToEdit.activity_id);
101-
this.entryForm.setValue({
102-
project: project ? project.name : '',
103-
>>>>>>> fix: #172 Create-time-entries-manually
10495
activity: activity ? activity.name : '',
10596
description: this.entryToEdit.description,
10697
start_date: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'yyyy-MM-dd', 'en') : '',
10798
start_hour: this.entryToEdit.start_date ? formatDate(this.entryToEdit.start_date, 'HH:mm', 'en') : '00:00',
10899
end_date: this.entryToEdit.end_date ? formatDate(this.entryToEdit.end_date, 'yyyy-MM-dd', 'en') : '',
109100
end_hour: this.entryToEdit.end_date ? formatDate(this.entryToEdit.end_date, 'HH:mm', 'en') : '00:00',
110101
uri: this.entryToEdit.uri,
111-
technology: '',
112102
});
113103
} else {
114104
this.selectedTechnology = [];
115-
<<<<<<< HEAD
116105
this.project = '';
117106
this.projectName = '';
118107
this.entryForm.setValue({
119-
=======
120-
this.entryForm.setValue({
121-
project: '',
122-
>>>>>>> fix: #172 Create-time-entries-manually
123108
activity: '',
124109
description: '',
125110
start_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
126111
start_hour: '00:00',
127112
end_date: formatDate(new Date(), 'yyyy-MM-dd', 'en'),
128113
end_hour: '00:00',
129114
uri: '',
130-
technology: '',
131115
});
132116
}
133117
}
@@ -140,28 +124,23 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
140124
}
141125

142126
setTechnology(name: string) {
143-
this.selectedTechnology = [...this.selectedTechnology, name];
144-
this.showlist = false;
145-
this.entryForm.get('technology').reset();
127+
const index = this.selectedTechnology.indexOf(name);
128+
if (index > -1) {
129+
this.removeTag(index);
130+
} else if (this.selectedTechnology.length < 10) {
131+
this.selectedTechnology = [...this.selectedTechnology, name];
132+
}
146133
}
147134

148135
removeTag(index) {
149136
this.selectedTechnology.splice(index, 1);
150-
this.selectedTechnology = [...this.selectedTechnology, name];
151-
this.showlist = false;
152-
this.entryForm.get('technology').reset();
153137
}
154138

155139
onSubmit() {
156140
const activity = this.activities.find((a) => a.name === this.entryForm.value.activity);
157-
<<<<<<< HEAD
158141
this.project = this.projectName.id ? this.projectName : this.project;
159142
const entry = {
160143
project_id: this.project.id,
161-
=======
162-
const entry = {
163-
project_id: this.entryForm.value.project.id,
164-
>>>>>>> fix: #172 Create-time-entries-manually
165144
activity_id: activity ? activity.id : null,
166145
technologies: this.selectedTechnology,
167146
description: this.entryForm.value.description,

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: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
data-target="#editRecordsByDate"
99
class="btn btn-primary"
1010
>
11-
Add new entry
11+
<i class="fa fa-plus-square"></i> New Entry
1212
</button>
1313
</div>
1414
</div>
15-
<<<<<<< HEAD
1615
<div class="card">
1716
<app-month-picker (monthSelected)="getMonth($event)"></app-month-picker>
1817
<div class="row m-0 header-entries">
@@ -54,7 +53,7 @@
5453
{{ item.time }}
5554
</div>
5655
<div class="col">
57-
{{ item.date }}
56+
{{ item.start_date | date: 'dd/MM/yyyy' }}
5857
</div>
5958
<div class="col-2">
6059
<button
@@ -68,53 +67,26 @@
6867
<button
6968
class="btn btn-sm btn-small"
7069
data-toggle="modal"
71-
=======
72-
<div style="height: 10px;"></div>
73-
<app-month-picker (monthSelected)="getMonth($event)"></app-month-picker>
74-
75-
<div style="height: 10px;"></div>
76-
77-
<table class="table table-sm table-striped">
78-
<thead class="thead-orange">
79-
<tr class="d-flex">
80-
<th class="col-5">Project</th>
81-
<th class="col-5">Duration</th>
82-
<th class="col-2"></th>
83-
</tr>
84-
</thead>
85-
<tbody>
86-
<tr
87-
class="d-flex"
88-
*ngFor="let item of dataByMonth"
89-
>
90-
<td class="col-sm-5">{{ item.project_id }}</td>
91-
<td class="col-sm-5">{{ item.time }}</td>
92-
<td class="col-sm-2 text-center">
93-
<button type="button" class="btn btn-sm btn-secondary"
94-
data-toggle="modal"
95-
data-target="#editRecordsByDate"
96-
(click)="editEntry(item.id)">
97-
<i class="fa fa-pencil fa-xs"></i>
98-
</button>
99-
<button type="button" class="btn btn-sm btn-danger ml-2"
100-
data-toggle="modal"
101-
>>>>>>> fix: #172 removing old styles
10270
data-target="#deleteModal"
103-
(click)="openModal(item)">
104-
<i class="fas fa-trash-alt fa-xs"></i>
105-
</button>
106-
</td>
107-
</tr>
108-
</tbody>
109-
</table>
110-
111-
71+
(click)="openModal(item)"
72+
>
73+
<i class="fa fa-trash"></i>
74+
</button>
75+
</div>
76+
</div>
77+
</div>
78+
</div>
79+
</div>
80+
<ng-template #emptyState>
81+
<app-empty-state></app-empty-state>
82+
</ng-template>
83+
</div>
11284
</div>
11385
<div class="modal fade" id="editRecordsByDate" tabindex="-1" role="dialog" aria-hidden="true">
11486
<div class="modal-dialog modal-dialog-centered" role="document">
11587
<div class="modal-content">
11688
<div class="modal-header">
117-
<h5 class="modal-title" id="exampleModalLongTitle">Edit Entry</h5>
89+
<h5 class="modal-title" id="exampleModalLongTitle">{{entryId ? "Edit Entry": "New Entry"}} </h5>
11890
</div>
11991
<div class="modal-body">
12092
<app-details-fields

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

Lines changed: 2 additions & 2 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,7 +33,7 @@ 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
}
3838
const item = { ...entry, time };
3939
return [...acc, item];

0 commit comments

Comments
 (0)