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;
94 constructor(property?:PropertyModel) {
97 // this.constraints = property.constraints;
98 this.source = property.source;
99 this.valueUniqueUid = property.valueUniqueUid;
100 this.path = property.path;
101 this.rules = property.rules;
102 this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
103 this.readonly = property.readonly;
104 this.simpleType = property.simpleType;
105 this.componentInstanceId = property.componentInstanceId;
106 this.parentValue = property.parentValue;
107 this.ownerId = property.ownerId;
110 if (!this.schema || !this.schema.property) {
111 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
113 //forcing creating new object, so editing different one than the object in the table
114 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
116 if (property && property.uniqueId) {
117 this.filterTerm = this.name + " " + (this.description || "") + " " + this.type.replace("org.openecomp.datatypes.heat.", "");
118 if (this.schema.property && this.schema.property.type) {
119 this.filterTerm += " " + this.schema.property.type.replace("org.openecomp.datatypes.heat.", "");
124 public convertToServerObject:Function = ():string => {
125 let serverObject = {};
128 "required": this.required || false,
129 "defaultValue": this.defaultValue != "" && this.defaultValue != "[]" && this.defaultValue != "{}" ? this.defaultValue : null,
130 "description": this.description,
131 "constraints": this.constraints,
132 "isPassword": this.password || false,
133 "schema": this.schema,
136 serverObject[this.name] = mapData;
138 return JSON.stringify(serverObject);
141 public toJSON = ():any => {
142 // if(!this.resourceInstanceUniqueId){
143 // this.value = undefined;
145 let temp = angular.copy(this);
146 temp.readonly = undefined;
147 temp.resourceInstanceUniqueId = undefined;
148 temp.simpleType = undefined;
149 temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
150 temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
151 temp.rules = undefined; //don't send rules to server until feature is fully supported
152 temp.isAlreadySelected = undefined;
153 temp.addOn = undefined;
154 temp.filterTerm = undefined;