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
[#47050] Extend file/location picker to be able to open on any location.
Eric Schubertc36391d9d887
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.tsindex 6698352ae31..c42f03621b9 100644--- a/frontend/src/app/core/state/storage-files/storage-file.model.ts+++ b/frontend/src/app/core/state/storage-files/storage-file.model.ts@@ -33,7 +33,7 @@ interface IStorageFileLocation {}interface IStorageFilePermissions {- permissions:Array<'readable'|'writeable'>+ permissions:Array<'readable'|'writeable'>;}export interface IStorageFile extends IFileLinkOriginData, IStorageFileLocation, IStorageFilePermissions {}diff --git a/frontend/src/app/core/state/storage-files/storage-files.model.ts b/frontend/src/app/core/state/storage-files/storage-files.model.tsindex ecb0fdb2235..b9cf9056b72 100644--- a/frontend/src/app/core/state/storage-files/storage-files.model.ts+++ b/frontend/src/app/core/state/storage-files/storage-files.model.ts@@ -31,6 +31,7 @@ import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.modexport interface IStorageFiles {files:IStorageFile[];+ ancestors:IStorageFile[];parent:IStorageFile;_type:'StorageFiles';_links:IHalResourceLinks;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.tsindex b741ec1e820..68a9261efe6 100644--- a/frontend/src/app/core/state/storage-files/storage-files.service.ts+++ b/frontend/src/app/core/state/storage-files/storage-files.service.ts@@ -53,10 +53,10 @@ export class StorageFilesResourceService {files(link:IHalResourceLink):Observable<IStorageFiles> {const value = this.store.getValue().files[link.href];if (value !== undefined) {- return combineLatest([this.lookupMany(value.files), this.lookup(value.parent)])+ return combineLatest([this.lookupMany(value.files), this.lookup(value.parent), this.lookupMany(value.ancestors)]).pipe(- map(([files, parent]):IStorageFiles => ({- files, parent, _type: 'StorageFiles', _links: { self: link },+ map(([files, parent, ancestors]):IStorageFiles => ({+ files, parent, ancestors, _type: 'StorageFiles', _links: { self: link },})),take(1),);@@ -87,10 +87,11 @@ export class StorageFilesResourceService {}private insert(storageFiles:IStorageFiles, link:string):void {- this.store.upsertMany([...storageFiles.files, storageFiles.parent]);+ this.store.upsertMany([...storageFiles.files, storageFiles.parent, ...storageFiles.ancestors]);const fileIds = storageFiles.files.map((file) => file.id);const parentId = storageFiles.parent.id;+ const ancestorIds = storageFiles.ancestors.map((file) => file.id);this.store.update(({ files }) => ({files: {@@ -98,6 +99,7 @@ export class StorageFilesResourceService {[link]: {files: fileIds,parent: parentId,+ ancestors: ancestorIds,},},}));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.tsindex a4a9890eb54..f4474b688d4 100644--- a/frontend/src/app/core/state/storage-files/storage-files.store.ts+++ b/frontend/src/app/core/state/storage-files/storage-files.store.ts@@ -33,6 +33,7 @@ import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.modexport interface IStorageFilesResponse {files:ID[];+ ancestors:ID[];parent:ID;}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.tsindex dade4df3203..4357ee58d96 100644--- 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@@ -94,24 +94,13 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent implngOnInit():void {super.ngOnInit();+ const location = this.locals.location as string || '/';+this.storageFilesResourceService- .files(makeFilesCollectionLink(this.storageLink, '/'))+ .files(makeFilesCollectionLink(this.storageLink, location)).subscribe((storageFiles) => {- const root = storageFiles.parent;- if (root === undefined) {- throw new Error('Collection does not contain a root directory!');- }-- this.currentDirectory = root;-- this.breadcrumbs = new BreadcrumbsContent(- [{- text: this.locals.storageName as string,- icon: getIconForStorageType(this.locals.storageType as string),- navigate: () => this.changeLevel(root, this.breadcrumbs.crumbs.slice(0, 1)),- }],- );-+ this.currentDirectory = storageFiles.parent;+ this.breadcrumbs = this.makeBreadcrumbs(storageFiles.ancestors, storageFiles.parent);this.storageFiles$.next(storageFiles.files);this.loading$.next(false);});@@ -130,32 +119,19 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent implreturn () => {};}- 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, this.breadcrumbs.crumbs.slice(0, end)),- };- this.changeLevel(directory, crumbs.concat(newCrumb));- };+ return () => this.changeLevel(directory);}- protected changeLevel(directory:IStorageFile, crumbs:Breadcrumb[]):void {- this.currentDirectory = directory;-+ protected changeLevel(ancestor:IStorageFile):void {this.cancelCurrentLoading();-this.loading$.next(true);- this.breadcrumbs = new BreadcrumbsContent(crumbs);this.loadingSubscription = this.storageFilesResourceService- .files(makeFilesCollectionLink(this.storageLink, directory.location))- .pipe(map((storageFiles) => storageFiles.files.filter((file) => file.name !== this.currentDirectory.name)))- .subscribe((files) => {- this.storageFiles$.next(files);+ .files(makeFilesCollectionLink(this.storageLink, ancestor.location))+ .subscribe((storageFiles) => {+ this.currentDirectory = storageFiles.parent;+ this.breadcrumbs = this.makeBreadcrumbs(storageFiles.ancestors, storageFiles.parent);+ this.storageFiles$.next(storageFiles.files);this.loading$.next(false);});}@@ -163,4 +139,15 @@ export abstract class FilePickerBaseModalComponent extends OpModalComponent implprivate cancelCurrentLoading():void {this.loadingSubscription?.unsubscribe();}++ private makeBreadcrumbs(ancestors:IStorageFile[], parent:IStorageFile):BreadcrumbsContent {+ const crumbs = ancestors.concat(parent).map((ancestor):Breadcrumb => {+ const isRoot = ancestor.location === '/';+ const icon = isRoot ? getIconForStorageType(this.locals.storageType as string) : undefined;+ const text = isRoot ? this.locals.storageName as string : ancestor.name;+ return { icon, text, navigate: () => this.changeLevel(ancestor) };+ });++ return new BreadcrumbsContent(crumbs);+ }}diff --git a/frontend/src/app/shared/components/storages/storage/storage.component.ts b/frontend/src/app/shared/components/storages/storage/storage.component.tsindex 81a77cd8a2d..0a32b77c4db 100644--- a/frontend/src/app/shared/components/storages/storage/storage.component.ts+++ b/frontend/src/app/shared/components/storages/storage/storage.component.ts@@ -283,6 +283,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnDstorageLink: this.storage._links.self,addFileLinksHref: this.addFileLinksHref,collectionKey: this.collectionKey,+ location: '/',fileLinks,};this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);@@ -317,6 +318,7 @@ export class StorageComponent extends UntilDestroyedMixin implements OnInit, OnDstorageType: this.storage._links.type.href,storageName: this.storage.name,storageLink: this.storage._links.self,+ location: '/',};return this.opModalService.show<LocationPickerModalComponent>(LocationPickerModalComponent, 'global', locals)diff --git a/frontend/src/app/spot/styles/sass/components/breadcrumbs.sass b/frontend/src/app/spot/styles/sass/components/breadcrumbs.sassindex 3e3bd166caa..3d4cff0eb37 100644--- a/frontend/src/app/spot/styles/sass/components/breadcrumbs.sass+++ b/frontend/src/app/spot/styles/sass/components/breadcrumbs.sass@@ -13,7 +13,9 @@> .spot-iconwidth: $spot-spacing-1_5height: $spot-spacing-1_5- color: var(--primary-color)++ &:not(.spot-breadcrumbs--crumb-divider)+ color: var(--primary-color)&_collapsed:beforecontent: '...'diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rbindex 4d11c8dda0d..387126d6bc8 100644--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb@@ -130,19 +130,25 @@ module Storages::Peripherals::StorageInteraction::Nextcloudlast = list.lastprefix = last.nil? || last.location[-1] != '/' ? '/' : ''location = "#{last&.location}#{prefix}#{item}"- list.append(::Storages::StorageFile.new(nil,- name(location),- nil,- nil,- nil,- nil,- nil,- nil,- location,- nil))+ list.append(forge_ancestor(location))endend+ # The ancestors are simply derived objects from the parents location string. Until we have real information+ # from the nextcloud API about the path to the parent, we need to derive name, location and forge an ID.+ def forge_ancestor(location)+ ::Storages::StorageFile.new(Digest::SHA256.hexdigest(location),+ name(location),+ nil,+ nil,+ nil,+ nil,+ nil,+ nil,+ location,+ nil)+ end+def name(location)location == '/' ? location : CGI.unescape(location.split('/').last)end