blob: f46bf8beb0a5c5b92a9ae6890cc746de2c87de64 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
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
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
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=========================================================
19 */
20
Michael Landoed64b5e2017-06-09 03:19:04 +030021'use strict';
22import {SchemaPropertyGroupModel, SchemaProperty} from "./aschema-property";
23import {InputPropertyBase} from "./input-property-base";
24
25export class PropertiesGroup {
26 constructor(propertiesObj?:PropertiesGroup) {
27 _.forEach(propertiesObj, (properties:Array<PropertyModel>, instance) => {
28 this[instance] = [];
29 _.forEach(properties, (property:PropertyModel):void => {
30 property.resourceInstanceUniqueId = instance;
31 property.readonly = true;
32 this[instance].push(new PropertyModel(property));
33 });
34 });
35 }
36}
37
38export interface IPropertyModel extends InputPropertyBase {
39
40 //server data
41 constraints:Array<Object>;
42 source:string;
43
44 //instance properties
45 valueUniqueUid:string;
46 path:Array<string>;
47 rules:Array<Object>;
48 propertiesName:string;
49 input:any;
50
51 //custom properties
52 resourceInstanceUniqueId:string;
53 readonly:boolean;
54 simpleType:string;
55}
56
57export class PropertyModel implements IPropertyModel {
58
59 //server data
60 uniqueId:string;
61 name:string;
62 constraints:Array<Object>;
63 defaultValue:string;
64 description:string;
65 password:boolean;
66 required:boolean;
67 type:string;
68 source:string;
69 parentUniqueId:string;
70 schema:SchemaPropertyGroupModel;
71 componentInstanceId:string;
72 parentValue:string;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030073 ownerId:string;
Michael Landoed64b5e2017-06-09 03:19:04 +030074
75 //instance properties
76 value:string;
77 valueUniqueUid:string;
78 path:Array<string>;
79 rules:Array<Object>;
80 propertiesName:string;
81 input:any;
82
83 //custom properties
84 resourceInstanceUniqueId:string;
85 readonly:boolean;
86 simpleType:string;
87 filterTerm:string;
88 isAlreadySelected:boolean;
89 addOn:string;
90
91
92 constructor(property?:PropertyModel) {
93 if (property) {
94 this.uniqueId = property.uniqueId;
95 this.name = property.name;
96 this.constraints = property.constraints;
97 this.defaultValue = property.defaultValue;
98 this.description = property.description;
99 this.password = property.password;
100 this.required = property.required;
101 this.type = property.type;
102 this.source = property.source;
103 this.parentUniqueId = property.parentUniqueId;
104 this.schema = property.schema;
105 this.value = property.value ? property.value : property.defaultValue;
106 this.valueUniqueUid = property.valueUniqueUid;
107 this.path = property.path;
108 this.rules = property.rules;
109 this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
110 this.readonly = property.readonly;
111 this.simpleType = property.simpleType;
112 this.componentInstanceId = property.componentInstanceId;
113 this.parentValue = property.parentValue;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +0300114 this.ownerId = property.ownerId;
Michael Landoed64b5e2017-06-09 03:19:04 +0300115 }
116
117 if (!this.schema || !this.schema.property) {
118 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
119 } else {
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));
122 }
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.", "");
127 }
128 }
129 }
130
131 public convertToServerObject:Function = ():string => {
132 let serverObject = {};
133 let mapData = {
134 "type": this.type,
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 "isPassword": this.password || false,
140 "schema": this.schema,
141 "name": this.name
142 };
143 serverObject[this.name] = mapData;
144
145 return JSON.stringify(serverObject);
146 };
147
148 public toJSON = ():any => {
149 // if(!this.resourceInstanceUniqueId){
150 // this.value = undefined;
151 // }
152 let temp = angular.copy(this);
153 temp.readonly = undefined;
154 temp.resourceInstanceUniqueId = undefined;
155 temp.simpleType = undefined;
156 temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
157 temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
158 temp.rules = null; //don't send rules to server until feature is fully supported
159 temp.isAlreadySelected = undefined;
160 temp.addOn = undefined;
161 return temp;
162 };
163}