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

[#46150] change DI initialization

Eric Schubertbad03b8d4ba0
diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts
index b8dbaf7799b..a2b02b4522e 100644
--- a/frontend/src/app/app.module.ts
+++ b/frontend/src/app/app.module.ts
@@ -135,6 +135,8 @@ export function initializeServices(injector:Injector) {
PreviewTrigger.setupListener();
keyboardShortcuts.register();
+
+ return injector.get(ConfigurationService).initialize();
};
}
diff --git a/frontend/src/app/core/config/configuration.service.ts b/frontend/src/app/core/config/configuration.service.ts
index e8ba8bcaf4c..1afdc83819f 100644
--- a/frontend/src/app/core/config/configuration.service.ts
+++ b/frontend/src/app/core/config/configuration.service.ts
@@ -25,10 +25,11 @@
//
// See COPYRIGHT and LICENSE files for more details.
//++
+
import { Injectable } from '@angular/core';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { ConfigurationResource } from 'core-app/features/hal/resources/configuration-resource';
import * as moment from 'moment';
+
+import { ConfigurationResource } from 'core-app/features/hal/resources/configuration-resource';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
@Injectable({ providedIn: 'root' })
@@ -38,16 +39,12 @@ export class ConfigurationService {
// but could easily be stored in localStorage
private configuration:ConfigurationResource;
- public initialized:Promise<boolean>;
-
public constructor(
- readonly I18n:I18nService,
- readonly apiV3Service:ApiV3Service,
- ) {
- this.initialized = this
- .loadConfiguration()
- .then(() => true)
- .catch(() => false);
+ private readonly apiV3Service:ApiV3Service,
+ ) { }
+
+ public initialize():Promise<void> {
+ return this.loadConfiguration();
}
public commentsSortedInDescendingOrder():boolean {
@@ -128,6 +125,8 @@ export class ConfigurationService {
.get()
.toPromise()
.then((configuration) => {
+ console.warn('set configuration');
+ console.warn(new Date().toISOString());
this.configuration = configuration;
});
}
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 e1e8a62d60d..b713997403e 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
@@ -52,7 +52,9 @@ import { States } from 'core-app/core/states/states.service';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { WorkPackageCollectionResource } from 'core-app/features/hal/resources/wp-collection-resource';
-import { WorkPackageViewFiltersService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
+import {
+ WorkPackageViewFiltersService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
import { WorkPackagesListService } from 'core-app/features/work-packages/components/wp-list/wp-list.service';
import { StateService } from '@uirouter/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
@@ -67,7 +69,9 @@ import interactionPlugin, {
EventDragStopArg,
EventResizeDoneArg,
} from '@fullcalendar/interaction';
-import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
+import {
+ HalResourceEditingService,
+} from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { splitViewRoute } from 'core-app/features/work-packages/routing/split-view-routes.helper';
import {
@@ -229,7 +233,7 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
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.workPackagesCalendar.isNonWorkingDay(start) || this.workPackagesCalendar.isNonWorkingDay(due))) {
+ || this.workPackagesCalendar.isNonWorkingDay(start) || this.workPackagesCalendar.isNonWorkingDay(due))) {
this.toastService.addError(this.text.cannot_drag_to_non_working_day);
resizeInfo?.revert();
return;
@@ -283,10 +287,8 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
additionalOptions.initialView = 'dayGridWeek';
}
- void Promise.all([
- this.configuration.initialized,
- this.weekdayService.loadWeekdays().toPromise(),
- ])
+ void this.weekdayService.loadWeekdays()
+ .toPromise()
.then(() => {
this.calendarOptions$.next(
this.workPackagesCalendar.calendarOptions(additionalOptions),
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 4c9bb9f2944..ba3847110da 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
@@ -74,7 +74,9 @@ import { FullCalendarComponent } from '@fullcalendar/angular';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { ConfigurationService } from 'core-app/core/config/configuration.service';
import { EventViewLookupService } from 'core-app/features/team-planner/team-planner/planner/event-view-lookup.service';
-import { WorkPackageViewFiltersService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
+import {
+ WorkPackageViewFiltersService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { splitViewRoute } from 'core-app/features/work-packages/routing/split-view-routes.helper';
@@ -88,14 +90,18 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packag
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { OpCalendarService } from 'core-app/features/calendar/op-calendar.service';
-import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
+import {
+ HalResourceEditingService,
+} from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { CalendarDragDropService } from 'core-app/features/team-planner/team-planner/calendar-drag-drop.service';
import { StatusResource } from 'core-app/features/hal/resources/status-resource';
import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
-import { KeepTabService } from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';
+import {
+ KeepTabService,
+} from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';
import { HalError } from 'core-app/features/hal/services/hal-error';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
import {
@@ -469,10 +475,8 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
}
private initializeCalendar() {
- void Promise.all([
- this.configuration.initialized,
- this.weekdayService.loadWeekdays().toPromise(),
- ])
+ void this.weekdayService.loadWeekdays()
+ .toPromise()
.then(() => {
this.calendarOptions$.next(
this.workPackagesCalendar.calendarOptions({
diff --git a/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts b/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts
index e80a786f3a6..d7315355ccc 100644
--- a/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts
@@ -78,7 +78,6 @@ export class WorkPackagesListService {
private queryLoading = this.queryRequests
.values$()
.pipe(
- switchMap((q:QueryDefinition) => from(this.ensurePerPageKnown().then(() => q))),
// Stream the query request, switchMap will call previous requests to be cancelled
switchMap((q:QueryDefinition) => this.streamQueryRequest(q.queryParams, q.projectIdentifier)),
// Map the observable from the stream to a new one that completes when states are loaded
@@ -411,13 +410,6 @@ export class WorkPackagesListService {
});
}
- private async ensurePerPageKnown() {
- if (this.pagination.isPerPageKnown) {
- return true;
- }
- return this.configuration.initialized;
- }
-
private createQueryAndView(query:QueryResource, form:QueryFormResource|undefined) {
return this
.apiV3Service
diff --git a/frontend/src/app/features/work-packages/components/wp-table/table-pagination/wp-table-pagination.component.spec.ts b/frontend/src/app/features/work-packages/components/wp-table/table-pagination/wp-table-pagination.component.spec.ts
index 6c0d8441deb..2326601bb44 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/table-pagination/wp-table-pagination.component.spec.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/table-pagination/wp-table-pagination.component.spec.ts
@@ -56,7 +56,7 @@ function setupMocks(paginationService:PaginationService) {
spyOn(paginationService, 'getOptionsTruncationSize').and.callFake(() => options.optionsTruncationSize);
- spyOn(paginationService, 'loadPaginationOptions').and.callFake(() => Promise.resolve(options));
+ spyOn(paginationService, 'getPaginationOptions').and.callFake(() => options);
}
function pageString(element:JQuery) {
diff --git a/frontend/src/app/features/work-packages/components/wp-table/table-pagination/wp-table-pagination.component.ts b/frontend/src/app/features/work-packages/components/wp-table/table-pagination/wp-table-pagination.component.ts
index 6ba86c5def5..150312c2d29 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/table-pagination/wp-table-pagination.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/table-pagination/wp-table-pagination.component.ts
@@ -27,17 +27,28 @@
//++
import {
- ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit,
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ OnDestroy,
+ OnInit,
} from '@angular/core';
+import { combineLatest } from 'rxjs';
+
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { WorkPackageViewPaginationService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-pagination.service';
-import { WorkPackageViewPagination } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-table-pagination';
-import { WorkPackageViewSortByService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-sort-by.service';
+import {
+ WorkPackageViewPaginationService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-pagination.service';
+import {
+ WorkPackageViewPagination,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-table-pagination';
+import {
+ WorkPackageViewSortByService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-sort-by.service';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
-import { combineLatest } from 'rxjs';
import { WorkPackageCollectionResource } from 'core-app/features/hal/resources/wp-collection-resource';
import { TablePaginationComponent } from 'core-app/shared/components/table-pagination/table-pagination.component';
-import { IPaginationOptions, PaginationService } from 'core-app/shared/components/table-pagination/pagination-service';
+import { PaginationService } from 'core-app/shared/components/table-pagination/pagination-service';
@Component({
templateUrl: '../../../../../shared/components/table-pagination/table-pagination.component.html',
@@ -45,22 +56,19 @@ import { IPaginationOptions, PaginationService } from 'core-app/shared/component
selector: 'wp-table-pagination',
})
export class WorkPackageTablePaginationComponent extends TablePaginationComponent implements OnInit, OnDestroy {
- constructor(protected paginationService:PaginationService,
+ constructor(
+ protected paginationService:PaginationService,
protected cdRef:ChangeDetectorRef,
protected wpTablePagination:WorkPackageViewPaginationService,
readonly querySpace:IsolatedQuerySpace,
readonly wpTableSortBy:WorkPackageViewSortByService,
- readonly I18n:I18nService) {
+ readonly I18n:I18nService,
+ ) {
super(paginationService, cdRef, I18n);
}
ngOnInit() {
- this.paginationService
- .loadPaginationOptions()
- .then((paginationOptions:IPaginationOptions) => {
- this.perPageOptions = paginationOptions.perPageOptions;
- this.cdRef.detectChanges();
- });
+ this.perPageOptions = this.paginationService.getPerPageOptions();
this.wpTablePagination
.live$()
diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.ts b/frontend/src/app/shared/components/storages/storage/storage.component.ts
index d9a47813a48..6c7996b5cbe 100644
--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts
+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts
@@ -37,7 +37,6 @@ import {
ViewChild,
} from '@angular/core';
import {
- HttpClient,
HttpErrorResponse,
} from '@angular/common/http';
import {
@@ -213,7 +212,6 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
};
constructor(
- private readonly http:HttpClient,
private readonly i18n:I18nService,
private readonly cdRef:ChangeDetectorRef,
private readonly toastService:ToastService,
diff --git a/frontend/src/app/shared/components/table-pagination/pagination-service.ts b/frontend/src/app/shared/components/table-pagination/pagination-service.ts
index a7ab732be56..6b114c8307c 100644
--- a/frontend/src/app/shared/components/table-pagination/pagination-service.ts
+++ b/frontend/src/app/shared/components/table-pagination/pagination-service.ts
@@ -82,10 +82,6 @@ export class PaginationService {
return this.paginationOptions;
}
- public get isPerPageKnown() {
- return !!(this.localStoragePerPage || this.paginationOptions);
- }
-
public getPerPage() {
return this.localStoragePerPage || this.paginationOptions.perPage;
}
@@ -111,16 +107,12 @@ export class PaginationService {
this.paginationOptions.perPageOptions = perPageOptions;
}
- public loadPaginationOptions() {
- return this.configuration.initialized.then(() => {
- this.paginationOptions = {
- perPage: this.getCachedPerPage(this.configuration.perPageOptions),
- perPageOptions: this.configuration.perPageOptions,
- maxVisiblePageOptions: DEFAULT_PAGINATION_OPTIONS.maxVisiblePageOptions,
- optionsTruncationSize: DEFAULT_PAGINATION_OPTIONS.optionsTruncationSize,
- };
-
- return this.paginationOptions;
- });
+ private loadPaginationOptions():void {
+ this.paginationOptions = {
+ perPage: this.getCachedPerPage(this.configuration.perPageOptions),
+ perPageOptions: this.configuration.perPageOptions,
+ maxVisiblePageOptions: DEFAULT_PAGINATION_OPTIONS.maxVisiblePageOptions,
+ optionsTruncationSize: DEFAULT_PAGINATION_OPTIONS.optionsTruncationSize,
+ };
}
}
diff --git a/frontend/src/app/shared/components/table-pagination/table-pagination.component.ts b/frontend/src/app/shared/components/table-pagination/table-pagination.component.ts
index 4af13c43ea2..5e06d4d2c2e 100644
--- a/frontend/src/app/shared/components/table-pagination/table-pagination.component.ts
+++ b/frontend/src/app/shared/components/table-pagination/table-pagination.component.ts
@@ -38,7 +38,7 @@ import {
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { PaginationInstance } from 'core-app/shared/components/table-pagination/pagination-instance';
-import { IPaginationOptions, PaginationService } from './pagination-service';
+import { PaginationService } from 'core-app/shared/components/table-pagination/pagination-service';
@Component({
selector: '[tablePagination]',
@@ -77,20 +77,18 @@ export class TablePaginationComponent extends UntilDestroyedMixin implements OnI
public perPageOptions:number[] = [];
- constructor(protected paginationService:PaginationService,
+ constructor(
+ protected paginationService:PaginationService,
protected cdRef:ChangeDetectorRef,
- protected I18n:I18nService) {
+ protected I18n:I18nService,
+ ) {
super();
}
ngOnInit():void {
- this.paginationService
- .loadPaginationOptions()
- .then((paginationOptions:IPaginationOptions) => {
- this.perPageOptions = paginationOptions.perPageOptions;
- this.pagination = new PaginationInstance(1, parseInt(this.totalEntries), paginationOptions.perPage);
- this.cdRef.detectChanges();
- });
+ const paginationOptions = this.paginationService.getPaginationOptions();
+ this.perPageOptions = paginationOptions.perPageOptions;
+ this.pagination = new PaginationInstance(1, parseInt(this.totalEntries, 10), paginationOptions.perPage);
}
public update() {