Merge pull request #3587 from vvlladd28/bugs/editor/ace/clear
UI: Fixed clear content for ace editor and show toast error
This commit is contained in:
commit
501a99daf1
@ -36,7 +36,6 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
import { CancelAnimationFrame, RafService } from '@core/services/raf.service';
|
import { CancelAnimationFrame, RafService } from '@core/services/raf.service';
|
||||||
import { ResizeObserver } from '@juggle/resize-observer';
|
import { ResizeObserver } from '@juggle/resize-observer';
|
||||||
import { TbEditorCompleter } from '@shared/models/ace/completion.models';
|
import { TbEditorCompleter } from '@shared/models/ace/completion.models';
|
||||||
import { widgetEditorCompleter } from '@home/pages/widget/widget-editor.models';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-js-func',
|
selector: 'tb-js-func',
|
||||||
@ -64,6 +63,7 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor,
|
|||||||
private jsEditor: ace.Ace.Editor;
|
private jsEditor: ace.Ace.Editor;
|
||||||
private editorsResizeCaf: CancelAnimationFrame;
|
private editorsResizeCaf: CancelAnimationFrame;
|
||||||
private editorResize$: ResizeObserver;
|
private editorResize$: ResizeObserver;
|
||||||
|
private ignoreChange = false;
|
||||||
|
|
||||||
toastTargetId = `jsFuncEditor-${guid()}`;
|
toastTargetId = `jsFuncEditor-${guid()}`;
|
||||||
|
|
||||||
@ -154,8 +154,10 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor,
|
|||||||
this.jsEditor.session.setUseWrapMode(true);
|
this.jsEditor.session.setUseWrapMode(true);
|
||||||
this.jsEditor.setValue(this.modelValue ? this.modelValue : '', -1);
|
this.jsEditor.setValue(this.modelValue ? this.modelValue : '', -1);
|
||||||
this.jsEditor.on('change', () => {
|
this.jsEditor.on('change', () => {
|
||||||
this.cleanupJsErrors();
|
if (!this.ignoreChange) {
|
||||||
this.updateView();
|
this.cleanupJsErrors();
|
||||||
|
this.updateView();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (this.editorCompleter) {
|
if (this.editorCompleter) {
|
||||||
this.jsEditor.completers = [this.editorCompleter, ...(this.jsEditor.completers || [])];
|
this.jsEditor.completers = [this.editorCompleter, ...(this.jsEditor.completers || [])];
|
||||||
@ -332,7 +334,9 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor,
|
|||||||
writeValue(value: string): void {
|
writeValue(value: string): void {
|
||||||
this.modelValue = value;
|
this.modelValue = value;
|
||||||
if (this.jsEditor) {
|
if (this.jsEditor) {
|
||||||
|
this.ignoreChange = true;
|
||||||
this.jsEditor.setValue(this.modelValue ? this.modelValue : '', -1);
|
this.jsEditor.setValue(this.modelValue ? this.modelValue : '', -1);
|
||||||
|
this.ignoreChange = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,7 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
|
|||||||
private jsonEditor: ace.Ace.Editor;
|
private jsonEditor: ace.Ace.Editor;
|
||||||
private editorsResizeCaf: CancelAnimationFrame;
|
private editorsResizeCaf: CancelAnimationFrame;
|
||||||
private editorResize$: ResizeObserver;
|
private editorResize$: ResizeObserver;
|
||||||
|
private ignoreChange = false;
|
||||||
|
|
||||||
toastTargetId = `jsonContentEditor-${guid()}`;
|
toastTargetId = `jsonContentEditor-${guid()}`;
|
||||||
|
|
||||||
@ -140,8 +141,13 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
|
|||||||
this.jsonEditor.session.setUseWrapMode(true);
|
this.jsonEditor.session.setUseWrapMode(true);
|
||||||
this.jsonEditor.setValue(this.contentBody ? this.contentBody : '', -1);
|
this.jsonEditor.setValue(this.contentBody ? this.contentBody : '', -1);
|
||||||
this.jsonEditor.on('change', () => {
|
this.jsonEditor.on('change', () => {
|
||||||
this.cleanupJsonErrors();
|
if (!this.ignoreChange) {
|
||||||
this.updateView();
|
this.cleanupJsonErrors();
|
||||||
|
this.updateView();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.jsonEditor.on('blur', () => {
|
||||||
|
this.contentValid = !this.validateContent || this.doValidate(true);
|
||||||
});
|
});
|
||||||
this.editorResize$ = new ResizeObserver(() => {
|
this.editorResize$ = new ResizeObserver(() => {
|
||||||
this.onAceEditorResize();
|
this.onAceEditorResize();
|
||||||
@ -210,34 +216,36 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
|
|||||||
this.cleanupJsonErrors();
|
this.cleanupJsonErrors();
|
||||||
this.contentValid = true;
|
this.contentValid = true;
|
||||||
this.propagateChange(this.contentBody);
|
this.propagateChange(this.contentBody);
|
||||||
this.contentValid = this.doValidate();
|
this.contentValid = this.doValidate(true);
|
||||||
this.propagateChange(this.contentBody);
|
this.propagateChange(this.contentBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private doValidate(): boolean {
|
private doValidate(showErrorToast = false): boolean {
|
||||||
try {
|
try {
|
||||||
if (this.validateContent && this.contentType === ContentType.JSON) {
|
if (this.validateContent && this.contentType === ContentType.JSON) {
|
||||||
JSON.parse(this.contentBody);
|
JSON.parse(this.contentBody);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
let errorInfo = 'Error:';
|
if (showErrorToast) {
|
||||||
if (ex.name) {
|
let errorInfo = 'Error:';
|
||||||
errorInfo += ' ' + ex.name + ':';
|
if (ex.name) {
|
||||||
|
errorInfo += ' ' + ex.name + ':';
|
||||||
|
}
|
||||||
|
if (ex.message) {
|
||||||
|
errorInfo += ' ' + ex.message;
|
||||||
|
}
|
||||||
|
this.store.dispatch(new ActionNotificationShow(
|
||||||
|
{
|
||||||
|
message: errorInfo,
|
||||||
|
type: 'error',
|
||||||
|
target: this.toastTargetId,
|
||||||
|
verticalPosition: 'bottom',
|
||||||
|
horizontalPosition: 'left'
|
||||||
|
}));
|
||||||
|
this.errorShowed = true;
|
||||||
}
|
}
|
||||||
if (ex.message) {
|
|
||||||
errorInfo += ' ' + ex.message;
|
|
||||||
}
|
|
||||||
this.store.dispatch(new ActionNotificationShow(
|
|
||||||
{
|
|
||||||
message: errorInfo,
|
|
||||||
type: 'error',
|
|
||||||
target: this.toastTargetId,
|
|
||||||
verticalPosition: 'bottom',
|
|
||||||
horizontalPosition: 'left'
|
|
||||||
}));
|
|
||||||
this.errorShowed = true;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,8 +264,9 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
|
|||||||
this.contentBody = value;
|
this.contentBody = value;
|
||||||
this.contentValid = true;
|
this.contentValid = true;
|
||||||
if (this.jsonEditor) {
|
if (this.jsonEditor) {
|
||||||
|
this.ignoreChange = true;
|
||||||
this.jsonEditor.setValue(this.contentBody ? this.contentBody : '', -1);
|
this.jsonEditor.setValue(this.contentBody ? this.contentBody : '', -1);
|
||||||
// this.jsonEditor.
|
this.ignoreChange = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user