dropdownValuesLabel: string;
dropDownErrorMsg: string;
indexListValues:Array<ToscaIndexObject>;
+ parentListTypeFlag : boolean;
private isInitialized: boolean = false;
private componentMetadata: ComponentMetadata;
ngOnInit(): void {
this.componentMetadata = this.workspaceService.metadata;
this.indexListValues = [];
+ if (this.property != null) {
+ this.parentListTypeFlag = (this.property.type != PROPERTY_TYPES.LIST && (!this.isComplexType(this.property.type) || (this.isComplexType(this.property.type)
+ && this.property instanceof PropertyDeclareAPIModel && (<PropertyDeclareAPIModel> this.property).input instanceof DerivedFEProperty && this.property.input.type != PROPERTY_TYPES.LIST)));
+ }
this.formGroup.valueChanges.subscribe(() => {
this.formValidation();
});
this.loadPropertyDropdown(() => {
this.selectedProperty
.setValue(this.propertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.propertyName));
- if (this.toscaGetFunction.toscaIndexList.length > 0) {
+ if (this.toscaGetFunction.toscaIndexList && this.toscaGetFunction.toscaIndexList.length > 0) {
let tempSelectedProperty : PropertyDropdownValue = this.selectedProperty.value;
this.toscaGetFunction.toscaIndexList.forEach((indexValue: string, index) => {
let tempIndexFlag = false;
let tempIndexValue = "0";
let tempIndexProperty = tempSelectedProperty;
let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
- if (index%2 == 0) {
+ if (!isNaN(Number(indexValue)) || indexValue.toLowerCase() === 'index') {
tempIndexFlag = true;
tempIndexValue = indexValue;
tempSelectedProperty = null;
const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, tempIndexProperty.schemaType);
this.addPropertiesToDropdown(dataTypeFound.properties, subPropertyDropdownList);
tempSelectedProperty = subPropertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.toscaIndexList[index+1])
+ if (tempSelectedProperty == null && this.toscaGetFunction.toscaIndexList[index+2]) {
+ tempSelectedProperty = subPropertyDropdownList.find(property => property.propertyName === this.toscaGetFunction.toscaIndexList[index+2])
+ }
}
}
let tempIndexValueMap : ToscaIndexObject = {indexFlag : tempIndexFlag, nestedFlag : tempNestedFlag, indexValue: tempIndexValue, indexProperty: tempSelectedProperty, subPropertyArray: subPropertyDropdownList};
this.indexListValues.forEach((indexObject : ToscaIndexObject) => {
indexAndProperty.push(indexObject.indexValue);
if(indexObject.nestedFlag && indexObject.indexProperty != null) {
- indexAndProperty.push(indexObject.indexProperty.propertyName);
+ indexAndProperty.push(...indexObject.indexProperty.propertyPath);
}
});
toscaGetFunction.toscaIndexList = indexAndProperty;
const selectedProperty: PropertyDropdownValue = this.formGroup.value.selectedProperty;
if (selectedProperty != null && selectedProperty.isList && formGroupStatus && this.indexListValues.length > 0) {
this.indexListValues.forEach((indexObject : ToscaIndexObject, index) => {
- if (indexObject.indexValue == null) {
+ if (indexObject.indexValue == '') {
formGroupStatus = false;
return;
}
if (this.property.type === PROPERTY_TYPES.ANY) {
return true;
}
- let validPropertyType = (this.property.type != PROPERTY_TYPES.LIST && property.type === PROPERTY_TYPES.LIST) ? property.schema.property.type : property.type;
- if (this.property.type != PROPERTY_TYPES.LIST && property.type === PROPERTY_TYPES.LIST && this.isComplexType(validPropertyType)) {
+ let validPropertyType = (this.parentListTypeFlag && property.type === PROPERTY_TYPES.LIST) ? property.schema.property.type : property.type;
+ if (this.parentListTypeFlag && property.type === PROPERTY_TYPES.LIST && this.isComplexType(validPropertyType)) {
let returnFlag : boolean = false;
const dataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, validPropertyType);
if (dataTypeFound && dataTypeFound.properties) {
if (this.hasSameType(dataTypeProperty)) {
returnFlag = true;
}
+ if (!returnFlag && this.isComplexType(dataTypeProperty.type)) {
+ const nestedDataTypeFound: DataTypeModel = this.dataTypeService.getDataTypeByModelAndTypeName(this.componentMetadata.model, dataTypeProperty.type);
+ if (nestedDataTypeFound && nestedDataTypeFound.properties) {
+ nestedDataTypeFound.properties.forEach( nestedDateTypeProperty => {
+ if (this.hasSameType(nestedDateTypeProperty)) {
+ returnFlag = true;
+ }
+ });
+ }
+ }
});
}
return returnFlag;
this.indexListValues = [];
let subPropertyDropdownList : Array<PropertyDropdownValue> = [];
const selectedProperty: PropertyDropdownValue = this.selectedProperty.value;
- if (selectedProperty.isList) {
+ if (this.parentListTypeFlag && selectedProperty.isList) {
toscaIndexFlag = true;
if (selectedProperty.schemaType != null) {
nestedToscaFlag = true;
}
indexTokenChange(indexObject : ToscaIndexObject): void {
- if ((indexObject.indexValue).toLowerCase() === 'index') {
+ if ((indexObject.indexValue).toLowerCase() === 'index' ) {
this.formValidation();
- return;
}
- let indexTokenValue = Number(indexObject.indexValue);
- if (isNaN(indexTokenValue)) {
- indexObject.indexValue = "0";
+
+ const regEx = /^[0-9]*$/;
+ const error = document.getElementById('error');
+
+ if (!(regEx.test(indexObject.indexValue)) && (indexObject.indexValue).toLowerCase() !== 'index') {
+ error.textContent='Invalid value - must be an integer or INDEX';
+ this.onValidityChange.emit({
+ isValid: false,
+ toscaGetFunction: this.formGroup.valid ? this.buildGetFunctionFromForm() : undefined
+ });
+ } else {
+ error.textContent='';
this.formValidation();
- return;
}
- this.formValidation();
}
showPropertySourceDropdown(): boolean {
return this.formGroup.get('selectedProperty') as FormControl;
}
+ onChangeIndexValue(index: ToscaIndexObject, value: any) {
+ this.indexTokenChange(index);
+ }
}
export interface PropertyDropdownValue {