From ca79913a46513c851717cc07c79cf833aa39a895 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Thu, 4 Feb 2021 15:55:18 -0600 Subject: [PATCH] #77 - pass along node ID to file box API, refresh sidebar on name change --- .../nodes/file-box/file-box.component.ts | 29 ++++++++------ src/app/service/api.service.ts | 40 +++++++++---------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/app/components/nodes/file-box/file-box.component.ts b/src/app/components/nodes/file-box/file-box.component.ts index d27638d..e20fae3 100644 --- a/src/app/components/nodes/file-box/file-box.component.ts +++ b/src/app/components/nodes/file-box/file-box.component.ts @@ -6,6 +6,7 @@ import {EditorNodeContract} from '../EditorNode.contract'; import {HttpClient} from '@angular/common/http'; import {AlertController, LoadingController, PopoverController} from '@ionic/angular'; import {OptionMenuComponent} from '../../option-menu/option-menu.component'; +import {NavigationService} from "../../../service/navigation.service"; export interface FileBoxFile { type: 'file'; @@ -75,6 +76,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { protected loading: LoadingController, protected popover: PopoverController, protected alerts: AlertController, + protected navService: NavigationService, @Inject(APP_BASE_HREF) private baseHref: string ) { super(); } @@ -106,12 +108,12 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { } if ( !this.node.Value.Value && !this.readonly ) { - this.record = await this.api.createFileBox(this.page.UUID, this.fileBoxName); + this.record = await this.api.createFileBox(this.page.UUID, this.node.UUID, this.fileBoxName); this.node.Value.Value = this.record.UUID; this.node.value = this.record.UUID; this.dirty = true; } else if ( this.node.Value.Value ) { - this.record = await this.api.getFileBox(this.page.UUID, this.node.Value.Value); + this.record = await this.api.getFileBox(this.page.UUID, this.node.UUID, this.node.Value.Value); } if ( !this.record ) { @@ -137,8 +139,8 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { public async loadBox(): Promise { this.fileBoxName = this.record.name; - const files = await this.api.getFileBoxFiles(this.page.UUID, this.record.UUID); - const children = await this.api.getFileBoxChildren(this.page.UUID, this.record.UUID); + const files = await this.api.getFileBoxFiles(this.page.UUID, this.node.UUID, this.record.UUID); + const children = await this.api.getFileBoxChildren(this.page.UUID, this.node.UUID, this.record.UUID); this.items = [...children, ...files]; this.refilter(); @@ -178,7 +180,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { public async performDelete(): Promise { const baseRecord = this.history.length > 0 ? this.history[0] : this.record; - await this.api.deleteFileBox(this.page.UUID, baseRecord.UUID); + await this.api.deleteFileBox(this.page.UUID, this.node.UUID, baseRecord.UUID); } ngOnInit() { @@ -254,7 +256,8 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { this.fileBoxName = name; this.record.name = name; this.record.title = name; - await this.api.updateFileBox(this.page.UUID, this.record.UUID, { name }); + await this.api.updateFileBox(this.page.UUID, this.node.UUID, this.record.UUID, { name }); + this.navService.requestSidebarRefresh({ quiet: true }); } async onItemContextMenu(item: FileBoxItem, event: MouseEvent) { @@ -322,7 +325,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { formData.append(`uploaded_file_${i}`, file, file.name); } - await this.api.uploadFileBoxFiles(this.page.UUID, this.record.UUID, formData); + await this.api.uploadFileBoxFiles(this.page.UUID, this.node.UUID, this.record.UUID, formData); await this.loadBox(); } @@ -335,7 +338,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { this.record = item; await this.loadBox(); } else if ( item.type === 'file' ) { - const url = this.api.getFileBoxFileDownloadUrl(this.page.UUID, this.record.UUID, item.id); + const url = this.api.getFileBoxFileDownloadUrl(this.page.UUID, this.node.UUID, this.record.UUID, item.id); window.open(url, '_blank'); } } @@ -379,7 +382,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { alert.onDidDismiss().then(async result => { if ( result.role === 'ok' ) { const name = result.data?.values?.name?.trim() || 'New Folder'; - await this.api.createFileBox(this.page.UUID, name, this.record.rootUUID, this.record.UUID); + await this.api.createFileBox(this.page.UUID, this.node.UUID, name, this.record.rootUUID, this.record.UUID); await this.loadBox(); } }); @@ -415,10 +418,10 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { if ( item.type === 'folder' ) { item.name = name; item.title = name; - await this.api.updateFileBox(this.page.UUID, item.UUID, { name }); + await this.api.updateFileBox(this.page.UUID, this.node.UUID, item.UUID, { name }); } else if ( item.type === 'file' ) { item.title = name; - await this.api.updateFileBoxFile(this.page.UUID, this.record.UUID, item.id, { name }); + await this.api.updateFileBoxFile(this.page.UUID, this.node.UUID, this.record.UUID, item.id, { name }); } } }); @@ -445,10 +448,10 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit { alert.onDidDismiss().then(async result => { if ( result.role === 'ok' ) { if ( item.type === 'file' ) { - await this.api.deleteFileBoxFile(this.page.UUID, this.record.UUID, item.id); + await this.api.deleteFileBoxFile(this.page.UUID, this.node.UUID, this.record.UUID, item.id); await this.loadBox(); } else if ( item.type === 'folder' ) { - await this.api.deleteFileBox(this.page.UUID, item.UUID); + await this.api.deleteFileBox(this.page.UUID, this.node.UUID, item.UUID); await this.loadBox(); } } diff --git a/src/app/service/api.service.ts b/src/app/service/api.service.ts index 53751bd..16ef267 100644 --- a/src/app/service/api.service.ts +++ b/src/app/service/api.service.ts @@ -1227,13 +1227,13 @@ export class ApiService { }); } - public createFileBox(PageId: string, name: string, rootUUID?: string, parentUUID?: string): Promise { + public createFileBox(PageId: string, NodeId: string, name: string, rootUUID?: string, parentUUID?: string): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.post(`/file-box/${PageId}/create`, { name, rootUUID, parentUUID }).subscribe({ + this.post(`/file-box/${PageId}/${NodeId}/create`, { name, rootUUID, parentUUID }).subscribe({ next: async result => { res(result.data); }, @@ -1242,13 +1242,13 @@ export class ApiService { }); } - public getFileBox(PageId: string, FileBoxId: string): Promise { + public getFileBox(PageId: string, NodeId: string, FileBoxId: string): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.get(`/file-box/${PageId}/${FileBoxId}`).subscribe({ + this.get(`/file-box/${PageId}/${NodeId}/${FileBoxId}`).subscribe({ next: async result => { res(result.data); }, @@ -1257,13 +1257,13 @@ export class ApiService { }); } - public getFileBoxFiles(PageId: string, FileBoxId: string): Promise { + public getFileBoxFiles(PageId: string, NodeId: string, FileBoxId: string): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.get(`/file-box/${PageId}/${FileBoxId}/files`).subscribe({ + this.get(`/file-box/${PageId}/${NodeId}/${FileBoxId}/files`).subscribe({ next: async result => { res(result.data); }, @@ -1272,13 +1272,13 @@ export class ApiService { }); } - public getFileBoxChildren(PageId: string, FileBoxId: string): Promise { + public getFileBoxChildren(PageId: string, NodeId: string, FileBoxId: string): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.get(`/file-box/${PageId}/${FileBoxId}/children`).subscribe({ + this.get(`/file-box/${PageId}/${NodeId}/${FileBoxId}/children`).subscribe({ next: async result => { res(result.data); }, @@ -1287,13 +1287,13 @@ export class ApiService { }); } - public updateFileBox(PageId: string, FileBoxId: string, data: any): Promise { + public updateFileBox(PageId: string, NodeId: string, FileBoxId: string, data: any): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.post(`/file-box/${PageId}/${FileBoxId}`, data).subscribe({ + this.post(`/file-box/${PageId}/${NodeId}/${FileBoxId}`, data).subscribe({ next: result => { res(result.data); }, @@ -1302,13 +1302,13 @@ export class ApiService { }); } - public updateFileBoxFile(PageId: string, FileBoxId: string, FileBoxFileId: string, data: any): Promise { + public updateFileBoxFile(PageId: string, NodeId: string, FileBoxId: string, FileBoxFileId: string, data: any): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.post(`/file-box/${PageId}/${FileBoxId}/files/${FileBoxFileId}`, data).subscribe({ + this.post(`/file-box/${PageId}/${NodeId}/${FileBoxId}/files/${FileBoxFileId}`, data).subscribe({ next: result => { res(result.data); }, @@ -1317,13 +1317,13 @@ export class ApiService { }); } - public deleteFileBoxFile(PageId: string, FileBoxId: string, FileBoxFileId: string): Promise { + public deleteFileBoxFile(PageId: string, NodeId: string, FileBoxId: string, FileBoxFileId: string): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.delete(`/file-box/${PageId}/${FileBoxId}/files/${FileBoxFileId}`).subscribe({ + this.delete(`/file-box/${PageId}/${NodeId}/${FileBoxId}/files/${FileBoxFileId}`).subscribe({ next: result => { res(result.data); }, @@ -1332,13 +1332,13 @@ export class ApiService { }); } - public deleteFileBox(PageId: string, FileBoxId: string): Promise { + public deleteFileBox(PageId: string, NodeId: string, FileBoxId: string): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.delete(`/file-box/${PageId}/${FileBoxId}`).subscribe({ + this.delete(`/file-box/${PageId}/${NodeId}/${FileBoxId}`).subscribe({ next: result => { res(result.data); }, @@ -1347,13 +1347,13 @@ export class ApiService { }); } - public uploadFileBoxFiles(PageId: string, FileBoxId: string, formData: FormData): Promise { + public uploadFileBoxFiles(PageId: string, NodeId: string, FileBoxId: string, formData: FormData): Promise { return new Promise(async (res, rej) => { if ( this.isOffline ) { return rej(new ResourceNotAvailableOfflineError()); } - this.post(`/file-box/${PageId}/${FileBoxId}/files`, formData).subscribe({ + this.post(`/file-box/${PageId}/${NodeId}/${FileBoxId}/files`, formData).subscribe({ next: async result => { return res(result.data); }, @@ -1362,8 +1362,8 @@ export class ApiService { }); } - public getFileBoxFileDownloadUrl(PageId: string, FileBoxId: string, FileBoxFileId: string): string { - return this._build_url(`/file-box/${PageId}/${FileBoxId}/files/${FileBoxFileId}`); + public getFileBoxFileDownloadUrl(PageId: string, NodeId: string, FileBoxId: string, FileBoxFileId: string): string { + return this._build_url(`/file-box/${PageId}/${NodeId}/${FileBoxId}/files/${FileBoxFileId}`); } public moveMenuNode(MovedPageId: string, ParentPageId: string): Promise {