Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 1 | /*- |
| 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 Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 21 | 'use strict'; |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 22 | import * as _ from "lodash"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 23 | import {SchemaPropertyGroupModel, SchemaProperty} from "./aschema-property"; |
| 24 | import {InputPropertyBase} from "./input-property-base"; |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 25 | import {PropertyBEModel} from "./properties-inputs/property-be-model"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 26 | |
| 27 | export 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 | |
| 40 | export interface IPropertyModel extends InputPropertyBase { |
| 41 | |
| 42 | //server data |
| 43 | constraints:Array<Object>; |
| 44 | 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 Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 59 | export class PropertyModel extends PropertyBEModel implements IPropertyModel { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 60 | //server data |
| 61 | uniqueId:string; |
| 62 | name:string; |
| 63 | constraints:Array<Object>; |
| 64 | 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 Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 74 | ownerId:string; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 75 | |
| 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 Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 94 | super(property); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 95 | if (property) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 96 | this.constraints = property.constraints; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 97 | this.source = property.source; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 98 | 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 Gitelman | ed7e1c3 | 2017-06-29 19:30:00 +0300 | [diff] [blame] | 106 | this.ownerId = property.ownerId; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 107 | } |
| 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 Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 150 | temp.rules = undefined; //don't send rules to server until feature is fully supported |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 151 | temp.isAlreadySelected = undefined; |
| 152 | temp.addOn = undefined; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 153 | temp.filterTerm = undefined; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 154 | return temp; |
| 155 | }; |
| 156 | } |