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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#43696] added traversing file levels
Eric Schubert47cf8f3e3767
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.tsindex 67bdd61edea..3fe389982d2 100644--- 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@@ -36,6 +36,7 @@ import {OnInit,} from '@angular/core';import { BehaviorSubject } from 'rxjs';+import { take } from 'rxjs/operators';import { I18nService } from 'core-app/core/i18n/i18n.service';import { IHalResourceLink } from 'core-app/core/state/hal-resource';@@ -45,11 +46,12 @@ 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 { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';-import { BreadcrumbsContent } from 'core-app/spot/components/breadcrumbs/breadcrumbs-content';+import { Breadcrumb, BreadcrumbsContent } from 'core-app/spot/components/breadcrumbs/breadcrumbs-content';import {IStorageFileListItem,} from 'core-app/shared/components/file-links/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/file-links/file-link-icons/file-icons.helper';import getIconForStorageType from 'core-app/shared/components/file-links/storage-icons/get-icon-for-storage-type';@Component({@@ -59,7 +61,7 @@ import getIconForStorageType from 'core-app/shared/components/file-links/storageexport class FilePickerModalComponent extends OpModalComponent implements OnInit, OnDestroy {public loading$ = new BehaviorSubject<boolean>(true);- public storageFiles$ = new BehaviorSubject<IStorageFileListItem[]>([]);+ public listItems$ = new BehaviorSubject<IStorageFileListItem[]>([]);public breadcrumbs:BreadcrumbsContent;@@ -77,11 +79,15 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInitreturn 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 storageLink:IHalResourceLink;+ private storageFiles$ = new BehaviorSubject<IStorageFile[]>([]);constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,@@ -100,25 +106,22 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInitthis.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.storageLink = (this.locals.storageLink as IHalResourceLink);- const filesLink:IHalResourceLink = {- href: `${this.storageLink.href}/files`,- title: 'Storage files',- };-- this.storageFilesResourceService.files(filesLink)+ this.storageFiles$+ .pipe(this.untilDestroyed()).subscribe((files) => {- const fileListItems = files.map((file, index) => ({- disabled: this.isAlreadyLinked(file),- isFirst: index === 0,- changeSelection: () => { this.changeSelection(file); },- ...file,- }));- this.storageFiles$.next(fileListItems);+ const fileListItems = files.map((file, index) => this.storageFileToListItem(file, index));+ this.listItems$.next(fileListItems);this.loading$.next(false);});++ this.storageFilesResourceService.files(this.makeFilesCollectionLink(null))+ .pipe(take(1))+ .subscribe((files) => {+ this.storageFiles$.next(files);+ });}ngOnDestroy():void {@@ -153,6 +156,50 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit}}+ private changeLevel(parent:string|null, crumbs:Breadcrumb[]):void {+ this.storageFilesResourceService.files(this.makeFilesCollectionLink(parent))+ .pipe(take(1))+ .subscribe((files) => {+ this.storageFiles$.next(files);+ this.breadcrumbs = new BreadcrumbsContent(crumbs);+ });+ }++ 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):IStorageFileListItem {+ const listItem:IStorageFileListItem = {+ disabled: this.isAlreadyLinked(file),+ isFirst: index === 0,+ selected: this.selection.has(file.id as string),+ changeSelection: () => { this.changeSelection(file); },+ ...file,+ };++ if (isDirectory(file.mimeType)) {+ listItem.enterDirectory = () => {+ 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));+ };+ }+ return listItem;+ }+private isAlreadyLinked(file:IStorageFile):boolean {const currentFileLinks = this.locals.fileLinks as IFileLink[];const found = currentFileLinks.find((a) => a.originData.id === file.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.htmlindex 7fc4d0f32aa..5ed24483079 100644--- 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@@ -24,7 +24,7 @@data-qa-selector="op-files-picker-modal--file-list"><li- *ngFor="let file of storageFiles$ | async | sortFiles; let i = index;"+ *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-itemdiff --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.htmlindex 2f731e24a1f..a49ee9cb2af 100644--- 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@@ -13,7 +13,7 @@[ngClass]="{ 'spot-list--item-action_disabled': fileListItemContent.disabled }"><spot-checkbox- [checked]="fileListItemContent.disabled"+ [checked]="fileListItemContent.disabled || fileListItemContent.selected"(checkedChange)="fileListItemContent.changeSelection()"[disabled]="fileListItemContent.disabled"></spot-checkbox>@@ -41,5 +41,13 @@[size]="'mini'"[link]="false"></op-principal>++ <button+ *ngIf="!showDetails"+ class="spot-link"+ (click)="fileListItemContent.enterDirectory()"+ >+ <span class="spot-icon spot-icon_arrow-right2"></span>+ </button></label></spot-tooltip>diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.tsindex c6b014e120f..fdc203ea81c 100644--- a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts@@ -31,5 +31,7 @@ import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.modexport interface IStorageFileListItem extends IStorageFile {disabled:boolean;isFirst:boolean;+ selected:boolean;changeSelection:() => void;+ enterDirectory?:() => void;}