Convert code editor to new format
continuous-integration/drone/push Build is failing Details

pull/18/head
Garrett Mills 4 years ago
parent 0a6a775fdb
commit ae24674717
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

@ -7,7 +7,7 @@
</ion-select> </ion-select>
</ion-item> </ion-item>
</ion-toolbar> </ion-toolbar>
<div class="ed-wrapper" style="width: 100%; height: 480px;"> <div class="ed-wrapper" style="width: 100%; height: 540px;">
<ngx-monaco-editor style="width: 100%; height: 100%;" <ngx-monaco-editor style="width: 100%; height: 100%;"
[options]="editorOptions" [options]="editorOptions"
[(ngModel)]="editorValue" [(ngModel)]="editorValue"
@ -15,10 +15,4 @@
#theEditor #theEditor
></ngx-monaco-editor> ></ngx-monaco-editor>
</div> </div>
<ion-toolbar *ngIf="!readonly">
<ion-buttons slot="end">
<ion-button (click)="onDropClick()"><ion-icon name="alert" color="danger"></ion-icon>&nbsp;Drop Editor</ion-button>
<ion-button (click)="onSaveClick()"><ion-icon name="save" [color]="dirty ? 'warning' : 'success'"></ion-icon>&nbsp;Save Changes</ion-button>
</ion-buttons>
</ion-toolbar>
</div> </div>

@ -1,209 +1,212 @@
import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import {v4} from 'uuid'; import {v4} from 'uuid';
import HostRecord from '../../../structures/HostRecord';
import {Observable} from 'rxjs';
import {ApiService} from '../../../service/api.service'; import {ApiService} from '../../../service/api.service';
import {AlertController, LoadingController} from '@ionic/angular'; import {EditorNodeContract} from '../../nodes/EditorNode.contract';
import {EditorService} from '../../../service/editor.service';
@Component({ @Component({
selector: 'editor-code', selector: 'editor-code',
templateUrl: './code.component.html', templateUrl: './code.component.html',
styleUrls: ['./code.component.scss'], styleUrls: ['./code.component.scss'],
}) })
export class CodeComponent implements OnInit { export class CodeComponent extends EditorNodeContract implements OnInit {
@Input() readonly = false; @Input() nodeId: string;
@Input() hostRecord: HostRecord; public dirty = false;
@Output() hostRecordChange = new EventEmitter<HostRecord>(); protected dbRecord: any = {};
@Output() requestParentSave = new EventEmitter<CodeComponent>(); protected codeRefId!: string;
@Output() requestParentDelete = new EventEmitter<CodeComponent>();
@ViewChild('theEditor') theEditor; public editorOptions = {
language: 'javascript',
public dirty = false; uri: v4(),
public pendingSetup = true; readOnly: false,
protected dbRecord: any = {}; };
public languageOptions: Array<string> = [ public editorValue = '';
'ABAP', public get readonly() {
'AES', return !this.node || !this.editorService.canEdit();
'Apex', }
'AZCLI',
'Bat', public languageOptions: Array<string> = [
'C', 'ABAP',
'Cameligo', 'AES',
'Clojure', 'Apex',
'CoffeeScript', 'AZCLI',
'Cpp', 'Bat',
'Csharp', 'C',
'CSP', 'Cameligo',
'CSS', 'Clojure',
'Dockerfile', 'CoffeeScript',
'Fsharp', 'Cpp',
'Go', 'Csharp',
'GraphQL', 'CSP',
'Handlebars', 'CSS',
'HTML', 'Dockerfile',
'INI', 'Fsharp',
'Java', 'Go',
'JavaScript', 'GraphQL',
'JSON', 'Handlebars',
'Kotlin', 'HTML',
'LeSS', 'INI',
'Lua', 'Java',
'Markdown', 'JavaScript',
'MiPS', 'JSON',
'MSDAX', 'Kotlin',
'MySQL', 'LeSS',
'Objective-C', 'Lua',
'Pascal', 'Markdown',
'Pascaligo', 'MiPS',
'Perl', 'MSDAX',
'pgSQL', 'MySQL',
'PHP', 'Objective-C',
'Plaintext', 'Pascal',
'Postiats', 'Pascaligo',
'PowerQuery', 'Perl',
'PowerShell', 'pgSQL',
'Pug', 'PHP',
'Python', 'Plaintext',
'R', 'Postiats',
'Razor', 'PowerQuery',
'Redis', 'PowerShell',
'RedShift', 'Pug',
'RestructuredText', 'Python',
'Ruby', 'R',
'Rust', 'Razor',
'SB', 'Redis',
'Scheme', 'RedShift',
'SCSS', 'RestructuredText',
'Shell', 'Ruby',
'SOL', 'Rust',
'SQL', 'SB',
'St', 'Scheme',
'Swift', 'SCSS',
'TCL', 'Shell',
'Twig', 'SOL',
'TypeScript', 'SQL',
'VB', 'St',
'XML', 'Swift',
'YAML', 'TCL',
]; 'Twig',
'TypeScript',
public editorOptions = { 'VB',
language: 'javascript', 'XML',
uri: v4(), 'YAML',
readOnly: this.readonly, ];
}; protected hadLoad = false;
public editorValue = '';
constructor(
constructor( public readonly editorService: EditorService,
protected api: ApiService, public readonly api: ApiService,
protected loader: LoadingController, ) { super(); }
protected alerts: AlertController,
) { } public isDirty(): boolean | Promise<boolean> {
return this.dirty;
ngOnInit() { }
this.loader.create({message: 'Loading code...'}).then(loader => {
loader.present().then(() => { public needsSave(): boolean | Promise<boolean> {
this.getInitObservable().subscribe(() => { return this.dirty;
this.editorOptions.language = this.dbRecord.Language; }
this.editorOptions.readOnly = this.readonly;
this.onSelectChange(false); public writeChangesToNode(): void | Promise<void> {
loader.dismiss(); this.node.Value.Mode = 'code';
}); this.node.Value.Value = this.codeRefId;
this.node.value = this.codeRefId;
}
public needsLoad(): boolean | Promise<boolean> {
return this.node && !this.hadLoad;
}
public performLoad(): void | Promise<void> {
return new Promise((res, rej) => {
if ( !this.node.Value ) {
this.node.Value = {};
}
if ( !this.node.Value.Value && this.editorService.canEdit() ) {
this.api.post(`/code/${this.page.UUID}/${this.node.UUID}/create`).subscribe({
next: result => {
this.dbRecord = result.data;
this.node.Value.Mode = 'code';
this.node.Value.Value = result.data.UUID;
this.node.value = result.data.UUID;
this.codeRefId = result.data.UUID;
this.editorOptions.readOnly = this.readonly;
this.onSelectChange(false);
this.hadLoad = true;
res();
},
error: rej,
});
} else {
this.api.get(`/code/${this.page.UUID}/${this.node.UUID}/get/${this.node.Value.Value}`).subscribe({
next: result => {
this.dbRecord = result.data;
this.initialValue = this.dbRecord.code;
this.editorValue = this.dbRecord.code;
this.editorOptions.language = this.dbRecord.Language;
this.codeRefId = this.node.Value.Value;
this.editorOptions.readOnly = this.readonly;
this.onSelectChange(false);
this.hadLoad = true;
res();
},
error: rej,
});
}
}); });
}); }
}
public performSave(): void | Promise<void> {
getInitObservable(): Observable<any> { if ( !this.editorService.canEdit() ) {
return new Observable<any>(sub => { return;
if ( this.hostRecord && this.pendingSetup ) {
if ( !this.hostRecord.Value ) {
this.hostRecord.Value = {};
} }
if ( !this.hostRecord.Value.Value && !this.readonly ) { return new Promise((res, rej) => {
this.api.post(`/code/${this.hostRecord.PageId}/${this.hostRecord.UUID}/create`).subscribe(res => { this.dbRecord.code = this.editorValue;
this.dbRecord = res.data; this.dbRecord.Language = this.editorOptions.language;
this.hostRecord.Value.Mode = 'code';
this.hostRecord.Value.Value = res.data.UUID; this.api.post(`/code/${this.page.UUID}/${this.node.UUID}/set/${this.node.Value.Value}`, this.dbRecord)
this.hostRecord.value = res.data.UUID; .subscribe({
this.hostRecordChange.emit(this.hostRecord); next: result => {
this.pendingSetup = false; this.dbRecord = result.data;
sub.next(true); this.editorOptions.language = this.dbRecord.Language;
sub.complete(); this.editorValue = this.dbRecord.code;
}); this.dirty = false;
} else { res();
this.api.get(`/code/${this.hostRecord.PageId}/${this.hostRecord.UUID}/get/${this.hostRecord.Value.Value}`).subscribe(res => { },
this.dbRecord = res.data; error: rej,
this.editorValue = this.dbRecord.code; });
this.editorOptions.language = this.dbRecord.Language; });
this.pendingSetup = false; }
sub.next(true);
sub.complete(); public performDelete(): void | Promise<void> {
return new Promise((res, rej) => {
this.api.post(`/code/${this.page.UUID}/${this.node.UUID}/delete/${this.node.Value.Value}`).subscribe({
next: result => {
res();
},
error: rej,
}); });
} });
} else {
this.pendingSetup = true;
}
});
}
onSaveClick() {
if ( this.readonly ) {
return;
}
this.dbRecord.code = this.editorValue;
this.dbRecord.Language = this.editorOptions.language;
this.api.post(`/code/${this.hostRecord.PageId}/${this.hostRecord.UUID}/set/${this.hostRecord.Value.Value}`, this.dbRecord)
.subscribe(res => {
this.dbRecord = res.data;
this.editorOptions.language = this.dbRecord.Language;
this.editorValue = this.dbRecord.code;
this.dirty = false;
});
}
async onDropClick() {
if ( this.readonly ) {
return;
}
const alert = await this.alerts.create({
header: 'Are you sure?',
message: `You are about to delete this code. This action cannot be undone.`,
buttons: [
{
text: 'Keep It',
role: 'cancel',
},
{
text: 'Delete It',
handler: async () => {
this.api.post(`/code/${this.hostRecord.PageId}/${this.hostRecord.UUID}/delete/${this.hostRecord.Value.Value}`)
.subscribe(res => {
this.requestParentDelete.emit(this);
});
},
},
],
});
await alert.present();
}
public onEditorModelChange($event) {
if ( this.editorValue !== this.dbRecord.code ) {
this.dirty = true;
} }
}
onSelectChange(updateDbRecord = true) { ngOnInit() {
if ( updateDbRecord ) { this.editorService.registerNodeEditor(this.nodeId, this).then(() => {
this.dbRecord.Language = this.editorOptions.language; this.editorOptions.readOnly = !this.editorService.canEdit();
});
}
public onEditorModelChange($event) {
if ( this.editorValue !== this.dbRecord.code ) {
this.dirty = true;
}
} }
this.editorOptions = {...this.editorOptions}; public onSelectChange(updateDbRecord = true) {
} if ( updateDbRecord ) {
this.dbRecord.Language = this.editorOptions.language;
}
this.editorOptions = {...this.editorOptions};
}
} }

@ -19,11 +19,11 @@
<div class="editor-root ion-padding"> <div class="editor-root ion-padding">
<div <div
class="host-container" class="host-container"
style="display: flex;" style="display: flex; margin-bottom: 20px;"
*ngFor="let node of editorService.immutableNodes" *ngFor="let node of editorService.immutableNodes"
> >
<div class="host-icons"> <div class="host-icons">
<i class="type-icon norm fa" [ngClass]="typeIcons.norm" title="WYSIWYG Node"></i> <i class="type-icon fa" [ngClass]="typeIcons[(node.isNorm() ? 'node' : node.type)] + ' ' + (node.isNorm() ? 'node' : node.type)" title="WYSIWYG Node"></i>
<button (click)="onOptionsClick($event, node)"> <button (click)="onOptionsClick($event, node)">
<i class="fa fa-ellipsis-v" title="Node options"></i> <i class="fa fa-ellipsis-v" title="Node options"></i>
</button> </button>
@ -31,6 +31,9 @@
<ng-container *ngIf="node.isNorm()"> <ng-container *ngIf="node.isNorm()">
<editor-norm style="flex: 1;" [nodeId]="node.UUID"></editor-norm> <editor-norm style="flex: 1;" [nodeId]="node.UUID"></editor-norm>
</ng-container> </ng-container>
<ng-container *ngIf="node.type === 'code_ref'">
<editor-code style="flex: 1;" [nodeId]="node.UUID"></editor-code>
</ng-container>
</div> </div>
<button class="host-add-button" (click)="onAddClick($event)"> <button class="host-add-button" (click)="onAddClick($event)">
<i class="fa fa-plus"></i> Add Node <i class="fa fa-plus"></i> Add Node

@ -15,10 +15,19 @@ ion-icon.invisible {
.type-icon { .type-icon {
margin-bottom: 15px; margin-bottom: 15px;
margin-top: 15px;
&.norm { &.node {
color: var(--noded-background-node); color: var(--noded-background-node);
} }
&.code_ref {
color: var(--noded-background-code);
}
&.db {
color: var(--noded-background-db);
}
} }
.host-add-button { .host-add-button {

@ -24,6 +24,7 @@ export class EditorPage implements OnInit {
page: 'fa fa-sticky-note', page: 'fa fa-sticky-note',
db: 'fa fa-database', db: 'fa fa-database',
code: 'fa fa-code', code: 'fa fa-code',
code_ref: 'fa fa-code',
}; };
@Input() pageId: string; @Input() pageId: string;

Loading…
Cancel
Save