Skip to content

Commit c766e7f

Browse files
feat: TTL-886 add logic to check empty fields on internal apps
1 parent 35c5075 commit c766e7f

File tree

1 file changed

+55
-32
lines changed

1 file changed

+55
-32
lines changed

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

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import { ParseDateTimeOffset } from '../../shared/formatters/parse-date-time-off
2424
})
2525
export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
2626
dtOptions: any = {
27-
order: [[ 0, 'desc' ]],
28-
columnDefs: [{orderable: false, targets: [6]}],
27+
order: [[0, 'desc']],
28+
columnDefs: [{ orderable: false, targets: [6] }],
2929
destroy: true,
3030
};
3131
dtTrigger: Subject<any> = new Subject();
@@ -56,7 +56,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
5656
private store: Store<EntryState>,
5757
private toastrService: ToastrService,
5858
private actionsSubject$: ActionsSubject,
59-
private cookiesService: CookieService) {
59+
private cookiesService: CookieService
60+
) {
6061
this.displayGridView = false;
6162
this.selectedDate = moment(new Date());
6263
this.actualDate = new Date();
@@ -66,17 +67,19 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
6667

6768
ngOnInit(): void {
6869
this.loadActiveEntry();
69-
this.entriesSubscription = this.actionsSubject$.pipe(
70-
filter((action: any) => (
71-
action.type === EntryActionTypes.CREATE_ENTRY_SUCCESS ||
72-
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS ||
73-
action.type === EntryActionTypes.DELETE_ENTRY_SUCCESS
70+
this.entriesSubscription = this.actionsSubject$
71+
.pipe(
72+
filter(
73+
(action: any) =>
74+
action.type === EntryActionTypes.CREATE_ENTRY_SUCCESS ||
75+
action.type === EntryActionTypes.UPDATE_ENTRY_SUCCESS ||
76+
action.type === EntryActionTypes.DELETE_ENTRY_SUCCESS
77+
)
7478
)
75-
)
76-
).subscribe((action) => {
77-
this.loadActiveEntry();
78-
this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear));
79-
});
79+
.subscribe((action) => {
80+
this.loadActiveEntry();
81+
this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear));
82+
});
8083
this.rerenderTableSubscription = this.timeEntriesDataSource$.subscribe((ds) => {
8184
this.dtTrigger.next();
8285
});
@@ -96,23 +99,24 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
9699
this.entry = null;
97100
}
98101
this.entryId = null;
99-
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
102+
this.store.pipe(select(getTimeEntriesDataSource)).subscribe((ds) => {
100103
this.canMarkEntryAsWIP = !this.isThereAnEntryRunning(ds.data);
101104
});
102105
}
103106
private getEntryRunning(entries: Entry[]) {
104-
const runningEntry: Entry = entries.find(entry => entry.running === true);
107+
const runningEntry: Entry = entries.find((entry) => entry.running === true);
105108
return runningEntry;
106109
}
107110
private isThereAnEntryRunning(entries: Entry[]) {
108111
return !!this.getEntryRunning(entries);
109112
}
110113
editEntry(entryId: string) {
111114
this.entryId = entryId;
112-
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
113-
this.entry = {... ds.data.find((entry) => entry.id === entryId)};
114-
this.canMarkEntryAsWIP = this.isEntryRunningEqualsToEntryToEdit(this.getEntryRunning(ds.data), this.entry)
115-
|| this.isTheEntryToEditTheLastOne(ds.data);
115+
this.store.pipe(select(getTimeEntriesDataSource)).subscribe((ds) => {
116+
this.entry = { ...ds.data.find((entry) => entry.id === entryId) };
117+
this.canMarkEntryAsWIP =
118+
this.isEntryRunningEqualsToEntryToEdit(this.getEntryRunning(ds.data), this.entry) ||
119+
this.isTheEntryToEditTheLastOne(ds.data);
116120
});
117121
this.wasEditingExistingTimeEntry = true;
118122
}
@@ -144,21 +148,39 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
144148
const isEndDateGreaterThanActiveEntry = endDateAsLocalDate > activeEntryAsLocalDate;
145149
const isTimeEntryOverlapping = isStartDateGreaterThanActiveEntry || isEndDateGreaterThanActiveEntry;
146150
this.checkIfActiveEntryOverlapping(isEditingEntryEqualToActiveEntry, startDateAsLocalDate);
147-
if (!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping || this.isActiveEntryOverlapping ) {
151+
if ((!isEditingEntryEqualToActiveEntry && isTimeEntryOverlapping) || this.isActiveEntryOverlapping) {
148152
const message = this.isActiveEntryOverlapping ? 'try another "Time in"' : 'try with earlier times';
149153
this.toastrService.error(`You are on the clock and this entry overlaps it, ${message}.`);
150154
this.isActiveEntryOverlapping = false;
151155
} else {
152-
this.doSave(event);
156+
if (this.entry.project_name.includes('(Applications)')) {
157+
if (event.entry.uri === '' && event.entry.description === '') {
158+
const message = 'The description field or ticket field should not be empty';
159+
this.toastrService.error(`Some fields are empty, ${message}.`);
160+
} else {
161+
this.doSave(event);
162+
}
163+
} else {
164+
this.doSave(event);
165+
}
153166
}
154167
} else {
155-
this.doSave(event);
168+
if (this.entry.project_name.includes('(Applications)')) {
169+
if (event.entry.uri === '' && event.entry.description === '') {
170+
const message = 'The description field or ticket field should not be empty';
171+
this.toastrService.error(`Some fields are empty, ${message}.`);
172+
} else {
173+
this.doSave(event);
174+
}
175+
} else {
176+
this.doSave(event);
177+
}
156178
}
157179
}
158180
projectSelected(event: ProjectSelectedEvent): void {
159181
this.wasEditingExistingTimeEntry = false;
160-
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
161-
const dataToUse = ds.data.find(item => item.project_id === event.projectId);
182+
this.store.pipe(select(getTimeEntriesDataSource)).subscribe((ds) => {
183+
const dataToUse = ds.data.find((item) => item.project_id === event.projectId);
162184
if (dataToUse && this.isNewEntry()) {
163185
const defaultSeconds = 0;
164186
const currentDate = new Date();
@@ -169,9 +191,10 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
169191
technologies: dataToUse.technologies ? dataToUse.technologies : [],
170192
uri: dataToUse.uri ? dataToUse.uri : '',
171193
activity_id: dataToUse.activity_id,
194+
project_name: dataToUse.project_name,
172195
project_id: dataToUse.project_id,
173196
start_date: currentDate,
174-
end_date: currentDate
197+
end_date: currentDate,
175198
};
176199
this.entry = entry;
177200
}
@@ -208,26 +231,26 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
208231
this.selectedMonthAsText = moment().month(event.monthIndex).format('MMMM');
209232
this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear));
210233
this.selectedDate = moment().month(event.monthIndex).year(event.year);
211-
if (this.actualDate.getMonth() !== event.monthIndex){
234+
if (this.actualDate.getMonth() !== event.monthIndex) {
212235
this.selectedDate = this.selectedDate.startOf('month');
213236
}
214237
}
215238

216-
changeDate(event: { date: Date }){
239+
changeDate(event: { date: Date }) {
217240
const newDate: moment.Moment = moment(event.date);
218-
if (this.selectedDate.month() !== newDate.month()){
241+
if (this.selectedDate.month() !== newDate.month()) {
219242
const monthSelected = newDate.month();
220243
const yearSelected = newDate.year();
221244
const selectedDate = {
222245
monthIndex: monthSelected,
223-
year: yearSelected
246+
year: yearSelected,
224247
};
225248
this.dateSelected(selectedDate);
226249
}
227250
this.selectedDate = newDate;
228251
}
229252

230-
changeView(event: { calendarView: CalendarView }){
253+
changeView(event: { calendarView: CalendarView }) {
231254
this.calendarView = event.calendarView || CalendarView.Month;
232255
}
233256

@@ -243,10 +266,10 @@ export class TimeEntriesComponent implements OnInit, OnDestroy, AfterViewInit {
243266

244267
checkIfActiveEntryOverlapping(isEditingEntryEqualToActiveEntry: boolean, startDateAsLocalDate: Date) {
245268
if (isEditingEntryEqualToActiveEntry) {
246-
this.store.pipe(select(getTimeEntriesDataSource)).subscribe(ds => {
269+
this.store.pipe(select(getTimeEntriesDataSource)).subscribe((ds) => {
247270
const overlappingEntry = ds.data.find((item) => {
248271
const itemEndDate = new Date(item.end_date);
249-
return startDateAsLocalDate < itemEndDate;
272+
return startDateAsLocalDate < itemEndDate;
250273
});
251274
this.isActiveEntryOverlapping = overlappingEntry ? true : false;
252275
});

0 commit comments

Comments
 (0)