diff --git a/package-lock.json b/package-lock.json index 3c977639b..d097b9906 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "time-tracker", - "version": "1.50.0", + "version": "1.50.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 655abbdbf..45f29d75f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "time-tracker", - "version": "1.50.0", + "version": "1.50.2", "scripts": { "preinstall": "npx npm-force-resolutions", "ng": "ng", diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 9be2a978d..4cb50a9bf 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -11,8 +11,6 @@ import { HomeComponent } from './modules/home/home.component'; import { LoginComponent } from './modules/login/login.component'; import { CustomerComponent } from './modules/customer-management/pages/customer.component'; import { UsersComponent } from './modules/users/pages/users.component'; -import { TechnologyReportComponent } from './modules/technology-report/pages/technology-report.component'; -import { TechnologiesReportGuard } from './guards/technologies-report-guard/technologies-report.guard'; const routes: Routes = [ { @@ -26,7 +24,6 @@ const routes: Routes = [ { path: 'activities-management', component: ActivitiesManagementComponent }, { path: 'customers-management', canActivate: [AdminGuard], component: CustomerComponent }, { path: 'users', canActivate: [AdminGuard], component: UsersComponent }, - { path: 'technology-report', canActivate: [AdminGuard, TechnologiesReportGuard], component: TechnologyReportComponent }, { path: '', pathMatch: 'full', redirectTo: 'time-clock' }, ], }, diff --git a/src/app/guards/technologies-report-guard/technologies-report.guard.spec.ts b/src/app/guards/technologies-report-guard/technologies-report.guard.spec.ts deleted file mode 100644 index 06a2ced97..000000000 --- a/src/app/guards/technologies-report-guard/technologies-report.guard.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { inject, TestBed } from '@angular/core/testing'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; -import { Observable, of } from 'rxjs'; -import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service'; -import { TechnologiesReportGuard } from './technologies-report.guard'; - -describe('TechnologiesReportGuard', () => { - - let technologiesReportGuard: TechnologiesReportGuard; - let featureManagerService: FeatureManagerService; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [ RouterTestingModule ] - }); - technologiesReportGuard = TestBed.inject(TechnologiesReportGuard); - featureManagerService = TestBed.inject(FeatureManagerService); - }); - - it('should be created', () => { - expect(technologiesReportGuard).toBeTruthy(); - }); - - it('can activate the route when feature is enabled for user', () => { - spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(true)); - - const canActivate: Observable = technologiesReportGuard.canActivate(); - - expect(featureManagerService.isToggleEnabledForUser).toHaveBeenCalled(); - canActivate.subscribe(value => expect(value).toEqual(true)); - }); - - it('can not active the route and is redirected to home if feature is not enabled for user', inject([Router], (router: Router) => { - spyOn(featureManagerService, 'isToggleEnabledForUser').and.returnValue(of(false)); - spyOn(router, 'navigate').and.stub(); - - const canActivate: Observable = technologiesReportGuard.canActivate(); - - expect(featureManagerService.isToggleEnabledForUser).toHaveBeenCalled(); - canActivate.subscribe(value => expect(value).toEqual(false)); - expect(router.navigate).toHaveBeenCalledWith(['']); - })); - -}); diff --git a/src/app/guards/technologies-report-guard/technologies-report.guard.ts b/src/app/guards/technologies-report-guard/technologies-report.guard.ts deleted file mode 100644 index 101c986e0..000000000 --- a/src/app/guards/technologies-report-guard/technologies-report.guard.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Router, CanActivate } from '@angular/router'; -import { map } from 'rxjs/operators'; -import { FeatureManagerService } from 'src/app/modules/shared/feature-toggles/feature-toggle-manager.service'; - -@Injectable({ - providedIn: 'root' -}) -export class TechnologiesReportGuard implements CanActivate { - - constructor( - private featureManagerService: FeatureManagerService, - private router: Router - ) { } - - canActivate() { - return this.featureManagerService - .isToggleEnabledForUser('ui-list-technologies') - .pipe(map((enabled) => { - if (enabled === true) { - return true; - } else { - this.router.navigate(['']); - return false; - } - })); - } -} diff --git a/src/app/modules/shared/components/sidebar/sidebar.component.spec.ts b/src/app/modules/shared/components/sidebar/sidebar.component.spec.ts index dea142b49..57a9402b1 100644 --- a/src/app/modules/shared/components/sidebar/sidebar.component.spec.ts +++ b/src/app/modules/shared/components/sidebar/sidebar.component.spec.ts @@ -5,14 +5,12 @@ import { RouterTestingModule } from '@angular/router/testing'; import { Router, Routes } from '@angular/router'; import { TimeClockComponent } from '../../../time-clock/pages/time-clock.component'; import { of } from 'rxjs'; -import { FeatureManagerService } from '../../feature-toggles/feature-toggle-manager.service'; import { UserInfoService } from 'src/app/modules/user/services/user-info.service'; describe('SidebarComponent', () => { let component: SidebarComponent; let fixture: ComponentFixture; let azureAdB2CServiceStubInjected; - let featureManagerServiceStubInjected: FeatureManagerService; let userInfoService: UserInfoService; let router; const routes: Routes = [{ path: 'time-clock', component: TimeClockComponent }]; @@ -47,7 +45,6 @@ describe('SidebarComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(SidebarComponent); azureAdB2CServiceStubInjected = TestBed.inject(AzureAdB2CService); - featureManagerServiceStubInjected = TestBed.inject(FeatureManagerService); userInfoService = TestBed.inject(UserInfoService); component = fixture.componentInstance; fixture.detectChanges(); @@ -86,21 +83,4 @@ describe('SidebarComponent', () => { }); }); - it('List Technologies item is added when feature flag "ui-list-technologies" is enabled for user', () => { - spyOn(featureManagerServiceStubInjected, 'isToggleEnabledForUser').and.returnValue(of(true)); - const itemsSidebar = []; - - component.toggleListTechnologies(itemsSidebar); - - expect(itemsSidebar.length).toBe(1); - }); - - it('List Technologies item is not added when feature flag "ui-list-technologies" is disabled for user', () => { - spyOn(featureManagerServiceStubInjected, 'isToggleEnabledForUser').and.returnValue(of(false)); - const itemsSidebar = []; - - component.toggleListTechnologies(itemsSidebar); - - expect(itemsSidebar.length).toBe(0); - }); }); diff --git a/src/app/modules/shared/components/sidebar/sidebar.component.ts b/src/app/modules/shared/components/sidebar/sidebar.component.ts index fdf51422f..6d733d0fc 100644 --- a/src/app/modules/shared/components/sidebar/sidebar.component.ts +++ b/src/app/modules/shared/components/sidebar/sidebar.component.ts @@ -3,7 +3,6 @@ import { ItemSidebar } from './models/item-sidebar.model'; import { NavigationStart, Router } from '@angular/router'; import { Observable, Subscription } from 'rxjs'; import { filter, map } from 'rxjs/operators'; -import { FeatureManagerService } from '../../feature-toggles/feature-toggle-manager.service'; import { UserInfoService } from 'src/app/modules/user/services/user-info.service'; @Component({ @@ -19,7 +18,6 @@ export class SidebarComponent implements OnInit, OnDestroy { constructor( private router: Router, private userInfoService: UserInfoService, - private featureManagerService: FeatureManagerService, ) { this.navStart = this.router.events.pipe( filter((evt) => evt instanceof NavigationStart) @@ -29,7 +27,6 @@ export class SidebarComponent implements OnInit, OnDestroy { ngOnInit(): void { this.toggleSideBar(); this.sidebarItems$ = this.getSidebarItems().subscribe(); - this.toggleListTechnologies(this.itemsSidebar); this.highlightMenuOption(this.router.routerState.snapshot.url); this.navStart.subscribe((evt) => { this.highlightMenuOption(evt.url); @@ -68,22 +65,6 @@ export class SidebarComponent implements OnInit, OnDestroy { ); } - toggleListTechnologies(itemsSidebar: ItemSidebar[]) { - this.featureManagerService - .isToggleEnabledForUser('ui-list-technologies') - .subscribe((enabled) => { - if (enabled === true) { - const listTechnologiesItem = { - route: '/technology-report', - icon: 'fas fa-user', - text: 'Technology Report', - active: false, - }; - itemsSidebar.push(listTechnologiesItem); - } - }); - } - highlightMenuOption(route) { this.itemsSidebar.map((item) => (item.active = false)); this.itemsSidebar.filter((item) => item.route === route).map((item) => (item.active = true)); diff --git a/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts b/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts index 72339a2cd..6150e75d2 100644 --- a/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts +++ b/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.spec.ts @@ -1,4 +1,3 @@ -import { FeatureToggle } from './../../../../../environments/enum'; import { TestBed } from '@angular/core/testing'; import { of } from 'rxjs'; import { FeatureManagerService } from '../feature-toggle-manager.service'; @@ -23,18 +22,6 @@ describe('FeatureToggleGeneralService', () => { expect(featureToggleGeneralService).toBeTruthy(); }); - const params = [{ bool: false }, { bool: true }]; - params.map((param) => { - it(`isActivated should return a boolean ${param.bool}`, () => { - const toggleName = FeatureToggle.SWITCH_GROUP; - featureManagerService.isToggleEnabledForUser = () => of(param.bool); - - featureToggleGeneralService.isActivated(toggleName).subscribe((enabled) => { - expect(enabled).toBe(param.bool); - }); - }); - }); - it('getActivated return a FeatureToggleModel', () => { const anyNotMatchingFilter = new TargetingFeatureFilterModel( { Audience: { Groups: ['a-group'], Users: ['user-a'] } }, diff --git a/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.ts b/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.ts index f73507733..921f2f607 100644 --- a/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.ts +++ b/src/app/modules/shared/feature-toggles/feature-toggle-general/feature-toggle-general.service.ts @@ -1,5 +1,3 @@ -import { map } from 'rxjs/operators'; -import { FeatureToggle } from './../../../../../environments/enum'; import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { FeatureManagerService } from '../feature-toggle-manager.service'; @@ -11,10 +9,6 @@ import { FeatureToggleModel } from '../feature-toggle.model'; export class FeatureToggleGeneralService { constructor(private featureManagerService: FeatureManagerService) {} - isActivated(featureToggle: FeatureToggle): Observable { - return this.featureManagerService.isToggleEnabledForUser(featureToggle); - } - getActivated(): Observable{ return this.featureManagerService.getAllFeatureToggleEnableForUser(); } diff --git a/src/app/modules/shared/feature-toggles/feature-toggle-manager.service.spec.ts b/src/app/modules/shared/feature-toggles/feature-toggle-manager.service.spec.ts index 8730168ab..4bdb2859b 100644 --- a/src/app/modules/shared/feature-toggles/feature-toggle-manager.service.spec.ts +++ b/src/app/modules/shared/feature-toggles/feature-toggle-manager.service.spec.ts @@ -9,8 +9,6 @@ import { TargetingFeatureFilterModel } from './filters/targeting/targeting-featu describe('FeatureToggleManager', () => { - const featureToggleKey = 'foo'; - const featureToggleLabel = 'dev'; const fakeAppConfigurationConnectionString = 'Endpoint=http://fake.foo;Id=fake.id;Secret=fake.secret'; const aFeatureToggle = new FeatureToggleModel('any-id', true, []); let service: FeatureManagerService; @@ -26,18 +24,6 @@ describe('FeatureToggleManager', () => { spyOn(fakeFeatureToggleProvider, 'getFeatureToggle').and.returnValue(of(aFeatureToggle)); service = new FeatureManagerService(fakeFeatureToggleProvider); }); - it('manager uses feature provider to build feature toggle model', async () => { - service.isToggleEnabled(featureToggleKey, featureToggleLabel).subscribe((value) => { - - expect(fakeFeatureToggleProvider).toHaveBeenCalledWith(featureToggleKey, featureToggleLabel); - }); - }); - - it('manager extracts enabled attribute from feature toggle model', async () => { - service.isToggleEnabled(featureToggleKey, featureToggleLabel).subscribe((value) => { - expect(value).toEqual(aFeatureToggle.enabled); - }); - }); }); @@ -52,7 +38,6 @@ describe('FeatureToggleManager', () => { ); let aToggleWithFilters; - let getFeatureToggleSpy; beforeEach(() => { aToggleWithFilters = new FeatureToggleModel('any-other-id', true, [anyMatchingFilter]); @@ -60,21 +45,7 @@ describe('FeatureToggleManager', () => { new AppConfigurationClient(fakeAppConfigurationConnectionString), new FeatureFilterProvider(new AzureAdB2CService()) ); - getFeatureToggleSpy = spyOn(fakeFeatureToggleProvider, 'getFeatureToggle').and.returnValue(of(aToggleWithFilters)); service = new FeatureManagerService(fakeFeatureToggleProvider); - spyOn(service, 'isToggleEnabled').and.returnValue(of(true)); - }); - - it('manager uses feature provider to build feature toggle model', async () => { - service.isToggleEnabledForUser(featureToggleKey, featureToggleLabel).subscribe((value) => { - expect(getFeatureToggleSpy).toHaveBeenCalledWith(featureToggleKey, featureToggleLabel); - }); - }); - - it('given a feature toggle with filters which match the verification, then the response is true', async () => { - service.isToggleEnabledForUser(featureToggleKey, featureToggleLabel).subscribe((value) => { - expect(value).toEqual(true); - }); }); it('given a feature toggle with filters which do not match the verification, then the response is false', async () => { @@ -87,9 +58,6 @@ describe('FeatureToggleManager', () => { spyOn(fakeFeatureToggleProvider, 'getFeatureToggle').and.returnValue(of(aToggleWithFilters)); service = new FeatureManagerService(fakeFeatureToggleProvider); - service.isToggleEnabledForUser(featureToggleKey, featureToggleLabel).subscribe((value) => { - expect(value).toEqual(false); - }); }); it('Get empty when getAllFeatureToggle() return empty', () => { diff --git a/src/app/modules/shared/feature-toggles/feature-toggle-manager.service.ts b/src/app/modules/shared/feature-toggles/feature-toggle-manager.service.ts index 68f4770fb..b4f3360a6 100644 --- a/src/app/modules/shared/feature-toggles/feature-toggle-manager.service.ts +++ b/src/app/modules/shared/feature-toggles/feature-toggle-manager.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { from, Observable, zip } from 'rxjs'; +import { from, Observable} from 'rxjs'; import { map } from 'rxjs/operators'; import { FeatureToggleProvider } from './feature-toggle-provider.service'; import { FeatureToggleModel } from './feature-toggle.model'; @@ -11,31 +11,6 @@ export class FeatureManagerService { constructor(private featureToggleProvider: FeatureToggleProvider) { } - public isToggleEnabled(toggleName: string, toggleLabel?: string): Observable { - return this.featureToggleProvider - .getFeatureToggle(toggleName, toggleLabel) - .pipe(map((featureToggle) => featureToggle.enabled)); - } - - public isToggleEnabledForUser(toggleName: string, toggleLabel?: string): Observable { - const matchesFilters$: Observable = this.featureToggleProvider - .getFeatureToggle(toggleName, toggleLabel) - .pipe( - map(featureToggle => featureToggle.filters), - map(filters => filters.map(filter => filter.evaluate())), - map(filterEvaluations => filterEvaluations.includes(true)) - ); - - const result$: Observable = zip( - this.isToggleEnabled(toggleName, toggleLabel), - matchesFilters$ - ).pipe( - map(([enabled, enabledForUser]) => enabled && enabledForUser) - ); - - return result$; - } - public getAllFeatureToggleEnableForUser(): Observable { return from(this.featureToggleProvider.getAllFeatureToggle()).pipe( map((allFeatureToggle) => diff --git a/src/app/modules/time-entries/components/calendar/calendar.component.spec.ts b/src/app/modules/time-entries/components/calendar/calendar.component.spec.ts index 3a1db6cc0..bf27672d7 100644 --- a/src/app/modules/time-entries/components/calendar/calendar.component.spec.ts +++ b/src/app/modules/time-entries/components/calendar/calendar.component.spec.ts @@ -198,10 +198,10 @@ describe('CalendarComponent', () => { }); it('emit current date and call navigationEnable when call handleChangeDateEvent', () => { + const calendarView: CalendarView = CalendarView.Month; const fakeValueEmit = { - date: currentDate.toDate(), + date: currentDate.toDate() }; - const calendarView = CalendarView.Month; spyOn(component, 'navigationEnable'); spyOn(component.changeDate, 'emit'); spyOn(component, 'isVisibleForCurrentDate'); @@ -221,6 +221,14 @@ describe('CalendarComponent', () => { expect(component.calendarView).toEqual(fakeCalendarView); }); + it('emit calendarView Day when call changeCalendarView', () => { + const fakeCalendarView: CalendarView = CalendarView.Day; + component.calendarView = CalendarView.Month; + spyOn(component.changeView, 'emit'); + component.changeCalendarView(fakeCalendarView); + expect(component.changeView.emit).toHaveBeenCalledWith({ calendarView: fakeCalendarView }); + }); + it('set srcoll to current time marker in calendarView when is call scrollToCurrentTimeMarker', () => { const fakeCalendarView: CalendarView = CalendarView.Week; spyOn(component, 'scrollToCurrentTimeMarker'); @@ -257,7 +265,7 @@ describe('CalendarComponent', () => { it('set true in nextDateDisabled when call navigationEnable and calendarView == Month and currentDate equal to initialDate', () => { component.currentDate = moment().toDate(); - component.initialDate = moment().add(2, 'day').toDate(); + component.initialDate = moment().toDate(); component.navigationEnable(CalendarView.Month); diff --git a/src/app/modules/time-entries/components/calendar/calendar.component.ts b/src/app/modules/time-entries/components/calendar/calendar.component.ts index 2a2cf9ac1..594946ad6 100644 --- a/src/app/modules/time-entries/components/calendar/calendar.component.ts +++ b/src/app/modules/time-entries/components/calendar/calendar.component.ts @@ -44,6 +44,9 @@ export class CalendarComponent implements OnInit { @Output() changeDate: EventEmitter = new EventEmitter<{ date: Date; }>(); + @Output() changeView: EventEmitter = new EventEmitter<{ + calendarView: CalendarView; + }>(); initialDate: Date; previusDate: Date; @@ -119,6 +122,7 @@ export class CalendarComponent implements OnInit { this.referenceChangeDetector.detectChanges(); this.scrollToCurrentTimeMarker(); } + this.changeView.emit({ calendarView }); } navigationEnable(calendarView: CalendarView) { diff --git a/src/app/modules/time-entries/pages/time-entries.component.html b/src/app/modules/time-entries/pages/time-entries.component.html index 17aecac39..7689bd59e 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.html +++ b/src/app/modules/time-entries/pages/time-entries.component.html @@ -32,7 +32,9 @@ *ngIf="!dataSource.isLoading" [timeEntries$]="timeEntriesDataSource$" [currentDate]="selectedDate.toDate()" + [calendarView]="calendarView" (changeDate)="changeDate($event)" + (changeView)="changeView($event)" (viewModal)="editEntry($event.id)" (deleteTimeEntry)="openModal($event.timeEntry)" > diff --git a/src/app/modules/time-entries/pages/time-entries.component.spec.ts b/src/app/modules/time-entries/pages/time-entries.component.spec.ts index 2406a1a59..8f87089db 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.spec.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.spec.ts @@ -21,6 +21,7 @@ import { NgxMaterialTimepickerModule } from 'ngx-material-timepicker'; import { CookieService } from 'ngx-cookie-service'; import { DebugElement } from '@angular/core'; import { FeatureToggle } from './../../../../environments/enum'; +import { CalendarView } from 'angular-calendar'; import * as moment from 'moment'; describe('TimeEntriesComponent', () => { @@ -560,6 +561,7 @@ describe('TimeEntriesComponent', () => { const dateMoment: moment.Moment = moment().month(monthIndex).year(year); jasmine.clock().mockDate(dateMoment.toDate()); + component.actualDate.setMonth(monthIndex); component.dateSelected(eventData); expect(component.selectedDate).toEqual(dateMoment); @@ -569,7 +571,7 @@ describe('TimeEntriesComponent', () => { const incomingDate = new Date('2021-06-07'); const incomingMoment: moment.Moment = moment(incomingDate); const eventData = { - date: incomingDate, + date: incomingDate }; spyOn(component, 'dateSelected'); component.selectedDate = moment(incomingMoment).subtract(1, 'day'); @@ -584,7 +586,7 @@ describe('TimeEntriesComponent', () => { const incomingDate = new Date('2021-01-07'); const incomingMoment: moment.Moment = moment(incomingDate); const eventData = { - date: incomingDate, + date: incomingDate }; const selectedDate = { monthIndex: incomingMoment.month(), @@ -598,6 +600,37 @@ describe('TimeEntriesComponent', () => { expect(component.dateSelected).toHaveBeenCalledWith(selectedDate); }); + it('change component selectedDate to be the first day of the month when call dateSelected', () => { + const actualDate: Date = new Date(2021, 5, 15); + const selectedDate: Date = new Date(2021, 2, 1); + const eventDate = { + monthIndex: selectedDate.getMonth(), + year: selectedDate.getFullYear() + }; + component.actualDate = actualDate; + component.dateSelected(eventDate); + expect(component.selectedDate.date()).toBe(selectedDate.getDate()); + }); + + it('change component calendarView from Month to Day when call changeView', () => { + const fakeCalendarView: CalendarView = CalendarView.Day; + const eventView = { + calendarView: fakeCalendarView + }; + component.calendarView = CalendarView.Month; + component.changeView(eventView); + expect(component.calendarView).toBe(fakeCalendarView); + }); + + it('change component calendarView to Month if undefined when call changeView', () => { + component.calendarView = CalendarView.Week; + const eventView = { + calendarView: undefined + }; + component.changeView(eventView); + expect(component.calendarView).toBe(CalendarView.Month); + }); + it('not view button onDisplayModeChange when isFeatureToggleCalendarActive is false', () => { component.isFeatureToggleCalendarActive = false; diff --git a/src/app/modules/time-entries/pages/time-entries.component.ts b/src/app/modules/time-entries/pages/time-entries.component.ts index 52c4b4976..c8e7b4660 100644 --- a/src/app/modules/time-entries/pages/time-entries.component.ts +++ b/src/app/modules/time-entries/pages/time-entries.component.ts @@ -14,6 +14,7 @@ import { EntryActionTypes } from './../../time-clock/store/entry.actions'; import { getActiveTimeEntry, getTimeEntriesDataSource } from './../../time-clock/store/entry.selectors'; import { CookieService } from 'ngx-cookie-service'; import { FeatureToggle } from './../../../../environments/enum'; +import { CalendarView } from 'angular-calendar'; @Component({ selector: 'app-time-entries', templateUrl: './time-entries.component.html', @@ -38,6 +39,8 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { selectedYear: number; selectedMonthAsText: string; isActiveEntryOverlapping = false; + calendarView: CalendarView = CalendarView.Month; + actualDate: Date; readonly NO_DATA_MESSAGE: string = 'No data available in table'; constructor( private store: Store, @@ -46,6 +49,7 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { private cookiesService: CookieService) { this.displayGridView = false; this.selectedDate = moment(new Date()); + this.actualDate = new Date(); this.timeEntriesDataSource$ = this.store.pipe(delay(0), select(getTimeEntriesDataSource)); } ngOnDestroy(): void { @@ -180,6 +184,9 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { this.selectedMonthAsText = moment().month(event.monthIndex).format('MMMM'); this.store.dispatch(new entryActions.LoadEntries(this.selectedMonth, this.selectedYear)); this.selectedDate = moment().month(event.monthIndex).year(event.year); + if (this.actualDate.getMonth() !== event.monthIndex){ + this.selectedDate = this.selectedDate.startOf('month'); + } } changeDate(event: { date: Date }){ @@ -196,6 +203,10 @@ export class TimeEntriesComponent implements OnInit, OnDestroy { this.selectedDate = newDate; } + changeView(event: { calendarView: CalendarView }){ + this.calendarView = event.calendarView || CalendarView.Month; + } + openModal(item: any) { this.idToDelete = item.id; this.message = `Are you sure you want to delete ${item.activity_name}?`;