Skip to content

Commit

Permalink
Describe the type of serialize info #7878
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Feb 19, 2024
1 parent 3e81f93 commit e39bf22
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/entries/chunks/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export {
JsonMissingTypeError,
JsonMissingTypeErrorBase,
JsonObject,
IJsonPropertyInfo,
JsonObjectProperty,
JsonRequiredPropertyError,
JsonUnknownPropertyError,
Expand Down
63 changes: 58 additions & 5 deletions src/jsonobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,63 @@ export interface IObject {
[key: string]: any;
}

export interface IJsonPropertyInfo {
name: string;
type?: string;
className?: string;
classNamePart?: string;
baseClassName?: string;
isRequired?: boolean;
isUnique?: boolean;
//uniquePropertyName
uniqueProperty?: string;
choices?: any;
visible?: boolean;
alternativeName?: string;
oldName?: string;
version?: string;
dataList?: Array<string>;
isLocalizable?: boolean;
isSerializable?: boolean;
isLightSerializable?: boolean;
readOnly?: boolean;
serializationProperty?: string;
dependsOn?: Array<string> | string;

isBindable?: boolean;
isArray?: boolean;
layout?: string;
default?: any;
defaultFunc?: (obj: Base) => any;
baseValue?: any;
onSerializeValue?: (obj: any) => any;
onGetValue?: (obj: any) => any;
onSettingValue?: (obj: any, value: any) => any;
onSetValue?: (obj: any, value: any, jsonConv: JsonObject) => any;
visibleIf?: (obj: any) => boolean;
enableIf?: (obj: any) => boolean;
onExecuteExpression?: (obj: any, res: any) => any;
onPropertyEditorUpdate?: (obj: any, propEditor: any) => any;

displayName?: string;
category?: string;
categoryIndex?: number;
visibleIndex?: number;
nextToProperty?: string;
overridingProperty?: string;
showMode?: string;
maxLength?: number;
maxValue?: any;
minValue?: any;
}
/**
* Contains information about a property of a survey element (page, panel, questions, and etc).
* @see addProperty
* @see removeProperty
* @see [Add Properties](https://surveyjs.io/Documentation/Survey-Creator#addproperties)
* @see [Remove Properties](https://surveyjs.io/Documentation/Survey-Creator#removeproperties)
*/
export class JsonObjectProperty implements IObject {
export class JsonObjectProperty implements IObject, IJsonPropertyInfo {
public static getItemValuesDefaultValue: (val: any, type: string) => any;
[key: string]: any;
private static Index = 1;
Expand Down Expand Up @@ -233,7 +282,7 @@ export class JsonObjectProperty implements IObject {
private classInfoValue: JsonMetadataClass;
private typeValue: string;
private choicesValue: Array<any>;
private baseValue: any;
public baseValue: any;
private isRequiredValue: boolean = false;
private isUniqueValue: boolean = false;
private uniquePropertyValue: string
Expand Down Expand Up @@ -286,6 +335,10 @@ export class JsonObjectProperty implements IObject {
this.isRequiredValue = isRequired;
this.idValue = JsonObjectProperty.Index++;
}
uniqueProperty?: string;
dependsOn?: string | string[];
default?: any;
defaultFunc?: (obj: Base) => any;
public get id(): number {
return this.idValue;
}
Expand Down Expand Up @@ -1058,7 +1111,7 @@ export class JsonMetadata {
}
public addClass(
name: string,
properties: Array<any>,
properties: Array<IJsonPropertyInfo | string>,
creator: (json?: any) => any = null,
parentName: string = null
): JsonMetadataClass {
Expand Down Expand Up @@ -1290,14 +1343,14 @@ export class JsonMetadata {
}
return res;
}
public addProperties(className: string, propertiesInfos: Array<any>) {
public addProperties(className: string, propertiesInfos: Array<IJsonPropertyInfo | string>): void {
className = className.toLowerCase();
var metaDataClass = this.findClass(className);
for (var i = 0; i < propertiesInfos.length; i++) {
this.addCustomPropertyCore(metaDataClass, propertiesInfos[i]);
}
}
public addProperty(className: string, propertyInfo: any): JsonObjectProperty {
public addProperty(className: string, propertyInfo: IJsonPropertyInfo | string): JsonObjectProperty {
return this.addCustomPropertyCore(this.findClass(className), propertyInfo);
}
private addCustomPropertyCore(
Expand Down
4 changes: 2 additions & 2 deletions tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5015,7 +5015,7 @@ QUnit.test("customWidgets support displayValue", function (assert) {
},
getDisplayValue: (question: Question): string => {
if (question.value === 1) return "one";
return null;
return "";
},
});
var survey = twoPageSimplestSurvey();
Expand Down Expand Up @@ -5044,7 +5044,7 @@ QUnit.test("customWidgets camel name", function (assert) {
},
});
if (!Serializer.findClass("camelName")) {
Serializer.addClass("camelName", [], null, "text");
Serializer.addClass("camelName", [], undefined, "text");
}

var survey = new SurveyModel({
Expand Down

0 comments on commit e39bf22

Please sign in to comment.