2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 import * as _ from "lodash";
23 import {SchemaPropertyGroupModel, SchemaProperty} from "./schema-property";
24 import {InputPropertyBase} from "./input-property-base";
25 import {PropertyBEModel} from "./properties-inputs/property-be-model";
27 export class PropertiesGroup {
28 constructor(propertiesObj?:PropertiesGroup) {
29 _.forEach(propertiesObj, (properties:Array<PropertyModel>, instance) => {
31 _.forEach(properties, (property:PropertyModel):void => {
32 property.resourceInstanceUniqueId = instance;
33 property.readonly = true;
34 this[instance].push(new PropertyModel(property));
40 export interface IPropertyModel extends InputPropertyBase {
43 //constraints:Array<Object>;
47 valueUniqueUid:string;
50 propertiesName:string;
54 resourceInstanceUniqueId:string;
59 export class PropertyModel extends PropertyBEModel implements IPropertyModel {
63 constraints:Array<Object>;
64 propertyConstraints:Array<string>;
71 parentUniqueId:string;
72 schema:SchemaPropertyGroupModel;
73 componentInstanceId:string;
79 valueUniqueUid:string;
82 propertiesName:string;
86 resourceInstanceUniqueId:string;
90 isAlreadySelected:boolean;
92 propertyView: boolean = false;
94 constructor(property?:PropertyModel) {
97 if (property.propertyConstraints) {
98 this.constraints = new Array();
99 property.propertyConstraints.forEach((constraint: any) => {
100 this.constraints.push(JSON.parse(constraint));
103 this.propertyConstraints = property.propertyConstraints;
104 this.source = property.source;
105 this.valueUniqueUid = property.valueUniqueUid;
106 this.path = property.path;
107 this.rules = property.rules;
108 this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
109 this.readonly = property.readonly;
110 this.simpleType = property.simpleType;
111 this.componentInstanceId = property.componentInstanceId;
112 this.parentValue = property.parentValue;
113 this.ownerId = property.ownerId;
114 this.propertyView = property.propertyView;
117 if (!this.schema || !this.schema.property) {
118 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
120 //forcing creating new object, so editing different one than the object in the table
121 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
123 if (property && property.uniqueId) {
124 this.filterTerm = this.name + " " + (this.description || "") + " " + this.type.replace("org.openecomp.datatypes.heat.", "");
125 if (this.schema.property && this.schema.property.type) {
126 this.filterTerm += " " + this.schema.property.type.replace("org.openecomp.datatypes.heat.", "");
131 public convertToServerObject:Function = ():string => {
132 let serverObject = {};
135 "required": this.required || false,
136 "defaultValue": this.defaultValue != "" && this.defaultValue != "[]" && this.defaultValue != "{}" ? this.defaultValue : null,
137 "description": this.description,
138 "constraints": this.constraints,
139 "metadata": this.metadata,
140 "propertyConstraints": this.propertyConstraints,
141 "isPassword": this.password || false,
142 "schema": this.schema,
145 serverObject[this.name] = mapData;
147 return JSON.stringify(serverObject);
150 public toJSON = ():any => {
151 // if(!this.resourceInstanceUniqueId){
152 // this.value = undefined;
154 let temp = angular.copy(this);
155 temp.readonly = undefined;
156 temp.resourceInstanceUniqueId = undefined;
157 temp.simpleType = undefined;
158 temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
159 temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
160 temp.rules = undefined; //don't send rules to server until feature is fully supported
161 temp.isAlreadySelected = undefined;
162 temp.addOn = undefined;
163 temp.filterTerm = undefined;