|
|
|
@ -93,8 +93,8 @@ export class EditorService {
|
|
|
|
|
await this.saveNodesAsPage(this.currentPage, this.currentNodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async saveNodesAsPage(page: PageRecord, nodes: HostRecord[]) {
|
|
|
|
|
await new Promise((res, rej) => {
|
|
|
|
|
async saveNodesAsPage(page: PageRecord, nodes: HostRecord[]): Promise<HostRecord[]> {
|
|
|
|
|
return new Promise((res, rej) => {
|
|
|
|
|
const saveNodes = nodes.map(x => {
|
|
|
|
|
x.PageId = page.UUID;
|
|
|
|
|
return x.toSave();
|
|
|
|
@ -102,7 +102,27 @@ export class EditorService {
|
|
|
|
|
|
|
|
|
|
this.api.post(`/page/${page.UUID}/nodes/save`, saveNodes).subscribe({
|
|
|
|
|
next: result => {
|
|
|
|
|
res(); // TODO load in returned data!!
|
|
|
|
|
res(result.data.map(rec => {
|
|
|
|
|
const host = new HostRecord(rec.Value.Value);
|
|
|
|
|
host.load(rec);
|
|
|
|
|
return host;
|
|
|
|
|
}));
|
|
|
|
|
},
|
|
|
|
|
error: rej,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async saveNodeToPage(page: PageRecord, node: HostRecord): Promise<HostRecord> {
|
|
|
|
|
return new Promise((res, rej) => {
|
|
|
|
|
node.PageId = page.UUID;
|
|
|
|
|
const nodeData = node.toSave();
|
|
|
|
|
|
|
|
|
|
this.api.post(`/page/${page.UUID}/nodes/save_one`, { nodeData }).subscribe({
|
|
|
|
|
next: result => {
|
|
|
|
|
const host = new HostRecord(result.data.Value.Value);
|
|
|
|
|
host.load(result.data);
|
|
|
|
|
res(host);
|
|
|
|
|
},
|
|
|
|
|
error: rej,
|
|
|
|
|
});
|
|
|
|
@ -140,6 +160,40 @@ export class EditorService {
|
|
|
|
|
this.dirtyOverride = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async addNode(type: 'paragraph' | 'code_ref' | 'database_ref' | 'file_ref', position?: 'before' | 'after', positionNodeId?: string) {
|
|
|
|
|
if ( !this.currentPage ) {
|
|
|
|
|
throw new NoPageLoadedError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const baseHost = new HostRecord();
|
|
|
|
|
baseHost.type = type;
|
|
|
|
|
baseHost.PageId = this.currentPage.UUID;
|
|
|
|
|
|
|
|
|
|
const host = await this.saveNodeToPage(this.currentPage, baseHost);
|
|
|
|
|
|
|
|
|
|
let placed = false;
|
|
|
|
|
if ( position === 'before' && positionNodeId ) {
|
|
|
|
|
const index = this.currentNodes.findIndex(node => node.UUID === positionNodeId);
|
|
|
|
|
if ( index > -1 ) {
|
|
|
|
|
this.currentNodes.splice(index, 0, host);
|
|
|
|
|
placed = true;
|
|
|
|
|
}
|
|
|
|
|
} else if ( position === 'after' && positionNodeId ) {
|
|
|
|
|
const index = this.currentNodes.findIndex(node => node.UUID === positionNodeId);
|
|
|
|
|
if ( index > -1 ) {
|
|
|
|
|
this.currentNodes.splice(index + 1, 0, host);
|
|
|
|
|
placed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !placed ) {
|
|
|
|
|
this.currentNodes.push(host);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.dirtyOverride = true;
|
|
|
|
|
return host;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
canEdit() {
|
|
|
|
|
if ( !this.currentPage ) {
|
|
|
|
|
throw new NoPageLoadedError();
|
|
|
|
|