blob: 7a1f1a39ef5e709ba55de1a211e029c125ebca88 [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";
Tal Gitelman51d50f02017-12-10 18:55:03 +020024import {PropertyBEModel} from "./properties-inputs/property-be-model";
Michael Landoed64b5e2017-06-09 03:19:04 +030025
26export class PropertiesGroup {
27 constructor(propertiesObj?:PropertiesGroup) {
28 _.forEach(propertiesObj, (properties:Array<PropertyModel>, instance) => {
29 this[instance] = [];
30 _.forEach(properties, (property:PropertyModel):void => {
31 property.resourceInstanceUniqueId = instance;
32 property.readonly = true;
33 this[instance].push(new PropertyModel(property));
34 });
35 });
36 }
37}
38
39export interface IPropertyModel extends InputPropertyBase {
40
41 //server data
42 constraints:Array<Object>;
43 source:string;
44
45 //instance properties
46 valueUniqueUid:string;
47 path:Array<string>;
48 rules:Array<Object>;
49 propertiesName:string;
50 input:any;
51
52 //custom properties
53 resourceInstanceUniqueId:string;
54 readonly:boolean;
55 simpleType:string;
56}
57
Tal Gitelman51d50f02017-12-10 18:55:03 +020058export class PropertyModel extends PropertyBEModel implements IPropertyModel {
Michael Landoed64b5e2017-06-09 03:19:04 +030059 //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) {
Tal Gitelman51d50f02017-12-10 18:55:03 +020093 super(property);
Michael Landoed64b5e2017-06-09 03:19:04 +030094 if (property) {
Michael Landoed64b5e2017-06-09 03:19:04 +030095 this.constraints = property.constraints;
Michael Landoed64b5e2017-06-09 03:19:04 +030096 this.source = property.source;
Michael Landoed64b5e2017-06-09 03:19:04 +030097 this.valueUniqueUid = property.valueUniqueUid;
98 this.path = property.path;
99 this.rules = property.rules;
100 this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
101 this.readonly = property.readonly;
102 this.simpleType = property.simpleType;
103 this.componentInstanceId = property.componentInstanceId;
104 this.parentValue = property.parentValue;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +0300105 this.ownerId = property.ownerId;
Michael Landoed64b5e2017-06-09 03:19:04 +0300106 }
107
108 if (!this.schema || !this.schema.property) {
109 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
110 } else {
111 //forcing creating new object, so editing different one than the object in the table
112 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
113 }
114 if (property && property.uniqueId) {
115 this.filterTerm = this.name + " " + (this.description || "") + " " + this.type.replace("org.openecomp.datatypes.heat.", "");
116 if (this.schema.property && this.schema.property.type) {
117 this.filterTerm += " " + this.schema.property.type.replace("org.openecomp.datatypes.heat.", "");
118 }
119 }
120 }
121
122 public convertToServerObject:Function = ():string => {
123 let serverObject = {};
124 let mapData = {
125 "type": this.type,
126 "required": this.required || false,
127 "defaultValue": this.defaultValue != "" && this.defaultValue != "[]" && this.defaultValue != "{}" ? this.defaultValue : null,
128 "description": this.description,
129 "constraints": this.constraints,
130 "isPassword": this.password || false,
131 "schema": this.schema,
132 "name": this.name
133 };
134 serverObject[this.name] = mapData;
135
136 return JSON.stringify(serverObject);
137 };
138
139 public toJSON = ():any => {
140 // if(!this.resourceInstanceUniqueId){
141 // this.value = undefined;
142 // }
143 let temp = angular.copy(this);
144 temp.readonly = undefined;
145 temp.resourceInstanceUniqueId = undefined;
146 temp.simpleType = undefined;
147 temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
148 temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
149 temp.rules = null; //don't send rules to server until feature is fully supported
150 temp.isAlreadySelected = undefined;
151 temp.addOn = undefined;
152 return temp;
153 };
154}