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

[chore] refactored storage information box

Eric Schubertf3cc003d9f0e
diff --git a/frontend/src/app/shared/components/storages/openproject-storages.module.ts b/frontend/src/app/shared/components/storages/openproject-storages.module.ts
index e17b7569e98..582ec898cf3 100644
--- a/frontend/src/app/shared/components/storages/openproject-storages.module.ts
+++ b/frontend/src/app/shared/components/storages/openproject-storages.module.ts
@@ -60,6 +60,9 @@ import {
import {
StorageInformationService,
} from 'core-app/shared/components/storages/storage-information/storage-information.service';
+import {
+ StorageLoginButtonComponent,
+} from 'core-app/shared/components/storages/storage-login-button/storage-login-button.component';
@NgModule({
imports: [
@@ -70,6 +73,7 @@ import {
],
declarations: [
StorageComponent,
+ StorageLoginButtonComponent,
FileLinkListItemComponent,
FilePickerModalComponent,
LocationPickerModalComponent,
diff --git a/frontend/src/app/shared/components/storages/storage-information/storage-information-box.ts b/frontend/src/app/shared/components/storages/storage-information/storage-information-box.ts
index c5f8325fe24..a8a58b89794 100644
--- a/frontend/src/app/shared/components/storages/storage-information/storage-information-box.ts
+++ b/frontend/src/app/shared/components/storages/storage-information/storage-information-box.ts
@@ -26,13 +26,13 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { StorageActionButton } from 'core-app/shared/components/storages/storage-information/storage-action-button';
+import { IStorageLoginInput } from 'core-app/shared/components/storages/storage-login-button/storage-login-input';
export class StorageInformationBox {
constructor(
public readonly iconClass:string,
public readonly header:string,
public readonly content:string,
- public readonly buttons:StorageActionButton[],
+ public readonly login?:IStorageLoginInput,
) { }
}
diff --git a/frontend/src/app/shared/components/storages/storage-information/storage-information.html b/frontend/src/app/shared/components/storages/storage-information/storage-information.html
index f3a5e49cae9..3c32f86ae08 100644
--- a/frontend/src/app/shared/components/storages/storage-information/storage-information.html
+++ b/frontend/src/app/shared/components/storages/storage-information/storage-information.html
@@ -16,14 +16,10 @@
</div>
<div
+ *ngIf="content.login"
class="button-box"
>
- <button *ngFor="let button of content.buttons"
- type="button"
- class="button op-files-tab--storage-info-box-button"
- (click)="button.action()"
- >
- <span>{{button.label}}</span>
- <span class="spot-icon spot-icon_external-link"></span>
- </button>
+ <op-storage-login-button
+ [input]="content.login"
+ ></op-storage-login-button>
</div>
diff --git a/frontend/src/app/shared/components/storages/storage-information/storage-information.service.ts b/frontend/src/app/shared/components/storages/storage-information/storage-information.service.ts
index 6472ef48262..bd7b3b335e2 100644
--- a/frontend/src/app/shared/components/storages/storage-information/storage-information.service.ts
+++ b/frontend/src/app/shared/components/storages/storage-information/storage-information.service.ts
@@ -27,15 +27,12 @@
//++
import { Injectable } from '@angular/core';
-import { CookieService } from 'ngx-cookie-service';
-import { v4 as uuidv4 } from 'uuid';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { IStorage } from 'core-app/core/state/storages/storage.model';
import { IFileLink } from 'core-app/core/state/file-links/file-link.model';
-import { StorageActionButton } from 'core-app/shared/components/storages/storage-information/storage-action-button';
import { StorageInformationBox } from 'core-app/shared/components/storages/storage-information/storage-information-box';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
import { storageLocaleString } from 'core-app/shared/components/storages/functions/storages.functions';
@@ -60,7 +57,6 @@ export class StorageInformationService {
constructor(
private readonly i18n:I18nService,
- private readonly cookieService:CookieService,
private readonly currentUserService:CurrentUserService,
) {}
@@ -92,22 +88,18 @@ export class StorageInformationService {
}
private failedAuthorizationInformation(storage:IStorage, storageType:string):StorageInformationBox {
+ if (!storage._links.authorize) {
+ throw new Error('Authorize link is missing!');
+ }
+
return new StorageInformationBox(
'import',
this.text.authorizationFailureHeader(storageType),
this.text.authorizationFailureContent(storageType),
- [new StorageActionButton(
- this.text.loginButton(storageType),
- () => {
- if (storage._links.authorize) {
- const nonce = uuidv4();
- this.setAuthorizationCallbackCookie(nonce);
- window.location.href = StorageInformationService.authorizationFailureActionUrl(storage._links.authorize.href, nonce);
- } else {
- throw new Error('Authorize link is missing!');
- }
- },
- )],
+ {
+ storageType: storage._links.type.href,
+ authorizationLink: storage._links.authorize,
+ },
);
}
@@ -116,7 +108,6 @@ export class StorageInformationService {
'remove-link',
this.text.connectionErrorHeader(storageType),
this.text.connectionErrorContent(storageType),
- [],
);
}
@@ -125,20 +116,9 @@ export class StorageInformationService {
'error',
this.text.fileLinkErrorHeader,
this.text.fileLinkErrorContent(storageType),
- [],
);
}
- private setAuthorizationCallbackCookie(nonce:string):void {
- this.cookieService.set(`oauth_state_${nonce}`, window.location.href, {
- path: '/',
- });
- }
-
- private static authorizationFailureActionUrl(baseUrl:string, nonce:string):string {
- return `${baseUrl}&state=${nonce}`;
- }
-
private hasFileLinkViewErrors(fileLinks:IFileLink[]):boolean {
return fileLinks.filter((fileLink) => fileLink._links.permission?.href === fileLinkViewError).length > 0;
}
diff --git a/frontend/src/app/shared/components/storages/storage-login-button/storage-login-button.component.html b/frontend/src/app/shared/components/storages/storage-login-button/storage-login-button.component.html
new file mode 100644
index 00000000000..09b5bf83a27
--- /dev/null
+++ b/frontend/src/app/shared/components/storages/storage-login-button/storage-login-button.component.html
@@ -0,0 +1,7 @@
+<button type="button"
+ class="button op-files-tab--storage-info-box-button"
+ (click)="login()"
+>
+ <span>{{label}}</span>
+ <span class="spot-icon spot-icon_external-link"></span>
+</button>
diff --git a/frontend/src/app/shared/components/storages/storage-login-button/storage-login-button.component.ts b/frontend/src/app/shared/components/storages/storage-login-button/storage-login-button.component.ts
new file mode 100644
index 00000000000..471f5aa5cb9
--- /dev/null
+++ b/frontend/src/app/shared/components/storages/storage-login-button/storage-login-button.component.ts
@@ -0,0 +1,77 @@
+// -- 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 {
+ ChangeDetectionStrategy,
+ Component,
+ Input,
+ OnInit,
+} from '@angular/core';
+import { CookieService } from 'ngx-cookie-service';
+import { v4 as uuidv4 } from 'uuid';
+
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { IStorageLoginInput } from 'core-app/shared/components/storages/storage-login-button/storage-login-input';
+import { storageLocaleString } from 'core-app/shared/components/storages/functions/storages.functions';
+
+@Component({
+ selector: 'op-storage-login-button',
+ templateUrl: 'storage-login-button.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class StorageLoginButtonComponent implements OnInit {
+ @Input() input:IStorageLoginInput;
+
+ label:string;
+
+ constructor(
+ private readonly i18n:I18nService,
+ private readonly cookieService:CookieService,
+ ) { }
+
+ ngOnInit():void {
+ const storageType = this.i18n.t(storageLocaleString(this.input.storageType));
+ this.label = this.i18n.t('js.storages.login', { storageType });
+ }
+
+ public login():void {
+ const nonce = uuidv4();
+ this.setAuthorizationCallbackCookie(nonce);
+ window.location.href = StorageLoginButtonComponent.authorizationFailureActionUrl(this.input.authorizationLink.href, nonce);
+ }
+
+ private setAuthorizationCallbackCookie(nonce:string):void {
+ this.cookieService.set(`oauth_state_${nonce}`, window.location.href, {
+ path: '/',
+ });
+ }
+
+ private static authorizationFailureActionUrl(baseUrl:string, nonce:string):string {
+ return `${baseUrl}&state=${nonce}`;
+ }
+}
diff --git a/frontend/src/app/shared/components/storages/storage-information/storage-action-button.ts b/frontend/src/app/shared/components/storages/storage-login-button/storage-login-input.ts
similarity index 88%
rename from frontend/src/app/shared/components/storages/storage-information/storage-action-button.ts
rename to frontend/src/app/shared/components/storages/storage-login-button/storage-login-input.ts
index 17a20f93bf9..4863a9731ae 100644
--- a/frontend/src/app/shared/components/storages/storage-information/storage-action-button.ts
+++ b/frontend/src/app/shared/components/storages/storage-login-button/storage-login-input.ts
@@ -26,6 +26,9 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-export class StorageActionButton {
- constructor(public readonly label:string, public readonly action:() => void) { }
+import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+
+export interface IStorageLoginInput {
+ storageType:string;
+ authorizationLink:IHalResourceLink;
}