Add logic to the editor service for saving
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-10-13 22:28:38 -05:00
parent ef5c53ae04
commit 331d40e49c
7 changed files with 272 additions and 13 deletions

View File

@@ -1,8 +1,9 @@
import PageRecord from '../../structures/PageRecord';
import HostRecord from '../../structures/HostRecord';
export abstract class EditorNodeContract {
protected pageRec!: PageRecord;
protected nodeRec!: any; // TODO
protected nodeRec!: HostRecord;
protected initialValue: any;
get page() {
@@ -13,11 +14,20 @@ export abstract class EditorNodeContract {
this.pageRec = page;
}
get node() {
return this.nodeRec;
}
set node(node: HostRecord) {
this.nodeRec = node;
}
get identifier() {
return this.nodeRec.UUID;
}
public abstract isDirty(): boolean | Promise<boolean>;
public abstract writeChangesToNode(): void | Promise<void>;
public needsSave(): boolean | Promise<boolean> {
return false;

View File

@@ -1,6 +1,9 @@
.editable-base {
padding: 20px;
background: aliceblue; // TODO temporary
&.focused {
background: aliceblue;
}
}
.toolbar-base {

View File

@@ -1,21 +1,25 @@
import {Component, HostListener, ViewChild} from '@angular/core';
import {Component, HostListener, Input, OnInit, ViewChild} from '@angular/core';
import {EditorNodeContract} from '../EditorNode.contract';
import {EditorService} from '../../../service/editor.service';
@Component({
selector: 'editor-norm',
templateUrl: './norm.component.html',
styleUrls: ['./norm.component.scss'],
})
export class NormComponent extends EditorNodeContract {
export class NormComponent extends EditorNodeContract implements OnInit {
@ViewChild('editable') editable;
@Input() nodeId: string;
public isFocused = false;
public initialValue = 'Content editable now...';
public initialValue = 'Click to edit...';
public contents = '';
private dirtyOverride = false;
constructor() {
constructor(
public readonly editorService: EditorService,
) {
super();
console.log('norm compt', this);
this.contents = this.initialValue;
}
@@ -23,6 +27,18 @@ export class NormComponent extends EditorNodeContract {
return this.dirtyOverride || this.contents !== this.initialValue;
}
public writeChangesToNode(): void | Promise<void> {
this.nodeRec.value = this.contents;
this.initialValue = this.contents;
}
ngOnInit() {
this.editorService.registerNodeEditor(this.nodeId, this).then(() => {
this.initialValue = this.node.Value.Value;
this.contents = this.initialValue;
});
}
onFocusIn(event: MouseEvent) {
this.isFocused = true;
}