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] extracted storage information box

Eric Schubert1b22dd951116
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index ee2231bd09d..26ef9f5f31e 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -40,8 +40,8 @@ en:
autocomplete_select:
placeholder:
- multi: "Add \"%{name}\""
- single: "Select \"%{name}\""
+ multi: "Add \"%{name}\""
+ single: "Select \"%{name}\""
remove: "Remove %{name}"
active: "Active %{label} %{name}"
@@ -422,6 +422,7 @@ en:
label_less_or_equal: "<="
label_less_than_ago: "less than days ago"
label_loading: "Loading..."
+ label_login_to_storage: "Login to %{storageType}"
label_mail_notification: "Email notifications"
label_me: "me"
label_meeting_agenda: "Agenda"
@@ -435,13 +436,17 @@ en:
label_no_data: "No data to display"
label_no_due_date: "no finish date"
label_no_start_date: "no start date"
+ label_no_storage_connection: "No %{storageType} connection"
label_no_value: "No value"
+ label_no_file_links_header: "Link files in %{storageType}"
+ label_no_file_links_content: "In order to link files to this work package please do it via %{storageType}."
label_none: "none"
label_not_contains: "doesn't contain"
label_not_equals: "is not"
label_on: "on"
label_open_menu: "Open menu"
label_open_context_menu: "Open context menu"
+ label_open_storage: "Open %{storageType}"
label_open_work_packages: "open"
label_password: "Password"
label_previous: "Previous"
@@ -470,6 +475,9 @@ en:
label_sorting: "Sorting"
label_spent_time: "Spent time"
label_star_query: "Favored"
+ label_storage_connection_error: "Some %{storageType} settings are not working. Please try to login again or contact your %{storageType} administrator."
+ label_storage_login: "%{storageType} login"
+ label_storage_not_connected: "To add a link, see or upload files related to this work package, please login to %{storageType}."
label_press_enter_to_save: "Press enter to save."
label_public_query: "Public"
label_sum: "Sum"
@@ -816,7 +824,7 @@ en:
sort:
sorted_asc: 'Ascending sort applied, '
sorted_dsc: 'Descending sort applied, '
- sorted_no : 'No sort applied, '
+ sorted_no: 'No sort applied, '
sorting_disabled: 'sorting is disabled'
activate_asc: 'activate to apply an ascending sort'
activate_dsc: 'activate to apply a descending sort'
@@ -858,12 +866,12 @@ en:
outline: "Reset Outline"
outlines:
aggregation: "Show aggregations only"
- level1: "Expand level 1"
- level2: "Expand level 2"
- level3: "Expand level 3"
- level4: "Expand level 4"
- level5: "Expand level 5"
- all: "Show all"
+ level1: "Expand level 1"
+ level2: "Expand level 2"
+ level3: "Expand level 3"
+ level4: "Expand level 4"
+ level5: "Expand level 5"
+ all: "Show all"
project_status: "Project status"
really_close_dialog: "Do you really want to close the dialog and lose the entered data?"
responsible: "Responsible"
@@ -936,7 +944,7 @@ en:
message_work_package_status_blocked: "Work package status is not writable due to closed status and closed version being assigned."
placeholder_filter_by_text: "Subject, description, comments, ..."
inline_create:
- title: 'Click here to add a new work package to this list'
+ title: 'Click here to add a new work package to this list'
create:
title: 'New work package'
header: 'New %{type}'
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.ts
index 965c8ac8cf2..b8a577e58fc 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
@@ -37,6 +37,7 @@ export interface IFileLinkHalResourceLinks extends IHalResourceLinks {
container:IHalResourceLink;
creator:IHalResourceLink;
delete?:IHalResourceLink;
+ permission:IHalResourceLink;
originOpen:IHalResourceLink;
staticOriginOpen:IHalResourceLink;
originOpenLocation:IHalResourceLink;
@@ -57,5 +58,5 @@ export interface IFileLink {
id:ID;
originData:IFileLinkOriginData;
- _links?:IFileLinkHalResourceLinks;
+ _links:IFileLinkHalResourceLinks;
}
diff --git a/frontend/src/app/core/state/storages/storage.model.ts b/frontend/src/app/core/state/storages/storage.model.ts
index baa43cb8386..e96e5aff8e1 100644
--- a/frontend/src/app/core/state/storages/storage.model.ts
+++ b/frontend/src/app/core/state/storages/storage.model.ts
@@ -42,5 +42,5 @@ export interface IStorage {
createdAt?:string;
lastModifiedAt?:string;
- _links?:IStorageHalResourceLinks;
+ _links:IStorageHalResourceLinks;
}
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 62c09137f45..21f549b9028 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
@@ -29,64 +29,152 @@
import {
ChangeDetectionStrategy, Component, Input, OnInit,
} from '@angular/core';
-import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { Observable } from 'rxjs';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
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 { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
-import { tap } from 'rxjs/operators';
@Component({
selector: 'op-file-link-list',
templateUrl: './file-link-list.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class FileLinkListComponent implements OnInit {
+export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit {
@Input() public resource:HalResource;
@Input() public storage:IStorage;
- $fileLinks:Observable<IFileLink[]>;
+ fileLinks$:Observable<IFileLink[]>;
+
+ informationBoxHeader:string;
+
+ informationBoxContent:string;
+
+ informationBoxButton:string;
+
+ informationBoxIcon:string;
+
+ showInformationBox = false;
+
+ showFileLinks = false;
- storageConnectionState:'connected'|'authenticationFailed'|'connectionError';
+ private readonly storageTypeMap:{ [urn:string]:string; } = {
+ 'urn:openproject-org:api:v3:storages:Nextcloud': 'Nextcloud',
+ };
- constructor(private readonly fileLinkResourceService:FileLinkResourceService) {}
+ private text:{
+ infoBox:{
+ emptyStorageHeader:string,
+ emptyStorageContent:string,
+ emptyStorageButton:string,
+ connectionErrorHeader:string,
+ connectionErrorContent:string,
+ authenticationFailureHeader:string,
+ authenticationFailureContent:string,
+ loginButton:string,
+ }
+ };
+
+ constructor(
+ private readonly i18n:I18nService,
+ private readonly fileLinkResourceService:FileLinkResourceService,
+ ) {
+ super();
+ }
ngOnInit():void {
+ this.initializeLocales();
+
this.fileLinkResourceService.fetchCurrent(this.fileLinkSelfLink);
- this.$fileLinks = this.fileLinkResourceService.all(this.collectionKey)
- .pipe(
- tap((fileLinks) => {
- if (isNewResource(this.resource)) {
- this.resource.fileLinks = { elements: fileLinks.map((a) => a._links?.self) };
- }
- }),
- );
+ this.fileLinks$ = this.fileLinkResourceService.all(this.collectionKey);
+
+ this.fileLinks$
+ .pipe(this.untilDestroyed())
+ .subscribe((fileLinks) => {
+ if (isNewResource(this.resource)) {
+ this.resource.fileLinks = { elements: fileLinks.map((a) => a._links?.self) };
+ }
+
+ this.deriveStorageInformation(fileLinks.length);
+ });
+ }
+
+ private get collectionKey():string {
+ return isNewResource(this.resource) ? 'new' : this.fileLinkSelfLink;
+ }
- this.deriveStorageInformation();
+ private get fileLinkSelfLink():string {
+ const fileLinks = this.resource.fileLinks as unknown&{ href:string };
+ return `${fileLinks.href}?filters=[{"storage":{"operator":"=","values":["${this.storage.id}"]}}]`;
}
- private deriveStorageInformation():void {
+ private deriveStorageInformation(fileLinkCount:number):void {
switch (this.storage._links?.connectionState.href) {
case 'urn:openproject-org:api:v3:storages:connection:FailedAuthentication':
- this.storageConnectionState = 'authenticationFailed';
+ this.setAuthenticationFailureState();
break;
case 'urn:openproject-org:api:v3:storages:connection:Error':
- this.storageConnectionState = 'connectionError';
+ this.setConnectionErrorState();
+ break;
+ case 'urn:openproject-org:api:v3:storages:connection:Connected':
+ if (fileLinkCount === 0) {
+ this.setEmptyFileLinkListState();
+ } else {
+ this.showInformationBox = false;
+ this.showFileLinks = true;
+ }
break;
default:
- this.storageConnectionState = 'connected';
+ this.showInformationBox = false;
+ this.showFileLinks = false;
}
}
- private get fileLinkSelfLink():string {
- const fileLinks = this.resource.fileLinks as unknown&{ href:string };
- return `${fileLinks.href}?filters=[{"storage":{"operator":"=","values":["${this.storage.id}"]}}]`;
+ private setAuthenticationFailureState():void {
+ this.informationBoxHeader = this.text.infoBox.authenticationFailureHeader;
+ this.informationBoxContent = this.text.infoBox.authenticationFailureContent;
+ this.informationBoxButton = this.text.infoBox.loginButton;
+ this.informationBoxIcon = 'info1';
+ this.showInformationBox = true;
+ this.showFileLinks = true;
}
- private get collectionKey():string {
- return isNewResource(this.resource) ? 'new' : this.fileLinkSelfLink;
+ private setConnectionErrorState():void {
+ this.informationBoxHeader = this.text.infoBox.connectionErrorHeader;
+ this.informationBoxContent = this.text.infoBox.connectionErrorContent;
+ this.informationBoxButton = this.text.infoBox.loginButton;
+ this.informationBoxIcon = 'info1';
+ this.showInformationBox = true;
+ this.showFileLinks = false;
+ }
+
+ private setEmptyFileLinkListState():void {
+ this.informationBoxHeader = this.text.infoBox.emptyStorageHeader;
+ this.informationBoxContent = this.text.infoBox.emptyStorageContent;
+ this.informationBoxButton = this.text.infoBox.emptyStorageButton;
+ this.informationBoxIcon = 'info1';
+ this.showInformationBox = true;
+ this.showFileLinks = true;
+ }
+
+ private initializeLocales():void {
+ const storageType = this.storageTypeMap[this.storage._links.type.href];
+ this.text = {
+ infoBox: {
+ emptyStorageHeader: this.i18n.t('js.label_no_file_links_header', { storageType }),
+ emptyStorageContent: this.i18n.t('js.label_no_file_links_content', { storageType }),
+ emptyStorageButton: this.i18n.t('js.label_open_storage', { storageType }),
+ connectionErrorHeader: this.i18n.t('js.label_no_storage_connection', { storageType }),
+ connectionErrorContent: this.i18n.t('js.label_storage_connection_error', { storageType }),
+ authenticationFailureHeader: this.i18n.t('js.label_login_to_storage', { storageType }),
+ authenticationFailureContent: this.i18n.t('js.label_storage_not_connected', { storageType }),
+ loginButton: this.i18n.t('js.label_storage_login', { storageType }),
+ },
+ };
}
}
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 43f01e2d41a..8a6f2a2d90b 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,125 +1,19 @@
<div class="work-package--attachments--files" *ngIf="resource" data-qa-selector="op-files-tab--file-link-list">
- <!-- 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>
+ <op-storage-information
+ *ngIf="showInformationBox"
+ [infoIcon]="'info1'"
+ [infoTextHeader]="informationBoxHeader"
+ [infoTextContent]="informationBoxContent"
+ [buttonText]="informationBoxButton"
+ ></op-storage-information>
<div
- *ngIf="storageConnectionState !== 'connectionError'"
+ *ngIf="showFileLinks"
>
<op-file-link-list-item
- *ngFor="let fileLink of $fileLinks | async; let i = index;"
+ *ngFor="let fileLink of fileLinks$ | async; let i = index;"
class="op-files-tab--file-list-item"
- [ngClass]="{ 'inactive': storageConnectionState === 'authenticationFailed' }"
+ [ngClass]="{ 'inactive': showInformationBox || fileLink._links.permission.href === 'urn:openproject-org:api:v3:file-links:permission:NotAllowed' }"
data-qa-selector="op-files-tab--file-list-item"
[fileLink]="fileLink"
[resource]="resource"
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/storage-information.component.ts b/frontend/src/app/shared/components/file-links/file-link-list/storage-information.component.ts
new file mode 100644
index 00000000000..2743abe3d31
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/file-link-list/storage-information.component.ts
@@ -0,0 +1,48 @@
+// -- 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 {
+ ChangeDetectionStrategy, Component, EventEmitter, Input, Output,
+} from '@angular/core';
+
+@Component({
+ selector: 'op-storage-information',
+ templateUrl: './storage-information.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class StorageInformationComponent {
+ @Input() infoIcon:string;
+
+ @Input() infoTextHeader:string;
+
+ @Input() infoTextContent:string;
+
+ @Input() buttonText:string;
+
+ @Output() buttonClickEventEmitter = new EventEmitter();
+}
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/storage-information.html b/frontend/src/app/shared/components/file-links/file-link-list/storage-information.html
new file mode 100644
index 00000000000..dea4edc322c
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/file-link-list/storage-information.html
@@ -0,0 +1,36 @@
+<div
+ class="op-files-tab--storage-info-box"
+>
+ <div
+ class="icon-box"
+ >
+ <i
+ class="icon icon-{{infoIcon}}"
+ ></i>
+ </div>
+
+ <div
+ class="text-box"
+ >
+ <div
+ class="text-box-header"
+ >
+ <span [textContent]="infoTextHeader"></span>
+ </div>
+ <div
+ class="text-box-content"
+ >
+ <span [textContent]="infoTextContent"></span>
+ </div>
+ </div>
+
+ <div
+ class="button-box"
+ >
+ <button
+ class="action-button"
+ [textContent]="buttonText"
+ (click)="buttonClickEventEmitter.emit()"
+ ></button>
+ </div>
+</div>
diff --git a/frontend/src/app/shared/components/file-links/openproject-file-links.module.ts b/frontend/src/app/shared/components/file-links/openproject-file-links.module.ts
index e701b14aac1..478448ee763 100644
--- a/frontend/src/app/shared/components/file-links/openproject-file-links.module.ts
+++ b/frontend/src/app/shared/components/file-links/openproject-file-links.module.ts
@@ -31,7 +31,12 @@ import { CommonModule } from '@angular/common';
import { IconModule } from 'core-app/shared/components/icon/icon.module';
import { FileLinkListComponent } from 'core-app/shared/components/file-links/file-link-list/file-link-list.component';
-import { FileLinkListItemComponent } from 'core-app/shared/components/file-links/file-link-list/file-link-list-item.component';
+import {
+ FileLinkListItemComponent,
+} from 'core-app/shared/components/file-links/file-link-list/file-link-list-item.component';
+import {
+ StorageInformationComponent,
+} from 'core-app/shared/components/file-links/file-link-list/storage-information.component';
@NgModule({
imports: [
@@ -41,6 +46,7 @@ import { FileLinkListItemComponent } from 'core-app/shared/components/file-links
declarations: [
FileLinkListComponent,
FileLinkListItemComponent,
+ StorageInformationComponent,
],
exports: [
FileLinkListComponent,
diff --git a/modules/storages/lib/api/v3/file_links/file_link_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_representer.rb
index 385f5ccfd97..1b478ca6e71 100644
--- a/modules/storages/lib/api/v3/file_links/file_link_representer.rb
+++ b/modules/storages/lib/api/v3/file_links/file_link_representer.rb
@@ -72,7 +72,7 @@ module API
link :permission do
# TODO: replace with service to check real permission state
{
- href: URN_PERMISSION_VIEW,
+ href: URN_PERMISSION_NOT_ALLOWED,
title: 'View'
}
end