finish database implementation
This commit is contained in:
@@ -18,14 +18,15 @@
|
||||
<ng-container>
|
||||
<div class="editor-root ion-padding">
|
||||
<div class="host-container ion-padding">
|
||||
<editor-host #editorHosts *ngFor="let record of hostRecords; let i = index" [(record)]="hostRecords[i]"
|
||||
(newHostRequested)="onNewHostRequested($event)" (destroyHostRequested)="onDestroyHostRequested($event)">
|
||||
<editor-host #editorHosts *ngFor="let record of hostRecords; let i = index" [record]="hostRecords[i]" (recordChange)="onHostRecordChange($event, i)"
|
||||
(newHostRequested)="onNewHostRequested($event)" (destroyHostRequested)="onDestroyHostRequested($event)"
|
||||
(saveHostRequested)="onSaveClick()">
|
||||
</editor-host>
|
||||
</div>
|
||||
</div>
|
||||
<div class="editor-buttons">
|
||||
<ion-button (click)="onAddClick($event)" class="ion-padding ion-margin" fill="outline" color="medium">Add Node</ion-button>
|
||||
<ion-button (click)="onSaveClick()" class="ion-padding ion-margin" fill="outline" color="medium">Save</ion-button>
|
||||
<ion-button (click)="onAddClick($event)" class="ion-padding ion-margin-start" fill="outline" color="medium">Add Node</ion-button>
|
||||
<ion-button (click)="onSaveClick()" class="ion-padding" fill="outline" color="medium">Save</ion-button>
|
||||
</div>
|
||||
</ng-container>
|
||||
</ion-content>
|
||||
|
||||
@@ -28,6 +28,8 @@ export class EditorPage implements OnInit {
|
||||
this.route.params.subscribe(params => {
|
||||
this.pageId = params.id;
|
||||
});
|
||||
|
||||
console.log('editor page', this);
|
||||
}
|
||||
|
||||
ngOnInit() {}
|
||||
@@ -45,18 +47,9 @@ export class EditorPage implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
/*onAddClick() {
|
||||
this.hostRecords.push(new HostRecord(''));
|
||||
setTimeout(() => {
|
||||
const host = this.editorHosts.toArray().reverse()[0].hostContainer.nativeElement;
|
||||
const s = window.getSelection();
|
||||
const r = document.createRange();
|
||||
r.setStart(host, 0);
|
||||
r.setEnd(host, 0);
|
||||
s.removeAllRanges();
|
||||
s.addRange(r);
|
||||
}, 0);
|
||||
}*/
|
||||
onHostRecordChange($event, i) {
|
||||
this.hostRecords[i] = $event;
|
||||
}
|
||||
|
||||
async onAddClick($event) {
|
||||
const popover = await this.popover.create({
|
||||
@@ -64,9 +57,52 @@ export class EditorPage implements OnInit {
|
||||
event: $event,
|
||||
});
|
||||
|
||||
popover.onDidDismiss().then(arg => {
|
||||
console.log({arg});
|
||||
const defValue = this.getDefaultValue(arg.data);
|
||||
const hostRec = new HostRecord(defValue);
|
||||
console.log({hostRec});
|
||||
hostRec.type = arg.data;
|
||||
hostRec.PageId = this.pageRecord.UUID;
|
||||
this.hostRecords.push(hostRec);
|
||||
if ( hostRec.isNorm() ) {
|
||||
setTimeout(() => {
|
||||
const host = this.editorHosts.toArray().reverse()[0].hostContainer.nativeElement;
|
||||
const s = window.getSelection();
|
||||
const r = document.createRange();
|
||||
r.setStart(host, defValue.length);
|
||||
r.setEnd(host, defValue.length);
|
||||
s.removeAllRanges();
|
||||
s.addRange(r);
|
||||
}, 0);
|
||||
} else {
|
||||
this.onSaveClick();
|
||||
}
|
||||
});
|
||||
|
||||
await popover.present();
|
||||
}
|
||||
|
||||
getDefaultValue(type: string) {
|
||||
if ( type === 'paragraph' ) {
|
||||
return '';
|
||||
} else if ( type === 'header1' ) {
|
||||
return '# ';
|
||||
} else if ( type === 'header2' ) {
|
||||
return '## ';
|
||||
} else if ( type === 'header3' ) {
|
||||
return '### ';
|
||||
} else if ( type === 'header4' ) {
|
||||
return '#### ';
|
||||
} else if ( type === 'block_code' ) {
|
||||
return '```';
|
||||
} else if ( type === 'click_link' ) {
|
||||
return 'https://';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
onNewHostRequested($event) {
|
||||
const insertAfter = this.getIndexFromRecord($event.record);
|
||||
const record = new HostRecord('');
|
||||
|
||||
Reference in New Issue
Block a user