Skip to content

Commit d7ad7ed

Browse files
committed
2 parents 76d763f + d12ce95 commit d7ad7ed

20 files changed

+1369
-105
lines changed

package-lock.json

Lines changed: 63 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "time-tracker",
3-
"version": "1.45.6",
3+
"version": "1.46.0",
44
"scripts": {
55
"preinstall": "npx npm-force-resolutions",
66
"ng": "ng",
@@ -31,6 +31,8 @@
3131
"@ngrx/store": "^10.0.1",
3232
"@ngrx/store-devtools": "^10.0.1",
3333
"@types/datatables.net-buttons": "^1.4.3",
34+
"angular-calendar": "^0.28.24",
35+
"date-fns": "^2.22.1",
3436
"angular-datatables": "^9.0.2",
3537
"bootstrap": "^4.4.1",
3638
"datatables.net": "^1.10.21",

src/app/app.module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { MatInputModule } from '@angular/material/input';
1616
import { MatMomentDateModule } from '@angular/material-moment-adapter';
1717
import { NgxPaginationModule } from 'ngx-pagination';
1818
import { AutocompleteLibModule } from 'angular-ng-autocomplete';
19+
import { CalendarModule, DateAdapter } from 'angular-calendar';
20+
import { adapterFactory } from 'angular-calendar/date-adapters/date-fns';
1921

2022
import { AppRoutingModule } from './app-routing.module';
2123
import { AppComponent } from './app.component';
@@ -81,6 +83,7 @@ import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker';
8183
// tslint:disable-next-line: max-line-length
8284
import { TechnologyReportTableComponent } from './modules/technology-report/components/technology-report-table/technology-report-table.component';
8385
import { TechnologyReportComponent } from './modules/technology-report/pages/technology-report.component';
86+
import { CalendarComponent } from './modules/time-entries/components/calendar/calendar.component';
8487

8588
const maskConfig: Partial<IConfig> = {
8689
validation: false,
@@ -133,6 +136,7 @@ const maskConfig: Partial<IConfig> = {
133136
UsersListComponent,
134137
TechnologyReportComponent,
135138
TechnologyReportTableComponent,
139+
CalendarComponent,
136140
],
137141
imports: [
138142
NgxMaskModule.forRoot(maskConfig),
@@ -171,6 +175,10 @@ const maskConfig: Partial<IConfig> = {
171175
UserEffects,
172176
]),
173177
ToastrModule.forRoot(),
178+
CalendarModule.forRoot({
179+
provide: DateAdapter,
180+
useFactory: adapterFactory,
181+
}),
174182
],
175183
providers: [
176184
{

src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AfterViewInit, Component, OnDestroy, OnInit, ViewChild} from '@angular/
33
import { select, Store } from '@ngrx/store';
44
import { DataTableDirective } from 'angular-datatables';
55
import * as moment from 'moment';
6-
import { Observable, Subject } from 'rxjs';
6+
import { Observable, Subject, Subscription } from 'rxjs';
77
import { Entry } from 'src/app/modules/shared/models';
88
import { DataSource } from 'src/app/modules/shared/models/data-source.model';
99
import { EntryState } from '../../../time-clock/store/entry.reducer';
@@ -60,13 +60,14 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
6060
dtElement: DataTableDirective;
6161
isLoading$: Observable<boolean>;
6262
reportDataSource$: Observable<DataSource<Entry>>;
63+
rerenderTableSubscription: Subscription;
6364

6465
constructor(private store: Store<EntryState>) {
6566
this.reportDataSource$ = this.store.pipe(select(getReportDataSource));
6667
}
6768

6869
ngOnInit(): void {
69-
this.reportDataSource$.subscribe((ds) => {
70+
this.rerenderTableSubscription = this.reportDataSource$.subscribe((ds) => {
7071
this.rerenderDataTable();
7172
});
7273
}
@@ -76,17 +77,18 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
7677
}
7778

7879
ngOnDestroy(): void {
80+
this.rerenderTableSubscription.unsubscribe();
7981
this.dtTrigger.unsubscribe();
8082
}
8183

8284
private rerenderDataTable(): void {
8385
if (this.dtElement && this.dtElement.dtInstance) {
8486
this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
85-
dtInstance.destroy();
86-
this.dtTrigger.next();
87+
dtInstance.destroy();
88+
this.dtTrigger.next();
8789
});
8890
} else {
89-
this.dtTrigger.next();
91+
this.dtTrigger.next();
9092
}
9193
}
9294

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,6 @@ describe('DetailsFieldsComponent', () => {
418418
expect(component.saveEntry.emit).toHaveBeenCalledWith(data);
419419
});
420420

421-
it('should not modify the start_date when start_hour has not been modified', () => {
422-
const currentDate = moment().format('YYYY-MM-DD');
423-
const startHour = moment().subtract(3, 'hours').format('HH:mm:ss');
424-
const expectedStartDate = new Date(`${currentDate}T${startHour.trim()}`);
425-
426-
component.entryToEdit = { ...entryToEdit, start_date: expectedStartDate };
427-
fixture.componentInstance.ngOnChanges();
428-
429-
component.entryForm.patchValue({ description: 'test' });
430-
431-
expect(component.dateToSubmit('start_date', 'start_hour')).toEqual(expectedStartDate);
432-
});
433-
434421
it('should modify the start_date when start_hour has been modified', () => {
435422
const startDate = new Date(mockCurrentDate);
436423

@@ -445,19 +432,6 @@ describe('DetailsFieldsComponent', () => {
445432
expect(component.dateToSubmit('start_date', 'start_hour')).toEqual(expectedStartDate);
446433
});
447434

448-
it('should not modify the end_date when end_hour has not been modified', () => {
449-
const currentDate = moment().format('YYYY-MM-DD');
450-
const endHour = moment().subtract(3, 'hours').format('HH:mm:ss');
451-
const expectedEndDate = new Date(`${currentDate}T${endHour.trim()}`);
452-
453-
component.entryToEdit = { ...entryToEdit, end_date: expectedEndDate };
454-
fixture.componentInstance.ngOnChanges();
455-
456-
component.entryForm.patchValue({ description: 'test' });
457-
458-
expect(component.dateToSubmit('end_date', 'end_hour')).toEqual(expectedEndDate);
459-
});
460-
461435
it('should modify the end_date when end_hour has been modified', () => {
462436
const endDate = new Date(mockCurrentDate);
463437

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
269269
const updatedHour = this.entryForm.value[hour];
270270
const updatedDate = new Date(`${entryFormDate}T${updatedHour.trim()}`).toISOString();
271271
const initialDate = get(this.entryToEdit, date, updatedDate);
272-
const initialHour = formatDate(get(this.entryToEdit, date, updatedDate), 'HH:mm', 'en');
273-
const dateHasNotChanged = updatedHour === initialHour;
272+
const dateHasNotChanged = (initialDate === updatedDate);
274273
const result = dateHasNotChanged ? initialDate : updatedDate;
275274
return result;
276275
}

0 commit comments

Comments
 (0)