Load non working days during initialization

pull/11928/head
Oliver Günther 2 years ago
parent fdcce2bca9
commit 542ddbfdc2
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 8
      frontend/src/app/core/state/days/day.service.ts
  2. 6
      frontend/src/app/features/calendar/op-calendar.service.ts
  3. 30
      frontend/src/app/features/calendar/op-work-packages-calendar.service.ts
  4. 4
      frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts
  5. 20
      frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts
  6. 12
      frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts

@ -43,13 +43,7 @@ export class DayResourceService extends ResourceCollectionService<IDay> {
);
}
public isNonWorkingDay(date:Date):boolean {
let isNonWorkingDay = false;
this.isNonWorkingDay$(date).subscribe((isNonWorking) => { isNonWorkingDay = isNonWorking; });
return isNonWorkingDay;
}
requireNonWorkingYear$(date:Date):Observable<IDay[]> {
requireNonWorkingYear$(date:Date|string):Observable<IDay[]> {
const from = moment(date).startOf('year').format('YYYY-MM-DD');
const to = moment(date).endOf('year').format('YYYY-MM-DD');

@ -6,6 +6,7 @@ import { Subject } from 'rxjs';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { WeekdayService } from 'core-app/core/days/weekday.service';
import { DayResourceService } from 'core-app/core/state/days/day.service';
import { IDay } from 'core-app/core/state/days/day.model';
@Injectable()
export class OpCalendarService extends UntilDestroyedMixin {
@ -32,8 +33,9 @@ export class OpCalendarService extends UntilDestroyedMixin {
this.resizeObs.observe(v.nativeElement);
}
applyNonWorkingDay({ date }:{ date?:Date }):string[] {
if (date && (this.weekdayService.isNonWorkingDay(date) || this.dayService.isNonWorkingDay(date))) {
applyNonWorkingDay({ date }:{ date?:Date }, nonWorkingDays:IDay[]):string[] {
const formatted = moment(date).format('YYYY-MM-DD');
if (date && (this.weekdayService.isNonWorkingDay(date) || nonWorkingDays.find((el) => !el.working && el.date === formatted))) {
return ['fc-non-working-day'];
}

@ -72,7 +72,7 @@ export class OpWorkPackagesCalendarService extends UntilDestroyedMixin {
tooManyResultsText:string|null;
public nonWorkigDays:IDay[];
public nonWorkingDays:IDay[] = [];
currentWorkPackages$:Observable<WorkPackageCollectionResource> = this
.querySpace
@ -153,11 +153,20 @@ export class OpWorkPackagesCalendarService extends UntilDestroyedMixin {
}
}
async requireNonWorkingDays(date:Date|string) {
this.nonWorkingDays = await this
.dayService
.requireNonWorkingYear$(date)
.pipe(take(1))
.toPromise();
}
async updateTimeframe(
fetchInfo:{ start:Date, end:Date, timeZone:string },
projectIdentifier:string|undefined,
nonWorkigDays: IDay[],
):Promise<unknown> {
await this.requireNonWorkingDays(fetchInfo.start);
if (this.areFiltersEmpty && this.querySpace.query.value) {
// nothing to do
@ -228,14 +237,11 @@ export class OpWorkPackagesCalendarService extends UntilDestroyedMixin {
this.wpListChecksumService.set(queryId, queryProps);
}
const nwds =
this.dayService.requireNonWorkingYear$(fetchInfo.start).toPromise();
return Promise.all([this
.wpListService
.fromQueryParams({ query_id: queryId, query_props: queryProps, }, projectIdentifier || undefined, this.nonWorkigDays)
.fromQueryParams({ query_id: queryId, query_props: queryProps, }, projectIdentifier || undefined)
.toPromise(),
nwds
])
])
}
public generateQueryProps(
@ -356,11 +362,11 @@ export class OpWorkPackagesCalendarService extends UntilDestroyedMixin {
initialDate: this.initialDate,
initialView: this.initialView,
datesSet: (dates) => this.updateDateParam(dates),
dayHeaderClassNames: (data:DayHeaderContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkigDays),
dayCellClassNames: (data:DayCellContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkigDays),
dayGridClassNames: (data:DayCellContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkigDays),
slotLaneClassNames: (data:SlotLaneContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkigDays),
slotLabelClassNames: (data:SlotLabelContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkigDays),
dayHeaderClassNames: (data:DayHeaderContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkingDays),
dayCellClassNames: (data:DayCellContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkingDays),
dayGridClassNames: (data:DayCellContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkingDays),
slotLaneClassNames: (data:SlotLaneContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkingDays),
slotLabelClassNames: (data:SlotLabelContentArg) => this.calendarService.applyNonWorkingDay(data, this.nonWorkingDays),
};
}

@ -156,8 +156,8 @@ export class TimeEntryCalendarComponent {
eventClick: this.dispatchEventClick.bind(this),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
eventDrop: this.moveEvent.bind(this),
dayHeaderClassNames: (data:DayHeaderMountArg) => this.calendar.applyNonWorkingDay(data),
dayCellClassNames: (data:DayCellMountArg) => this.calendar.applyNonWorkingDay(data),
dayHeaderClassNames: (data:DayHeaderMountArg) => this.calendar.applyNonWorkingDay(data, []),
dayCellClassNames: (data:DayCellMountArg) => this.calendar.applyNonWorkingDay(data, []),
};
constructor(

@ -150,8 +150,12 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
this.initializeCalendar();
}
public calendarEventsFunction(fetchInfo:{ start:Date, end:Date, timeZone:string },
successCallback:(events:EventInput[]) => void):void|PromiseLike<EventInput[]> {
public async calendarEventsFunction(
fetchInfo:{ start:Date, end:Date, timeZone:string },
successCallback:(events:EventInput[]) => void,
):Promise<void> {
await this.workPackagesCalendar.updateTimeframe(fetchInfo, this.currentProject.identifier || undefined);
if (this.alreadyLoaded) {
this.alreadyLoaded = false;
const events = this.updateResults(this.querySpace.results.value!);
@ -165,8 +169,6 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
successCallback(events);
});
}
void this.workPackagesCalendar.updateTimeframe(fetchInfo, this.currentProject.identifier || undefined);
}
// eslint-disable-next-line @angular-eslint/use-lifecycle-interface
@ -215,8 +217,7 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
const due = moment(resizeInfo.event.endStr).subtract(1, 'day').toDate();
const start = moment(resizeInfo.event.startStr).toDate();
const wp = resizeInfo.event.extendedProps.workPackage as WorkPackageResource;
if (!wp.ignoreNonWorkingDays && (this.weekdayService.isNonWorkingDay(start) || this.weekdayService.isNonWorkingDay(due)
|| this.dayService.isNonWorkingDay(start) || this.dayService.isNonWorkingDay(due))) {
if (!wp.ignoreNonWorkingDays && (this.weekdayService.isNonWorkingDay(start) || this.weekdayService.isNonWorkingDay(due))) {
this.toastService.addError(this.text.cannot_drag_to_non_working_day);
resizeInfo?.revert();
return;
@ -226,7 +227,7 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
eventDrop: (dropInfo:EventDropArg) => {
const start = moment(dropInfo.event.startStr).toDate();
const wp = dropInfo.event.extendedProps.workPackage as WorkPackageResource;
if (!wp.ignoreNonWorkingDays && (this.weekdayService.isNonWorkingDay(start) || this.dayService.isNonWorkingDay(start))) {
if (!wp.ignoreNonWorkingDays && (this.weekdayService.isNonWorkingDay(start))) {
this.toastService.addError(this.text.cannot_drag_to_non_working_day);
dropInfo?.revert();
return;
@ -347,8 +348,7 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
private handleDateClicked(info:DateSelectArg) {
const due = moment(info.endStr).subtract(1, 'day').toDate();
const nonWorkingDays = this.weekdayService.isNonWorkingDay(info.start) || this.weekdayService.isNonWorkingDay(due)
|| this.dayService.isNonWorkingDay(info.start) || this.dayService.isNonWorkingDay(due);
const nonWorkingDays = this.weekdayService.isNonWorkingDay(info.start) || this.weekdayService.isNonWorkingDay(due);
const defaults = {
startDate: info.startStr,
@ -381,7 +381,7 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
const nonWorkingDays = new Array<{ start:Date|string, end:Date|string }>();
while (currentStartDate.toString() !== currentEndDate.toString()) {
if (this.weekdayService.isNonWorkingDay(currentStartDate) || this.dayService.isNonWorkingDay(currentStartDate)) {
if (this.weekdayService.isNonWorkingDay(currentStartDate)) {
nonWorkingDays.push({
start: moment(currentStartDate).format('YYYY-MM-DD'),
end: moment(currentStartDate).add('1', 'day').format('YYYY-MM-DD'),

@ -114,11 +114,11 @@ import { ICapability } from 'core-app/core/state/capabilities/capability.model';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { LoadingIndicatorService } from 'core-app/core/loading-indicator/loading-indicator.service';
import { OpWorkPackagesCalendarService } from 'core-app/features/calendar/op-work-packages-calendar.service';
import { DeviceService } from 'core-app/core/browser/device.service';
import { WeekdayService } from 'core-app/core/days/weekday.service';
import { RawOptionsFromRefiners } from '@fullcalendar/core/internal';
import { ViewOptionRefiners } from '@fullcalendar/common';
import { ResourceApi } from '@fullcalendar/resource';
import { DeviceService } from 'core-app/core/browser/device.service';
export type TeamPlannerViewOptionKey = 'resourceTimelineWorkWeek'|'resourceTimelineWeek'|'resourceTimelineTwoWeeks';
export type TeamPlannerViewOptions = { [K in TeamPlannerViewOptionKey]:RawOptionsFromRefiners<Required<ViewOptionRefiners>> };
@ -473,7 +473,8 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
void Promise.all([
this.configuration.initialized,
this.weekdayService.loadWeekdays().toPromise(),
])
this.workPackagesCalendar.requireNonWorkingDays(new Date()),
])
.then(() => {
this.calendarOptions$.next(
this.workPackagesCalendar.calendarOptions({
@ -584,11 +585,13 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
});
}
public calendarEventsFunction(
public async calendarEventsFunction(
fetchInfo:{ start:Date, end:Date, timeZone:string },
successCallback:(events:EventInput[]) => void,
failureCallback:(error:unknown) => void,
):void|PromiseLike<EventInput[]> {
):Promise<void> {
await this.workPackagesCalendar.updateTimeframe(fetchInfo, this.projectIdentifier);
this
.workPackagesCalendar
.currentWorkPackages$
@ -610,7 +613,6 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
failureCallback,
);
void this.workPackagesCalendar.updateTimeframe(fetchInfo, this.projectIdentifier);
}
public switchView(key:TeamPlannerViewOptionKey):void {

Loading…
Cancel
Save