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] reworked structure for fetching storages
Eric Schubert4a4ba2f898a4
diff --git a/frontend/src/app/core/state/projects/projects.service.ts b/frontend/src/app/core/state/projects/projects.service.tsindex e87026e6190..e004952300c 100644--- a/frontend/src/app/core/state/projects/projects.service.ts+++ b/frontend/src/app/core/state/projects/projects.service.ts@@ -1,3 +1,31 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2022 the OpenProject GmbH+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License version 3.+//+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+// Copyright (C) 2006-2013 Jean-Philippe Lang+// Copyright (C) 2010-2013 the ChiliProject Team+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License+// as published by the Free Software Foundation; either version 2+// of the License, or (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+//+// See COPYRIGHT and LICENSE files for more details.+//+++import { Injectable } from '@angular/core';import {catchError,@@ -53,7 +81,19 @@ export class ProjectsResourceService {);}- lookup(id:ID):Observable<IProject|undefined> {+ lookup(id:ID, require = false):Observable<IProject|undefined> {+ if (require && !this.query.hasEntity(id)) {+ return this.http+ .get<IProject>(`${this.projectsPath}/${id}`)+ .pipe(+ tap((project) => {+ if (project) {+ this.store.add(project);+ }+ }),+ );+ }+return this.query.selectEntity(id);}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.tsindex 37dd6dd2530..f598fc9c4e3 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@@ -34,12 +34,14 @@ import {import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { I18nService } from 'core-app/core/i18n/i18n.service';import { HookService } from 'core-app/features/plugins/hook-service';-import { forkJoin, Observable } from 'rxjs';+import { forkJoin, Observable, of } from 'rxjs';import { CurrentUserService } from 'core-app/core/current-user/current-user.service';import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';-import { IProject } from 'core-app/core/state/projects/project.model';import { IHalResourceLink, IHalResourceLinks } from 'core-app/core/state/hal-resource';import { switchMap } from 'rxjs/operators';+import { IStorage } from 'core-app/core/state/storages/storage.model';+import { ProjectsResourceService } from 'core-app/core/state/projects/projects.service';+import { HalResource } from 'core-app/features/hal/resources/hal-resource';export interface ILiveFileLinkCollectionsLinks extends IHalResourceLinks {self:IHalResourceLink@@ -73,32 +75,40 @@ export class WorkPackageFilesTabComponent implements OnInit {canViewFileLinks$:Observable<boolean>;- fileLinkCollections$:Observable<ILiveFileLinkCollection[]>;+ storages$:Observable<IStorage[]>;constructor(readonly I18n:I18nService,protected hook:HookService,private currentUserService:CurrentUserService,- private storagesResourceService:StoragesResourceService,+ private readonly projectsResourceService:ProjectsResourceService,+ private readonly storagesResourceService:StoragesResourceService,) { }ngOnInit():void {- const project = this.workPackage.$embedded.project as IProject;+ const project = this.workPackage.$embedded.project as HalResource;+ if (project.id === null) {+ return;+ }this.canViewFileLinks$ = this.currentUserService- .hasCapabilities$('file_links/view', project.id as string);+ .hasCapabilities$('file_links/view', project.id);- const storageLinks = project._links.storages;- this.fileLinkCollections$ = forkJoin(- storageLinks.map((link) => this- .storagesResourceService- .lookup(link)- .pipe(- switchMap((storage) => this- .storagesResourceService- .liveLinks(storage)('WorkPackage', this.workPackage.id as string)),- )),- );+ this.storages$ = this.projectsResourceService.lookup(project.id, true)+ .pipe(+ switchMap((p) => {+ if (!p) {+ return of([]);+ }++ const storageLinks = p._links.storages;+ return forkJoin(+ storageLinks.map((link) => this+ .storagesResourceService+ .lookup(link)),+ );+ }),+ );}}diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.html b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.htmlindex 2590631bf1e..af1d1b7cd53 100644--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.html+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.html@@ -15,6 +15,9 @@<h3 class="op-tab-content--header-text" [textContent]="storage.name"></h3></div>- <op-file-link-list [resource]="workPackage"></op-file-link-list>+ <op-file-link-list+ [resource]="workPackage"+ [storage]="storage"+ ></op-file-link-list></section></div>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 1bfcf170470..2405fa86126 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@@ -32,6 +32,7 @@ import {import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { Observable } from 'rxjs';import { IFileLink } from 'core-app/core/state/file-links/file-link.model';+import { IStorage } from 'core-app/core/state/storages/storage.model';import { FileLinkResourceService } from 'core-app/core/state/file-links/file-links.service';import isNewResource from 'core-app/features/hal/helpers/is-new-resource';import { tap } from 'rxjs/operators';@@ -44,6 +45,8 @@ import { tap } from 'rxjs/operators';export class FileLinkListComponent implements OnInit {@Input() public resource:HalResource;+ @Input() public storage:IStorage;+$fileLinks:Observable<IFileLink[]>;constructor(private readonly fileLinkResourceService:FileLinkResourceService) {}@@ -63,7 +66,7 @@ export class FileLinkListComponent implements OnInit {private get fileLinkSelfLink():string {const fileLinks = this.resource.fileLinks as unknown&{ href:string };- return fileLinks.href;+ return `${fileLinks.href}?filters=[{"storage":{"operator":"=","values":["${this.storage.id}"]}}]`;}private get collectionKey():string {diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rbindex 61ecdccc21c..7be89f7c23a 100644--- a/lib/api/v3/projects/project_representer.rb+++ b/lib/api/v3/projects/project_representer.rb@@ -88,10 +88,10 @@ module API{ href: api_v3_paths.work_packages_by_project(represented.id) }end- link :storages,- cache_if: -> {- current_user_allowed_to(:view_file_links, context: represented)- } do+ links :storages,+ cache_if: -> {+ current_user_allowed_to(:view_file_links, context: represented)+ } dorepresented.storages.map do |storage|{href: api_v3_paths.storage(storage.id),@@ -210,7 +210,7 @@ module APInext unless represented.status&.code::API::V3::Projects::Statuses::StatusRepresenter- .create(represented.status.code, current_user: current_user, embed_links: embed_links)+ .create(represented.status.code, current_user:, embed_links:)},link: ->(*) {if represented.status&.code