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

[#42157] added styles and logic for storage information

Eric Schubert2c0b6849b76b
diff --git a/frontend/src/app/core/state/projects/projects.service.ts b/frontend/src/app/core/state/projects/projects.service.ts
index e004952300c..ab203d71a8b 100644
--- a/frontend/src/app/core/state/projects/projects.service.ts
+++ b/frontend/src/app/core/state/projects/projects.service.ts
@@ -28,7 +28,7 @@
import { Injectable } from '@angular/core';
import {
- catchError,
+ catchError, map,
tap,
} from 'rxjs/operators';
import { Observable } from 'rxjs';
@@ -81,7 +81,7 @@ export class ProjectsResourceService {
);
}
- lookup(id:ID, require = false):Observable<IProject|undefined> {
+ lookup(id:ID, require = false):Observable<IProject> {
if (require && !this.query.hasEntity(id)) {
return this.http
.get<IProject>(`${this.projectsPath}/${id}`)
@@ -94,7 +94,15 @@ export class ProjectsResourceService {
);
}
- return this.query.selectEntity(id);
+ return this.query.selectEntity(id)
+ .pipe(
+ map((project) => {
+ if (!project) {
+ throw new Error('not found');
+ }
+ return project;
+ }),
+ );
}
update(id:ID, project:Partial<IProject>):void {
diff --git a/frontend/src/app/core/state/storages/storage.model.ts b/frontend/src/app/core/state/storages/storage.model.ts
index 94f728395c4..baa43cb8386 100644
--- a/frontend/src/app/core/state/storages/storage.model.ts
+++ b/frontend/src/app/core/state/storages/storage.model.ts
@@ -33,6 +33,7 @@ export interface IStorageHalResourceLinks extends IHalResourceLinks {
self:IHalResourceLink;
type:IHalResourceLink;
origin:IHalResourceLink;
+ connectionState:IHalResourceLink;
}
export interface IStorage {
diff --git a/frontend/src/app/core/state/storages/storages.query.ts b/frontend/src/app/core/state/storages/storages.query.ts
new file mode 100644
index 00000000000..1a737d475a3
--- /dev/null
+++ b/frontend/src/app/core/state/storages/storages.query.ts
@@ -0,0 +1,32 @@
+// -- 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 { QueryEntity } from '@datorama/akita';
+import { StoragesState } from 'core-app/core/state/storages/storages.store';
+
+export class StoragesQuery extends QueryEntity<StoragesState> {}
diff --git a/frontend/src/app/core/state/storages/storages.service.ts b/frontend/src/app/core/state/storages/storages.service.ts
index df8310a5c2f..7d3e9a2523b 100644
--- a/frontend/src/app/core/state/storages/storages.service.ts
+++ b/frontend/src/app/core/state/storages/storages.service.ts
@@ -28,25 +28,59 @@
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 { catchError, map, tap } from 'rxjs/operators';
import { IStorage } from 'core-app/core/state/storages/storage.model';
-import {
- ILiveFileLinkCollection,
-} from 'core-app/features/work-packages/components/wp-single-view-tabs/files-tab/op-files-tab.component';
+import { StoragesStore } from 'core-app/core/state/storages/storages.store';
+import { StoragesQuery } from 'core-app/core/state/storages/storages.query';
+import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { ToastService } from 'core-app/shared/components/toaster/toast.service';
+import idFromLink from 'core-app/features/hal/helpers/id-from-link';
@Injectable()
export class StoragesResourceService {
- constructor(private httpClient:HttpClient) {}
+ protected store = new StoragesStore();
+
+ protected readonly query = new StoragesQuery(this.store);
- lookup(storageLink:IHalResourceLink):Observable<IStorage> {
- return this.httpClient.get<IStorage>(storageLink.href);
+ private get storagesPath():string {
+ return `${this.apiV3Service.root.path}/storages`;
}
- liveLinks(storage:IStorage):(containerType:string, containerId:string) => Observable<ILiveFileLinkCollection> {
- return (containerType:string, containerId:string):Observable<ILiveFileLinkCollection> => {
- const url = `${storage._links?.self.href || ''}/live_file_links?container_type=${containerType}&container_id=${containerId}`;
- return this.httpClient.get<ILiveFileLinkCollection>(url);
- };
+ constructor(
+ private readonly http:HttpClient,
+ private readonly toastService:ToastService,
+ private readonly apiV3Service:ApiV3Service,
+ ) {}
+
+ lookup(link:IHalResourceLink, require = false):Observable<IStorage> {
+ const id = idFromLink(link.href);
+
+ if (require && !this.query.hasEntity(id)) {
+ return this.http
+ .get<IStorage>(`${this.storagesPath}/${id}`)
+ .pipe(
+ tap((storage) => {
+ if (storage) {
+ this.store.add(storage);
+ }
+ }),
+ catchError((error) => {
+ this.toastService.addError(error);
+ throw error;
+ }),
+ );
+ }
+
+ return this.query.selectEntity(id)
+ .pipe(
+ map((storage) => {
+ if (!storage) {
+ throw new Error('not found');
+ }
+ return storage;
+ }),
+ );
}
}
diff --git a/frontend/src/app/core/state/storages/storages.store.ts b/frontend/src/app/core/state/storages/storages.store.ts
new file mode 100644
index 00000000000..c3eb3210ffe
--- /dev/null
+++ b/frontend/src/app/core/state/storages/storages.store.ts
@@ -0,0 +1,40 @@
+// -- 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 { EntityStore, StoreConfig } from '@datorama/akita';
+import { CollectionState, createInitialCollectionState } from 'core-app/core/state/collection-store';
+import { IStorage } from 'core-app/core/state/storages/storage.model';
+
+export interface StoragesState extends CollectionState<IStorage> {}
+
+@StoreConfig({ name: 'storages' })
+export class StoragesStore extends EntityStore<StoragesState> {
+ constructor() {
+ super(createInitialCollectionState());
+ }
+}
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 f598fc9c4e3..c8e719ca282 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,28 +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, of } from 'rxjs';
+import { forkJoin, Observable } from 'rxjs';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
import { StoragesResourceService } from 'core-app/core/state/storages/storages.service';
-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
-}
-
-export interface ILiveFileLinkCollectionEmbeddings {
-
-}
-
-export interface ILiveFileLinkCollection {
- _links:ILiveFileLinkCollectionsLinks;
- _embedded:ILiveFileLinkCollectionEmbeddings;
-}
-
@Component({
selector: 'op-files-tab',
templateUrl: './op-files-tab.html',
@@ -98,15 +84,12 @@ export class WorkPackageFilesTabComponent implements OnInit {
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)),
+ .lookup(link, true)),
);
}),
);
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.ts
index 2405fa86126..62c09137f45 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
@@ -49,6 +49,8 @@ export class FileLinkListComponent implements OnInit {
$fileLinks:Observable<IFileLink[]>;
+ storageConnectionState:'connected'|'authenticationFailed'|'connectionError';
+
constructor(private readonly fileLinkResourceService:FileLinkResourceService) {}
ngOnInit():void {
@@ -62,6 +64,21 @@ export class FileLinkListComponent implements OnInit {
}
}),
);
+
+ this.deriveStorageInformation();
+ }
+
+ private deriveStorageInformation():void {
+ switch (this.storage._links?.connectionState.href) {
+ case 'urn:openproject-org:api:v3:storages:connection:FailedAuthentication':
+ this.storageConnectionState = 'authenticationFailed';
+ break;
+ case 'urn:openproject-org:api:v3:storages:connection:Error':
+ this.storageConnectionState = 'connectionError';
+ break;
+ default:
+ this.storageConnectionState = 'connected';
+ }
}
private get fileLinkSelfLink():string {
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html
index 10d84ea0457..43f01e2d41a 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html
+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html
@@ -1,10 +1,129 @@
<div class="work-package--attachments--files" *ngIf="resource" data-qa-selector="op-files-tab--file-link-list">
- <op-file-link-list-item
- *ngFor="let fileLink of $fileLinks | async; let i = index;"
- class="op-files-tab--file-list-item"
- data-qa-selector="op-files-tab--file-list-item"
- [fileLink]="fileLink"
- [resource]="resource"
- [index]="i">
- </op-file-link-list-item>
-</div>
\ No newline at end of file
+ <!-- Textbox for no file links TODO: extract to shared component -->
+ <div
+ *ngIf="($fileLinks | async).length === 0 && storageConnectionState === 'connected'"
+ class="op-files-tab--storage-info-box"
+ >
+ <div
+ class="icon-box"
+ >
+ <i
+ class="icon icon-info1"
+ ></i>
+ </div>
+
+ <div
+ class="text-box"
+ >
+ <div
+ class="text-box-header"
+ >
+ <span>Link files in Nextcloud</span>
+ </div>
+ <div
+ class="text-box-content"
+ >
+ <span>In order to link files to this work package please do it via Nextcloud</span>
+ </div>
+ </div>
+
+ <div
+ class="button-box"
+ >
+ <button
+ class="action-button"
+ [textContent]="'Open Nextcloud'"
+ ></button>
+ </div>
+ </div>
+
+ <!-- Textbox for authentication error -->
+ <div
+ *ngIf="storageConnectionState === 'authenticationFailed'"
+ class="op-files-tab--storage-info-box"
+ >
+ <div
+ class="icon-box"
+ >
+ <i
+ class="icon icon-info1"
+ ></i>
+ </div>
+
+ <div
+ class="text-box"
+ >
+ <div
+ class="text-box-header"
+ >
+ <span>Login to Nextcloud</span>
+ </div>
+ <div
+ class="text-box-content"
+ >
+ <span>To add a link, see or upload files related to this work package, please login to Nextcloud</span>
+ </div>
+ </div>
+
+ <div
+ class="button-box"
+ >
+ <button
+ class="action-button"
+ [textContent]="'Nextcloud login'"
+ ></button>
+ </div>
+ </div>
+
+ <!-- Textbox for connection error -->
+ <div
+ *ngIf="storageConnectionState === 'connectionError'"
+ class="op-files-tab--storage-info-box"
+ >
+ <div
+ class="icon-box"
+ >
+ <i
+ class="icon icon-info1"
+ ></i>
+ </div>
+
+ <div
+ class="text-box"
+ >
+ <div
+ class="text-box-header"
+ >
+ <span>No Nextcloud connection</span>
+ </div>
+ <div
+ class="text-box-content"
+ >
+ <span>Some Nextcloud settings are not working. Please try to login again or contact your Nexcloud administrator</span>
+ </div>
+ </div>
+
+ <div
+ class="button-box"
+ >
+ <button
+ class="action-button"
+ [textContent]="'Nextcloud login'"
+ ></button>
+ </div>
+ </div>
+
+ <div
+ *ngIf="storageConnectionState !== 'connectionError'"
+ >
+ <op-file-link-list-item
+ *ngFor="let fileLink of $fileLinks | async; let i = index;"
+ class="op-files-tab--file-list-item"
+ [ngClass]="{ 'inactive': storageConnectionState === 'authenticationFailed' }"
+ data-qa-selector="op-files-tab--file-list-item"
+ [fileLink]="fileLink"
+ [resource]="resource"
+ [index]="i">
+ </op-file-link-list-item>
+ </div>
+</div>
diff --git a/frontend/src/global_styles/content/work_packages/tabs/_files.sass b/frontend/src/global_styles/content/work_packages/tabs/_files.sass
index 801ef4b6f8a..94606308977 100644
--- a/frontend/src/global_styles/content/work_packages/tabs/_files.sass
+++ b/frontend/src/global_styles/content/work_packages/tabs/_files.sass
@@ -32,6 +32,9 @@
grid-template-columns: 1fr 1fr
height: 40px
+ &.inactive
+ opacity: 0.5
+
&--content
align-self: center
width: 100%
@@ -49,6 +52,47 @@
&--file-info-timestamp
margin-right: 8px
+ &--storage-info-box
+ margin-top: 14px
+ display: grid
+ grid-template: "icon text" "button button" / auto 1fr
+
+ .icon-box
+ height: 54px
+ width: 54px
+ grid-area: icon
+ display: flex
+ justify-content: center
+ align-items: center
+
+ .icon
+ color: #878787
+ font-size: 36px
+
+ .text-box
+ grid-area: text
+
+ .text-box-header
+ font-size: 16px
+ font-weight: 700
+ line-height: 24px
+
+ .text-box-content
+ font-size: 14px
+ font-weight: 400
+ line-height: 20px
+ color: #878787
+
+ .button-box
+ grid-area: button
+ display: flex
+ justify-content: end
+
+ .action-button
+ padding: 4px 12px
+ font-size: 14px
+ line-height: 20px
+
&--color
&-red
color: #B93A33