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

[#47501] Open file picker based on project folder from database

Eric Schubert7dc2e5727abc
diff --git a/frontend/src/app/core/apiv3/api-v3.service.ts b/frontend/src/app/core/apiv3/api-v3.service.ts
index dc29fe42ab3..e019869c519 100644
--- a/frontend/src/app/core/apiv3/api-v3.service.ts
+++ b/frontend/src/app/core/apiv3/api-v3.service.ts
@@ -55,14 +55,19 @@ import { ApiV3HelpTextsPaths } from 'core-app/core/apiv3/endpoints/help_texts/ap
import { ApiV3ConfigurationPath } from 'core-app/core/apiv3/endpoints/configuration/apiv3-configuration-path';
import { ApiV3BoardsPaths } from 'core-app/core/apiv3/virtual/apiv3-boards-paths';
import { RootResource } from 'core-app/features/hal/resources/root-resource';
-import { ApiV3PlaceholderUsersPaths } from 'core-app/core/apiv3/endpoints/placeholder-users/apiv3-placeholder-users-paths';
+import {
+ ApiV3PlaceholderUsersPaths,
+} from 'core-app/core/apiv3/endpoints/placeholder-users/apiv3-placeholder-users-paths';
import { ApiV3GroupsPaths } from 'core-app/core/apiv3/endpoints/groups/apiv3-groups-paths';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { ApiV3NotificationsPaths } from 'core-app/core/apiv3/endpoints/notifications/apiv3-notifications-paths';
import { ApiV3ViewsPaths } from 'core-app/core/apiv3/endpoints/views/apiv3-views-paths';
import { Apiv3BackupsPath } from 'core-app/core/apiv3/endpoints/backups/apiv3-backups-path';
import { ApiV3DaysPaths } from 'core-app/core/apiv3/endpoints/days/api-v3-days-paths';
-import { Apiv3StoragesPaths } from 'core-app/core/apiv3/endpoints/storages/apiv3-storages-paths';
+import { ApiV3StoragesPaths } from 'core-app/core/apiv3/endpoints/storages/api-v3-storages-paths';
+import {
+ ApiV3ProjectStoragesPaths,
+} from 'core-app/core/apiv3/endpoints/project-storages/api-v3-project-storages-paths';
@Injectable({ providedIn: 'root' })
export class ApiV3Service {
@@ -121,7 +126,10 @@ export class ApiV3Service {
public readonly news = this.apiV3CustomEndpoint(ApiV3NewsPaths);
// /api/v3/storages
- public readonly storages = this.apiV3CustomEndpoint(Apiv3StoragesPaths);
+ public readonly storages = this.apiV3CustomEndpoint(ApiV3StoragesPaths);
+
+ // /api/v3/project_storages
+ public readonly projectStorages = this.apiV3CustomEndpoint(ApiV3ProjectStoragesPaths);
// /api/v3/types
public readonly types = this.apiV3CustomEndpoint(ApiV3TypesPaths);
@@ -162,9 +170,10 @@ export class ApiV3Service {
// VIRTUAL boards are /api/v3/grids + a scope filter
public readonly boards = this.apiV3CustomEndpoint(ApiV3BoardsPaths);
- constructor(readonly injector:Injector,
- readonly pathHelper:PathHelperService) {
- }
+ constructor(
+ readonly injector:Injector,
+ readonly pathHelper:PathHelperService,
+ ) { }
/**
* Returns the part of the API that exists both
@@ -193,6 +202,7 @@ export class ApiV3Service {
}
private apiV3CustomEndpoint<T>(cls:Constructor<T>):T {
+ // eslint-disable-next-line new-cap
return new cls(this, this.pathHelper.api.v3.apiV3Base);
}
diff --git a/frontend/src/app/core/apiv3/endpoints/project-storages/api-v3-project-storages-paths.ts b/frontend/src/app/core/apiv3/endpoints/project-storages/api-v3-project-storages-paths.ts
new file mode 100644
index 00000000000..60268a01c05
--- /dev/null
+++ b/frontend/src/app/core/apiv3/endpoints/project-storages/api-v3-project-storages-paths.ts
@@ -0,0 +1,44 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 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 {
+ ApiV3GettableResource,
+ ApiV3ResourceCollection,
+} from 'core-app/core/apiv3/paths/apiv3-resource';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { IProjectStorage } from 'core-app/core/state/project-storages/project-storage.model';
+
+export class ApiV3ProjectStoragesPaths
+ extends ApiV3ResourceCollection<IProjectStorage, ApiV3GettableResource<IProjectStorage>> {
+ constructor(
+ protected apiRoot:ApiV3Service,
+ protected basePath:string,
+ ) {
+ super(apiRoot, basePath, 'project_storages');
+ }
+}
diff --git a/frontend/src/app/core/apiv3/endpoints/storages/apiv3-storages-paths.ts b/frontend/src/app/core/apiv3/endpoints/storages/api-v3-storages-paths.ts
similarity index 93%
rename from frontend/src/app/core/apiv3/endpoints/storages/apiv3-storages-paths.ts
rename to frontend/src/app/core/apiv3/endpoints/storages/api-v3-storages-paths.ts
index f5a40e42102..2d7579feec6 100644
--- a/frontend/src/app/core/apiv3/endpoints/storages/apiv3-storages-paths.ts
+++ b/frontend/src/app/core/apiv3/endpoints/storages/api-v3-storages-paths.ts
@@ -33,13 +33,15 @@ import {
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { IStorage } from 'core-app/core/state/storages/storage.model';
-export class Apiv3StoragesPaths
+export class ApiV3StoragesPaths
extends ApiV3ResourceCollection<IStorage, ApiV3GettableResource<IStorage>> {
// /api/v3/storages/files
public readonly files = this.subResource('files');
- constructor(protected apiRoot:ApiV3Service,
- protected basePath:string) {
+ constructor(
+ protected apiRoot:ApiV3Service,
+ protected basePath:string,
+ ) {
super(apiRoot, basePath, 'storages');
}
}
diff --git a/frontend/src/app/core/apiv3/paths/apiv3-resource.ts b/frontend/src/app/core/apiv3/paths/apiv3-resource.ts
index 3aab822ad17..92c21f8bc89 100644
--- a/frontend/src/app/core/apiv3/paths/apiv3-resource.ts
+++ b/frontend/src/app/core/apiv3/paths/apiv3-resource.ts
@@ -1,22 +1,20 @@
/* eslint-disable max-classes-per-file */
import { Constructor } from '@angular/cdk/table';
+import { Observable } from 'rxjs';
+import { HttpClient } from '@angular/common/http';
+
import {
SimpleResource,
SimpleResourceCollection,
} from 'core-app/core/apiv3/paths/path-resources';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
-import { Observable } from 'rxjs';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import {
- ApiV3Filter,
- ApiV3FilterBuilder,
-} from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
+import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';
import { getPaginatedResults } from 'core-app/core/apiv3/helpers/get-paginated-results';
-import { HttpClient } from '@angular/common/http';
import { addFiltersToPath } from 'core-app/core/apiv3/helpers/add-filters-to-path';
export class ApiV3ResourcePath<T = HalResource> extends SimpleResource {
@@ -24,10 +22,12 @@ export class ApiV3ResourcePath<T = HalResource> extends SimpleResource {
@InjectField() halResourceService:HalResourceService;
- constructor(protected apiRoot:ApiV3Service,
+ constructor(
+ protected apiRoot:ApiV3Service,
readonly basePath:string,
readonly id:string|number,
- protected parent?:ApiV3ResourcePath|ApiV3ResourceCollection<T, ApiV3GettableResource<T>>) {
+ protected parent?:ApiV3ResourcePath|ApiV3ResourceCollection<T, ApiV3GettableResource<T>>,
+ ) {
super(basePath, id);
}
@@ -78,10 +78,12 @@ export class ApiV3ResourceCollection<V, T extends ApiV3GettableResource<V>> exte
@InjectField() halResourceService:HalResourceService;
- constructor(protected apiRoot:ApiV3Service,
+ constructor(
+ protected apiRoot:ApiV3Service,
protected basePath:string,
segment:string,
- protected resource?:Constructor<T>) {
+ protected resource?:Constructor<T>,
+ ) {
super(basePath, segment, resource);
}
@@ -130,7 +132,11 @@ export class ApiV3ResourceCollection<V, T extends ApiV3GettableResource<V>> exte
* @param params additional URL params to append
* @param resourceClass The APIV3 resource class to instantiate
*/
- public filtered<R = ApiV3GettableResourceCollection<V>>(filters:ApiV3FilterBuilder, params:{ [key:string]:string } = {}, resourceClass?:Constructor<R>):R {
+ public filtered<R = ApiV3GettableResourceCollection<V>>(
+ filters:ApiV3FilterBuilder,
+ params:{ [key:string]:string } = {},
+ resourceClass?:Constructor<R>,
+ ):R {
const url = addFiltersToPath(this.path, filters, params);
const cls = resourceClass || ApiV3GettableResourceCollection;
// eslint-disable-next-line new-cap
@@ -159,7 +165,7 @@ export class ApiV3ResourceCollection<V, T extends ApiV3GettableResource<V>> exte
* @param segment Additional segment to add to the current path
* @param cls Class to use as return type
*/
- protected subResource<R = ApiV3GettableResource<HalResource>>(
+ protected subResource<R = ApiV3GettableResource>(
segment:string,
cls:Constructor<R> = ApiV3GettableResource as unknown as Constructor<R>,
):R {
diff --git a/frontend/src/app/core/state/collection-store.ts b/frontend/src/app/core/state/collection-store.ts
index 4c196d0c00a..3969bc09f4b 100644
--- a/frontend/src/app/core/state/collection-store.ts
+++ b/frontend/src/app/core/state/collection-store.ts
@@ -59,7 +59,6 @@ export function collectionKey(params:ApiV3ListParameters):string {
*
* @param store An entity store for the collection
* @param collectionUrl The key to insert the collection at
- * @param loading The loading state
*/
export function setCollectionLoading<T extends { id:ID }>(
store:EntityStore<CollectionState<T>>,
diff --git a/frontend/src/app/core/state/project-storages/project-storage.model.ts b/frontend/src/app/core/state/project-storages/project-storage.model.ts
new file mode 100644
index 00000000000..1a486ceb89f
--- /dev/null
+++ b/frontend/src/app/core/state/project-storages/project-storage.model.ts
@@ -0,0 +1,46 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 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 { ID } from '@datorama/akita';
+import { IHalResourceLink, IHalResourceLinks } from 'core-app/core/state/hal-resource';
+
+export interface IProjectStorageHalResourceLinks extends IHalResourceLinks {
+ storage:IHalResourceLink;
+ project:IHalResourceLink;
+ creator:IHalResourceLink;
+}
+
+export interface IProjectStorage {
+ id:ID;
+ projectFolderMode:string;
+ projectFolderId:string|null;
+ createdAt?:string;
+ lastModifiedAt?:string;
+
+ _links:IProjectStorageHalResourceLinks;
+}
diff --git a/frontend/src/app/core/state/project-storages/project-storages.service.ts b/frontend/src/app/core/state/project-storages/project-storages.service.ts
new file mode 100644
index 00000000000..9100ff26ef0
--- /dev/null
+++ b/frontend/src/app/core/state/project-storages/project-storages.service.ts
@@ -0,0 +1,47 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 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 {
+ CollectionStore,
+ ResourceCollectionService,
+} from 'core-app/core/state/resource-collection.service';
+import { IProjectStorage } from 'core-app/core/state/project-storages/project-storage.model';
+import { ProjectStoragesStore } from 'core-app/core/state/project-storages/project-storages.store';
+
+@Injectable()
+export class ProjectStoragesResourceService extends ResourceCollectionService<IProjectStorage> {
+ protected createStore():CollectionStore<IProjectStorage> {
+ return new ProjectStoragesStore();
+ }
+
+ protected basePath():string {
+ return this.apiV3Service.projectStorages.path;
+ }
+}
diff --git a/frontend/src/app/core/state/project-storages/project-storages.store.ts b/frontend/src/app/core/state/project-storages/project-storages.store.ts
new file mode 100644
index 00000000000..65ebd76a470
--- /dev/null
+++ b/frontend/src/app/core/state/project-storages/project-storages.store.ts
@@ -0,0 +1,41 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2023 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 { EntityStore, StoreConfig } from '@datorama/akita';
+
+import { IProjectStorage } from 'core-app/core/state/project-storages/project-storage.model';
+import { CollectionState, createInitialCollectionState } from 'core-app/core/state/collection-store';
+
+export interface ProjectStoragesState extends CollectionState<IProjectStorage> {}
+
+@StoreConfig({ name: 'project-storages' })
+export class ProjectStoragesStore extends EntityStore<ProjectStoragesState> {
+ constructor() {
+ super(createInitialCollectionState());
+ }
+}
diff --git a/frontend/src/app/core/state/resource-collection.service.ts b/frontend/src/app/core/state/resource-collection.service.ts
index 00a4593667a..5783f55f616 100644
--- a/frontend/src/app/core/state/resource-collection.service.ts
+++ b/frontend/src/app/core/state/resource-collection.service.ts
@@ -124,7 +124,7 @@ export abstract class ResourceCollectionService<T extends { id:ID }> {
return this
.collectionState(key)
.pipe(
- filter((collection) => !!collection),
+ filter(isDefinedEntity),
switchMap((collection:CollectionResponse) => this.query.selectMany(collection.ids)),
);
}
diff --git a/frontend/src/app/core/state/storage-files/storage-files.service.ts b/frontend/src/app/core/state/storage-files/storage-files.service.ts
index 68a9261efe6..8b1cd1de205 100644
--- a/frontend/src/app/core/state/storage-files/storage-files.service.ts
+++ b/frontend/src/app/core/state/storage-files/storage-files.service.ts
@@ -41,6 +41,7 @@ import { HttpClient } from '@angular/common/http';
import { ID, QueryEntity } from '@datorama/akita';
import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
import isDefinedEntity from 'core-app/core/state/is-defined-entity';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
@Injectable()
export class StorageFilesResourceService {
@@ -48,7 +49,10 @@ export class StorageFilesResourceService {
private readonly query = new QueryEntity(this.store);
- constructor(private readonly httpClient:HttpClient) {}
+ constructor(
+ private readonly httpClient:HttpClient,
+ private readonly apiV3Service:ApiV3Service,
+ ) {}
files(link:IHalResourceLink):Observable<IStorageFiles> {
const value = this.store.getValue().files[link.href];
@@ -67,6 +71,11 @@ export class StorageFilesResourceService {
.pipe(tap((storageFiles) => this.insert(storageFiles, link.href)));
}
+ file(storageId:ID, id:ID):Observable<IStorageFile> {
+ return this.httpClient
+ .get<IStorageFile>(`${this.apiV3Service.storages.id(storageId).path}/files/${id}`);
+ }
+
uploadLink(link:IPrepareUploadLink):Observable<IUploadLink> {
return this.httpClient.request<IUploadLink>(link.method, link.href, { body: link.payload });
}
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
index 322d1b2473a..dba8e7c7c68 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component.html
@@ -18,13 +18,14 @@
</section>
<section
- *ngFor="let storage of storages$ | async"
+ *ngFor="let sec of storageSections$ | async"
data-qa-selector="op-tab-content--tab-section"
class="op-tab-content--tab-section"
>
<op-storage
[resource]="workPackage"
- [storage]="storage"
+ [storage]="sec.storage | async"
+ [projectStorage]="sec.projectStorage"
[allowUploading]="allowManageFileLinks$ | async"
[allowLinking]="allowManageFileLinks$ | async"
></op-storage>
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 9a14a614494..6b379cfb157 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
@@ -26,15 +26,8 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import {
- ChangeDetectionStrategy,
- Component,
- OnInit,
-} from '@angular/core';
-import {
- combineLatest,
- Observable,
-} from 'rxjs';
+import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
+import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
@@ -43,8 +36,10 @@ import { HookService } from 'core-app/features/plugins/hook-service';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';
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';
+import { ProjectStoragesResourceService } from 'core-app/core/state/project-storages/project-storages.service';
+import idFromLink from 'core-app/features/hal/helpers/id-from-link';
+import { IProjectStorage } from 'core-app/core/state/project-storages/project-storage.model';
@Component({
selector: 'op-files-tab',
@@ -62,7 +57,7 @@ export class WorkPackageFilesTabComponent implements OnInit {
showAttachmentHeader$:Observable<boolean>;
- storages$:Observable<IStorage[]>;
+ storageSections$:Observable<{ projectStorage:IProjectStorage, storage:Observable<IStorage> }[]>;
allowManageFileLinks$:Observable<boolean>;
@@ -70,8 +65,8 @@ export class WorkPackageFilesTabComponent implements OnInit {
private readonly i18n:I18nService,
private readonly hook:HookService,
private readonly currentUserService:CurrentUserService,
- private readonly projectsResourceService:ProjectsResourceService,
private readonly storagesResourceService:StoragesResourceService,
+ private readonly projectStoragesResourceService:ProjectStoragesResourceService,
) { }
ngOnInit():void {
@@ -82,17 +77,23 @@ export class WorkPackageFilesTabComponent implements OnInit {
const canViewFileLinks = this.currentUserService.hasCapabilities$('file_links/view', project.id);
- this.storages$ = this
- .storagesResourceService
- .collection(project.href as string);
+ this.storageSections$ = this.projectStoragesResourceService.require({ filters: [['projectId', '=', [project.id]]] })
+ .pipe(
+ map((projectStorages) =>
+ projectStorages
+ .map((ps) => ({
+ projectStorage: ps,
+ storage: this.storagesResourceService.lookup(idFromLink(ps._links.storage.href)),
+ }))),
+ );
this.allowManageFileLinks$ = this
.currentUserService
- .hasCapabilities$('file_links/manage', (this.workPackage.project as unknown&{ id:string }).id);
+ .hasCapabilities$('file_links/manage', project.id);
this.showAttachmentHeader$ = combineLatest(
[
- this.storages$,
+ this.storageSections$,
canViewFileLinks,
],
).pipe(
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.html b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.html
index e2644d96d01..f6cd3d6c6be 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.html
+++ b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.html
@@ -145,9 +145,10 @@
</div>
<op-storage
- *ngFor="let storage of storages$ | async"
+ *ngFor="let sec of storageSections$ | async"
[resource]="workPackage"
- [storage]="storage"
+ [storage]="sec.storage | async"
+ [projectStorage]="sec.projectStorage"
[allowLinking]="true"
[allowUploading]="true"
></op-storage>
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts
index 9a560e56833..cc52eb0ac95 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view/wp-single-view.component.ts
@@ -36,12 +36,17 @@ import {
OnInit,
} from '@angular/core';
import { StateService } from '@uirouter/core';
-import { BehaviorSubject, combineLatest, of } from 'rxjs';
+import {
+ BehaviorSubject,
+ combineLatest,
+ Observable,
+ of,
+} from 'rxjs';
import {
distinctUntilChanged,
+ first,
map,
switchMap,
- take,
} from 'rxjs/operators';
import { I18nService } from 'core-app/core/i18n/i18n.service';
@@ -69,6 +74,8 @@ import { CurrentUserService } from 'core-app/core/current-user/current-user.serv
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
+import { ProjectStoragesResourceService } from 'core-app/core/state/project-storages/project-storages.service';
+import { IProjectStorage } from 'core-app/core/state/project-storages/project-storage.model';
export interface FieldDescriptor {
name:string;
@@ -148,7 +155,8 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
$element:JQuery;
- storages$ = new BehaviorSubject<IStorage[]>([]);
+ // storages$ = new BehaviorSubject<IStorage[]>([]);
+ storageSections$ = new BehaviorSubject<{ projectStorage:IProjectStorage, storage:Observable<IStorage> }[]>([]);
constructor(
protected readonly injector:Injector,
@@ -167,6 +175,7 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
private readonly storagesService:StoragesResourceService,
private readonly displayFieldService:DisplayFieldService,
private readonly projectsResourceService:ProjectsResourceService,
+ private readonly projectStoragesService:ProjectStoragesResourceService,
) {
super();
}
@@ -232,25 +241,35 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemen
}
if (resource.project === null) {
- this.storages$.next([]);
+ this.storageSections$.next([]);
} else {
const project = resource.project as unknown&{ href:string, id:string };
combineLatest([
this.projectsResourceService.update(project.href),
+ this.projectStoragesService.require({ filters: [['projectId', '=', [project.id]]] }),
this.currentUserService.hasCapabilities$('file_links/manage', project.id),
])
.pipe(
- switchMap(([p, manageFileLinks]) => {
+ switchMap(([p, projectStorages, manageFileLinks]) => {
if (!p._links.storages || !manageFileLinks) {
- return of([] as IStorage[]);
+ return of([]);
}
- return this.storagesService.updateCollection(p._links.self.href, p._links.storages);
+ return this.storagesService
+ .updateCollection(p._links.self.href, p._links.storages)
+ .pipe(
+ map(() =>
+ projectStorages
+ .map((ps) => ({
+ projectStorage: ps,
+ storage: this.storagesService.lookup(idFromLink(ps._links.storage.href)),
+ }))),
+ );
}),
- take(1),
+ first(),
)
.subscribe((storages) => {
- this.storages$.next(storages);
+ this.storageSections$.next(storages);
});
}
}
diff --git a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
index 5a8f5f0343c..1874f36e4a9 100644
--- a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
+++ b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
@@ -180,6 +180,7 @@ import { OpenprojectStoragesModule } from 'core-app/shared/components/storages/o
import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';
import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';
import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';
+import { ProjectStoragesResourceService } from 'core-app/core/state/project-storages/project-storages.service';
@NgModule({
imports: [
@@ -238,6 +239,7 @@ import { StorageFilesResourceService } from 'core-app/core/state/storage-files/s
StorageFilesResourceService,
StoragesResourceService,
+ ProjectStoragesResourceService,
],
declarations: [
// Routing
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 3148bdba9b3..cff3c2cb07e 100644
--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts
+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts
@@ -36,11 +36,9 @@ import {
OnInit,
ViewChild,
} from '@angular/core';
+import { HttpErrorResponse } from '@angular/common/http';
import {
- HttpErrorResponse,
-} from '@angular/common/http';
-import {
- BehaviorSubject,
+ BehaviorSubject, combineLatest,
Observable,
of,
throwError,
@@ -59,6 +57,7 @@ import { v4 as uuidv4 } from 'uuid';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { IFileLink, IFileLinkOriginData } from 'core-app/core/state/file-links/file-link.model';
import { IPrepareUploadLink, IStorage } from 'core-app/core/state/storages/storage.model';
+import { IProjectStorage } from 'core-app/core/state/project-storages/project-storage.model';
import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';
import {
fileLinkViewError,
@@ -114,6 +113,8 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
@Input() public storage:IStorage;
+ @Input() public projectStorage:IProjectStorage;
+
@Input() public allowUploading = true;
@Input() public allowLinking = true;
@@ -272,20 +273,21 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
}
public openLinkFilesDialog():void {
- this.fileLinks$
- .pipe(take(1))
- .subscribe((fileLinks) => {
- const locals = {
- storageType: this.storage._links.type.href,
- storageName: this.storage.name,
- storageLink: this.storage._links.self,
- addFileLinksHref: this.addFileLinksHref,
- collectionKey: this.collectionKey,
- location: '/',
- fileLinks,
- };
- this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);
- });
+ combineLatest([
+ this.fileLinks$.pipe(take(1)),
+ this.entryLocation(),
+ ]).subscribe(([fileLinks, location]) => {
+ const locals = {
+ storageType: this.storage._links.type.href,
+ storageName: this.storage.name,
+ storageLink: this.storage._links.self,
+ addFileLinksHref: this.addFileLinksHref,
+ collectionKey: this.collectionKey,
+ location,
+ fileLinks,
+ };
+ this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);
+ });
}
public triggerFileInput():void {
@@ -301,9 +303,24 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
this.filePicker.nativeElement.value = '';
}
+ private entryLocation():Observable<string> {
+ if (this.projectStorage.projectFolderMode === 'inactive') {
+ return of('/');
+ }
+
+ if (this.projectStorage.projectFolderId === null) {
+ throw new Error(`Project folder id 'null' not allowed for project folder mode '${this.projectStorage.projectFolderMode}'.`);
+ }
+
+ return this.storageFilesResourceService
+ .file(this.storage.id, this.projectStorage.projectFolderId)
+ .pipe(map((file) => file.location));
+ }
+
private storageFileUpload(file:File):void {
- this.selectUploadLocation()
+ this.entryLocation()
.pipe(
+ switchMap((entryLocation) => this.selectUploadLocation(entryLocation)),
switchMap((data) => this.resolveUploadConflicts(file, data.files, data.location)),
)
.subscribe((data) => {
@@ -311,12 +328,12 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnD
});
}
- private selectUploadLocation():Observable<LocationData> {
+ private selectUploadLocation(entryLocation:string):Observable<LocationData> {
const locals = {
storageType: this.storage._links.type.href,
storageName: this.storage.name,
storageLink: this.storage._links.self,
- location: '/',
+ location: entryLocation,
};
return this.opModalService.show<LocationPickerModalComponent>(LocationPickerModalComponent, 'global', locals)