|
|
|
@ -137,20 +137,6 @@ export class FieldFormatter implements FieldPropertiesVisitor<FieldValue> { |
|
|
|
return field.properties.accept(new FieldFormatter(value, allowHtml)); |
|
|
|
} |
|
|
|
|
|
|
|
public visitDateTime(properties: DateTimeFieldPropertiesDto): FieldValue { |
|
|
|
try { |
|
|
|
const parsed = DateTime.parseISO_UTC(this.value); |
|
|
|
|
|
|
|
if (properties.editor === 'Date') { |
|
|
|
return parsed.toUTCStringFormat('YYYY-MM-DD'); |
|
|
|
} else { |
|
|
|
return parsed.toUTCStringFormat('YYYY-MM-DD HH:mm:ss'); |
|
|
|
} |
|
|
|
} catch (ex) { |
|
|
|
return this.value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public visitArray(_: ArrayFieldPropertiesDto): string { |
|
|
|
if (this.value.length) { |
|
|
|
return `${this.value.length} Item(s)`; |
|
|
|
@ -167,24 +153,22 @@ export class FieldFormatter implements FieldPropertiesVisitor<FieldValue> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public visitReferences(_: ReferencesFieldPropertiesDto): string { |
|
|
|
if (this.value.length) { |
|
|
|
return `${this.value.length} Reference(s)`; |
|
|
|
} else { |
|
|
|
return '0 References'; |
|
|
|
} |
|
|
|
public visitBoolean(_: BooleanFieldPropertiesDto): string { |
|
|
|
return this.value ? 'Yes' : 'No'; |
|
|
|
} |
|
|
|
|
|
|
|
public visitTags(_: TagsFieldPropertiesDto): string { |
|
|
|
if (this.value.length) { |
|
|
|
return this.value.join(', '); |
|
|
|
public visitDateTime(properties: DateTimeFieldPropertiesDto): FieldValue { |
|
|
|
try { |
|
|
|
const parsed = DateTime.parseISO_UTC(this.value); |
|
|
|
|
|
|
|
if (properties.editor === 'Date') { |
|
|
|
return parsed.toUTCStringFormat('YYYY-MM-DD'); |
|
|
|
} else { |
|
|
|
return ''; |
|
|
|
return parsed.toUTCStringFormat('YYYY-MM-DD HH:mm:ss'); |
|
|
|
} |
|
|
|
} catch (ex) { |
|
|
|
return this.value; |
|
|
|
} |
|
|
|
|
|
|
|
public visitBoolean(_: BooleanFieldPropertiesDto): string { |
|
|
|
return this.value ? 'Yes' : 'No'; |
|
|
|
} |
|
|
|
|
|
|
|
public visitGeolocation(_: GeolocationFieldPropertiesDto): string { |
|
|
|
@ -212,10 +196,26 @@ export class FieldFormatter implements FieldPropertiesVisitor<FieldValue> { |
|
|
|
return `${this.value}`; |
|
|
|
} |
|
|
|
|
|
|
|
public visitReferences(_: ReferencesFieldPropertiesDto): string { |
|
|
|
if (this.value.length) { |
|
|
|
return `${this.value.length} Reference(s)`; |
|
|
|
} else { |
|
|
|
return '0 References'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public visitString(_: StringFieldPropertiesDto): any { |
|
|
|
return this.value; |
|
|
|
} |
|
|
|
|
|
|
|
public visitTags(_: TagsFieldPropertiesDto): string { |
|
|
|
if (this.value.length) { |
|
|
|
return this.value.join(', '); |
|
|
|
} else { |
|
|
|
return ''; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public visitUI(_: UIFieldPropertiesDto): any { |
|
|
|
return ''; |
|
|
|
} |
|
|
|
@ -237,35 +237,49 @@ export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<Va |
|
|
|
return validators; |
|
|
|
} |
|
|
|
|
|
|
|
public visitNumber(properties: NumberFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
public visitArray(properties: ArrayFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
const validators: ValidatorFn[] = [ |
|
|
|
ValidatorsEx.between(properties.minValue, properties.maxValue) |
|
|
|
ValidatorsEx.betweenLength(properties.minItems, properties.maxItems) |
|
|
|
]; |
|
|
|
|
|
|
|
if (properties.allowedValues && properties.allowedValues.length > 0) { |
|
|
|
const values: ReadonlyArray<(number | null)> = properties.allowedValues; |
|
|
|
|
|
|
|
if (properties.isRequired && !this.isOptional) { |
|
|
|
validators.push(ValidatorsEx.validValues(values)); |
|
|
|
} else { |
|
|
|
validators.push(ValidatorsEx.validValues(values.concat([null]))); |
|
|
|
return validators; |
|
|
|
} |
|
|
|
|
|
|
|
public visitAssets(properties: AssetsFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
const validators: ValidatorFn[] = [ |
|
|
|
ValidatorsEx.betweenLength(properties.minItems, properties.maxItems) |
|
|
|
]; |
|
|
|
|
|
|
|
if (!properties.allowDuplicates) { |
|
|
|
validators.push(ValidatorsEx.uniqueStrings()); |
|
|
|
} |
|
|
|
|
|
|
|
return validators; |
|
|
|
} |
|
|
|
|
|
|
|
public visitString(properties: StringFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
const validators: ValidatorFn[] = [ |
|
|
|
ValidatorsEx.betweenLength(properties.minLength, properties.maxLength) |
|
|
|
]; |
|
|
|
public visitBoolean(_: BooleanFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
if (properties.pattern && properties.pattern.length > 0) { |
|
|
|
validators.push(ValidatorsEx.pattern(properties.pattern, properties.patternMessage)); |
|
|
|
public visitDateTime(_: DateTimeFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public visitGeolocation(_: GeolocationFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public visitJson(_: JsonFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public visitNumber(properties: NumberFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
const validators: ValidatorFn[] = [ |
|
|
|
ValidatorsEx.between(properties.minValue, properties.maxValue) |
|
|
|
]; |
|
|
|
|
|
|
|
if (properties.allowedValues && properties.allowedValues.length > 0) { |
|
|
|
const values: ReadonlyArray<string | null> = properties.allowedValues; |
|
|
|
const values: ReadonlyArray<(number | null)> = properties.allowedValues; |
|
|
|
|
|
|
|
if (properties.isRequired && !this.isOptional) { |
|
|
|
validators.push(ValidatorsEx.validValues(values)); |
|
|
|
@ -277,15 +291,7 @@ export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<Va |
|
|
|
return validators; |
|
|
|
} |
|
|
|
|
|
|
|
public visitArray(properties: ArrayFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
const validators: ValidatorFn[] = [ |
|
|
|
ValidatorsEx.betweenLength(properties.minItems, properties.maxItems) |
|
|
|
]; |
|
|
|
|
|
|
|
return validators; |
|
|
|
} |
|
|
|
|
|
|
|
public visitAssets(properties: AssetsFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
public visitReferences(properties: ReferencesFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
const validators: ValidatorFn[] = [ |
|
|
|
ValidatorsEx.betweenLength(properties.minItems, properties.maxItems) |
|
|
|
]; |
|
|
|
@ -297,13 +303,23 @@ export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<Va |
|
|
|
return validators; |
|
|
|
} |
|
|
|
|
|
|
|
public visitReferences(properties: ReferencesFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
public visitString(properties: StringFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
const validators: ValidatorFn[] = [ |
|
|
|
ValidatorsEx.betweenLength(properties.minItems, properties.maxItems) |
|
|
|
ValidatorsEx.betweenLength(properties.minLength, properties.maxLength) |
|
|
|
]; |
|
|
|
|
|
|
|
if (!properties.allowDuplicates) { |
|
|
|
validators.push(ValidatorsEx.uniqueStrings()); |
|
|
|
if (properties.pattern && properties.pattern.length > 0) { |
|
|
|
validators.push(ValidatorsEx.pattern(properties.pattern, properties.patternMessage)); |
|
|
|
} |
|
|
|
|
|
|
|
if (properties.allowedValues && properties.allowedValues.length > 0) { |
|
|
|
const values: ReadonlyArray<string | null> = properties.allowedValues; |
|
|
|
|
|
|
|
if (properties.isRequired && !this.isOptional) { |
|
|
|
validators.push(ValidatorsEx.validValues(values)); |
|
|
|
} else { |
|
|
|
validators.push(ValidatorsEx.validValues(values.concat([null]))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return validators; |
|
|
|
@ -323,22 +339,6 @@ export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<Va |
|
|
|
return validators; |
|
|
|
} |
|
|
|
|
|
|
|
public visitBoolean(_: BooleanFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public visitDateTime(_: DateTimeFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public visitGeolocation(_: GeolocationFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public visitJson(_: JsonFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|
|
|
|
public visitUI(_: UIFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
return []; |
|
|
|
} |
|
|
|
|