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

Moved storages collection initialization to WorkPackageSingleViewBase

Andreas Pfohl7673a37e68a5
diff --git a/frontend/src/app/core/state/storages/storage.model.ts b/frontend/src/app/core/state/storages/storage.model.ts
index 2df92f5622d..e96e5aff8e1 100644
--- a/frontend/src/app/core/state/storages/storage.model.ts
+++ b/frontend/src/app/core/state/storages/storage.model.ts
@@ -28,29 +28,6 @@
import { ID } from '@datorama/akita';
import { IHalResourceLink, IHalResourceLinks } from 'core-app/core/state/hal-resource';
-import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';
-
-export class StorageCollection implements IHALCollection<IStorage> {
- readonly _type:'Collection';
-
- readonly _embedded:{ elements:IStorage[] } = { elements: [] };
-
- readonly count:number;
-
- readonly offset:number;
-
- readonly pageSize:number;
-
- readonly total:number;
-
- constructor(storages:IStorage[]) {
- this._embedded.elements = storages;
- this.count = storages.length;
- this.offset = 0;
- this.pageSize = 1;
- this.total = storages.length;
- }
-}
export interface IStorageHalResourceLinks extends IHalResourceLinks {
self:IHalResourceLink;
diff --git a/frontend/src/app/core/state/storages/storages.service.ts b/frontend/src/app/core/state/storages/storages.service.ts
index b161b29e517..7ca746d95c9 100644
--- a/frontend/src/app/core/state/storages/storages.service.ts
+++ b/frontend/src/app/core/state/storages/storages.service.ts
@@ -30,11 +30,11 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { forkJoin, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
-import { IStorage, StorageCollection } from 'core-app/core/state/storages/storage.model';
+import { IStorage } from 'core-app/core/state/storages/storage.model';
import { StoragesStore } from 'core-app/core/state/storages/storages.store';
import { StoragesQuery } from 'core-app/core/state/storages/storages.query';
import { insertCollectionIntoState } from 'core-app/core/state/collection-store';
-import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';
@Injectable()
export class StoragesResourceService {
@@ -44,28 +44,38 @@ export class StoragesResourceService {
constructor(private readonly http:HttpClient) {}
- collection(project:HalResource):Observable<IStorage[]> {
+ collection(key:string):Observable<IStorage[]> {
return this
.query
.select()
.pipe(
- map((state) => state.collections[project.id as string]?.ids),
+ map((state) => state.collections[key]?.ids),
switchMap((ids) => this.query.selectMany(ids)),
);
}
- lookup(id:string):Observable<IStorage|undefined> {
- return this.query.selectEntity(id);
+ lookup(id:string):Observable<IStorage> {
+ return this
+ .query
+ .selectEntity(id)
+ .pipe(
+ map((storage) => {
+ if (storage === undefined) {
+ throw new Error('not found');
+ }
+
+ return storage;
+ }),
+ );
}
- async updateCollection(project:HalResource):Promise<void> {
+ async updateCollection(key:string, storageLinks:{ href:string }[]):Promise<void> {
const storages = await forkJoin(
- (project.$links as { storages:{ href:string }[] })
- .storages
- .map((link) => this.http.get<IStorage>(link.href)),
+ storageLinks.map((link) => this.http.get<IStorage>(link.href)),
).toPromise();
- const storageCollection = new StorageCollection(storages);
- insertCollectionIntoState(this.store, storageCollection, project.id as string);
+ const storageCollection = { _embedded: { elements: storages } } as IHALCollection<IStorage>;
+
+ insertCollectionIntoState(this.store, storageCollection, key);
}
}
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
index b596853c4bd..0d77b7fbb8b 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.ts
@@ -71,29 +71,24 @@ export class WorkPackageFilesTabComponent implements OnInit {
private readonly toast:ToastService,
) { }
- async ngOnInit():Promise<void> {
+ ngOnInit():void {
const project = this.workPackage.$embedded.project as HalResource;
if (project.id === null) {
return;
}
- try {
- await this.storagesResourceService.updateCollection(project);
- } catch (error) {
- this.toast.addError(error);
- return;
- }
-
this.canViewFileLinks$ = this
.currentUserService
- .hasCapabilities$('file_links/view', project.id.toString());
+ .hasCapabilities$('file_links/view', project.id);
this.storages$ = this
.storagesResourceService
- .collection(project)
- .pipe(catchError((error) => {
- this.toast.addError(error);
- throw error;
- }));
+ .collection(project.href as string)
+ .pipe(
+ catchError((error) => {
+ this.toast.addError(error);
+ throw error;
+ }),
+ );
}
}
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts
index c3bde8ef8aa..75a3e20e8f1 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts
@@ -32,14 +32,22 @@ import {
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { WorkPackageViewFocusService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-focus.service';
+import {
+ WorkPackageViewFocusService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-focus.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { OpTitleService } from 'core-app/core/html/op-title.service';
import { AuthorisationService } from 'core-app/core/model-auth/model-auth.service';
import { States } from 'core-app/core/states/states.service';
-import { KeepTabService } from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';
-import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
-import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
+import {
+ KeepTabService,
+} from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';
+import {
+ HalResourceEditingService,
+} from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
+import {
+ WorkPackageNotificationService,
+} from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
@@ -48,6 +56,7 @@ import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-
import { Observable } from 'rxjs';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
import { AttachmentsResourceService } from 'core-app/core/state/attachments/attachments.service';
+import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';
export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
@InjectField() states:States;
@@ -80,6 +89,8 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
@InjectField() readonly storeService:WpSingleViewService;
+ @InjectField() private readonly storages:StoragesResourceService;
+
// Static texts
public text:any = {};
@@ -177,6 +188,9 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {
.subscribe((tabs:any) => {
this.updateFocusAnchorLabel(tabs.active);
});
+
+ const project = this.workPackage.project as { $links:{ storages:{ href:string }[] }, href:string };
+ void this.storages.updateCollection(project.href, project.$links.storages);
}
protected handleLoadingError(error:unknown):void {