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

Added dynamic viewing of storages in work package view

Andreas Pfohldd6688f2735e
diff --git a/frontend/src/app/core/state/projects/project.model.ts b/frontend/src/app/core/state/projects/project.model.ts
index 5af6b823b8b..4fe8d3c29fc 100644
--- a/frontend/src/app/core/state/projects/project.model.ts
+++ b/frontend/src/app/core/state/projects/project.model.ts
@@ -5,8 +5,6 @@ import {
IFormattable,
} from 'core-app/core/state/hal-resource';
-export const PROJECTS_MAX_SIZE = 100;
-
export interface IProjectHalResourceLinks extends IHalResourceLinks {
ancestors:IHalResourceLink[];
categories:IHalResourceLink;
@@ -15,6 +13,7 @@ export interface IProjectHalResourceLinks extends IHalResourceLinks {
self:IHalResourceLink;
status:IHalResourceLink;
schema:IHalResourceLink;
+ storages:IHalResourceLink[];
}
export interface IProject {
diff --git a/frontend/src/app/core/state/projects/projects.service.ts b/frontend/src/app/core/state/projects/projects.service.ts
index 3d06b39c9a8..8488b9212ec 100644
--- a/frontend/src/app/core/state/projects/projects.service.ts
+++ b/frontend/src/app/core/state/projects/projects.service.ts
@@ -4,10 +4,7 @@ import {
tap,
} from 'rxjs/operators';
import { Observable } from 'rxjs';
-import {
- applyTransaction,
- ID,
-} from '@datorama/akita';
+import { ID } from '@datorama/akita';
import { HttpClient } from '@angular/common/http';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
@@ -56,22 +53,11 @@ export class ProjectsResourceService {
);
}
- update(id:ID, project:Partial<IProject>):void {
- this.store.update(id, project);
+ lookup(id:ID):Observable<IProject | undefined> {
+ return this.query.selectEntity(id);
}
- modifyCollection(params:ApiV3ListParameters, callback:(collection:ID[]) => ID[]):void {
- const key = collectionKey(params);
- this.store.update(({ collections }) => (
- {
- collections: {
- ...collections,
- [key]: {
- ...collections[key],
- ids: [...callback(collections[key]?.ids || [])],
- },
- },
- }
- ));
+ update(id:ID, project:Partial<IProject>):void {
+ this.store.update(id, project);
}
}
diff --git a/frontend/src/app/core/state/storages/storage.model.ts b/frontend/src/app/core/state/storages/storage.model.ts
new file mode 100644
index 00000000000..94f728395c4
--- /dev/null
+++ b/frontend/src/app/core/state/storages/storage.model.ts
@@ -0,0 +1,45 @@
+// -- 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 { ID } from '@datorama/akita';
+import { IHalResourceLink, IHalResourceLinks } from 'core-app/core/state/hal-resource';
+
+export interface IStorageHalResourceLinks extends IHalResourceLinks {
+ self:IHalResourceLink;
+ type:IHalResourceLink;
+ origin:IHalResourceLink;
+}
+
+export interface IStorage {
+ id:ID;
+ name:string;
+ createdAt?:string;
+ lastModifiedAt?:string;
+
+ _links?:IStorageHalResourceLinks;
+}
diff --git a/frontend/src/app/core/state/storages/storages.service.ts b/frontend/src/app/core/state/storages/storages.service.ts
new file mode 100644
index 00000000000..c13ee5bc011
--- /dev/null
+++ b/frontend/src/app/core/state/storages/storages.service.ts
@@ -0,0 +1,42 @@
+// -- 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 { HttpClient } from '@angular/common/http';
+import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+import { Observable } from 'rxjs';
+import { IStorage } from 'core-app/core/state/storages/storage.model';
+
+@Injectable()
+export class StoragesResourceService {
+ constructor(private httpClient:HttpClient) {}
+
+ lookup(storageLink:IHalResourceLink):Observable<IStorage> {
+ return this.httpClient.get<IStorage>(storageLink.href);
+ }
+}
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 07005124e40..e6378bdd7a8 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
@@ -29,25 +29,28 @@
import {
ChangeDetectionStrategy,
Component,
- OnDestroy,
OnInit,
} from '@angular/core';
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 { Subscription } from 'rxjs';
+import { forkJoin, Observable, of } from 'rxjs';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
+import { ProjectsResourceService } from 'core-app/core/state/projects/projects.service';
+import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';
+import { switchMap } from 'rxjs/operators';
+import { IStorage } from 'core-app/core/state/storages/storage.model';
@Component({
selector: 'op-files-tab',
templateUrl: './op-files-tab.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class WorkPackageFilesTabComponent implements OnInit, OnDestroy {
- public workPackage:WorkPackageResource;
+export class WorkPackageFilesTabComponent implements OnInit {
+ workPackage:WorkPackageResource;
- public text = {
+ text = {
attachments: {
label: this.I18n.t('js.label_attachments'),
},
@@ -56,27 +59,35 @@ export class WorkPackageFilesTabComponent implements OnInit, OnDestroy {
},
};
- public canViewFileLinks = true;
+ canViewFileLinks$:Observable<boolean>;
- private subscription:Subscription;
+ storages$:Observable<IStorage[]>;
constructor(
readonly I18n:I18nService,
protected hook:HookService,
private currentUserService:CurrentUserService,
private currentProjectService:CurrentProjectService,
+ private projectsResourceService:ProjectsResourceService,
+ private storagesResourceService:StoragesResourceService,
) { }
ngOnInit():void {
- this.subscription = this
+ const projectId = this.currentProjectService.id as string;
+
+ this.canViewFileLinks$ = this
.currentUserService
- .hasCapabilities$('file_links/view', this.currentProjectService.id as string)
- .subscribe((value) => {
- this.canViewFileLinks = value;
- });
- }
+ .hasCapabilities$('file_links/view', projectId);
+
+ this.storages$ = this.projectsResourceService.lookup(projectId)
+ .pipe(
+ switchMap((project) => {
+ if (project === undefined) {
+ return of([]);
+ }
- ngOnDestroy():void {
- this.subscription.unsubscribe();
+ return forkJoin(project._links.storages.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.html
index 199687aeb13..2590631bf1e 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
@@ -1,6 +1,6 @@
<div class="op-tab-content--container">
<section data-qa-selector="op-tab-content--tab-section">
- <div class="op-tab-content--header">
+ <div *ngIf="canViewFileLinks$ | async" class="op-tab-content--header">
<h3 class="op-tab-content--header-text" [textContent]="text.attachments.label"></h3>
</div>
@@ -9,10 +9,10 @@
<op-attachments-upload [resource]="workPackage"></op-attachments-upload>
</section>
- <section *ngIf="canViewFileLinks" data-qa-selector="op-tab-content--tab-section">
+ <section *ngFor="let storage of storages$ | async" data-qa-selector="op-tab-content--tab-section">
<div class=op-tab-content--header>
<op-icon icon-classes="icon3 icon-nextcloud-circle op-files-tab--color-blue-deep"></op-icon>
- <h3 class="op-tab-content--header-text" [textContent]="text.file_links.label"></h3>
+ <h3 class="op-tab-content--header-text" [textContent]="storage.name"></h3>
</div>
<op-file-link-list [resource]="workPackage"></op-file-link-list>
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 6d980cd1ee3..3bcff5fd787 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
@@ -395,6 +395,7 @@ import { WorkPackagesQueryViewService } from 'core-app/features/work-packages/co
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
import { OpenprojectFileLinksModule } from 'core-app/shared/components/file-links/openproject-file-links.module';
import { FileLinkResourceService } from 'core-app/core/state/file-links/file-links.service';
+import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';
@NgModule({
imports: [
@@ -450,6 +451,8 @@ import { FileLinkResourceService } from 'core-app/core/state/file-links/file-lin
HalEventsService,
FileLinkResourceService,
+
+ StoragesResourceService,
],
declarations: [
// Routing