Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Load query only when a query is actually present Use observable for calendar options to trigger automatic change detection

Henriette Dargeacfcb0e9ceaa
diff --git a/frontend/src/app/features/calendar/op-calendar.service.ts b/frontend/src/app/features/calendar/op-calendar.service.ts
index 7c4b8433b18..b97953cb1e7 100644
--- a/frontend/src/app/features/calendar/op-calendar.service.ts
+++ b/frontend/src/app/features/calendar/op-calendar.service.ts
@@ -254,6 +254,11 @@ export class OpCalendarService extends UntilDestroyedMixin {
private openSplitView(event:EventClickArg) {
const workPackage = event.event.extendedProps.workPackage as WorkPackageResource;
+ if (event.el) {
+ // do not display the tooltip on the wp show page
+ this.removeTooltip(event.el);
+ }
+
void this.$state.go(
`${splitViewRoute(this.$state)}.tabs`,
{ workPackageId: workPackage.id, tabIdentifier: 'overview' },
diff --git a/frontend/src/app/features/calendar/wp-calendar-page/wp-calendar-page.component.ts b/frontend/src/app/features/calendar/wp-calendar-page/wp-calendar-page.component.ts
index ff1d2d6154e..d44b0221cf5 100644
--- a/frontend/src/app/features/calendar/wp-calendar-page/wp-calendar-page.component.ts
+++ b/frontend/src/app/features/calendar/wp-calendar-page/wp-calendar-page.component.ts
@@ -120,4 +120,15 @@ export class WorkPackagesCalendarPageComponent extends PartitionedQuerySpacePage
protected staticQueryName(query:QueryResource):string {
return this.text.unsaved_title;
}
+
+ /**
+ * We only want to load the initial query if it is saved
+ * @protected
+ */
+ protected loadInitialQuery():void {
+ const queryId = this.uiRouterGlobals.params.queryId as string|null;
+ if (queryId) {
+ super.loadInitialQuery();
+ }
+ }
}
diff --git a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts
index 9c29e416237..9e2025840cc 100644
--- a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts
+++ b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts
@@ -20,7 +20,6 @@ import { StateService } from '@uirouter/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { DomSanitizer } from '@angular/platform-browser';
-import { WorkPackagesListChecksumService } from 'core-app/features/work-packages/components/wp-list/wp-list-checksum.service';
import { OpTitleService } from 'core-app/core/html/op-title.service';
import dayGridPlugin from '@fullcalendar/daygrid';
import {
@@ -31,10 +30,9 @@ import { debounceTime } from 'rxjs/operators';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
-import {
- CalendarViewEvent,
- OpCalendarService,
-} from 'core-app/features/calendar/op-calendar.service';
+import { OpCalendarService } from 'core-app/features/calendar/op-calendar.service';
+import { Subject } from 'rxjs';
+import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
@Component({
templateUrl: './wp-calendar.template.html',
@@ -52,11 +50,9 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
this.calendar.resizeObserver(v);
}
- @Input() projectIdentifier:string;
-
@Input() static = false;
- calendarOptions:CalendarOptions|undefined;
+ calendarOptions$ = new Subject<CalendarOptions>();
private alreadyLoaded = false;
@@ -66,7 +62,6 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
readonly wpTableFilters:WorkPackageViewFiltersService,
readonly wpListService:WorkPackagesListService,
readonly querySpace:IsolatedQuerySpace,
- readonly wpListChecksumService:WorkPackagesListChecksumService,
readonly schemaCache:SchemaCacheService,
readonly titleService:OpTitleService,
private element:ElementRef,
@@ -75,6 +70,7 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
private sanitizer:DomSanitizer,
private configuration:ConfigurationService,
readonly calendar:OpCalendarService,
+ readonly currentProject:CurrentProjectService,
) {
super();
}
@@ -112,7 +108,7 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
});
}
- this.calendar.updateTimeframe(fetchInfo, this.projectIdentifier);
+ this.calendar.updateTimeframe(fetchInfo, this.currentProject.identifier || undefined);
}
// eslint-disable-next-line @angular-eslint/use-lifecycle-interface
@@ -124,43 +120,23 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
private initializeCalendar() {
void this.configuration.initialized
.then(() => {
- this.calendarOptions = this.calendar.calendarOptions({
- height: this.calendarHeight(),
- headerToolbar: this.buildHeader(),
- eventClick: this.toWPFullView.bind(this),
- events: this.calendarEventsFunction.bind(this),
- plugins: [dayGridPlugin],
- initialView: (() => {
- if (this.static) {
- return 'dayGridWeek';
- }
- return undefined;
- })(),
- });
+ this.calendarOptions$.next(
+ this.calendar.calendarOptions({
+ height: this.calendarHeight(),
+ headerToolbar: this.buildHeader(),
+ events: this.calendarEventsFunction.bind(this),
+ plugins: [dayGridPlugin],
+ initialView: (() => {
+ if (this.static) {
+ return 'dayGridWeek';
+ }
+ return undefined;
+ })(),
+ }),
+ );
});
}
- toWPFullView(event:CalendarViewEvent):void {
- const { workPackage } = event.event.extendedProps;
-
- if (event.el) {
- // do not display the tooltip on the wp show page
- this.calendar.removeTooltip(event.el);
- }
-
- // Ensure checksum is removed to allow queries to load
- this.wpListChecksumService.clear();
-
- // Ensure current calendar URL is pushed to history
- window.history.pushState({}, this.titleService.current, window.location.href);
-
- void this.$state.go(
- 'work-packages.show',
- { workPackageId: workPackage.id },
- { inherit: false },
- );
- }
-
private get calendarElement() {
return jQuery(this.element.nativeElement).find('[data-qa-selector="op-wp-calendar"]');
}
@@ -217,9 +193,9 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
}
if (calendarDate) {
- this.ucCalendar.getApi().changeView(calendarUnit, calendarDate.toDate());
+ this.ucCalendar.getApi().changeView(calendarUnit, calendarDate.toDate());
} else {
- this.ucCalendar.getApi().changeView(calendarUnit);
+ this.ucCalendar.getApi().changeView(calendarUnit);
}
}
diff --git a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.template.html b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.template.html
index 98be86116cc..e214743597b 100644
--- a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.template.html
+++ b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.template.html
@@ -1,12 +1,15 @@
-<!-- position: relative added in order for the loading indicator to be positioned correctly -->
-<div class="op-wp-calendar loading-indicator--location"
+<div class="op-wp-calendar"
data-qa-selector="op-wp-calendar"
- [attr.data-indicator-name]="'table'"
- style="position: relative">
- <full-calendar #ucCalendar
- *ngIf="calendarOptions"
- [options]="calendarOptions">
- </full-calendar>
+ [attr.data-indicator-name]="'table'">
+ <ng-container
+ *ngIf="(calendarOptions$ | async) as calendarOptions"
+ >
+ <full-calendar
+ #ucCalendar
+ *ngIf="calendarOptions"
+ [options]="calendarOptions"
+ ></full-calendar>
+ </ng-container>
<div
*ngIf="static"
[textContent]="calendar.tooManyResultsText"
diff --git a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts
index 2a0005111d3..5349815cb72 100644
--- a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts
+++ b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts
@@ -128,7 +128,7 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
ngOnInit():void {
this.initializeCalendar();
- this.projectIdentifier = this.currentProject.identifier ? this.currentProject.identifier : undefined;
+ this.projectIdentifier = this.currentProject.identifier || undefined;
this
.querySpace
@@ -231,7 +231,6 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
},
events: this.calendarEventsFunction.bind(this) as unknown,
resources: [],
- eventClick: this.openSplitView.bind(this) as unknown,
select: this.handleDateClicked.bind(this) as unknown,
resourceLabelContent: (data:ResourceLabelContentArg) => this.renderTemplate(this.resourceContent, data.resource.id, data),
resourceLabelWillUnmount: (data:ResourceLabelContentArg) => this.unrenderTemplate(data.resource.id),
@@ -304,20 +303,6 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
}
}
- private openSplitView(event:EventClickArg):void {
- const workPackage = event.event.extendedProps.workPackage as WorkPackageResource;
-
- if (event.el) {
- // do not display the tooltip on the wp show page
- this.calendar.removeTooltip(event.el);
- }
-
- void this.$state.go(
- `${splitViewRoute(this.$state)}.tabs`,
- { workPackageId: workPackage.id, tabIdentifier: 'overview' },
- );
- }
-
private mapToCalendarEvents(workPackages:WorkPackageResource[]):EventInput[] {
return workPackages
.map((workPackage:WorkPackageResource):EventInput|undefined => {
diff --git a/frontend/src/app/shared/components/grids/widgets/wp-calendar/wp-calendar.component.html b/frontend/src/app/shared/components/grids/widgets/wp-calendar/wp-calendar.component.html
index b743fccdb20..9a407873d0c 100644
--- a/frontend/src/app/shared/components/grids/widgets/wp-calendar/wp-calendar.component.html
+++ b/frontend/src/app/shared/components/grids/widgets/wp-calendar/wp-calendar.component.html
@@ -10,6 +10,5 @@
<ng-container wp-isolated-query-space>
<wp-calendar
- [static]="true"
- [projectIdentifier]="projectIdentifier"></wp-calendar>
+ [static]="true"></wp-calendar>
</ng-container>