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

[#44854] Add "Location picker" modal and action button to open it (#11625)

Eric Schubert7d00ddc1ccf3
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
index 2d625365a0c..433cd259419 100644
--- a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
+++ b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
@@ -47,13 +47,11 @@ import { PathHelperService } from 'core-app/core/path-helper/path-helper.service
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { PrincipalsResourceService } from 'core-app/core/state/principals/principals.service';
import { PrincipalRendererService } from 'core-app/shared/components/principal/principal-renderer.service';
-import idFromLink from 'core-app/features/hal/helpers/id-from-link';
-import { IFileIcon } from 'core-app/shared/components/storages/file-link-icons/icon-mappings';
-import {
- getIconForMimeType,
-} from 'core-app/shared/components/storages/file-link-icons/file-link-list-item-icon.factory';
import { ConfirmDialogService } from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.service';
import { ConfirmDialogOptions } from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.modal';
+import { getIconForMimeType } from 'core-app/shared/components/storages/functions/storages.functions';
+import { IFileIcon } from 'core-app/shared/components/storages/icons.mapping';
+import idFromLink from 'core-app/features/hal/helpers/id-from-link';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
diff --git a/frontend/src/app/shared/components/modal/modal.component.ts b/frontend/src/app/shared/components/modal/modal.component.ts
index 403038e8f01..d240eb8c90a 100644
--- a/frontend/src/app/shared/components/modal/modal.component.ts
+++ b/frontend/src/app/shared/components/modal/modal.component.ts
@@ -28,11 +28,11 @@ export abstract class OpModalComponent extends UntilDestroyedMixin implements On
super();
}
- ngOnInit() {
+ ngOnInit():void {
this.$element = this.elementRef.nativeElement as HTMLElement;
}
- ngOnDestroy() {
+ ngOnDestroy():void {
this.closingEvent.complete();
this.openingEvent.complete();
}
diff --git a/frontend/src/app/shared/components/storages/file-link-icons/file-icons.helper.ts b/frontend/src/app/shared/components/storages/file-link-icons/file-icons.helper.ts
deleted file mode 100644
index 438ec4600cb..00000000000
--- a/frontend/src/app/shared/components/storages/file-link-icons/file-icons.helper.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-// -- 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.
-//++
-
-export function isDirectory(mimeType?:string):boolean {
- return mimeType === 'application/x-op-directory';
-}
diff --git a/frontend/src/app/shared/components/storages/file-link-list-item/file-link-list-item.component.ts b/frontend/src/app/shared/components/storages/file-link-list-item/file-link-list-item.component.ts
index b9e1ff15b76..798fd68a1eb 100644
--- a/frontend/src/app/shared/components/storages/file-link-list-item/file-link-list-item.component.ts
+++ b/frontend/src/app/shared/components/storages/file-link-list-item/file-link-list-item.component.ts
@@ -40,17 +40,14 @@ import {
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import { IFileIcon } from 'core-app/shared/components/storages/file-link-icons/icon-mappings';
+import { IFileIcon } from 'core-app/shared/components/storages/icons.mapping';
import { IFileLink, IFileLinkOriginData } from 'core-app/core/state/file-links/file-link.model';
import { fileLinkViewAllowed } from 'core-app/shared/components/storages/storages-constants.const';
import { PrincipalRendererService } from 'core-app/shared/components/principal/principal-renderer.service';
-import {
- getIconForMimeType,
-} from 'core-app/shared/components/storages/file-link-icons/file-link-list-item-icon.factory';
-import SpotDropAlignmentOption from 'core-app/spot/drop-alignment-options';
import { ConfirmDialogOptions } from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.modal';
import { ConfirmDialogService } from 'core-app/shared/components/modals/confirm-dialog/confirm-dialog.service';
-import { isDirectory } from 'core-app/shared/components/storages/file-link-icons/file-icons.helper';
+import { getIconForMimeType, isDirectory } from 'core-app/shared/components/storages/functions/storages.functions';
+import SpotDropAlignmentOption from 'core-app/spot/drop-alignment-options';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
diff --git a/frontend/src/app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component.ts b/frontend/src/app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component.ts
new file mode 100644
index 00000000000..7134941d318
--- /dev/null
+++ b/frontend/src/app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component.ts
@@ -0,0 +1,153 @@
+// -- 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 {
+ ChangeDetectorRef,
+ Directive,
+ ElementRef,
+ Inject,
+ OnDestroy,
+ OnInit,
+} from '@angular/core';
+import { BehaviorSubject, Observable, Subscription } from 'rxjs';
+import { map, take } from 'rxjs/operators';
+
+import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
+import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
+import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';
+import { SortFilesPipe } from 'core-app/shared/components/storages/pipes/sort-files.pipe';
+import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';
+import { Breadcrumb, BreadcrumbsContent } from 'core-app/spot/components/breadcrumbs/breadcrumbs-content';
+import {
+ StorageFileListItem,
+} from 'core-app/shared/components/storages/storage-file-list-item/storage-file-list-item';
+import {
+ isDirectory,
+ getIconForStorageType,
+ makeFilesCollectionLink,
+} from 'core-app/shared/components/storages/functions/storages.functions';
+
+@Directive()
+export abstract class FilePickerBaseModalComponent extends OpModalComponent implements OnInit, OnDestroy {
+ protected readonly storageFiles$ = new BehaviorSubject<IStorageFile[]>([]);
+
+ public breadcrumbs:BreadcrumbsContent = new BreadcrumbsContent(
+ [{
+ text: this.locals.storageName as string,
+ icon: getIconForStorageType(this.locals.storageType as string),
+ navigate: () => this.changeLevel(null, this.breadcrumbs.crumbs.slice(0, 1)),
+ }],
+ );
+
+ public listItems$:Observable<StorageFileListItem[]> = this.storageFiles$
+ .pipe(
+ map((files) =>
+ this.sortFilesPipe.transform(files)
+ .map((file, index) => this.storageFileToListItem(file, index))),
+ );
+
+ public readonly loading$ = new BehaviorSubject<boolean>(true);
+
+ protected get storageLink():IHalResourceLink {
+ return this.locals.storageLink as IHalResourceLink;
+ }
+
+ private loadingSubscription:Subscription;
+
+ protected constructor(
+ @Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
+ readonly elementRef:ElementRef,
+ readonly cdRef:ChangeDetectorRef,
+ protected readonly sortFilesPipe:SortFilesPipe,
+ protected readonly storageFilesResourceService:StorageFilesResourceService,
+ ) {
+ super(locals, cdRef, elementRef);
+ }
+
+ ngOnInit():void {
+ super.ngOnInit();
+
+ this.storageFilesResourceService.files(makeFilesCollectionLink(this.storageLink, null))
+ .pipe(take(1))
+ .subscribe((files) => {
+ this.storageFiles$.next(files);
+ this.loading$.next(false);
+ });
+ }
+
+ ngOnDestroy():void {
+ super.ngOnDestroy();
+
+ this.storageFilesResourceService.reset();
+ }
+
+ public openStorageLocation():void {
+ window.open(this.locals.storageLocation, '_blank');
+ }
+
+ protected abstract storageFileToListItem(file:IStorageFile, index:number):StorageFileListItem;
+
+ protected enterDirectoryCallback(directory:IStorageFile):() => void {
+ if (!isDirectory(directory.mimeType)) {
+ return () => {};
+ }
+
+ return () => {
+ const crumbs = this.breadcrumbs.crumbs;
+ const end = crumbs.length + 1;
+ const newCrumb:Breadcrumb = {
+ text: directory.name,
+ // The navigate-callback needs to slice the future breadcrumb, which contains the new crumb itself.
+ // Therefore, we need the closure in here.
+ navigate: () => this.changeLevel(directory.location, this.breadcrumbs.crumbs.slice(0, end)),
+ };
+ this.changeLevel(directory.location, crumbs.concat(newCrumb));
+ };
+ }
+
+ private changeLevel(parent:string|null, crumbs:Breadcrumb[]):void {
+ this.cancelCurrentLoading();
+ this.loading$.next(true);
+ this.breadcrumbs = new BreadcrumbsContent(crumbs);
+
+ this.loadingSubscription = this.storageFilesResourceService.files(makeFilesCollectionLink(this.storageLink, parent))
+ .pipe(take(1))
+ .subscribe((files) => {
+ this.storageFiles$.next(files);
+ this.loading$.next(false);
+ });
+ }
+
+ private cancelCurrentLoading():void {
+ if (this.loadingSubscription) {
+ this.loadingSubscription.unsubscribe();
+ }
+ }
+}
diff --git a/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.html b/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.html
similarity index 100%
rename from frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.html
rename to frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.html
diff --git a/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.ts b/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.ts
index 36ebad24007..3461af07250 100644
--- a/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.ts
+++ b/frontend/src/app/shared/components/storages/file-picker-modal/file-picker-modal.component.ts
@@ -32,41 +32,31 @@ import {
Component,
ElementRef,
Inject,
- OnDestroy,
- OnInit,
} from '@angular/core';
-import { BehaviorSubject, Observable, Subscription } from 'rxjs';
-import { map, take } from 'rxjs/operators';
+import { take } from 'rxjs/operators';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { IHalResourceLink } from 'core-app/core/state/hal-resource';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { IFileLink } from 'core-app/core/state/file-links/file-link.model';
import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
-import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';
+import { SortFilesPipe } from 'core-app/shared/components/storages/pipes/sort-files.pipe';
import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';
-import { Breadcrumb, BreadcrumbsContent } from 'core-app/spot/components/breadcrumbs/breadcrumbs-content';
+import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';
import {
StorageFileListItem,
} from 'core-app/shared/components/storages/storage-file-list-item/storage-file-list-item';
-import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';
-import { isDirectory } from 'core-app/shared/components/storages/file-link-icons/file-icons.helper';
-import { SortFilesPipe } from 'core-app/shared/components/storages/file-picker-modal/sort-files.pipe';
-import getIconForStorageType from 'core-app/shared/components/storages/storage-icons/get-icon-for-storage-type';
+import { isDirectory } from 'core-app/shared/components/storages/functions/storages.functions';
+import {
+ FilePickerBaseModalComponent,
+} from 'core-app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component';
@Component({
- templateUrl: 'file-picker-modal.html',
+ templateUrl: 'file-picker-modal.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class FilePickerModalComponent extends OpModalComponent implements OnInit, OnDestroy {
- public breadcrumbs:BreadcrumbsContent;
-
- public listItems$:Observable<StorageFileListItem[]>;
-
- public readonly loading$ = new BehaviorSubject<boolean>(true);
-
+export class FilePickerModalComponent extends FilePickerBaseModalComponent {
public readonly text = {
header: this.i18n.t('js.storages.file_links.select'),
buttons: {
@@ -76,69 +66,37 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
cancel: this.i18n.t('js.button_cancel'),
selectAll: this.i18n.t('js.storages.file_links.select_all'),
},
+ tooltip: {
+ alreadyLinkedFile: this.i18n.t('js.storages.file_links.already_linked_file'),
+ alreadyLinkedDirectory: this.i18n.t('js.storages.file_links.already_linked_directory'),
+ },
};
public get selectedFileCount():number {
return this.selection.size;
}
- private get storageLink():IHalResourceLink {
- return this.locals.storageLink as IHalResourceLink;
- }
-
private readonly selection = new Set<string>();
private readonly fileMap:Record<string, IStorageFile> = {};
- private readonly storageFiles$ = new BehaviorSubject<IStorageFile[]>([]);
-
- private loadingSubscription:Subscription;
-
constructor(
@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
readonly elementRef:ElementRef,
readonly cdRef:ChangeDetectorRef,
+ protected readonly sortFilesPipe:SortFilesPipe,
+ protected readonly storageFilesResourceService:StorageFilesResourceService,
private readonly i18n:I18nService,
private readonly timezoneService:TimezoneService,
- private readonly sortFilesPipe:SortFilesPipe,
private readonly fileLinksResourceService:FileLinksResourceService,
- private readonly storageFilesResourceService:StorageFilesResourceService,
) {
- super(locals, cdRef, elementRef);
- }
-
- ngOnInit():void {
- super.ngOnInit();
-
- this.breadcrumbs = new BreadcrumbsContent([{
- text: this.locals.storageName as string,
- icon: getIconForStorageType(this.locals.storageType as string),
- navigate: () => this.changeLevel(null, this.breadcrumbs.crumbs.slice(0, 1)),
- }]);
-
- this.listItems$ = this.storageFiles$
- .pipe(
- map((files) =>
- this.sortFilesPipe.transform(files)
- .map((file, index) => this.storageFileToListItem(file, index))),
- );
-
- this.storageFilesResourceService.files(this.makeFilesCollectionLink(null))
- .pipe(take(1))
- .subscribe((files) => {
- this.storageFiles$.next(files);
- this.loading$.next(false);
- });
- }
-
- ngOnDestroy():void {
- super.ngOnDestroy();
-
- this.storageFilesResourceService.reset();
- }
-
- public openStorageLocation():void {
- window.open(this.locals.storageLocation, '_blank');
+ super(
+ locals,
+ elementRef,
+ cdRef,
+ sortFilesPipe,
+ storageFilesResourceService,
+ );
}
public createSelectedFileLinks():void {
@@ -181,57 +139,20 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
}
}
- private changeLevel(parent:string|null, crumbs:Breadcrumb[]):void {
- this.cancelCurrentLoading();
- this.loading$.next(true);
- this.breadcrumbs = new BreadcrumbsContent(crumbs);
-
- this.loadingSubscription = this.storageFilesResourceService.files(this.makeFilesCollectionLink(parent))
- .pipe(take(1))
- .subscribe((files) => {
- this.storageFiles$.next(files);
- this.loading$.next(false);
- });
- }
-
- private cancelCurrentLoading():void {
- if (this.loadingSubscription) {
- this.loadingSubscription.unsubscribe();
- }
- }
-
- private makeFilesCollectionLink(parent:string|null):IHalResourceLink {
- let query = '';
- if (parent !== null) {
- query = `?parent=${parent}`;
- }
-
- return {
- href: `${this.storageLink.href}/files${query}`,
- title: 'Storage files',
- };
- }
-
- private storageFileToListItem(file:IStorageFile, index:number):StorageFileListItem {
- const enterDirectoryCallback = isDirectory(file.mimeType)
- ? () => {
- const crumbs = this.breadcrumbs.crumbs;
- const end = crumbs.length + 1;
- const newCrumb:Breadcrumb = {
- text: file.name,
- navigate: () => this.changeLevel(file.location, this.breadcrumbs.crumbs.slice(0, end)),
- };
- this.changeLevel(file.location, crumbs.concat(newCrumb));
- }
- : undefined;
+ protected storageFileToListItem(file:IStorageFile, index:number):StorageFileListItem {
+ const isFolder = isDirectory(file.mimeType);
+ const enterDirectoryCallback = isFolder ? this.enterDirectoryCallback(file) : undefined;
return new StorageFileListItem(
this.timezoneService,
file,
this.isAlreadyLinked(file),
index === 0,
- this.selection.has(file.id as string),
- () => { this.changeSelection(file); },
+ isFolder ? this.text.tooltip.alreadyLinkedDirectory : this.text.tooltip.alreadyLinkedFile,
+ {
+ selected: this.selection.has(file.id as string),
+ changeSelection: () => { this.changeSelection(file); },
+ },
enterDirectoryCallback,
);
}
diff --git a/frontend/src/app/shared/components/storages/file-link-icons/file-link-list-item-icon.factory.ts b/frontend/src/app/shared/components/storages/functions/storages.functions.ts
similarity index 66%
rename from frontend/src/app/shared/components/storages/file-link-icons/file-link-list-item-icon.factory.ts
rename to frontend/src/app/shared/components/storages/functions/storages.functions.ts
index 35b3d162da1..0be6272f71d 100644
--- a/frontend/src/app/shared/components/storages/file-link-icons/file-link-list-item-icon.factory.ts
+++ b/frontend/src/app/shared/components/storages/functions/storages.functions.ts
@@ -29,7 +29,13 @@
import {
fileIconMappings,
IFileIcon,
-} from 'core-app/shared/components/storages/file-link-icons/icon-mappings';
+ storageIconMappings,
+} from 'core-app/shared/components/storages/icons.mapping';
+import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+
+export function isDirectory(mimeType?:string):boolean {
+ return mimeType === 'application/x-op-directory';
+}
export function getIconForMimeType(mimeType?:string):IFileIcon {
if (mimeType && fileIconMappings[mimeType]) {
@@ -38,3 +44,20 @@ export function getIconForMimeType(mimeType?:string):IFileIcon {
return fileIconMappings.default;
}
+
+export function getIconForStorageType(storageType?:string):string {
+ if (storageType && storageIconMappings[storageType]) {
+ return storageIconMappings[storageType];
+ }
+
+ return storageIconMappings.default;
+}
+
+export function makeFilesCollectionLink(storageLink:IHalResourceLink, location:string|null):IHalResourceLink {
+ const query = location !== null ? `?parent=${location}` : '';
+
+ return {
+ href: `${storageLink.href}/files${query}`,
+ title: 'Storage files',
+ };
+}
diff --git a/frontend/src/app/shared/components/storages/file-link-icons/icon-mappings.ts b/frontend/src/app/shared/components/storages/icons.mapping.ts
similarity index 95%
rename from frontend/src/app/shared/components/storages/file-link-icons/icon-mappings.ts
rename to frontend/src/app/shared/components/storages/icons.mapping.ts
index 51cb1cdae34..c1b79c28b78 100644
--- a/frontend/src/app/shared/components/storages/file-link-icons/icon-mappings.ts
+++ b/frontend/src/app/shared/components/storages/icons.mapping.ts
@@ -1,4 +1,4 @@
-// -- copyright
+// --copyright
// OpenProject is an open source project management software.
// Copyright (C) 2012-2022 the OpenProject GmbH
//
@@ -26,6 +26,8 @@
// See COPYRIGHT and LICENSE files for more details.
//++
+import { nextcloud } from 'core-app/shared/components/storages/storages-constants.const';
+
export interface IFileIcon {
icon:'image1'|'movie'|'file-text'|'export-pdf-descr'|'file-doc'|'file-sheet'|'file-presentation'|'folder'|'ticket'
clazz:'pdf'|'img'|'txt'|'doc'|'sheet'|'presentation'|'form'|'dir'|'mov'|'default'
@@ -101,3 +103,9 @@ export const fileIconMappings:Record<string, IFileIcon> = {
default: { icon: 'ticket', clazz: 'default' },
};
+
+export const storageIconMappings:Record<string, string> = {
+ [nextcloud]: 'nextcloud-circle',
+
+ default: 'ticket',
+};
diff --git a/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.html b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.html
new file mode 100644
index 00000000000..bc686066be4
--- /dev/null
+++ b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.html
@@ -0,0 +1,60 @@
+<div
+ class="spot-modal spot-modal_wide"
+ data-qa-selector="op-files-picker-modal"
+>
+ <div class="spot-modal--header">
+ <span class="spot-modal--header-title">{{text.header}}</span>
+ <button
+ type="button"
+ class="button button_no-margin"
+ (click)="openStorageLocation()"
+ >
+ <span>{{text.buttons.openStorage()}}</span>
+ <span class="spot-icon spot-icon_external-link"></span>
+ </button>
+ </div>
+
+ <div class="spot-divider"></div>
+
+ <div class="spot-modal--body spot-container">
+ <ng-container *ngIf="(loading$ | async) === false; else loadingTemplate">
+ <spot-breadcrumbs [content]="breadcrumbs"></spot-breadcrumbs>
+
+ <ul
+ class="spot-list spot-list_compact op-file-list"
+ data-qa-selector="op-files-picker-modal--file-list"
+ >
+ <li
+ *ngFor="let file of listItems$ | async | sortFiles; let i = index;"
+ class="spot-list--item op-file-list--item"
+ data-qa-selector="op-file-list--item"
+ op-storage-file-list-item
+ [content]="file"
+ ></li>
+ </ul>
+ </ng-container>
+
+ <ng-template #loadingTemplate>
+ <op-loading-file-list></op-loading-file-list>
+ </ng-template>
+ </div>
+
+ <div class="spot-action-bar">
+ <div class="spot-action-bar--right">
+ <button
+ type="button"
+ class="button spot-action-bar--action"
+ [textContent]="text.buttons.cancel"
+ (click)="closeMe()"
+ ></button>
+ <button
+ type="button"
+ class="button spot-action-bar--action -highlight"
+ data-qa-selector="op-files-picker-modal--confirm"
+ [disabled]="!canChooseLocation"
+ [textContent]="text.buttons.submit"
+ (click)="chooseLocation()"
+ ></button>
+ </div>
+ </div>
+</div>
diff --git a/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts
new file mode 100644
index 00000000000..451d564b6ff
--- /dev/null
+++ b/frontend/src/app/shared/components/storages/location-picker-modal/location-picker-modal.component.ts
@@ -0,0 +1,108 @@
+// -- 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,
+ ChangeDetectorRef,
+ Component,
+ ElementRef,
+ Inject,
+} from '@angular/core';
+
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { TimezoneService } from 'core-app/core/datetime/timezone.service';
+import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
+import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';
+import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';
+import { SortFilesPipe } from 'core-app/shared/components/storages/pipes/sort-files.pipe';
+import { isDirectory } from 'core-app/shared/components/storages/functions/storages.functions';
+import {
+ StorageFileListItem,
+} from 'core-app/shared/components/storages/storage-file-list-item/storage-file-list-item';
+import {
+ FilePickerBaseModalComponent,
+} from 'core-app/shared/components/storages/file-picker-base-modal.component.ts/file-picker-base-modal.component';
+
+@Component({
+ templateUrl: 'location-picker-modal.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class LocationPickerModalComponent extends FilePickerBaseModalComponent {
+ public readonly text = {
+ header: this.i18n.t('js.storages.select_location'),
+ buttons: {
+ openStorage: ():string => this.i18n.t('js.storages.open_storage', { storageType: this.locals.storageTypeName as string }),
+ submit: this.i18n.t('js.storages.choose_location'),
+ submitEmptySelection: this.i18n.t('js.storages.file_links.selection_none'),
+ cancel: this.i18n.t('js.button_cancel'),
+ selectAll: this.i18n.t('js.storages.file_links.select_all'),
+ },
+ };
+
+ public get canChooseLocation():boolean {
+ return this.breadcrumbs.crumbs.length > 1;
+ }
+
+ constructor(
+ @Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
+ readonly elementRef:ElementRef,
+ readonly cdRef:ChangeDetectorRef,
+ protected sortFilesPipe:SortFilesPipe,
+ protected readonly storageFilesResourceService:StorageFilesResourceService,
+ private readonly i18n:I18nService,
+ private readonly timezoneService:TimezoneService,
+ ) {
+ super(
+ locals,
+ elementRef,
+ cdRef,
+ sortFilesPipe,
+ storageFilesResourceService,
+ );
+ }
+
+ public chooseLocation():void {
+ this.service.close();
+ }
+
+ protected storageFileToListItem(file:IStorageFile, index:number):StorageFileListItem {
+ const isFolder = isDirectory(file.mimeType);
+ const enterDirectoryCallback = isFolder ? this.enterDirectoryCallback(file) : undefined;
+
+ return new StorageFileListItem(
+ this.timezoneService,
+ file,
+ !isFolder,
+ index === 0,
+ undefined,
+ undefined,
+ enterDirectoryCallback,
+ );
+ }
+}
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 17f91552420..a14904d4e10 100644
--- a/frontend/src/app/shared/components/storages/openproject-storages.module.ts
+++ b/frontend/src/app/shared/components/storages/openproject-storages.module.ts
@@ -44,10 +44,13 @@ import {
FilePickerModalComponent,
} from 'core-app/shared/components/storages/file-picker-modal/file-picker-modal.component';
import { OPSharedModule } from 'core-app/shared/shared.module';
+import { SortFilesPipe } from 'core-app/shared/components/storages/pipes/sort-files.pipe';
import {
StorageFileListItemComponent,
} from 'core-app/shared/components/storages/storage-file-list-item/storage-file-list-item.component';
-import { SortFilesPipe } from 'core-app/shared/components/storages/file-picker-modal/sort-files.pipe';
+import {
+ LocationPickerModalComponent,
+} from 'core-app/shared/components/storages/location-picker-modal/location-picker-modal.component';
import {
LoadingFileListComponent,
} from 'core-app/shared/components/storages/loading-file-list/loading-file-list.component';
@@ -63,6 +66,7 @@ import {
StorageComponent,
FileLinkListItemComponent,
FilePickerModalComponent,
+ LocationPickerModalComponent,
LoadingFileListComponent,
StorageInformationComponent,
StorageFileListItemComponent,
diff --git a/frontend/src/app/shared/components/storages/file-picker-modal/sort-files.pipe.ts b/frontend/src/app/shared/components/storages/pipes/sort-files.pipe.ts
similarity index 94%
rename from frontend/src/app/shared/components/storages/file-picker-modal/sort-files.pipe.ts
rename to frontend/src/app/shared/components/storages/pipes/sort-files.pipe.ts
index 7679617701d..b0a6e106a99 100644
--- a/frontend/src/app/shared/components/storages/file-picker-modal/sort-files.pipe.ts
+++ b/frontend/src/app/shared/components/storages/pipes/sort-files.pipe.ts
@@ -1,5 +1,6 @@
import { Pipe, PipeTransform } from '@angular/core';
-import { isDirectory } from 'core-app/shared/components/storages/file-link-icons/file-icons.helper';
+
+import { isDirectory } from 'core-app/shared/components/storages/functions/storages.functions';
@Pipe({
name: 'sortFiles',
diff --git a/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.component.ts b/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.component.ts
index 548072d67f7..92750750aa9 100644
--- a/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.component.ts
+++ b/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.component.ts
@@ -37,7 +37,6 @@ import {
StorageFileListItem,
} from 'core-app/shared/components/storages/storage-file-list-item/storage-file-list-item';
import SpotDropAlignmentOption from 'core-app/spot/drop-alignment-options';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
@@ -48,11 +47,6 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';
export class StorageFileListItemComponent {
@Input() public content:StorageFileListItem;
- text = {
- alreadyLinkedFile: this.i18n.t('js.storages.file_links.already_linked_file'),
- alreadyLinkedDirectory: this.i18n.t('js.storages.file_links.already_linked_directory'),
- };
-
get principal():PrincipalLike {
return this.content.createdByName
? {
@@ -65,10 +59,6 @@ export class StorageFileListItemComponent {
};
}
- get tooltip():string {
- return this.content.isDirectory ? this.text.alreadyLinkedDirectory : this.text.alreadyLinkedFile;
- }
-
get getTooltipAlignment():SpotDropAlignmentOption {
if (this.content.isFirst) {
return SpotDropAlignmentOption.BottomLeft;
@@ -76,8 +66,4 @@ export class StorageFileListItemComponent {
return SpotDropAlignmentOption.TopLeft;
}
-
- constructor(
- private readonly i18n:I18nService,
- ) {}
}
diff --git a/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.html b/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.html
index b2ab41f2fbe..b99a99bafe5 100644
--- a/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.html
+++ b/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.html
@@ -1,11 +1,11 @@
<spot-tooltip
[alignment]="getTooltipAlignment"
- [disabled]="!content.disabled"
+ [disabled]="!content.disabled || !content.tooltip"
>
<p
slot="body"
class="spot-body-small"
- >{{tooltip}}</p>
+ >{{content.tooltip}}</p>
<label
slot="trigger"
@@ -14,8 +14,9 @@
[ngClass]="{ 'spot-list--item-action_disabled': content.disabled }"
>
<spot-checkbox
- [checked]="content.disabled || content.selected"
- (checkedChange)="content.changeSelection()"
+ *ngIf="!!content.checkbox"
+ [checked]="content.disabled || content.checkbox.selected"
+ (checkedChange)="content.checkbox.changeSelection()"
[disabled]="content.disabled"
></spot-checkbox>
diff --git a/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.ts b/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.ts
index 959baa8ae0d..1422e9ed8a7 100644
--- a/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.ts
+++ b/frontend/src/app/shared/components/storages/storage-file-list-item/storage-file-list-item.ts
@@ -28,11 +28,13 @@
import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import {
- getIconForMimeType,
-} from 'core-app/shared/components/storages/file-link-icons/file-link-list-item-icon.factory';
-import { IFileIcon } from 'core-app/shared/components/storages/file-link-icons/icon-mappings';
-import { isDirectory } from 'core-app/shared/components/storages/file-link-icons/file-icons.helper';
+import { IFileIcon } from 'core-app/shared/components/storages/icons.mapping';
+import { getIconForMimeType, isDirectory } from 'core-app/shared/components/storages/functions/storages.functions';
+
+interface StorageFileListItemCheckbox {
+ selected:boolean;
+ changeSelection?:() => void;
+}
export class StorageFileListItem {
get name():string {
@@ -66,8 +68,8 @@ export class StorageFileListItem {
private readonly storageFile:IStorageFile,
public readonly disabled:boolean,
public readonly isFirst:boolean,
- public readonly selected:boolean,
- public readonly changeSelection:() => void,
+ public readonly tooltip?:string,
+ public readonly checkbox?:StorageFileListItemCheckbox,
public readonly enterDirectory?:() => void,
) {}
}
diff --git a/frontend/src/app/shared/components/storages/storage-icons/get-icon-for-storage-type.ts b/frontend/src/app/shared/components/storages/storage-icons/get-icon-for-storage-type.ts
deleted file mode 100644
index 480d151da98..00000000000
--- a/frontend/src/app/shared/components/storages/storage-icons/get-icon-for-storage-type.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-// -- 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 { storageIconMappings } from 'core-app/shared/components/storages/storage-icons/icon-mappings';
-
-export default function getIconForStorageType(storageType?:string):string {
- if (storageType && storageIconMappings[storageType]) {
- return storageIconMappings[storageType];
- }
-
- return storageIconMappings.default;
-}
diff --git a/frontend/src/app/shared/components/storages/storage-icons/icon-mappings.ts b/frontend/src/app/shared/components/storages/storage-icons/icon-mappings.ts
deleted file mode 100644
index 8e76f95c771..00000000000
--- a/frontend/src/app/shared/components/storages/storage-icons/icon-mappings.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-// -- 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 { nextcloud } from 'core-app/shared/components/storages/storages-constants.const';
-
-export const storageIconMappings:Record<string, string> = {
- [nextcloud]: 'nextcloud-circle',
-
- default: 'ticket',
-};
diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.html b/frontend/src/app/shared/components/storages/storage/storage.component.html
index 9b39f79d4d7..745069fe973 100644
--- a/frontend/src/app/shared/components/storages/storage/storage.component.html
+++ b/frontend/src/app/shared/components/storages/storage/storage.component.html
@@ -52,5 +52,15 @@
<span class="spot-icon spot-icon_add-link"></span>
<span [textContent]="text.actions.linkExisting"></span>
</button>
+ <button
+ *ngIf="storageFileUploadEnabled"
+ type="button"
+ class="spot-link op-file-list--action-button"
+ data-qa-selector="op-file-list--upload-file-button"
+ (click)="openSelectLocationDialog()"
+ >
+ <span class="spot-icon spot-icon_upload-arrow"></span>
+ <span [textContent]="text.actions.uploadFile"></span>
+ </button>
</p>
</ng-container>
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 3e4ebb28656..c195c21b67f 100644
--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts
+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts
@@ -65,6 +65,9 @@ import {
FilePickerModalComponent,
} from 'core-app/shared/components/storages/file-picker-modal/file-picker-modal.component';
import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+import {
+ LocationPickerModalComponent,
+} from 'core-app/shared/components/storages/location-picker-modal/location-picker-modal.component';
@Component({
selector: 'op-storage',
@@ -107,6 +110,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit {
},
actions: {
linkExisting: this.i18n.t('js.storages.link_existing_files'),
+ uploadFile: this.i18n.t('js.storages.upload_files'),
},
openStorage: ():string => this.i18n.t('js.storages.open_storage', { storageType: this.storageType }),
};
@@ -115,6 +119,10 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit {
return this.configurationService.activeFeatureFlags.includes('storageFileLinking');
}
+ public get storageFileUploadEnabled():boolean {
+ return this.configurationService.activeFeatureFlags.includes('storageFileUpload');
+ }
+
public get storageFilesLocation():string {
return this.storage._links.open.href;
}
@@ -181,6 +189,17 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit {
});
}
+ public openSelectLocationDialog():void {
+ const locals = {
+ storageType: this.storage._links.type.href,
+ storageTypeName: this.storageType,
+ storageName: this.storage.name,
+ storageLocation: this.storageFilesLocation,
+ storageLink: this.storage._links.self,
+ };
+ this.opModalService.show<LocationPickerModalComponent>(LocationPickerModalComponent, 'global', locals);
+ }
+
private instantiateStorageInformation(fileLinks:IFileLink[]):StorageInformationBox[] {
// ToDo: Replace with anonymous user capabilities check.
// https://community.openproject.org/projects/openproject/work_packages/44850/activity
diff --git a/modules/storages/config/locales/js-en.yml b/modules/storages/config/locales/js-en.yml
index 243a3561e0b..64deaa498bd 100644
--- a/modules/storages/config/locales/js-en.yml
+++ b/modules/storages/config/locales/js-en.yml
@@ -4,10 +4,13 @@ en:
storages:
link_files_in_storage: "Link files in %{storageType}"
link_existing_files: "Link existing files"
+ upload_files: "Upload files"
login: "%{storageType} login"
login_to: "Login to %{storageType}"
no_connection: "No %{storageType} connection"
open_storage: "Open %{storageType}"
+ select_location: "Select location"
+ choose_location: "Choose location"
types:
nextcloud: "Nextcloud"
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb
index 75998707ccf..4d27b93b836 100644
--- a/modules/storages/lib/open_project/storages/engine.rb
+++ b/modules/storages/lib/open_project/storages/engine.rb
@@ -41,7 +41,8 @@ module OpenProject::Storages
include OpenProject::Plugins::ActsAsOpEngine
initializer 'openproject_storages.feature_decisions' do
- OpenProject::FeatureDecisions.add(:storage_file_linking)
+ OpenProject::FeatureDecisions.add :storage_file_linking
+ OpenProject::FeatureDecisions.add :storage_file_upload
end
# For documentation see the definition of register in "ActsAsOpEngine"