|
|
@ -119,16 +119,26 @@ export class FieldFormatter implements FieldPropertiesVisitor<FieldValue> { |
|
|
return this.formatArray('Asset', 'Assets'); |
|
|
return this.formatArray('Asset', 'Assets'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitComponents(_: ComponentsFieldPropertiesDto): string { |
|
|
|
|
|
return this.formatArray('Component', 'Components'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitReferences(_: ReferencesFieldPropertiesDto): string { |
|
|
|
|
|
return this.formatArray('Reference', 'References'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public visitBoolean(_: BooleanFieldPropertiesDto): string { |
|
|
public visitBoolean(_: BooleanFieldPropertiesDto): string { |
|
|
return this.value ? 'Yes' : 'No'; |
|
|
return Types.booleanToString(this.value); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitComponent(_: ComponentFieldPropertiesDto): string { |
|
|
public visitComponent(_: ComponentFieldPropertiesDto): string { |
|
|
return '{ Component }'; |
|
|
const inner = Types.objectToString(this.value, ['schemaId'], 100); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitComponents(_: ComponentsFieldPropertiesDto): string { |
|
|
if (inner.length > 0) { |
|
|
return this.formatArray('Component', 'Components'); |
|
|
return `Component: ${inner}`; |
|
|
|
|
|
} else { |
|
|
|
|
|
return 'Component'; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitDateTime(properties: DateTimeFieldPropertiesDto): FieldValue { |
|
|
public visitDateTime(properties: DateTimeFieldPropertiesDto): FieldValue { |
|
|
@ -145,15 +155,19 @@ export class FieldFormatter implements FieldPropertiesVisitor<FieldValue> { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitGeolocation(_: GeolocationFieldPropertiesDto): string { |
|
|
|
|
|
return `${this.value.longitude}, ${this.value.latitude}`; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitJson(_: JsonFieldPropertiesDto): string { |
|
|
public visitJson(_: JsonFieldPropertiesDto): string { |
|
|
return '<Json />'; |
|
|
return '<Json />'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitUI(_: UIFieldPropertiesDto): any { |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public visitNumber(properties: NumberFieldPropertiesDto): FieldValue { |
|
|
public visitNumber(properties: NumberFieldPropertiesDto): FieldValue { |
|
|
|
|
|
if (!Types.isNumber(this.value)) { |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (Types.isNumber(this.value) && properties.editor === 'Stars' && this.allowHtml) { |
|
|
if (Types.isNumber(this.value) && properties.editor === 'Stars' && this.allowHtml) { |
|
|
if (this.value <= 0 || this.value > 6) { |
|
|
if (this.value <= 0 || this.value > 6) { |
|
|
return new HtmlValue(`★ ${this.value}`); |
|
|
return new HtmlValue(`★ ${this.value}`); |
|
|
@ -167,47 +181,48 @@ export class FieldFormatter implements FieldPropertiesVisitor<FieldValue> { |
|
|
return new HtmlValue(html); |
|
|
return new HtmlValue(html); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return `${this.value}`; |
|
|
return `${this.value}`; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitReferences(_: ReferencesFieldPropertiesDto): string { |
|
|
public visitGeolocation(_: GeolocationFieldPropertiesDto): string { |
|
|
return this.formatArray('Reference', 'References'); |
|
|
if (!Types.isObject(this.value)) { |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return `${this.value.longitude}, ${this.value.latitude}`; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitTags(_: TagsFieldPropertiesDto): string { |
|
|
public visitTags(_: TagsFieldPropertiesDto): string { |
|
|
if (this.value.length) { |
|
|
if (!Types.isArrayOfString(this.value)) { |
|
|
return this.value.join(', '); |
|
|
|
|
|
} else { |
|
|
|
|
|
return ''; |
|
|
return ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.value.join(', '); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitString(properties: StringFieldPropertiesDto): any { |
|
|
public visitString(properties: StringFieldPropertiesDto): any { |
|
|
if (properties.editor === 'StockPhoto' && this.allowHtml && this.value) { |
|
|
if (!Types.isString(this.value)) { |
|
|
const src = thumbnail(this.value, undefined, 50); |
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (src) { |
|
|
if (properties.editor === 'StockPhoto' && this.allowHtml && this.value) { |
|
|
return new HtmlValue(`<img src="${src}" />`); |
|
|
return new HtmlValue(`<img src="${thumbnail(this.value, undefined, 50)}" />`); |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return this.value; |
|
|
return this.value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitUI(_: UIFieldPropertiesDto): any { |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private formatArray(singularName: string, pluralName: string) { |
|
|
private formatArray(singularName: string, pluralName: string) { |
|
|
if (Types.isArray(this.value)) { |
|
|
if (!Types.isArray(this.value)) { |
|
|
if (this.value.length > 1) { |
|
|
return `0 ${pluralName}`; |
|
|
return `${this.value.length} ${pluralName}`; |
|
|
|
|
|
} else if (this.value.length === 1) { |
|
|
|
|
|
return `1 ${singularName}`; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return `0 ${pluralName}`; |
|
|
if (this.value.length > 1) { |
|
|
|
|
|
return `${this.value.length} ${pluralName}`; |
|
|
|
|
|
} else { |
|
|
|
|
|
return `1 ${singularName}`; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -222,7 +237,7 @@ export function thumbnail(url: string, width?: number, height?: number) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return undefined; |
|
|
return url; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<ValidatorFn>> { |
|
|
export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<ValidatorFn>> { |
|
|
@ -265,14 +280,6 @@ export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<Va |
|
|
return validators; |
|
|
return validators; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitBoolean(_: BooleanFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
|
|
return []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitComponent(_: ComponentFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
|
|
return []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitComponents(properties: ComponentsFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
public visitComponents(properties: ComponentsFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
const validators: ValidatorFn[] = [ |
|
|
const validators: ValidatorFn[] = [ |
|
|
ValidatorsEx.betweenLength(properties.minItems, properties.maxItems), |
|
|
ValidatorsEx.betweenLength(properties.minItems, properties.maxItems), |
|
|
@ -285,18 +292,6 @@ export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<Va |
|
|
return validators; |
|
|
return validators; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public visitDateTime(_: DateTimeFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
|
|
return []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitGeolocation(_: GeolocationFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
|
|
return []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitJson(_: JsonFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
|
|
return []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitNumber(properties: NumberFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
public visitNumber(properties: NumberFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
const validators: ValidatorFn[] = [ |
|
|
const validators: ValidatorFn[] = [ |
|
|
ValidatorsEx.between(properties.minValue, properties.maxValue), |
|
|
ValidatorsEx.between(properties.minValue, properties.maxValue), |
|
|
@ -363,6 +358,26 @@ export class FieldsValidators implements FieldPropertiesVisitor<ReadonlyArray<Va |
|
|
return validators; |
|
|
return validators; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitBoolean(_: BooleanFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
|
|
|
return []; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public visitComponent(_: ComponentFieldPropertiesDto): 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> { |
|
|
public visitUI(_: UIFieldPropertiesDto): ReadonlyArray<ValidatorFn> { |
|
|
return []; |
|
|
return []; |
|
|
} |
|
|
} |
|
|
|