diff options
Diffstat (limited to 'catalog-ui/src/app/models/properties-inputs')
6 files changed, 165 insertions, 138 deletions
diff --git a/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts b/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts index 1d79353453..f7117e456c 100644 --- a/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts +++ b/catalog-ui/src/app/models/properties-inputs/derived-fe-property.ts @@ -1,15 +1,11 @@ import { SchemaPropertyGroupModel, SchemaProperty } from '../aschema-property'; -import { PROPERTY_DATA, PROPERTY_TYPES} from 'app/utils'; -import { PropertyBEModel } from '../../models'; +import { DerivedPropertyType, PropertyBEModel } from '../../models'; +import { PROPERTY_TYPES } from 'app/utils'; +import { UUID } from "angular2-uuid"; -export enum DerivedPropertyType { - SIMPLE, - LIST, - MAP, - COMPLEX //other datatype, list of non-simple, or map of non-simple -} export class DerivedFEProperty extends PropertyBEModel { + valueObj: any; parentName: string; propertiesName: string; //"network_assignments#ipv4_subnet#use_ipv4 = parentPath + name derivedDataType: DerivedPropertyType; @@ -17,56 +13,39 @@ export class DerivedFEProperty extends PropertyBEModel { isSelected: boolean; isDisabled: boolean; isChildOfListOrMap: boolean; + canBeDeclared: boolean; + mapKey: string; - constructor(property: PropertyBEModel, parentName?: string) - constructor(name: string, parentName: string, type: string, value: string, isChildOfListOrMap?:boolean, schema?: SchemaPropertyGroupModel); - constructor(nameOrPropertyObj?: string | PropertyBEModel, parentName?: string, type?: string, value?: string, isChildOfListOrMap?: boolean, schema?: SchemaPropertyGroupModel) { - - super(typeof nameOrPropertyObj === 'string' ? null : nameOrPropertyObj); - - if (typeof nameOrPropertyObj !== 'string') { //constructor #1 + constructor(property: PropertyBEModel, parentName?: string, createChildOfListOrMap?: boolean, key?:string, value?:any) { + if (!createChildOfListOrMap) { //creating a standard derived prop + super(property); this.parentName = parentName ? parentName : null; - this.propertiesName = (parentName) ? parentName + '#' + nameOrPropertyObj.name : nameOrPropertyObj.name; - } else { //constructor #2 - this.name = nameOrPropertyObj; - this.type = type; + this.propertiesName = (parentName) ? parentName + '#' + property.name : property.name; + this.canBeDeclared = true; //defaults to true + } else { //creating a direct child of list or map (ie. Item that can be deleted, with UUID instead of name) + super(null); + this.isChildOfListOrMap = true; + this.canBeDeclared = false; + this.name = UUID.UUID(); this.parentName = parentName; - this.propertiesName = parentName + '#' + nameOrPropertyObj; - this.value = value; - if (schema) { - this.schema = new SchemaPropertyGroupModel(new SchemaProperty(schema.property)); + this.propertiesName = parentName + '#' + this.name; + + + if (property.type == PROPERTY_TYPES.LIST) { + this.mapKey = property.schema.property.type.split('.').pop(); + this.type = property.schema.property.type; + } else { //map + this.mapKey = key || ""; + this.type = property.type; } + this.valueObj = (this.type == PROPERTY_TYPES.JSON && typeof value == 'object') ? JSON.stringify(value) : value; + this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property)); } this.derivedDataType = this.getDerivedPropertyType(); - this.isChildOfListOrMap = (isChildOfListOrMap) ? isChildOfListOrMap : false; } - - public getDerivedPropertyType = () => { - if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) { - return DerivedPropertyType.SIMPLE; - } else if (this.type == PROPERTY_TYPES.LIST) { - return DerivedPropertyType.LIST; - } else if (this.type == PROPERTY_TYPES.MAP) { - return DerivedPropertyType.MAP; - } else { - return DerivedPropertyType.COMPLEX; - } - } } export class DerivedFEPropertyMap { [parentPath: string]: Array<DerivedFEProperty>; } - - -// isDataType: boolean; - - -// canAdd: boolean; -// canCollapse: boolean; -// canBeDeclared: boolean; - -// derivedValue: string; -// derivedValueType: string; -// propertiesName: string;
\ No newline at end of file diff --git a/catalog-ui/src/app/models/properties-inputs/input-be-model.ts b/catalog-ui/src/app/models/properties-inputs/input-be-model.ts new file mode 100644 index 0000000000..6d7854a6bf --- /dev/null +++ b/catalog-ui/src/app/models/properties-inputs/input-be-model.ts @@ -0,0 +1,49 @@ +import {PropertyBEModel} from 'app/models'; +/** + * Created by rc2122 on 6/1/2017. + */ +export class InputBEModel extends PropertyBEModel { + properties:Array<ComponentInstanceProperty>; + inputs:Array<ComponentInstanceInput>; + + constructor(input?: PropertyBEModel) { + super(input); + } + + + + public toJSON = (): any => { + }; + +} + +export class ComponentInstanceProperty extends PropertyBEModel { + componentInstanceId:string; + componentInstanceName:string; + + constructor(property?: PropertyBEModel) { + super(property); + } + + + + public toJSON = (): any => { + }; + +} + +export class ComponentInstanceInput extends InputBEModel { + componentInstanceId:string; + componentInstanceName:string; + + constructor(property?: PropertyBEModel) { + super(property); + } + + + + public toJSON = (): any => { + }; + +} + diff --git a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts index 1261df3d6d..03c923c228 100644 --- a/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts @@ -1,25 +1,37 @@ import { SchemaPropertyGroupModel, SchemaProperty } from "../aschema-property"; import { PropertyBEModel } from "../../models"; import {PROPERTY_DATA} from "../../utils/constants"; +import {InputBEModel} from "./input-be-model"; -export class InputFEModel extends PropertyBEModel { +export class InputFEModel extends InputBEModel { isSimpleType: boolean; isDataType: boolean; instanceName: string; + instanceId: string; propertyName: string; - constructor(input?: PropertyBEModel) { + constructor(input?: InputBEModel) { super(input); if (input) { this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1; this.isDataType = PROPERTY_DATA.TYPES.indexOf(this.type) == -1; + let propNameIndex:number = this.name.indexOf('_'); this.instanceName = this.name.substring(0, propNameIndex); - if (input.inputPath) { - this.propertyName = input.inputPath.substring(0, input.inputPath.indexOf('#')) - } else { - this.propertyName = this.name.substring(propNameIndex + 1); + + if(input.properties && input.properties.length){ + this.instanceId = input.properties[0].componentInstanceId; + this.propertyName = input.properties[0].name; + }else if(input.inputs && input.inputs.length){ + this.instanceId = input.inputs[0].componentInstanceId; + this.propertyName = input.inputs[0].name; + }else{ + if (input.inputPath) { + this.propertyName = input.inputPath.substring(0, input.inputPath.indexOf('#')) + } else { + this.propertyName = this.name.substring(propNameIndex + 1); + } } } } diff --git a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts index a5279d0668..f5cd4094f5 100644 --- a/catalog-ui/src/app/models/properties-inputs/property-be-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/property-be-model.ts @@ -1,4 +1,11 @@ import { SchemaPropertyGroupModel, SchemaProperty } from "../aschema-property"; +import { PROPERTY_DATA, PROPERTY_TYPES } from 'app/utils'; +export enum DerivedPropertyType { + SIMPLE, + LIST, + MAP, + COMPLEX +} export class PropertyBEModel { @@ -16,6 +23,7 @@ export class PropertyBEModel { definition: boolean; inputPath: string; propertiesName: string; + ownerId: string; input: PropertyBEModel; constructor(property?: PropertyBEModel, childProperty?:PropertyBEModel) { @@ -32,6 +40,7 @@ export class PropertyBEModel { this.uniqueId = property.uniqueId; this.value = property.value ? property.value : property.defaultValue; this.definition = property.definition; + this.ownerId = property.ownerId; if (property.inputPath) { this.inputPath = property.inputPath; } @@ -39,6 +48,8 @@ export class PropertyBEModel { if (childProperty) { this.input = childProperty; this.propertiesName = childProperty.propertiesName; + } else { + this.propertiesName = this.name; } if (!this.schema || !this.schema.property) { @@ -48,7 +59,7 @@ export class PropertyBEModel { } } - + public toJSON = (): any => { let temp = angular.copy(this); @@ -57,6 +68,18 @@ export class PropertyBEModel { return temp; }; + public getDerivedPropertyType = () => { + if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) { + return DerivedPropertyType.SIMPLE; + } else if (this.type == PROPERTY_TYPES.LIST) { + return DerivedPropertyType.LIST; + } else if (this.type == PROPERTY_TYPES.MAP) { + return DerivedPropertyType.MAP; + } else { + return DerivedPropertyType.COMPLEX; + } + } + } diff --git a/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts b/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts index 29f2c79225..564611c344 100644 --- a/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts +++ b/catalog-ui/src/app/models/properties-inputs/property-fe-model.ts @@ -1,86 +1,40 @@ import {SchemaPropertyGroupModel, SchemaProperty} from '../aschema-property'; -import { PROPERTY_DATA } from 'app/utils'; -import { PropertyBEModel, DerivedFEPropertyMap, DerivedFEProperty } from '../../models'; +import { PROPERTY_DATA, PROPERTY_TYPES } from 'app/utils'; +import { FilterPropertiesAssignmentData, PropertyBEModel, DerivedPropertyType, DerivedFEPropertyMap, DerivedFEProperty } from 'app/models'; export class PropertyFEModel extends PropertyBEModel { - //START - TO REMOVE: - treeNodeId: string; - parent: PropertyFEModel; - - childrenProperties: Array<PropertyFEModel>; - isAllChildrenLevelsCalculated: boolean; - uniqueId: string; - valueObjectRef: any; - //END - TO REMOVE: - expandedChildPropertyId: string; flattenedChildren: Array<DerivedFEProperty>; //[parentPath] : Array<DerivedFEProp> - isDataType: boolean; //aka- isComplexType. (Type is NOT: simple, list, or map) isDeclared: boolean; isDisabled: boolean; isSelected: boolean; - isSimpleType: boolean; - - private _derivedFromSimpleTypeName:string; - get derivedFromSimpleTypeName():string { - return this._derivedFromSimpleTypeName; - } - set derivedFromSimpleTypeName(derivedFromSimpleTypeName:string) { - this._derivedFromSimpleTypeName = derivedFromSimpleTypeName; - } - - constructor(property?: PropertyBEModel); - constructor(name: string, type: string, treeNodeId: string, parent: PropertyFEModel, valueObjectRef: any, schema?: SchemaPropertyGroupModel); - constructor(nameOrPropertyObj?: string | PropertyBEModel, type?: string, treeNodeId?: string, parent?: PropertyFEModel, valueObjectRef?: any, schema?: SchemaPropertyGroupModel) { - - super(typeof nameOrPropertyObj === 'string' ? null : nameOrPropertyObj); - - if (typeof nameOrPropertyObj === 'string') { - this.name = nameOrPropertyObj; - this.type = type; - this.treeNodeId = treeNodeId; - this.parent = parent; - this.valueObjectRef = valueObjectRef; - this.value = this.value || this.defaultValue; - if(schema){ - this.schema = new SchemaPropertyGroupModel(new SchemaProperty(schema.property)); - } - } + isSimpleType: boolean; //for convenience only - we can really just check if derivedDataType == derivedPropertyTypes.SIMPLE to know if the prop is simple + uniqueId: string; + valueObj: any; //this is the only value we relate to in the html templates + derivedDataType: DerivedPropertyType; + constructor(property: PropertyBEModel){ + super(property); this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1; - this.isDataType = PROPERTY_DATA.TYPES.indexOf(this.type) == -1; this.setNonDeclared(); + this.derivedDataType = this.getDerivedPropertyType(); + this.flattenedChildren = []; } - public convertChildToInput = (childName: string): void => { - //childName: "mac_count_required" - let childJson = this.flattenedChildren[childName].map((child) => { - }); - }; - - public getChildJsonRecursive = (child: string, value?: string): void => { - //TODO: use array.map for the below - /* value += "{" + this.flattenedChildren[child].name + ":"; - if (this.flattenedChildren[child].valueType == 'simple') { - value += this.flattenedChildren[child].value + '}'; - return value; - } else { - this.flattenedChildren[child].forEach(grandChild => { - if (this.flattenedChildren[grandChild].valueType == 'simple') { - return "{" + this.flattenedChildren[grandChild].name + ':' + this.flattenedChildren[child].value.toString() + "}"; - } else { - return this.getChildJsonRecursive(grandChild + '#' + this.flattenedChildren[child].name); - } - }); + public getJSONValue = (): string => { + //If type is JSON, need to try parsing it before we stringify it so that it appears property in TOSCA - change per Bracha due to AMDOCS + //TODO: handle this.derivedDataType == DerivedPropertyType.MAP + if (this.derivedDataType == DerivedPropertyType.LIST && this.schema.property.type == PROPERTY_TYPES.JSON) { + try { + return JSON.stringify(this.valueObj.map(item => JSON.parse(item))); + } catch (e){} } - return "{" + this.flattenedChildren[child].name + this.flattenedChildren[child].value.toString() + "}"; -*/ - - }; + return (this.derivedDataType == DerivedPropertyType.SIMPLE) ? this.valueObj : JSON.stringify(this.valueObj); + } public setNonDeclared = (childPath?: string): void => { if (!childPath) { //declaring a child prop @@ -102,31 +56,26 @@ export class PropertyFEModel extends PropertyBEModel { } } - - - //For expand-collapse functionality + //For expand-collapse functionality - used within HTML template public updateExpandedChildPropertyId = (childPropertyId: string): void => { if (childPropertyId.lastIndexOf('#') > -1) { this.expandedChildPropertyId = (this.expandedChildPropertyId == childPropertyId) ? (childPropertyId.substring(0, childPropertyId.lastIndexOf('#'))) : childPropertyId; } else { this.expandedChildPropertyId = this.name; } - //console.log("expandedChild is now " + this.expandedChildPropertyId); } - public convertToServerObject: Function = (): any => { //TODO: Idan, Rachel, Nechama: Decide what we need to do here - // let serverObject = {}; - // let mapData = { - // 'type': this.type, - // 'required': this.required || false, - // 'defaultValue': this.defaultValue != '' && this.defaultValue != '[]' && this.defaultValue != '{}' ? this.defaultValue : null, - // 'description': this.description, - // 'isPassword': this.password || false, - // 'schema': this.schema, - // 'name': this.name - // }; - // serverObject[this.name] = mapData; + public getIndexOfChild = (childPropName: string): number => { + return this.flattenedChildren.findIndex(prop => prop.propertiesName.indexOf(childPropName) === 0); + } + + public getCountOfChildren = (childPropName: string):number => { + let matchingChildren:Array<DerivedFEProperty> = this.flattenedChildren.filter(prop => prop.propertiesName.indexOf(childPropName) === 0) || []; + return matchingChildren.length; + } + + // public getListIndexOfChild = (childPropName: string): number => { //gets list of siblings and then the index within that list + // this.flattenedChildren.filter(prop => prop.parentName == item.parentName).map(prop => prop.propertiesName).indexOf(item.propertiesName) + // } - //return JSON.stringify(serverObject); - }; } diff --git a/catalog-ui/src/app/models/properties-inputs/simple-flat-property.ts b/catalog-ui/src/app/models/properties-inputs/simple-flat-property.ts new file mode 100644 index 0000000000..d67a7d4d14 --- /dev/null +++ b/catalog-ui/src/app/models/properties-inputs/simple-flat-property.ts @@ -0,0 +1,15 @@ +export class SimpleFlatProperty { + uniqueId: string; + path: string; + name: string; + parentName: string; + instanceName: string; + + constructor(uniqueId?: string, path?: string, name?: string, parentName?: string, instanceName?: string) { + this.uniqueId = uniqueId; + this.path = path; + this.name = name; + this.parentName = parentName; + this.instanceName = instanceName; + } +}
\ No newline at end of file |