blob: 99a5b86fb938a43a46afb270625d38e37c00027c [file] [log] [blame]
Michael Landoed64b5e2017-06-09 03:19:04 +03001'use strict';
2import {SchemaPropertyGroupModel, SchemaProperty} from "./aschema-property";
3import {InputPropertyBase} from "./input-property-base";
4
5export class PropertiesGroup {
6 constructor(propertiesObj?:PropertiesGroup) {
7 _.forEach(propertiesObj, (properties:Array<PropertyModel>, instance) => {
8 this[instance] = [];
9 _.forEach(properties, (property:PropertyModel):void => {
10 property.resourceInstanceUniqueId = instance;
11 property.readonly = true;
12 this[instance].push(new PropertyModel(property));
13 });
14 });
15 }
16}
17
18export interface IPropertyModel extends InputPropertyBase {
19
20 //server data
21 constraints:Array<Object>;
22 source:string;
23
24 //instance properties
25 valueUniqueUid:string;
26 path:Array<string>;
27 rules:Array<Object>;
28 propertiesName:string;
29 input:any;
30
31 //custom properties
32 resourceInstanceUniqueId:string;
33 readonly:boolean;
34 simpleType:string;
35}
36
37export class PropertyModel implements IPropertyModel {
38
39 //server data
40 uniqueId:string;
41 name:string;
42 constraints:Array<Object>;
43 defaultValue:string;
44 description:string;
45 password:boolean;
46 required:boolean;
47 type:string;
48 source:string;
49 parentUniqueId:string;
50 schema:SchemaPropertyGroupModel;
51 componentInstanceId:string;
52 parentValue:string;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030053 ownerId:string;
Michael Landoed64b5e2017-06-09 03:19:04 +030054
55 //instance properties
56 value:string;
57 valueUniqueUid:string;
58 path:Array<string>;
59 rules:Array<Object>;
60 propertiesName:string;
61 input:any;
62
63 //custom properties
64 resourceInstanceUniqueId:string;
65 readonly:boolean;
66 simpleType:string;
67 filterTerm:string;
68 isAlreadySelected:boolean;
69 addOn:string;
70
71
72 constructor(property?:PropertyModel) {
73 if (property) {
74 this.uniqueId = property.uniqueId;
75 this.name = property.name;
76 this.constraints = property.constraints;
77 this.defaultValue = property.defaultValue;
78 this.description = property.description;
79 this.password = property.password;
80 this.required = property.required;
81 this.type = property.type;
82 this.source = property.source;
83 this.parentUniqueId = property.parentUniqueId;
84 this.schema = property.schema;
85 this.value = property.value ? property.value : property.defaultValue;
86 this.valueUniqueUid = property.valueUniqueUid;
87 this.path = property.path;
88 this.rules = property.rules;
89 this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
90 this.readonly = property.readonly;
91 this.simpleType = property.simpleType;
92 this.componentInstanceId = property.componentInstanceId;
93 this.parentValue = property.parentValue;
Tal Gitelmaned7e1c32017-06-29 19:30:00 +030094 this.ownerId = property.ownerId;
Michael Landoed64b5e2017-06-09 03:19:04 +030095 }
96
97 if (!this.schema || !this.schema.property) {
98 this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
99 } else {
100 //forcing creating new object, so editing different one than the object in the table
101 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
102 }
103 if (property && property.uniqueId) {
104 this.filterTerm = this.name + " " + (this.description || "") + " " + this.type.replace("org.openecomp.datatypes.heat.", "");
105 if (this.schema.property && this.schema.property.type) {
106 this.filterTerm += " " + this.schema.property.type.replace("org.openecomp.datatypes.heat.", "");
107 }
108 }
109 }
110
111 public convertToServerObject:Function = ():string => {
112 let serverObject = {};
113 let mapData = {
114 "type": this.type,
115 "required": this.required || false,
116 "defaultValue": this.defaultValue != "" && this.defaultValue != "[]" && this.defaultValue != "{}" ? this.defaultValue : null,
117 "description": this.description,
118 "constraints": this.constraints,
119 "isPassword": this.password || false,
120 "schema": this.schema,
121 "name": this.name
122 };
123 serverObject[this.name] = mapData;
124
125 return JSON.stringify(serverObject);
126 };
127
128 public toJSON = ():any => {
129 // if(!this.resourceInstanceUniqueId){
130 // this.value = undefined;
131 // }
132 let temp = angular.copy(this);
133 temp.readonly = undefined;
134 temp.resourceInstanceUniqueId = undefined;
135 temp.simpleType = undefined;
136 temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
137 temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
138 temp.rules = null; //don't send rules to server until feature is fully supported
139 temp.isAlreadySelected = undefined;
140 temp.addOn = undefined;
141 return temp;
142 };
143}