|
|
|
@ -24,7 +24,14 @@ import { |
|
|
|
OnInit, |
|
|
|
ViewChild |
|
|
|
} from '@angular/core'; |
|
|
|
import { ControlValueAccessor, UntypedFormControl, NG_VALIDATORS, NG_VALUE_ACCESSOR, Validator } from '@angular/forms'; |
|
|
|
import { |
|
|
|
ControlValueAccessor, |
|
|
|
UntypedFormControl, |
|
|
|
NG_VALIDATORS, |
|
|
|
NG_VALUE_ACCESSOR, |
|
|
|
Validator, |
|
|
|
AbstractControl, ValidationErrors |
|
|
|
} from '@angular/forms'; |
|
|
|
import { Ace } from 'ace-builds'; |
|
|
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|
|
|
import { ActionNotificationHide, ActionNotificationShow } from '@core/notification/notification.actions'; |
|
|
|
@ -34,6 +41,9 @@ import { CancelAnimationFrame, RafService } from '@core/services/raf.service'; |
|
|
|
import { guid, isDefinedAndNotNull, isObject, isUndefined } from '@core/utils'; |
|
|
|
import { ResizeObserver } from '@juggle/resize-observer'; |
|
|
|
import { getAce } from '@shared/models/ace/ace.models'; |
|
|
|
import { coerceBoolean } from '@shared/decorators/coercion'; |
|
|
|
|
|
|
|
export const jsonRequired = (control: AbstractControl): ValidationErrors | null => !control.value ? {required: true} : null; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-json-object-edit', |
|
|
|
@ -73,27 +83,13 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va |
|
|
|
|
|
|
|
@Input() sort: (key: string, value: any) => any; |
|
|
|
|
|
|
|
private requiredValue: boolean; |
|
|
|
|
|
|
|
get required(): boolean { |
|
|
|
return this.requiredValue; |
|
|
|
} |
|
|
|
|
|
|
|
@coerceBoolean() |
|
|
|
@Input() |
|
|
|
set required(value: boolean) { |
|
|
|
this.requiredValue = coerceBooleanProperty(value); |
|
|
|
} |
|
|
|
|
|
|
|
private readonlyValue: boolean; |
|
|
|
|
|
|
|
get readonly(): boolean { |
|
|
|
return this.readonlyValue; |
|
|
|
} |
|
|
|
jsonRequired: boolean; |
|
|
|
|
|
|
|
@coerceBoolean() |
|
|
|
@Input() |
|
|
|
set readonly(value: boolean) { |
|
|
|
this.readonlyValue = coerceBooleanProperty(value); |
|
|
|
} |
|
|
|
readonly: boolean; |
|
|
|
|
|
|
|
fullscreen = false; |
|
|
|
|
|
|
|
@ -245,12 +241,10 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va |
|
|
|
try { |
|
|
|
if (isDefinedAndNotNull(this.modelValue)) { |
|
|
|
this.contentValue = JSON.stringify(this.modelValue, isUndefined(this.sort) ? undefined : |
|
|
|
(key, objectValue) => { |
|
|
|
return this.sort(key, objectValue); |
|
|
|
}, 2); |
|
|
|
(key, objectValue) => this.sort(key, objectValue), 2); |
|
|
|
this.objectValid = true; |
|
|
|
} else { |
|
|
|
this.objectValid = !this.required; |
|
|
|
this.objectValid = !this.jsonRequired; |
|
|
|
this.validationError = 'Json object is required.'; |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
@ -288,8 +282,8 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va |
|
|
|
this.validationError = errorInfo; |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.objectValid = !this.required; |
|
|
|
this.validationError = this.required ? 'Json object is required.' : ''; |
|
|
|
this.objectValid = !this.jsonRequired; |
|
|
|
this.validationError = this.jsonRequired ? 'Json object is required.' : ''; |
|
|
|
} |
|
|
|
this.modelValue = data; |
|
|
|
this.propagateChange(data); |
|
|
|
|