Commit 965870a980ec613076e0ec1aa311d5bff85f1c40
1 parent
9a7d5a43
UI: Fixed clear content for ace editor and show toast error
Showing
2 changed files
with
36 additions
and
23 deletions
@@ -36,7 +36,6 @@ import { TranslateService } from '@ngx-translate/core'; | @@ -36,7 +36,6 @@ import { TranslateService } from '@ngx-translate/core'; | ||
36 | import { CancelAnimationFrame, RafService } from '@core/services/raf.service'; | 36 | import { CancelAnimationFrame, RafService } from '@core/services/raf.service'; |
37 | import { ResizeObserver } from '@juggle/resize-observer'; | 37 | import { ResizeObserver } from '@juggle/resize-observer'; |
38 | import { TbEditorCompleter } from '@shared/models/ace/completion.models'; | 38 | import { TbEditorCompleter } from '@shared/models/ace/completion.models'; |
39 | -import { widgetEditorCompleter } from '@home/pages/widget/widget-editor.models'; | ||
40 | 39 | ||
41 | @Component({ | 40 | @Component({ |
42 | selector: 'tb-js-func', | 41 | selector: 'tb-js-func', |
@@ -64,6 +63,7 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, | @@ -64,6 +63,7 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, | ||
64 | private jsEditor: ace.Ace.Editor; | 63 | private jsEditor: ace.Ace.Editor; |
65 | private editorsResizeCaf: CancelAnimationFrame; | 64 | private editorsResizeCaf: CancelAnimationFrame; |
66 | private editorResize$: ResizeObserver; | 65 | private editorResize$: ResizeObserver; |
66 | + private ignoreChange = false; | ||
67 | 67 | ||
68 | toastTargetId = `jsFuncEditor-${guid()}`; | 68 | toastTargetId = `jsFuncEditor-${guid()}`; |
69 | 69 | ||
@@ -154,8 +154,10 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, | @@ -154,8 +154,10 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, | ||
154 | this.jsEditor.session.setUseWrapMode(true); | 154 | this.jsEditor.session.setUseWrapMode(true); |
155 | this.jsEditor.setValue(this.modelValue ? this.modelValue : '', -1); | 155 | this.jsEditor.setValue(this.modelValue ? this.modelValue : '', -1); |
156 | this.jsEditor.on('change', () => { | 156 | this.jsEditor.on('change', () => { |
157 | - this.cleanupJsErrors(); | ||
158 | - this.updateView(); | 157 | + if (!this.ignoreChange) { |
158 | + this.cleanupJsErrors(); | ||
159 | + this.updateView(); | ||
160 | + } | ||
159 | }); | 161 | }); |
160 | if (this.editorCompleter) { | 162 | if (this.editorCompleter) { |
161 | this.jsEditor.completers = [this.editorCompleter, ...(this.jsEditor.completers || [])]; | 163 | this.jsEditor.completers = [this.editorCompleter, ...(this.jsEditor.completers || [])]; |
@@ -332,7 +334,9 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, | @@ -332,7 +334,9 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor, | ||
332 | writeValue(value: string): void { | 334 | writeValue(value: string): void { |
333 | this.modelValue = value; | 335 | this.modelValue = value; |
334 | if (this.jsEditor) { | 336 | if (this.jsEditor) { |
337 | + this.ignoreChange = true; | ||
335 | this.jsEditor.setValue(this.modelValue ? this.modelValue : '', -1); | 338 | this.jsEditor.setValue(this.modelValue ? this.modelValue : '', -1); |
339 | + this.ignoreChange = false; | ||
336 | } | 340 | } |
337 | } | 341 | } |
338 | 342 |
@@ -61,6 +61,7 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid | @@ -61,6 +61,7 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid | ||
61 | private jsonEditor: ace.Ace.Editor; | 61 | private jsonEditor: ace.Ace.Editor; |
62 | private editorsResizeCaf: CancelAnimationFrame; | 62 | private editorsResizeCaf: CancelAnimationFrame; |
63 | private editorResize$: ResizeObserver; | 63 | private editorResize$: ResizeObserver; |
64 | + private ignoreChange = false; | ||
64 | 65 | ||
65 | toastTargetId = `jsonContentEditor-${guid()}`; | 66 | toastTargetId = `jsonContentEditor-${guid()}`; |
66 | 67 | ||
@@ -140,8 +141,13 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid | @@ -140,8 +141,13 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid | ||
140 | this.jsonEditor.session.setUseWrapMode(true); | 141 | this.jsonEditor.session.setUseWrapMode(true); |
141 | this.jsonEditor.setValue(this.contentBody ? this.contentBody : '', -1); | 142 | this.jsonEditor.setValue(this.contentBody ? this.contentBody : '', -1); |
142 | this.jsonEditor.on('change', () => { | 143 | this.jsonEditor.on('change', () => { |
143 | - this.cleanupJsonErrors(); | ||
144 | - this.updateView(); | 144 | + if (!this.ignoreChange) { |
145 | + this.cleanupJsonErrors(); | ||
146 | + this.updateView(); | ||
147 | + } | ||
148 | + }); | ||
149 | + this.jsonEditor.on('blur', () => { | ||
150 | + this.contentValid = !this.validateContent || this.doValidate(true); | ||
145 | }); | 151 | }); |
146 | this.editorResize$ = new ResizeObserver(() => { | 152 | this.editorResize$ = new ResizeObserver(() => { |
147 | this.onAceEditorResize(); | 153 | this.onAceEditorResize(); |
@@ -210,34 +216,36 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid | @@ -210,34 +216,36 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid | ||
210 | this.cleanupJsonErrors(); | 216 | this.cleanupJsonErrors(); |
211 | this.contentValid = true; | 217 | this.contentValid = true; |
212 | this.propagateChange(this.contentBody); | 218 | this.propagateChange(this.contentBody); |
213 | - this.contentValid = this.doValidate(); | 219 | + this.contentValid = this.doValidate(true); |
214 | this.propagateChange(this.contentBody); | 220 | this.propagateChange(this.contentBody); |
215 | } | 221 | } |
216 | } | 222 | } |
217 | 223 | ||
218 | - private doValidate(): boolean { | 224 | + private doValidate(showErrorToast = false): boolean { |
219 | try { | 225 | try { |
220 | if (this.validateContent && this.contentType === ContentType.JSON) { | 226 | if (this.validateContent && this.contentType === ContentType.JSON) { |
221 | JSON.parse(this.contentBody); | 227 | JSON.parse(this.contentBody); |
222 | } | 228 | } |
223 | return true; | 229 | return true; |
224 | } catch (ex) { | 230 | } catch (ex) { |
225 | - let errorInfo = 'Error:'; | ||
226 | - if (ex.name) { | ||
227 | - errorInfo += ' ' + ex.name + ':'; | ||
228 | - } | ||
229 | - if (ex.message) { | ||
230 | - errorInfo += ' ' + ex.message; | 231 | + if (showErrorToast) { |
232 | + let errorInfo = 'Error:'; | ||
233 | + if (ex.name) { | ||
234 | + errorInfo += ' ' + ex.name + ':'; | ||
235 | + } | ||
236 | + if (ex.message) { | ||
237 | + errorInfo += ' ' + ex.message; | ||
238 | + } | ||
239 | + this.store.dispatch(new ActionNotificationShow( | ||
240 | + { | ||
241 | + message: errorInfo, | ||
242 | + type: 'error', | ||
243 | + target: this.toastTargetId, | ||
244 | + verticalPosition: 'bottom', | ||
245 | + horizontalPosition: 'left' | ||
246 | + })); | ||
247 | + this.errorShowed = true; | ||
231 | } | 248 | } |
232 | - this.store.dispatch(new ActionNotificationShow( | ||
233 | - { | ||
234 | - message: errorInfo, | ||
235 | - type: 'error', | ||
236 | - target: this.toastTargetId, | ||
237 | - verticalPosition: 'bottom', | ||
238 | - horizontalPosition: 'left' | ||
239 | - })); | ||
240 | - this.errorShowed = true; | ||
241 | return false; | 249 | return false; |
242 | } | 250 | } |
243 | } | 251 | } |
@@ -256,8 +264,9 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid | @@ -256,8 +264,9 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid | ||
256 | this.contentBody = value; | 264 | this.contentBody = value; |
257 | this.contentValid = true; | 265 | this.contentValid = true; |
258 | if (this.jsonEditor) { | 266 | if (this.jsonEditor) { |
267 | + this.ignoreChange = true; | ||
259 | this.jsonEditor.setValue(this.contentBody ? this.contentBody : '', -1); | 268 | this.jsonEditor.setValue(this.contentBody ? this.contentBody : '', -1); |
260 | - // this.jsonEditor. | 269 | + this.ignoreChange = false; |
261 | } | 270 | } |
262 | } | 271 | } |
263 | 272 |