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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#42157] added file link resource service functionality
Eric Schubert59aefd9b8730
diff --git a/frontend/src/app/core/state/collection-store.ts b/frontend/src/app/core/state/collection-store.tsindex 5f706d0ffeb..15fecd087d6 100644--- a/frontend/src/app/core/state/collection-store.ts+++ b/frontend/src/app/core/state/collection-store.ts@@ -121,7 +121,7 @@ export function insertCollectionIntoState<T extends { id:ID }>(applyTransaction(() => {// Avoid inserting when elements is not definedif (elements && elements.length > 0) {- store.upsertMany(collection._embedded.elements);+ store.upsertMany(elements);}store.update(({ collections }) => (diff --git a/frontend/src/app/core/state/file-links/file-link.model.ts b/frontend/src/app/core/state/file-links/file-link.model.tsindex b8a577e58fc..aedc6210006 100644--- a/frontend/src/app/core/state/file-links/file-link.model.ts+++ b/frontend/src/app/core/state/file-links/file-link.model.ts@@ -33,7 +33,7 @@ import {} from 'core-app/core/state/hal-resource';export interface IFileLinkHalResourceLinks extends IHalResourceLinks {- storage?:IHalResourceLink;+ storage:IHalResourceLink;container:IHalResourceLink;creator:IHalResourceLink;delete?:IHalResourceLink;diff --git a/frontend/src/app/core/state/file-links/file-links.service.ts b/frontend/src/app/core/state/file-links/file-links.service.tsindex 6ea7fd6baf1..04fd48c8a82 100644--- a/frontend/src/app/core/state/file-links/file-links.service.ts+++ b/frontend/src/app/core/state/file-links/file-links.service.ts@@ -29,35 +29,63 @@import { Injectable } from '@angular/core';import { HttpClient } from '@angular/common/http';import { QueryEntity } from '@datorama/akita';-import { Observable } from 'rxjs';+import { from, Observable } from 'rxjs';import {- catchError, map, switchMap, tap,+ catchError, groupBy, map, mergeMap, reduce, switchMap, tap,} from 'rxjs/operators';import { IFileLink } from 'core-app/core/state/file-links/file-link.model';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';import { ToastService } from 'core-app/shared/components/toaster/toast.service';import { FileLinksStore } from 'core-app/core/state/file-links/file-links.store';import { insertCollectionIntoState } from 'core-app/core/state/collection-store';+import idFromLink from 'core-app/features/hal/helpers/id-from-link';@Injectable()export class FileLinkResourceService {- protected store = new FileLinksStore();+ private store = new FileLinksStore();constructor(private readonly http:HttpClient,private readonly toastService:ToastService,) {}- fetchCurrent(fileLinksSelfLink:string):void {+ updateCollectionsForWorkPackage(fileLinksSelfLink:string):void {this.http.get<IHALCollection<IFileLink>>(fileLinksSelfLink).pipe(tap((collection) => insertCollectionIntoState(this.store, collection, fileLinksSelfLink)),+ switchMap((collection) => from(collection._embedded.elements)),+ groupBy(+ (fileLink) => fileLink._links.storage.href,+ (fileLink) => fileLink,+ ),+ mergeMap((group$) => {+ const seed = { storage: group$.key, fileLinks: [] as IFileLink[] };+ return group$.pipe(reduce((acc, fileLink) => {+ acc.fileLinks = [...acc.fileLinks, fileLink];+ return acc;+ }, seed));+ }),catchError((error) => {this.toastService.addError(error);throw error;}),- ).subscribe();+ )+ .subscribe((fileLinkCollections) => {+ const storageId = idFromLink(fileLinkCollections.storage);+ const collectionKey = `${fileLinksSelfLink}?filters=[{"storage":{"operator":"=","values":["${storageId}"]}}]`;+ const collection:IHALCollection<IFileLink> = {+ _type: 'Collection',+ count: fileLinkCollections.fileLinks.length,+ total: fileLinkCollections.fileLinks.length,+ pageSize: fileLinkCollections.fileLinks.length,+ offset: 0,+ _embedded: {+ elements: fileLinkCollections.fileLinks,+ },+ };+ insertCollectionIntoState(this.store, collection, collectionKey);+ });}all(key:string):Observable<IFileLink[]> {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.tsindex 75a3e20e8f1..b56aa4bba0c 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@@ -57,6 +57,7 @@ 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';+import { FileLinkResourceService } from 'core-app/core/state/file-links/file-links.service';export class WorkPackageSingleViewBase extends UntilDestroyedMixin {@InjectField() states:States;@@ -77,6 +78,8 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {@InjectField() attachmentsResourceService:AttachmentsResourceService;+ @InjectField() fileLinkResourceService:FileLinkResourceService;+@InjectField() cdRef:ChangeDetectorRef;@InjectField() readonly titleService:OpTitleService;@@ -180,6 +183,9 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {const attachments = this.workPackage.attachments as unknown&{ href:string };this.attachmentsResourceService.fetchAttachments(attachments.href).subscribe();+ // Fetch file link collections for work package+ this.fileLinkResourceService.updateCollectionsForWorkPackage(this.workPackage.$links.fileLinks.href as string);+// Listen to tab changes to update the tab labelthis.keepTab.observable.pipe(diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.tsindex 21f549b9028..ee9fcc0de9f 100644--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts@@ -89,8 +89,6 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInitngOnInit():void {this.initializeLocales();- this.fileLinkResourceService.fetchCurrent(this.fileLinkSelfLink);-this.fileLinks$ = this.fileLinkResourceService.all(this.collectionKey);this.fileLinks$