blob: b87edff0c125530c69802131d8f65714f9f020c3 [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
ys969316a9fce2020-01-19 13:50:02 +020043 //constraints:Array<Object>;
Michael Landoed64b5e2017-06-09 03:19:04 +030044 source:string;
45
46 //instance properties
47 valueUniqueUid:string;
48 path:Array<string>;
49 rules:Array<Object>;
50 propertiesName:string;
51 input:any;
52
53 //custom properties
54 resourceInstanceUniqueId:string;
55 readonly:boolean;
56 simpleType:string;
57}
58
Tal Gitelman51d50f02017-12-10 18:55:03 +020059export class PropertyModel extends PropertyBEModel implements IPropertyModel {
Michael Landoed64b5e2017-06-09 03:19:04 +030060 //server data
61 uniqueId:string;
62 name:string;
ys969316a9fce2020-01-19 13:50:02 +020063 constraints:Array<Object>;
Michael Landoed64b5e2017-06-09 03:19:04 +030064 defaultValue:string;
65 description:string;
66 password:boolean;
67 required:boolean;
68 type:string;
69 source:string;
70 parentUniqueId:string;
71 schema:SchemaPropertyGroupModel;
72 componentInstanceId:string;
73 parentValue:string;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030074 ownerId:string;
Michael Landoed64b5e2017-06-09 03:19:04 +030075
76 //instance properties
77 value:string;
78 valueUniqueUid:string;
79 path:Array<string>;
80 rules:Array<Object>;
81 propertiesName:string;
82 input:any;
83
84 //custom properties
85 resourceInstanceUniqueId:string;
86 readonly:boolean;
87 simpleType:string;
88 filterTerm:string;
89 isAlreadySelected:boolean;
90 addOn:string;
91
92
93 constructor(property?:PropertyModel) {
Tal Gitelman51d50f02017-12-10 18:55:03 +020094 super(property);
Michael Landoed64b5e2017-06-09 03:19:04 +030095 if (property) {
ys969316a9fce2020-01-19 13:50:02 +020096 // this.constraints = property.constraints;
Michael Landoed64b5e2017-06-09 03:19:04 +030097 this.source = property.source;
Michael Landoed64b5e2017-06-09 03:19:04 +030098 this.valueUniqueUid = property.valueUniqueUid;
99 this.path = property.path;
100 this.rules = property.rules;
101 this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
102 this.readonly = property.readonly;
103 this.simpleType = property.simpleType;
104 this.componentInstanceId = property.componentInstanceId;
105 this.parentValue = property.parentValue;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +0300106 this.ownerId = property.ownerId;
Michael Landoed64b5e2017-06-09 03:19:04 +0300107 }
108
109 if (!this.schema || !this.schema.property) {
110 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
111 } else {
112 //forcing creating new object, so editing different one than the object in the table
113 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
114 }
115 if (property && property.uniqueId) {
116 this.filterTerm = this.name + " " + (this.description || "") + " " + this.type.replace("org.openecomp.datatypes.heat.", "");
117 if (this.schema.property && this.schema.property.type) {
118 this.filterTerm += " " + this.schema.property.type.replace("org.openecomp.datatypes.heat.", "");
119 }
120 }
121 }
122
123 public convertToServerObject:Function = ():string => {
124 let serverObject = {};
125 let mapData = {
126 "type": this.type,
127 "required": this.required || false,
128 "defaultValue": this.defaultValue != "" && this.defaultValue != "[]" && this.defaultValue != "{}" ? this.defaultValue : null,
129 "description": this.description,
130 "constraints": this.constraints,
131 "isPassword": this.password || false,
132 "schema": this.schema,
133 "name": this.name
134 };
135 serverObject[this.name] = mapData;
136
137 return JSON.stringify(serverObject);
138 };
139
140 public toJSON = ():any => {
141 // if(!this.resourceInstanceUniqueId){
142 // this.value = undefined;
143 // }
144 let temp = angular.copy(this);
145 temp.readonly = undefined;
146 temp.resourceInstanceUniqueId = undefined;
147 temp.simpleType = undefined;
148 temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
149 temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
Michael Lando5b593492018-07-29 16:13:45 +0300150 temp.rules = undefined; //don't send rules to server until feature is fully supported
Michael Landoed64b5e2017-06-09 03:19:04 +0300151 temp.isAlreadySelected = undefined;
152 temp.addOn = undefined;
Michael Lando5b593492018-07-29 16:13:45 +0300153 temp.filterTerm = undefined;
Michael Landoed64b5e2017-06-09 03:19:04 +0300154 return temp;
155 };
156}