diff --git a/src/models.ts b/src/models.ts index 064690c..8fd97f1 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1087,6 +1087,7 @@ export interface ISettings { visualRenderedEvents?: boolean; visualSettings?: IVisualSettings; localeSettings?: ILocaleSettings; + zoomLevel?: number; } export interface IReportBars { @@ -1769,3 +1770,8 @@ export function validateCustomTheme(input: any): IError[] { const errors: any[] = Validators.customThemeValidator.validate(input); return errors ? errors.map(normalizeError) : undefined; } + +export function validateZoomLevel(input: any): IError[] { + const errors: any[] = Validators.zoomLevelValidator.validate(input); + return errors ? errors.map(normalizeError) : undefined; +} \ No newline at end of file diff --git a/src/validators/core/typeValidator.ts b/src/validators/core/typeValidator.ts index 536bc4d..786c382 100644 --- a/src/validators/core/typeValidator.ts +++ b/src/validators/core/typeValidator.ts @@ -189,3 +189,29 @@ export class NumberArrayValidator extends ArrayValidator { return null; } } + +export class RangeValidator extends NumberValidator { + + constructor(private minValue: number, private maxValue: number) { + super(); + } + + public validate(input: any, path?: string, field?: string): IValidationError[] { + if (input == null) { + return null; + } + const errors = super.validate(input, path, field); + if (errors) { + return errors; + } + // input is a number, now check if it's in the given range + if(input > this.maxValue || input < this.minValue) { + return [{ + message: field + " must be a number between " + this.minValue + " and " + this.maxValue, + path: (path ? path + "." : "") + field, + keyword: "range" + }]; + } + return null; + } +} diff --git a/src/validators/core/validator.ts b/src/validators/core/validator.ts index cca8acb..1ce3f59 100644 --- a/src/validators/core/validator.ts +++ b/src/validators/core/validator.ts @@ -58,7 +58,7 @@ import { AnyOfValidator } from './anyOfValidator'; import { FieldForbiddenValidator } from './fieldForbiddenValidator'; import { FieldRequiredValidator } from './fieldRequiredValidator'; import { MapValidator } from './mapValidator'; -import { ArrayValidator, BooleanArrayValidator, BooleanValidator, EnumValidator, NumberArrayValidator, NumberValidator, StringArrayValidator, StringValidator } from './typeValidator'; +import { ArrayValidator, BooleanArrayValidator, BooleanValidator, EnumValidator, NumberArrayValidator, NumberValidator, RangeValidator, StringArrayValidator, StringValidator } from './typeValidator'; import { ParametersPanelValidator } from '../models/parameterPanelValidator'; export interface IValidationError { @@ -198,4 +198,5 @@ export const Validators = { visualSelectorValidator: new VisualSelectorValidator(), visualSettingsValidator: new VisualSettingsValidator(), visualTypeSelectorValidator: new VisualTypeSelectorValidator(), + zoomLevelValidator: new RangeValidator(0.25, 4), };