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

[#43695] added file picker modal base

Eric Schubert12ed963f5fca
diff --git a/frontend/src/app/core/state/storage-files/storage-file.model.ts b/frontend/src/app/core/state/storage-files/storage-file.model.ts
new file mode 100644
index 00000000000..d9b4387f097
--- /dev/null
+++ b/frontend/src/app/core/state/storage-files/storage-file.model.ts
@@ -0,0 +1,35 @@
+// -- 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 { IFileLinkOriginData } from 'core-app/core/state/file-links/file-link.model';
+
+export interface IStorageFile extends IFileLinkOriginData {
+ id:ID;
+}
diff --git a/frontend/src/app/core/state/storage-files/storage-files.service.ts b/frontend/src/app/core/state/storage-files/storage-files.service.ts
new file mode 100644
index 00000000000..28abc69977f
--- /dev/null
+++ b/frontend/src/app/core/state/storage-files/storage-files.service.ts
@@ -0,0 +1,68 @@
+// -- 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 {
+ CollectionStore,
+ ResourceCollectionService,
+} from 'core-app/core/state/resource-collection.service';
+import { StorageFilesStore } from 'core-app/core/state/storage-files/storage-files.store';
+import { Observable, of } from 'rxjs';
+import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+
+@Injectable()
+export class StorageFilesResourceService extends ResourceCollectionService<IStorageFile> {
+ constructor(private readonly http:HttpClient) {
+ super();
+ }
+
+ protected createStore():CollectionStore<IStorageFile> {
+ return new StorageFilesStore();
+ }
+
+ public getMockData():Observable<IStorageFile[]> {
+ return of([
+ {
+ id: 1,
+ name: 'image.png',
+ mimeType: 'image/png',
+ lastModifiedAt: '2022-09-16T12:00Z',
+ lastModifiedByName: 'Leia Organa',
+ },
+ {
+ id: 2,
+ name: 'Readme.md',
+ mimeType: 'text/markdown',
+ lastModifiedAt: '2022-09-16T13:00Z',
+ lastModifiedByName: 'Anakin Skywalker',
+ },
+ { id: 3, name: 'folder', mimeType: 'application/x-op-directory' },
+ ]);
+ }
+}
diff --git a/frontend/src/app/core/state/storage-files/storage-files.store.ts b/frontend/src/app/core/state/storage-files/storage-files.store.ts
new file mode 100644
index 00000000000..99a75f2b075
--- /dev/null
+++ b/frontend/src/app/core/state/storage-files/storage-files.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 { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+
+export interface StorageFilesState extends CollectionState<IStorageFile> {}
+
+@StoreConfig({ name: 'storage-files' })
+export class StorageFilesStore extends EntityStore<StorageFilesState> {
+ constructor() {
+ super(createInitialCollectionState());
+ }
+}
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 f62cda3d6fa..493b016b7b7 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
@@ -185,6 +185,7 @@ import { SingleDateModalComponent } from 'core-app/shared/components/datepicker/
import { MultiDateModalComponent } from 'core-app/shared/components/datepicker/multi-date-modal/multi-date.modal';
import { DatepickerWorkingDaysToggleComponent } from 'core-app/shared/components/datepicker/toggle/datepicker-working-days-toggle.component';
import { DatepickerSchedulingToggleComponent } from 'core-app/shared/components/datepicker/scheduling-mode/datepicker-scheduling-toggle.component';
+import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';
@NgModule({
imports: [
@@ -240,6 +241,7 @@ import { DatepickerSchedulingToggleComponent } from 'core-app/shared/components/
HalEventsService,
FileLinksResourceService,
+ StorageFilesResourceService,
StoragesResourceService,
],
diff --git a/frontend/src/app/shared/components/file-links/file-link-icons/file-icons.helper.ts b/frontend/src/app/shared/components/file-links/file-link-icons/file-icons.helper.ts
new file mode 100644
index 00000000000..438ec4600cb
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/file-link-icons/file-icons.helper.ts
@@ -0,0 +1,31 @@
+// -- 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/file-links/file-link-list-item/file-link-list-item.component.ts b/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.component.ts
index 485652021e1..5413a4b1572 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.component.ts
+++ b/frontend/src/app/shared/components/file-links/file-link-list-item/file-link-list-item.component.ts
@@ -50,6 +50,7 @@ import {
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/file-links/file-link-icons/file-icons.helper';
@Component({
// eslint-disable-next-line @angular-eslint/component-selector
@@ -112,7 +113,7 @@ export class FileLinkListItemComponent implements OnInit, AfterViewInit {
this.fileLinkIcon = getIconForMimeType(this.originData.mimeType);
- this.downloadAllowed = this.originData.mimeType !== 'application/x-op-directory';
+ this.downloadAllowed = !isDirectory(this.originData.mimeType);
this.text.title.downloadFileLink = this.i18n.t(
'js.storages.file_links.download',
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 9f2058e0a51..0536e8906c5 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
@@ -55,7 +55,13 @@ import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destr
import { I18nService } from 'core-app/core/i18n/i18n.service';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
import { StorageActionButton } from 'core-app/shared/components/file-links/storage-information/storage-action-button';
-import { StorageInformationBox } from 'core-app/shared/components/file-links/storage-information/storage-information-box';
+import {
+ StorageInformationBox,
+} from 'core-app/shared/components/file-links/storage-information/storage-information-box';
+import { OpModalService } from 'core-app/shared/components/modal/modal.service';
+import {
+ FilePickerModalComponent,
+} from 'core-app/shared/components/file-links/file-picker-modal/file-picker-modal.component';
@Component({
selector: 'op-file-link-list',
@@ -96,6 +102,7 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit
},
actions: {
linkFile: (storageType:string):string => this.i18n.t('js.storages.link_files_in_storage', { storageType }),
+ linkExisting: 'Link existing files',
},
};
@@ -105,6 +112,7 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit
constructor(
private readonly i18n:I18nService,
+ private readonly opModalService:OpModalService,
private readonly fileLinkResourceService:FileLinksResourceService,
private readonly currentUserService:CurrentUserService,
private readonly cookieService:CookieService,
@@ -145,6 +153,14 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit
window.open(this.storageFilesLocation, '_blank');
}
+ public openLinkFilesDialog():void {
+ const locals = {
+ storageType: this.storageType,
+ storageLocation: this.storageFilesLocation,
+ };
+ this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);
+ }
+
private instantiateStorageInformation(fileLinks:IFileLink[]):StorageInformationBox[] {
switch (this.storage._links.authorizationState.href) {
case storageFailedAuthorization:
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 8124a914ec5..4c122845287 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
@@ -26,7 +26,7 @@
<p
*ngIf="showLinkFilesAction | async"
- class="spot-body-small"
+ class="spot-body-small op-files-tab--file-list-actions"
>
<a
class="spot-link op-files-tab--file-list-action-button"
@@ -35,5 +35,12 @@
<span class="spot-icon spot-icon_external-link"></span>
<span [textContent]="text.actions.linkFile(storageType)"></span>
</a>
+ <a
+ class="spot-link op-files-tab--file-list-action-button"
+ (click)="openLinkFilesDialog()"
+ >
+ <span class="spot-icon spot-icon_add-link"></span>
+ <span [textContent]="text.actions.linkExisting"></span>
+ </a>
</p>
</ng-container>
diff --git a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts
new file mode 100644
index 00000000000..98f3d4a655d
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts
@@ -0,0 +1,107 @@
+// -- 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,
+ OnInit,
+} from '@angular/core';
+import { BehaviorSubject, Observable } from 'rxjs';
+
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
+import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
+import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';
+import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';
+
+@Component({
+ templateUrl: 'file-picker-modal.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class FilePickerModalComponent extends OpModalComponent implements OnInit {
+ public loading$ = new BehaviorSubject<boolean>(true);
+
+ public storageFiles$:Observable<IStorageFile[]>;
+
+ public text = {
+ header: this.i18n.t('js.storages.file_links.select'),
+ buttons: {
+ openStorage: ():string => this.i18n.t('js.storages.open_storage', { storageType: this.locals.storageType as string }),
+ submit: ():string => this.i18n.t('js.storages.file_links.selection_any', { number: this.selectedFileCount }),
+ submitEmptySelection: this.i18n.t('js.storages.file_links.selection_none'),
+ cancel: this.i18n.t('js.button_cancel'),
+ },
+ };
+
+ public get selectedFileCount():number {
+ return this.selection.size;
+ }
+
+ private readonly selection = new Set<string>();
+
+ constructor(
+ @Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
+ readonly elementRef:ElementRef,
+ readonly cdRef:ChangeDetectorRef,
+ private readonly i18n:I18nService,
+ private readonly storageFilesResourceService:StorageFilesResourceService,
+ ) {
+ super(locals, cdRef, elementRef);
+ }
+
+ ngOnInit():void {
+ super.ngOnInit();
+
+ this.storageFiles$ = this.storageFilesResourceService.getMockData();
+
+ this.storageFiles$.subscribe(() => {
+ this.loading$.next(false);
+ });
+ }
+
+ public openStorageLocation():void {
+ window.open(this.locals.storageLocation, '_blank');
+ }
+
+ public createSelectedFileLinks():void {
+ this.service.close();
+ }
+
+ public changeSelection(file:IStorageFile):void {
+ const id = file.id as string;
+ if (this.selection.has(id)) {
+ this.selection.delete(id);
+ } else {
+ this.selection.add(id);
+ }
+ }
+}
diff --git a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html
new file mode 100644
index 00000000000..023ffef53f5
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html
@@ -0,0 +1,57 @@
+<div
+ class="spot-modal spot-modal_wide"
+>
+ <div class="spot-modal--header">
+ <span class="spot-modal--header_title">{{text.header}}</span>
+ <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">
+ <ng-container *ngIf="(loading$ | async) === false; else loadingTemplate">
+ <ul
+ class="spot-list spot-list_compact op-files-tab--file-list"
+ data-qa-selector="op-files-picker-modal--file-list"
+ >
+ <li
+ *ngFor="let file of storageFiles$ | async | sortFiles; let i = index;"
+ class="spot-list--item op-files-tab--file-list-item"
+ data-qa-selector="op-files-tab--file-list-item"
+ op-storage-file-list-item
+ [storageFile]="file"
+ (changeSelection)="changeSelection(file)"
+ ></li>
+ </ul>
+ </ng-container>
+
+ <ng-template #loadingTemplate>
+ <op-loading-project-list></op-loading-project-list>
+ </ng-template>
+ </div>
+
+ <div class="spot-modal--footer spot-action-bar">
+ <div class="spot-action-bar--right">
+ <button
+ class="button button_no-margin spot-action-bar--action"
+ [textContent]="text.buttons.cancel"
+ (click)="closeMe()"
+ ></button>
+ <button
+ class="button -highlight button_no-margin spot-action-bar--action"
+ [ngClass]="{ '-highlight': selectedFileCount > 0 }"
+ [disabled]="selectedFileCount === 0"
+ (click)="createSelectedFileLinks()"
+ >
+ <span class="spot-icon spot-icon_add-link"></span>
+ <span>{{selectedFileCount > 0 ? text.buttons.submit() : text.buttons.submitEmptySelection}}</span>
+ </button>
+ </div>
+ </div>
+</div>
diff --git a/frontend/src/app/shared/components/file-links/file-picker-modal/sort-files.pipe.ts b/frontend/src/app/shared/components/file-links/file-picker-modal/sort-files.pipe.ts
new file mode 100644
index 00000000000..2af763f8404
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/file-picker-modal/sort-files.pipe.ts
@@ -0,0 +1,21 @@
+import { Pipe, PipeTransform } from '@angular/core';
+import { isDirectory } from 'core-app/shared/components/file-links/file-link-icons/file-icons.helper';
+
+@Pipe({
+ name: 'sortFiles',
+})
+export class SortFilesPipe implements PipeTransform {
+ transform<T extends { mimeType?:string, name:string }>(array:T[]):T[] {
+ return array.sort((a, b):number => {
+ if (isDirectory(a.mimeType)) {
+ return -1;
+ }
+
+ if (isDirectory(b.mimeType)) {
+ return 1;
+ }
+
+ return a.name > b.name ? -1 : 1;
+ });
+ }
+}
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 7841874153c..ad4cd8a6296 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
@@ -40,17 +40,29 @@ import {
import {
StorageInformationComponent,
} from 'core-app/shared/components/file-links/storage-information/storage-information.component';
+import {
+ FilePickerModalComponent,
+} from 'core-app/shared/components/file-links/file-picker-modal/file-picker-modal.component';
+import { OPSharedModule } from 'core-app/shared/shared.module';
+import {
+ StorageFileListItemComponent,
+} from 'core-app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component';
+import { SortFilesPipe } from 'core-app/shared/components/file-links/file-picker-modal/sort-files.pipe';
@NgModule({
imports: [
CommonModule,
IconModule,
OpSpotModule,
+ OPSharedModule,
],
declarations: [
FileLinkListComponent,
FileLinkListItemComponent,
+ FilePickerModalComponent,
StorageInformationComponent,
+ StorageFileListItemComponent,
+ SortFilesPipe,
],
exports: [
FileLinkListComponent,
diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts
new file mode 100644
index 00000000000..0d51ea7f816
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts
@@ -0,0 +1,106 @@
+// -- 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 {
+ AfterViewInit,
+ ChangeDetectionStrategy,
+ Component,
+ ElementRef,
+ EventEmitter,
+ Input,
+ OnInit, Output,
+ ViewChild,
+} from '@angular/core';
+
+import { TimezoneService } from 'core-app/core/datetime/timezone.service';
+import { IFileIcon } from 'core-app/shared/components/file-links/file-link-icons/icon-mappings';
+import { PrincipalRendererService } from 'core-app/shared/components/principal/principal-renderer.service';
+import {
+ getIconForMimeType,
+} from 'core-app/shared/components/file-links/file-link-icons/file-link-list-item-icon.factory';
+import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+import { isDirectory } from 'core-app/shared/components/file-links/file-link-icons/file-icons.helper';
+
+@Component({
+ // eslint-disable-next-line @angular-eslint/component-selector
+ selector: '[op-storage-file-list-item]',
+ templateUrl: './storage-file-list-item.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+})
+export class StorageFileListItemComponent implements OnInit, AfterViewInit {
+ @Input() public storageFile:IStorageFile;
+
+ @Input() public selected = false;
+
+ @Output() public changeSelection = new EventEmitter();
+
+ @ViewChild('avatar') avatar:ElementRef;
+
+ infoTimestampText:string;
+
+ fileLinkIcon:IFileIcon;
+
+ showDetails:boolean;
+
+ constructor(
+ private readonly timezoneService:TimezoneService,
+ private readonly principalRendererService:PrincipalRendererService,
+ ) {}
+
+ ngOnInit():void {
+ if (this.storageFile.lastModifiedAt) {
+ this.infoTimestampText = this.timezoneService.parseDatetime(this.storageFile.lastModifiedAt).fromNow();
+ }
+
+ this.fileLinkIcon = getIconForMimeType(this.storageFile.mimeType);
+
+ this.showDetails = !isDirectory(this.storageFile.mimeType);
+ }
+
+ ngAfterViewInit():void {
+ if (!this.showDetails) {
+ return;
+ }
+
+ if (this.storageFile.lastModifiedByName) {
+ this.principalRendererService.render(
+ this.avatar.nativeElement,
+ { name: this.storageFile.lastModifiedByName, href: '/external_users/1' },
+ { hide: true, link: false },
+ { hide: false, size: 'mini' },
+ );
+ } else {
+ this.principalRendererService.render(
+ this.avatar.nativeElement,
+ { name: 'Not Available', href: '/placeholder_users/1' },
+ { hide: true, link: false },
+ { hide: false, size: 'mini' },
+ );
+ }
+ }
+}
diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html
new file mode 100644
index 00000000000..b3245f096fa
--- /dev/null
+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html
@@ -0,0 +1,29 @@
+<label
+ class="spot-list--item-action"
+>
+ <spot-checkbox
+ [checked]="selected"
+ (click)="changeSelection.emit()"
+ ></spot-checkbox>
+ <span
+ class="spot-icon spot-icon_{{fileLinkIcon.icon}} op-files-tab--icon op-files-tab--icon_{{fileLinkIcon.clazz}}"
+ ></span>
+
+ <span
+ [textContent]="storageFile.name"
+ [title]="storageFile.name"
+ class="spot-list--item-title op-files-tab--file-list-item-title"
+ ></span>
+
+ <span
+ *ngIf="showDetails"
+ class="op-files-tab--file-list-item-text"
+ [textContent]="infoTimestampText"
+ ></span>
+
+ <div
+ #avatar
+ *ngIf="showDetails"
+ class="op-files-tab--file-list-item-avatar"
+ ></div>
+</label>
diff --git a/frontend/src/app/shared/components/project-include/project-include.component.ts b/frontend/src/app/shared/components/project-include/project-include.component.ts
index 396357e2459..2d85188b46a 100644
--- a/frontend/src/app/shared/components/project-include/project-include.component.ts
+++ b/frontend/src/app/shared/components/project-include/project-include.component.ts
@@ -14,21 +14,25 @@ import {
distinctUntilChanged,
filter,
map,
- tap,
mergeMap,
shareReplay,
- skip,
take,
} from 'rxjs/operators';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { WorkPackageViewFiltersService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
-import { WorkPackageViewIncludeSubprojectsService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-include-subprojects.service';
+import {
+ WorkPackageViewFiltersService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
+import {
+ WorkPackageViewIncludeSubprojectsService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-include-subprojects.service';
import { QueryFilterInstanceResource } from 'core-app/features/hal/resources/query-filter-instance-resource';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { IProject } from 'core-app/core/state/projects/project.model';
-import { SearchableProjectListService } from 'core-app/shared/components/searchable-project-list/searchable-project-list.service';
+import {
+ SearchableProjectListService,
+} from 'core-app/shared/components/searchable-project-list/searchable-project-list.service';
import { IProjectData } from 'core-app/shared/components/searchable-project-list/project-data';
import { insertInList } from './insert-in-list';
@@ -135,91 +139,89 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
this.includeSubprojects$.pipe(debounceTime(20)),
this.searchableProjectListService.searchText$.pipe(debounceTime(200)),
]).pipe(
- mergeMap(([projects, displayMode, includeSubprojects, searchText]) => this.selectedProjects$.pipe(
- take(1),
- map((selected) => [projects, displayMode, includeSubprojects, searchText, selected]),
- )),
- map(
- ([projects, displayMode, includeSubprojects, searchText, selected]:[IProject[], string, boolean, string, string[]]) => [
- projects
- .filter(
- (project) => {
- if (searchText.length) {
- const matches = project.name.toLowerCase().includes(searchText.toLowerCase());
-
- if (!matches) {
- return false;
- }
- }
-
- if (displayMode !== 'selected') {
- return true;
+ mergeMap(([projects, displayMode, includeSubprojects, searchText]) => this.selectedProjects$.pipe(
+ take(1),
+ map((selected) => [projects, displayMode, includeSubprojects, searchText, selected]),
+ )),
+ map(
+ ([projects, displayMode, includeSubprojects, searchText, selected]:[IProject[], string, boolean, string, string[]]) => [
+ projects
+ .filter(
+ (project) => {
+ if (searchText.length) {
+ const matches = project.name.toLowerCase().includes(searchText.toLowerCase());
+
+ if (!matches) {
+ return false;
}
+ }
+
+ if (displayMode !== 'selected') {
+ return true;
+ }
+
+ if (selected.includes(project._links.self.href)) {
+ return true;
+ }
+
+ const hasSelectedAncestor = project._links.ancestors.reduce(
+ (anySelected, ancestor) => anySelected || selected.includes(ancestor.href),
+ false,
+ );
+
+ if (includeSubprojects && hasSelectedAncestor) {
+ return true;
+ }
+
+ return false;
+ },
+ )
+ .sort((a, b) => a._links.ancestors.length - b._links.ancestors.length)
+ .reduce(
+ (list, project) => {
+ const { ancestors } = project._links;
+
+ return insertInList(
+ projects,
+ project,
+ list,
+ ancestors,
+ );
+ },
+ [] as IProjectData[],
+ ),
+ includeSubprojects,
+ ],
+ ),
+ mergeMap(([projects, includeSubprojects]) => this.selectedProjects$.pipe(
+ map((selected) => [projects, includeSubprojects, selected]),
+ )),
+ map(([projects, includeSubprojects, selected]:[IProjectData[], boolean, string[]]) => {
+ const isDisabled = (project:IProjectData, parentChecked:boolean) => {
+ if (project.disabled) {
+ return true;
+ }
- if (selected.includes(project._links.self.href)) {
- return true;
- }
+ if (project.href === this.currentProjectService.apiv3Path) {
+ return true;
+ }
- const hasSelectedAncestor = project._links.ancestors.reduce(
- (anySelected, ancestor) => anySelected || selected.includes(ancestor.href),
- false,
- );
+ return includeSubprojects && parentChecked;
+ };
- if (includeSubprojects && hasSelectedAncestor) {
- return true;
- }
+ const setDisabledStatus = (project:IProjectData, parentChecked:boolean):IProjectData => ({
+ ...project,
+ disabled: isDisabled(project, parentChecked),
+ children: project.children.map(
+ (child) => setDisabledStatus(child, parentChecked || selected.includes(project.href)),
+ ),
+ });
- return false;
- },
- )
- .sort((a, b) => a._links.ancestors.length - b._links.ancestors.length)
- .reduce(
- (list, project) => {
- const { ancestors } = project._links;
-
- return insertInList(
- projects,
- project,
- list,
- ancestors,
- );
- },
- [] as IProjectData[],
- ),
- includeSubprojects,
- ],
- ),
- mergeMap(([projects, includeSubprojects]) => this.selectedProjects$.pipe(
- map((selected) => [projects, includeSubprojects, selected]),
- )),
- map(([projects, includeSubprojects, selected]: [IProjectData[], boolean, string[]]) => {
- const isDisabled = (project:IProjectData, parentChecked:boolean) => {
- if (project.disabled) {
- return true;
- }
-
- if (project.href === this.currentProjectService.apiv3Path) {
- return true;
- }
-
- return includeSubprojects && parentChecked;
- };
-
- const setDisabledStatus = (project:IProjectData, parentChecked:boolean):IProjectData => {
- return {
- ...project,
- disabled: isDisabled(project, parentChecked),
- children: project.children.map(
- (child) => setDisabledStatus(child, parentChecked || selected.includes(project.href)),
- ),
- };
- };
-
- return projects.map((project) => setDisabledStatus(project, false));
- }),
- map((projects) => recursiveSort(projects)),
- shareReplay(),
- );
+ return projects.map((project) => setDisabledStatus(project, false));
+ }),
+ map((projects) => recursiveSort(projects)),
+ shareReplay(),
+ );
/* This seems like a way too convoluted loading check, but there's a good reason we need it.
* The searchableProjectListService says fetching is "done" when the request returns.
@@ -252,7 +254,7 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
this.projects$
.pipe(
this.untilDestroyed(),
- filter(p => p.length > 0),
+ filter((p) => p.length > 0),
take(1),
)
.subscribe((projects) => {
diff --git a/frontend/src/app/spot/styles/sass/common/container.sass b/frontend/src/app/spot/styles/sass/common/container.sass
index bb157e14b21..a505ab5a854 100644
--- a/frontend/src/app/spot/styles/sass/common/container.sass
+++ b/frontend/src/app/spot/styles/sass/common/container.sass
@@ -10,8 +10,7 @@
> .spot-body-small,
> .spot-caption,
> .spot-text-field
- margin: 0 $spot-spacing-1
- margin-top: $spot-spacing-1
+ margin: $spot-spacing-1 $spot-spacing-1 0
&:first-child
margin-top: $spot-spacing-0-5
diff --git a/frontend/src/app/spot/styles/sass/components/modal.sass b/frontend/src/app/spot/styles/sass/components/modal.sass
index ab352bddafb..9a1cc1da2ab 100644
--- a/frontend/src/app/spot/styles/sass/components/modal.sass
+++ b/frontend/src/app/spot/styles/sass/components/modal.sass
@@ -38,11 +38,14 @@
position: relative
align-items: center
- .spot-icon
+ > .spot-icon
width: $spot-spacing-1-5
height: $spot-spacing-1-5
margin-right: $spot-spacing-0-5
+ &_title
+ flex-grow: 1
+
&_highlight
background-color: var(--header-bg-color)
border-bottom-width: var(--header-border-bottom-width)
@@ -64,5 +67,9 @@
&:focus
outline-style: none
+ .spot-list
+ margin-left: -$spot-spacing-1
+ margin-right: -$spot-spacing-1
+
&--footer
width: 100%
diff --git a/frontend/src/global_styles/content/_buttons.sass b/frontend/src/global_styles/content/_buttons.sass
index e1b67a16b35..76586179c00 100644
--- a/frontend/src/global_styles/content/_buttons.sass
+++ b/frontend/src/global_styles/content/_buttons.sass
@@ -127,6 +127,21 @@ a.button
&_no-margin
margin: 0
+ .spot-icon
+ // Add rules for using new spot icons boxed within the old buttons
+ font-size: 0.875rem
+ width: 1.5rem
+ height: 1.5rem
+ // prevent icon box to inflate button height
+ margin-top: -1rem
+ margin-bottom: -1rem
+
+ &:not(:last-child)
+ margin-right: 0.25rem
+
+ &:not(:first-child)
+ margin-left: 0.25rem
+
.button--icon
@include icon-common
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 cf4d4c23aa5..8db4afc2b8f 100644
--- a/frontend/src/global_styles/content/work_packages/tabs/_files.sass
+++ b/frontend/src/global_styles/content/work_packages/tabs/_files.sass
@@ -88,6 +88,9 @@
&-icon
margin-right: $spot-spacing-0-5
+ &-actions > &-action-button:not(:last-child)
+ margin-right: $spot-spacing-1
+
&--file-list &--file-list-item &--file-list-item-action
padding-left: 0
padding-right: 0
@@ -133,6 +136,9 @@
width: $spot-spacing-1-5
height: $spot-spacing-1-5
+ &:not(:first-child)
+ margin-left: $spot-spacing-0-5
+
&_pdf
color: #B93A33
diff --git a/modules/storages/config/locales/js-en.yml b/modules/storages/config/locales/js-en.yml
index 33d2af365d1..9cc19c94c96 100644
--- a/modules/storages/config/locales/js-en.yml
+++ b/modules/storages/config/locales/js-en.yml
@@ -32,4 +32,7 @@ en:
Are you sure you want to unlink the file from this work package? Unlinking does not affect the original file
and only removes the connection to this work package.
remove_short: "Remove link"
+ select: "Select files"
+ selection_none: "Select files to link"
+ selection_any: "Link %{number} files"
not_allowed_tooltip: "Please log in to Nextcloud to access this file"