import { PropertyFEModel, DerivedFEProperty, DerivedPropertyType } from "app/models";
import { PROPERTY_TYPES } from 'app/utils';
import { DataTypeService } from "../../../../services/data-type.service";
-import { trigger, state, style, transition, animate } from '@angular/core';
+import { trigger, state, style, transition, animate } from '@angular/animations';
import {PropertiesUtils} from "../../../../pages/properties-assignment/services/properties.utils";
import {IUiElementChangeEvent} from "../../../ui/form-components/ui-element-base.component";
import {DynamicElementComponent} from "../../../ui/dynamic-element/dynamic-element.component";
+import {SubPropertyToscaFunction} from "app/models/sub-property-tosca-function";
@Component({
selector: 'dynamic-property',
propPath: string;
isPropertyFEModel: boolean;
nestedLevel: number;
+ propertyTestsId: string;
+ constraints:string[];
@Input() canBeDeclared: boolean;
@Input() property: PropertyFEModel | DerivedFEProperty;
@Input() readonly: boolean;
@Input() hasChildren: boolean;
@Input() hasDeclareOption:boolean;
+ @Input() rootProperty: PropertyFEModel;
@Output('propertyChanged') emitter: EventEmitter<void> = new EventEmitter<void>();
@Output() expandChild: EventEmitter<string> = new EventEmitter<string>();
@Output() checkProperty: EventEmitter<string> = new EventEmitter<string>();
+ @Output() toggleTosca: EventEmitter<DerivedFEProperty> = new EventEmitter<DerivedFEProperty>();
@Output() deleteItem: EventEmitter<string> = new EventEmitter<string>();
@Output() clickOnPropertyRow: EventEmitter<PropertyFEModel | DerivedFEProperty> = new EventEmitter<PropertyFEModel | DerivedFEProperty>();
@Output() mapKeyChanged: EventEmitter<string> = new EventEmitter<string>();
this.propType = this.property.derivedDataType;
this.propPath = (this.property instanceof PropertyFEModel) ? this.property.name : this.property.propertiesName;
this.nestedLevel = (this.property.propertiesName.match(/#/g) || []).length;
+ this.rootProperty = (this.rootProperty) ? this.rootProperty : <PropertyFEModel>this.property;
+ this.propertyTestsId = this.getPropertyTestsId();
+
+ this.initConsraintsValues();
+ }
+
+ initConsraintsValues(){
+ let primitiveProperties = ['string', 'integer', 'float', 'boolean', PROPERTY_TYPES.TIMESTAMP];
+
+ //Property has constraints
+ if(this.property.constraints && this.property.constraints[0]){
+ this.constraints = this.property.constraints[0].validValues
+ }
+
+ //Complex Type
+ else if (primitiveProperties.indexOf(this.rootProperty.type) == -1 && primitiveProperties.indexOf(this.property.type) >= 0 ){
+ this.constraints = this.dataTypeService.getConstraintsByParentTypeAndUniqueID(this.rootProperty.type, this.property.name);
+ }
+
+ else{
+ this.constraints = null;
+ }
+
}
ngDoCheck() {
}
}
+ ngOnChanges() {
+ this.propType = this.property.derivedDataType;
+ this.propPath = (this.property instanceof PropertyFEModel) ? this.property.name : this.property.propertiesName;
+ this.rootProperty = (this.rootProperty) ? this.rootProperty : <PropertyFEModel>this.property;
+ this.propertyTestsId = this.getPropertyTestsId();
+ }
onClickPropertyRow = (property, event) => {
// Because DynamicPropertyComponent is recrusive second time the event is fire event.stopPropagation = undefined
this.clickOnPropertyRow.emit(property);
}
-
expandChildById = (id: string) => {
this.expandedChildId = id;
this.expandChild.emit(id);
this.checkProperty.emit(propName);
}
+ toggleToscaFunction = (prop: DerivedFEProperty) => {
+ this.toggleTosca.emit(prop);
+ }
+
getHasChildren = (property:DerivedFEProperty): boolean => {// enter to this function only from base property (PropertyFEModel) and check for child property if it has children
return _.filter((<PropertyFEModel>this.property).flattenedChildren,(prop:DerivedFEProperty)=>{
return _.startsWith(prop.propertiesName + '#', property.propertiesName);
}).length > 1;
}
+ getPropertyTestsId = () => {
+ return [this.rootProperty.name].concat(this.rootProperty.getParentNamesArray(this.property.propertiesName, [], true)).join('.');
+ };
+
onElementChanged = (event: IUiElementChangeEvent) => {
this.property.updateValueObj(event.value, event.isValid);
this.emitter.emit();
createNewChildProperty = (): void => {
- let newProps: Array<DerivedFEProperty> = this.propertiesUtils.createListOrMapChildren(this.property, "", null);
+ let mapKeyValue = this.property instanceof DerivedFEProperty ? this.property.mapKey : "";
+ if (this.property.type == PROPERTY_TYPES.LIST && mapKeyValue === "") {
+ if (this.property.schemaType != PROPERTY_TYPES.MAP) {
+ if (this.property.value != null) {
+ const valueJson = JSON.parse(this.property.value);
+ if (this.property instanceof PropertyFEModel && this.property.expandedChildPropertyId != null) {
+ let indexNumber = Number(Object.keys(valueJson).sort().reverse()[0]) + 1;
+ mapKeyValue = indexNumber.toString();
+ }else{
+ mapKeyValue = Object.keys(valueJson).sort().reverse()[0];
+ }
+ }else {
+ mapKeyValue = "0";
+ }
+ }
+ }
+ let newProps: Array<DerivedFEProperty> = this.propertiesUtils.createListOrMapChildren(this.property, mapKeyValue, null);
+
this.propertiesUtils.assignFlattenedChildrenValues(this.property.valueObj, [newProps[0]], this.property.propertiesName);
if (this.property instanceof PropertyFEModel) {
this.addChildProps(newProps, this.property.name);
this.expandChildById(newProps[0].propertiesName);
this.updateMapKeyValueOnMainParent(newProps);
- this.emitter.emit();
}
}
if (!itemParent) {
return;
}
-
- if (item.derivedDataType == DerivedPropertyType.MAP) {
- const oldKey = item.getActualMapKey();
+ const oldKey = item.getActualMapKey();
+ if (this.property.subPropertyToscaFunctions !== null) {
+ let tempSubToscaFunction: SubPropertyToscaFunction[] = [];
+ this.property.subPropertyToscaFunctions.forEach((item : SubPropertyToscaFunction, index) => {
+ if(item.subPropertyPath[0] != oldKey){
+ tempSubToscaFunction.push(item);
+ }
+ });
+ this.property.subPropertyToscaFunctions = tempSubToscaFunction;
+ }
+ if (item.derivedDataType == DerivedPropertyType.MAP && !item.mapInlist) {
delete itemParent.valueObj[oldKey];
if (itemParent instanceof PropertyFEModel) {
delete itemParent.valueObjValidation[oldKey];
updateChildKeyInParent(childProp: DerivedFEProperty, newMapKey: string) {
if (this.property instanceof PropertyFEModel) {
+ let oldKey = childProp.getActualMapKey();
this.property.childPropMapKeyUpdated(childProp, newMapKey);
+ this.property.flattenedChildren.forEach(tempDervObj => {
+ if (childProp.propertiesName === tempDervObj.parentName) {
+ tempDervObj.mapKey = newMapKey;
+ }
+ });
+ if (this.property.subPropertyToscaFunctions != null) {
+ this.property.subPropertyToscaFunctions.forEach((item : SubPropertyToscaFunction) => {
+ if(item.subPropertyPath[0] === oldKey){
+ item.subPropertyPath = [newMapKey];
+ }
+ });
+ }
this.emitter.emit();
}
}
preventInsertItem = (property:DerivedFEProperty):boolean => {
- if(property.type == PROPERTY_TYPES.MAP && Object.keys(property.valueObj).indexOf('') > -1 ){
+ if(property.type == PROPERTY_TYPES.MAP && property.valueObj != null && Object.keys(property.valueObj).indexOf('') > -1 ){
return true;
}
return false;