|
|
|
@ -3,7 +3,6 @@ import { |
|
|
|
|
Component, |
|
|
|
|
ElementRef, |
|
|
|
|
Injector, |
|
|
|
|
OnInit, |
|
|
|
|
ViewChild, |
|
|
|
|
} from '@angular/core'; |
|
|
|
|
import { BannersService } from 'core-app/core/enterprise/banners.service'; |
|
|
|
@ -11,20 +10,14 @@ import { I18nService } from 'core-app/core/i18n/i18n.service'; |
|
|
|
|
import { OpModalService } from '../modal/modal.service'; |
|
|
|
|
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service'; |
|
|
|
|
import { populateInputsFromDataset } from 'core-app/shared/components/dataset-inputs'; |
|
|
|
|
import { FullCalendarComponent } from '@fullcalendar/angular'; |
|
|
|
|
import { |
|
|
|
|
CalendarOptions, |
|
|
|
|
DayCellMountArg, |
|
|
|
|
DayHeaderMountArg, |
|
|
|
|
Duration, |
|
|
|
|
EventApi, |
|
|
|
|
EventInput, |
|
|
|
|
CalendarOptions, |
|
|
|
|
} from '@fullcalendar/core'; |
|
|
|
|
import listPlugin from '@fullcalendar/list'; |
|
|
|
|
import { CollectionResource } from 'core-app/features/hal/resources/collection-resource'; |
|
|
|
|
import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource'; |
|
|
|
|
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service'; |
|
|
|
|
import { FullCalendarComponent } from '@fullcalendar/angular'; |
|
|
|
|
import { DayResourceService } from 'core-app/core/state/days/day.service'; |
|
|
|
|
import { DayResourceService } from 'core-app/core/state/days/day.service'; |
|
|
|
|
import { IDay } from 'core-app/core/state/days/day.model'; |
|
|
|
|
|
|
|
|
|
export const listCalendarSelector = 'op-list-calendar'; |
|
|
|
@ -35,14 +28,11 @@ export const listCalendarSelector = 'op-list-calendar'; |
|
|
|
|
styleUrls: ['./op-list-calendar.component.sass'], |
|
|
|
|
templateUrl: './op-list-calendar.component.html', |
|
|
|
|
}) |
|
|
|
|
export class OpListCalendarComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
export class OpListCalendarComponent { |
|
|
|
|
@ViewChild(FullCalendarComponent) ucCalendar:FullCalendarComponent; |
|
|
|
|
|
|
|
|
|
protected memoizedTimeEntries:{ start:Date, end:Date, entries:Promise<CollectionResource<TimeEntryResource>> }; |
|
|
|
|
|
|
|
|
|
calendarOptions:CalendarOptions = { |
|
|
|
|
|
|
|
|
|
plugins: [ listPlugin ], |
|
|
|
|
plugins: [listPlugin], |
|
|
|
|
initialView: 'listYear', |
|
|
|
|
editable: false, |
|
|
|
|
fixedWeekCount: false, |
|
|
|
@ -52,10 +42,12 @@ export class OpListCalendarComponent implements OnInit { |
|
|
|
|
center: '', |
|
|
|
|
left: 'title', |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
|
|
|
events: this.calendarEventsFunction.bind(this), |
|
|
|
|
}; |
|
|
|
|
nonWorkingDays : IDay[]; |
|
|
|
|
|
|
|
|
|
nonWorkingDays:IDay[]; |
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
readonly elementRef:ElementRef, |
|
|
|
|
protected I18n:I18nService, |
|
|
|
@ -69,30 +61,25 @@ export class OpListCalendarComponent implements OnInit { |
|
|
|
|
populateInputsFromDataset(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ngOnInit():void { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public calendarEventsFunction( |
|
|
|
|
fetchInfo:{ start:Date }, |
|
|
|
|
successCallback:(events:EventInput[]) => void, |
|
|
|
|
failureCallback:(error:unknown) => void, |
|
|
|
|
):void|PromiseLike<EventInput[]> { |
|
|
|
|
const today = moment().startOf('day').toDate(); |
|
|
|
|
this.dayService.requireNonWorkingYear$(today).toPromise() |
|
|
|
|
.then((collection) => { |
|
|
|
|
|
|
|
|
|
successCallback(this.mapToCalendarEvents(collection)); |
|
|
|
|
}) |
|
|
|
|
.catch(failureCallback); |
|
|
|
|
this.dayService.requireNonWorkingYear$(fetchInfo.start) |
|
|
|
|
.subscribe( |
|
|
|
|
(days:IDay[]) => { |
|
|
|
|
const events = this.mapToCalendarEvents(days); |
|
|
|
|
successCallback(events); |
|
|
|
|
}, |
|
|
|
|
failureCallback, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private mapToCalendarEvents(nonWorkingDays:IDay[]) { |
|
|
|
|
return nonWorkingDays.map((NWD:IDay) => { |
|
|
|
|
return { |
|
|
|
|
title: NWD.name, |
|
|
|
|
start: NWD.date, |
|
|
|
|
}; |
|
|
|
|
}).filter((event) => !!event) as EventInput[]; |
|
|
|
|
return nonWorkingDays.map((NWD:IDay) => ({ |
|
|
|
|
title: NWD.name, |
|
|
|
|
start: NWD.date, |
|
|
|
|
})).filter((event) => !!event) as EventInput[]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|