blob: 016c5b9f20f322bb8ae419d74f242520823f3a46 [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';
Michael Landoa5445102018-03-04 14:53:33 +020022import * as _ from "lodash";
Michael Landoed64b5e2017-06-09 03:19:04 +030023import {SchemaPropertyGroupModel, SchemaProperty} from "./aschema-property";
24import {InputPropertyBase} from "./input-property-base";
Tal Gitelman51d50f02017-12-10 18:55:03 +020025import {PropertyBEModel} from "./properties-inputs/property-be-model";
Michael Landoed64b5e2017-06-09 03:19:04 +030026
27export class PropertiesGroup {
28 constructor(propertiesObj?:PropertiesGroup) {
29 _.forEach(propertiesObj, (properties:Array<PropertyModel>, instance) => {
30 this[instance] = [];
31 _.forEach(properties, (property:PropertyModel):void => {
32 property.resourceInstanceUniqueId = instance;
33 property.readonly = true;
34 this[instance].push(new PropertyModel(property));
35 });
36 });
37 }
38}
39
40export interface IPropertyModel extends InputPropertyBase {
41
42 //server data
Michael Landoed64b5e2017-06-09 03:19:04 +030043 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;
Michael Landoed64b5e2017-06-09 03:19:04 +030062 defaultValue:string;
63 description:string;
64 password:boolean;
65 required:boolean;
66 type:string;
67 source:string;
68 parentUniqueId:string;
69 schema:SchemaPropertyGroupModel;
70 componentInstanceId:string;
71 parentValue:string;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030072 ownerId:string;
Michael Landoed64b5e2017-06-09 03:19:04 +030073
74 //instance properties
75 value:string;
76 valueUniqueUid:string;
77 path:Array<string>;
78 rules:Array<Object>;
79 propertiesName:string;
80 input:any;
81
82 //custom properties
83 resourceInstanceUniqueId:string;
84 readonly:boolean;
85 simpleType:string;
86 filterTerm:string;
87 isAlreadySelected:boolean;
88 addOn:string;
89
90
91 constructor(property?:PropertyModel) {
Tal Gitelman51d50f02017-12-10 18:55:03 +020092 super(property);
Michael Landoed64b5e2017-06-09 03:19:04 +030093 if (property) {
Michael Landoed64b5e2017-06-09 03:19:04 +030094 this.source = property.source;
Michael Landoed64b5e2017-06-09 03:19:04 +030095 this.valueUniqueUid = property.valueUniqueUid;
96 this.path = property.path;
97 this.rules = property.rules;
98 this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
99 this.readonly = property.readonly;
100 this.simpleType = property.simpleType;
101 this.componentInstanceId = property.componentInstanceId;
102 this.parentValue = property.parentValue;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +0300103 this.ownerId = property.ownerId;
Michael Landoed64b5e2017-06-09 03:19:04 +0300104 }
105
106 if (!this.schema || !this.schema.property) {
107 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
108 } else {
109 //forcing creating new object, so editing different one than the object in the table
110 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
111 }
112 if (property && property.uniqueId) {
113 this.filterTerm = this.name + " " + (this.description || "") + " " + this.type.replace("org.openecomp.datatypes.heat.", "");
114 if (this.schema.property && this.schema.property.type) {
115 this.filterTerm += " " + this.schema.property.type.replace("org.openecomp.datatypes.heat.", "");
116 }
117 }
118 }
119
120 public convertToServerObject:Function = ():string => {
121 let serverObject = {};
122 let mapData = {
123 "type": this.type,
124 "required": this.required || false,
125 "defaultValue": this.defaultValue != "" && this.defaultValue != "[]" && this.defaultValue != "{}" ? this.defaultValue : null,
126 "description": this.description,
127 "constraints": this.constraints,
128 "isPassword": this.password || false,
129 "schema": this.schema,
130 "name": this.name
131 };
132 serverObject[this.name] = mapData;
133
134 return JSON.stringify(serverObject);
135 };
136
137 public toJSON = ():any => {
138 // if(!this.resourceInstanceUniqueId){
139 // this.value = undefined;
140 // }
141 let temp = angular.copy(this);
142 temp.readonly = undefined;
143 temp.resourceInstanceUniqueId = undefined;
144 temp.simpleType = undefined;
145 temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
146 temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
Michael Lando5b593492018-07-29 16:13:45 +0300147 temp.rules = undefined; //don't send rules to server until feature is fully supported
Michael Landoed64b5e2017-06-09 03:19:04 +0300148 temp.isAlreadySelected = undefined;
149 temp.addOn = undefined;
Michael Lando5b593492018-07-29 16:13:45 +0300150 temp.filterTerm = undefined;
Michael Landoed64b5e2017-06-09 03:19:04 +0300151 return temp;
152 };
153}