|
|
@ -4,6 +4,7 @@ import PageRecord from '../structures/PageRecord';
|
|
|
|
import HostRecord from '../structures/HostRecord';
|
|
|
|
import HostRecord from '../structures/HostRecord';
|
|
|
|
import {EditorNodeContract} from '../components/nodes/EditorNode.contract';
|
|
|
|
import {EditorNodeContract} from '../components/nodes/EditorNode.contract';
|
|
|
|
import {BehaviorSubject, Subscription} from 'rxjs';
|
|
|
|
import {BehaviorSubject, Subscription} from 'rxjs';
|
|
|
|
|
|
|
|
import {NavigationService} from './navigation.service';
|
|
|
|
|
|
|
|
|
|
|
|
export class NoPageLoadedError extends Error {
|
|
|
|
export class NoPageLoadedError extends Error {
|
|
|
|
constructor(msg = 'There is no page open for editing.') {
|
|
|
|
constructor(msg = 'There is no page open for editing.') {
|
|
|
@ -73,6 +74,7 @@ export class EditorService {
|
|
|
|
if ( this.currentPage && this.canEdit() ) {
|
|
|
|
if ( this.currentPage && this.canEdit() ) {
|
|
|
|
if ( this.currentPage.Name !== name ) {
|
|
|
|
if ( this.currentPage.Name !== name ) {
|
|
|
|
this.dirtyOverride = true;
|
|
|
|
this.dirtyOverride = true;
|
|
|
|
|
|
|
|
this.triggerSave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.currentPage.Name = name;
|
|
|
|
this.currentPage.Name = name;
|
|
|
@ -81,6 +83,7 @@ export class EditorService {
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
protected api: ApiService,
|
|
|
|
protected api: ApiService,
|
|
|
|
|
|
|
|
protected nav: NavigationService,
|
|
|
|
) { }
|
|
|
|
) { }
|
|
|
|
|
|
|
|
|
|
|
|
async startEditing(pageId: string) {
|
|
|
|
async startEditing(pageId: string) {
|
|
|
@ -122,9 +125,11 @@ export class EditorService {
|
|
|
|
await editor.writeChangesToNode();
|
|
|
|
await editor.writeChangesToNode();
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.savePage(this.currentPage);
|
|
|
|
await this.saveNodesAsPage(this.currentPage, this.currentNodes);
|
|
|
|
await this.saveNodesAsPage(this.currentPage, this.currentNodes);
|
|
|
|
this.dirtyOverride = false;
|
|
|
|
this.dirtyOverride = false;
|
|
|
|
this.saving = false;
|
|
|
|
this.saving = false;
|
|
|
|
|
|
|
|
this.nav.requestSidebarRefresh({ quiet: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async moveNode(node: HostRecord, direction: 'up' | 'down') {
|
|
|
|
async moveNode(node: HostRecord, direction: 'up' | 'down') {
|
|
|
@ -153,6 +158,20 @@ export class EditorService {
|
|
|
|
this.triggerSave();
|
|
|
|
this.triggerSave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async savePage(page: PageRecord): Promise<void> {
|
|
|
|
|
|
|
|
await new Promise((res, rej) => {
|
|
|
|
|
|
|
|
const saveData = page.toSave();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.api.post(`/page/${page.UUID}/save`, saveData).subscribe({
|
|
|
|
|
|
|
|
next: result => {
|
|
|
|
|
|
|
|
console.log('save result', result);
|
|
|
|
|
|
|
|
res();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
error: rej,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async saveNodesAsPage(page: PageRecord, nodes: HostRecord[]): Promise<HostRecord[]> {
|
|
|
|
async saveNodesAsPage(page: PageRecord, nodes: HostRecord[]): Promise<HostRecord[]> {
|
|
|
|
return new Promise((res, rej) => {
|
|
|
|
return new Promise((res, rej) => {
|
|
|
|
const saveNodes = nodes.map(x => {
|
|
|
|
const saveNodes = nodes.map(x => {
|
|
|
|