#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:
2021-02-04 15:55:18 -06:00
parent ed81610f31
commit ca79913a46
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 {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<void> {
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<void> {
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();
}
}