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

Wired up file picker dialog to actually fetch data from backend

Andreas Pfohlad297fd91535
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
index fd1c4d67c30..937f24e6c6c 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
@@ -33,7 +33,7 @@ import {
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 { Observable } from 'rxjs';
import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
import { IHalResourceLink } from 'core-app/core/state/hal-resource';
import { insertCollectionIntoState } from 'core-app/core/state/collection-store';
@@ -50,12 +50,13 @@ export class StorageFilesResourceService extends ResourceCollectionService<IStor
return new StorageFilesStore();
}
- // fetch(link:IHalResourceLink):void {
- fetch():void {
- // this.http
- // .get<[IStorageFile]>(link.href)
- this.mockedFileList()
- .pipe(map((fileList) => ({ _embedded: { elements: fileList } } as unknown as IHALCollection<IStorageFile>)))
+ fetch(link:IHalResourceLink):void {
+ this.http
+ .get<[IStorageFile]>(link.href)
+ .pipe(
+ map((fileList) => ({ _embedded: { elements: fileList } } as unknown as IHALCollection<IStorageFile>)),
+ // delay(5000),
+ )
.subscribe((fileList) => insertCollectionIntoState(this.store, fileList, 'root'));
}
@@ -63,36 +64,7 @@ export class StorageFilesResourceService extends ResourceCollectionService<IStor
return this.collection('root');
}
- private mockedFileList():Observable<IStorageFile[]> {
- return of([
- {
- id: 1,
- name: 'image.png',
- mimeType: 'image/png',
- lastModifiedAt: '2022-09-16T12:00Z',
- lastModifiedByName: 'Leia Organa',
- location: '/data',
- },
- {
- id: 2,
- name: 'Readme.md',
- mimeType: 'text/markdown',
- lastModifiedAt: '2022-09-16T13:00Z',
- lastModifiedByName: 'Anakin Skywalker',
- location: '/data',
- },
- {
- id: 3,
- name: 'folder',
- mimeType: 'application/x-op-directory',
- location: '/data',
- },
- {
- id: 4,
- name: 'directory',
- mimeType: 'application/x-op-directory',
- location: '/data',
- },
- ]);
+ reset():void {
+ this.store.reset();
}
}
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 0536e8906c5..7406f02230a 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
@@ -157,6 +157,7 @@ export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit
const locals = {
storageType: this.storageType,
storageLocation: this.storageFilesLocation,
+ storageLink: this.storage._links.self,
};
this.opModalService.show<FilePickerModalComponent>(FilePickerModalComponent, 'global', locals);
}
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
index aef85d05a0e..f42028c8fe9 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
@@ -32,6 +32,7 @@ import {
Component,
ElementRef,
Inject,
+ OnDestroy,
OnInit,
} from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
@@ -42,12 +43,13 @@ import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.mod
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 { IHalResourceLink } from 'core-app/core/state/hal-resource';
@Component({
templateUrl: 'file-picker-modal.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class FilePickerModalComponent extends OpModalComponent implements OnInit {
+export class FilePickerModalComponent extends OpModalComponent implements OnInit, OnDestroy {
public loading$ = new BehaviorSubject<boolean>(true);
public storageFiles$:Observable<IStorageFile[]>;
@@ -80,7 +82,13 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
ngOnInit():void {
super.ngOnInit();
- this.storageFilesResourceService.fetch();
+
+ const filesLink:IHalResourceLink = {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
+ href: `${this.locals.storageLink.href}/files`,
+ title: 'Storage files',
+ };
+ this.storageFilesResourceService.fetch(filesLink);
this.storageFiles$ = this.storageFilesResourceService.files();
@@ -89,6 +97,12 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
});
}
+ ngOnDestroy():void {
+ super.ngOnDestroy();
+
+ this.storageFilesResourceService.reset();
+ }
+
public openStorageLocation():void {
window.open(this.locals.storageLocation, '_blank');
}
diff --git a/modules/storages/lib/api/v3/storages/storage_files_api.rb b/modules/storages/lib/api/v3/storages/storage_files_api.rb
new file mode 100644
index 00000000000..8bfbf87d859
--- /dev/null
+++ b/modules/storages/lib/api/v3/storages/storage_files_api.rb
@@ -0,0 +1,70 @@
+#-- 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.
+#++
+
+module API
+ module V3
+ module Storages
+ class StorageFilesAPI < ::API::OpenProjectAPI
+ resources :files do
+ get do
+ [
+ {
+ id: 1,
+ name: 'image.png',
+ mimeType: 'image/png',
+ lastModifiedAt: '2022-09-16T12:00Z',
+ lastModifiedByName: 'Leia Organa',
+ location: '/data',
+ },
+ {
+ id: 2,
+ name: 'Readme.md',
+ mimeType: 'text/markdown',
+ lastModifiedAt: '2022-09-16T13:00Z',
+ lastModifiedByName: 'Anakin Skywalker',
+ location: '/data',
+ },
+ {
+ id: 3,
+ name: 'folder',
+ mimeType: 'application/x-op-directory',
+ location: '/data',
+ },
+ {
+ id: 4,
+ name: 'directory',
+ mimeType: 'application/x-op-directory',
+ location: '/data',
+ },
+ ]
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rb
index 42d0268c64b..25e54c7b2d8 100644
--- a/modules/storages/lib/api/v3/storages/storages_api.rb
+++ b/modules/storages/lib/api/v3/storages/storages_api.rb
@@ -59,6 +59,8 @@ module API
# The block will get called everytime a GET request is sent to this
# route.
get &::API::V3::Utilities::Endpoints::Show.new(model: ::Storages::Storage).mount
+
+ mount API::V3::Storages::StorageFilesAPI
end
end
end