#77 - pass along node ID to file box API, refresh sidebar on name change
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2021-02-04 15:55:18 -06:00
parent ed81610f31
commit ca79913a46
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
2 changed files with 36 additions and 33 deletions

View File

@ -6,6 +6,7 @@ import {EditorNodeContract} from '../EditorNode.contract';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {AlertController, LoadingController, PopoverController} from '@ionic/angular'; import {AlertController, LoadingController, PopoverController} from '@ionic/angular';
import {OptionMenuComponent} from '../../option-menu/option-menu.component'; import {OptionMenuComponent} from '../../option-menu/option-menu.component';
import {NavigationService} from "../../../service/navigation.service";
export interface FileBoxFile { export interface FileBoxFile {
type: 'file'; type: 'file';
@ -75,6 +76,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
protected loading: LoadingController, protected loading: LoadingController,
protected popover: PopoverController, protected popover: PopoverController,
protected alerts: AlertController, protected alerts: AlertController,
protected navService: NavigationService,
@Inject(APP_BASE_HREF) private baseHref: string @Inject(APP_BASE_HREF) private baseHref: string
) { super(); } ) { super(); }
@ -106,12 +108,12 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
} }
if ( !this.node.Value.Value && !this.readonly ) { 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.Value = this.record.UUID;
this.node.value = this.record.UUID; this.node.value = this.record.UUID;
this.dirty = true; this.dirty = true;
} else if ( this.node.Value.Value ) { } 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 ) { if ( !this.record ) {
@ -137,8 +139,8 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
public async loadBox(): Promise<void> { public async loadBox(): Promise<void> {
this.fileBoxName = this.record.name; this.fileBoxName = this.record.name;
const files = await this.api.getFileBoxFiles(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.record.UUID); const children = await this.api.getFileBoxChildren(this.page.UUID, this.node.UUID, this.record.UUID);
this.items = [...children, ...files]; this.items = [...children, ...files];
this.refilter(); this.refilter();
@ -178,7 +180,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
public async performDelete(): Promise<void> { public async performDelete(): Promise<void> {
const baseRecord = this.history.length > 0 ? this.history[0] : this.record; 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() { ngOnInit() {
@ -254,7 +256,8 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
this.fileBoxName = name; this.fileBoxName = name;
this.record.name = name; this.record.name = name;
this.record.title = 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) { 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); 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(); await this.loadBox();
} }
@ -335,7 +338,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
this.record = item; this.record = item;
await this.loadBox(); await this.loadBox();
} else if ( item.type === 'file' ) { } 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'); window.open(url, '_blank');
} }
} }
@ -379,7 +382,7 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
alert.onDidDismiss().then(async result => { alert.onDidDismiss().then(async result => {
if ( result.role === 'ok' ) { if ( result.role === 'ok' ) {
const name = result.data?.values?.name?.trim() || 'New Folder'; 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(); await this.loadBox();
} }
}); });
@ -415,10 +418,10 @@ export class FileBoxComponent extends EditorNodeContract implements OnInit {
if ( item.type === 'folder' ) { if ( item.type === 'folder' ) {
item.name = name; item.name = name;
item.title = 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' ) { } else if ( item.type === 'file' ) {
item.title = name; 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 => { alert.onDidDismiss().then(async result => {
if ( result.role === 'ok' ) { if ( result.role === 'ok' ) {
if ( item.type === 'file' ) { 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(); await this.loadBox();
} else if ( item.type === 'folder' ) { } 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(); await this.loadBox();
} }
} }

View File

@ -1227,13 +1227,13 @@ export class ApiService {
}); });
} }
public createFileBox(PageId: string, name: string, rootUUID?: string, parentUUID?: string): Promise<any> { public createFileBox(PageId: string, NodeId: string, name: string, rootUUID?: string, parentUUID?: string): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); 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 => { next: async result => {
res(result.data); res(result.data);
}, },
@ -1242,13 +1242,13 @@ export class ApiService {
}); });
} }
public getFileBox(PageId: string, FileBoxId: string): Promise<any> { public getFileBox(PageId: string, NodeId: string, FileBoxId: string): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); return rej(new ResourceNotAvailableOfflineError());
} }
this.get(`/file-box/${PageId}/${FileBoxId}`).subscribe({ this.get(`/file-box/${PageId}/${NodeId}/${FileBoxId}`).subscribe({
next: async result => { next: async result => {
res(result.data); res(result.data);
}, },
@ -1257,13 +1257,13 @@ export class ApiService {
}); });
} }
public getFileBoxFiles(PageId: string, FileBoxId: string): Promise<any> { public getFileBoxFiles(PageId: string, NodeId: string, FileBoxId: string): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); return rej(new ResourceNotAvailableOfflineError());
} }
this.get(`/file-box/${PageId}/${FileBoxId}/files`).subscribe({ this.get(`/file-box/${PageId}/${NodeId}/${FileBoxId}/files`).subscribe({
next: async result => { next: async result => {
res(result.data); res(result.data);
}, },
@ -1272,13 +1272,13 @@ export class ApiService {
}); });
} }
public getFileBoxChildren(PageId: string, FileBoxId: string): Promise<any> { public getFileBoxChildren(PageId: string, NodeId: string, FileBoxId: string): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); return rej(new ResourceNotAvailableOfflineError());
} }
this.get(`/file-box/${PageId}/${FileBoxId}/children`).subscribe({ this.get(`/file-box/${PageId}/${NodeId}/${FileBoxId}/children`).subscribe({
next: async result => { next: async result => {
res(result.data); res(result.data);
}, },
@ -1287,13 +1287,13 @@ export class ApiService {
}); });
} }
public updateFileBox(PageId: string, FileBoxId: string, data: any): Promise<any> { public updateFileBox(PageId: string, NodeId: string, FileBoxId: string, data: any): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); return rej(new ResourceNotAvailableOfflineError());
} }
this.post(`/file-box/${PageId}/${FileBoxId}`, data).subscribe({ this.post(`/file-box/${PageId}/${NodeId}/${FileBoxId}`, data).subscribe({
next: result => { next: result => {
res(result.data); res(result.data);
}, },
@ -1302,13 +1302,13 @@ export class ApiService {
}); });
} }
public updateFileBoxFile(PageId: string, FileBoxId: string, FileBoxFileId: string, data: any): Promise<any> { public updateFileBoxFile(PageId: string, NodeId: string, FileBoxId: string, FileBoxFileId: string, data: any): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); 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 => { next: result => {
res(result.data); res(result.data);
}, },
@ -1317,13 +1317,13 @@ export class ApiService {
}); });
} }
public deleteFileBoxFile(PageId: string, FileBoxId: string, FileBoxFileId: string): Promise<any> { public deleteFileBoxFile(PageId: string, NodeId: string, FileBoxId: string, FileBoxFileId: string): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); 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 => { next: result => {
res(result.data); res(result.data);
}, },
@ -1332,13 +1332,13 @@ export class ApiService {
}); });
} }
public deleteFileBox(PageId: string, FileBoxId: string): Promise<any> { public deleteFileBox(PageId: string, NodeId: string, FileBoxId: string): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); return rej(new ResourceNotAvailableOfflineError());
} }
this.delete(`/file-box/${PageId}/${FileBoxId}`).subscribe({ this.delete(`/file-box/${PageId}/${NodeId}/${FileBoxId}`).subscribe({
next: result => { next: result => {
res(result.data); res(result.data);
}, },
@ -1347,13 +1347,13 @@ export class ApiService {
}); });
} }
public uploadFileBoxFiles(PageId: string, FileBoxId: string, formData: FormData): Promise<any> { public uploadFileBoxFiles(PageId: string, NodeId: string, FileBoxId: string, formData: FormData): Promise<any> {
return new Promise(async (res, rej) => { return new Promise(async (res, rej) => {
if ( this.isOffline ) { if ( this.isOffline ) {
return rej(new ResourceNotAvailableOfflineError()); 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 => { next: async result => {
return res(result.data); return res(result.data);
}, },
@ -1362,8 +1362,8 @@ export class ApiService {
}); });
} }
public getFileBoxFileDownloadUrl(PageId: string, FileBoxId: string, FileBoxFileId: string): string { public getFileBoxFileDownloadUrl(PageId: string, NodeId: string, FileBoxId: string, FileBoxFileId: string): string {
return this._build_url(`/file-box/${PageId}/${FileBoxId}/files/${FileBoxFileId}`); return this._build_url(`/file-box/${PageId}/${NodeId}/${FileBoxId}/files/${FileBoxFileId}`);
} }
public moveMenuNode(MovedPageId: string, ParentPageId: string): Promise<any> { public moveMenuNode(MovedPageId: string, ParentPageId: string): Promise<any> {