|
|
|
@ -10,7 +10,7 @@ import {Page} from './db/Page';
|
|
|
|
|
import {PageNode} from './db/PageNode';
|
|
|
|
|
import {MenuItem} from './db/MenuItem';
|
|
|
|
|
import {SessionService} from './session.service';
|
|
|
|
|
import {debounce} from '../utility';
|
|
|
|
|
import {debounce, uuid_v4} from '../utility';
|
|
|
|
|
|
|
|
|
|
export class NoPageLoadedError extends Error {
|
|
|
|
|
constructor(msg = 'There is no page open for editing.') {
|
|
|
|
@ -22,6 +22,8 @@ export class NoPageLoadedError extends Error {
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class EditorService {
|
|
|
|
|
private static instances: {[key: string]: EditorService} = {};
|
|
|
|
|
|
|
|
|
|
protected currentPage?: PageRecord;
|
|
|
|
|
protected currentNodes: HostRecord[] = [];
|
|
|
|
|
protected nodeIdToEditorContract: { [key: string]: EditorNodeContract } = {};
|
|
|
|
@ -31,6 +33,7 @@ export class EditorService {
|
|
|
|
|
protected saving = false;
|
|
|
|
|
protected saveTriggered = false;
|
|
|
|
|
public notAvailable = false;
|
|
|
|
|
public readonly instanceUUID: string;
|
|
|
|
|
|
|
|
|
|
protected privTriggerSave = debounce(() => {
|
|
|
|
|
if ( this.saving ) {
|
|
|
|
@ -42,6 +45,10 @@ export class EditorService {
|
|
|
|
|
this.saveTriggered = false;
|
|
|
|
|
}, 3000);
|
|
|
|
|
|
|
|
|
|
public static registerInstance(inst: EditorService) {
|
|
|
|
|
this.instances[inst.instanceUUID] = inst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public triggerSave() {
|
|
|
|
|
this.saveTriggered = true;
|
|
|
|
|
this.privTriggerSave();
|
|
|
|
@ -87,7 +94,20 @@ export class EditorService {
|
|
|
|
|
protected nav: NavigationService,
|
|
|
|
|
protected db: DatabaseService,
|
|
|
|
|
protected session: SessionService,
|
|
|
|
|
) { }
|
|
|
|
|
) {
|
|
|
|
|
this.instanceUUID = uuid_v4();
|
|
|
|
|
console.log('editor service', this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getEditor(uuid?: string) {
|
|
|
|
|
if ( uuid ) {
|
|
|
|
|
return EditorService.instances[uuid];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const inst = new EditorService(this.api, this.nav, this.db, this.session);
|
|
|
|
|
EditorService.registerInstance(inst);
|
|
|
|
|
return inst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async startEditing(pageId: string) {
|
|
|
|
|
if ( this.currentPage ) {
|
|
|
|
|