Merge "Revert "[sdc] - ecomp portal version fix""
[sdc.git] / catalog-ui / src / app / models / properties-inputs / property-be-model.ts
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
21 import { PropertyInputDetail, SchemaPropertyGroupModel, SchemaProperty } from "app/models";
22 import { PROPERTY_DATA, PROPERTY_TYPES } from 'app/utils';
23 export enum DerivedPropertyType {
24     SIMPLE,
25     LIST,
26     MAP,
27     COMPLEX
28 }
29
30 export class PropertyBEModel {
31
32     defaultValue: string;
33     definition: boolean;
34     description: string;
35     fromDerived: boolean;
36     getInputValues: Array<PropertyInputDetail>
37     name: string;
38     parentUniqueId: string;
39     password: boolean;
40     required: boolean;
41     schema: SchemaPropertyGroupModel;
42     type: string;
43     uniqueId: string;
44     value: string;
45
46     constructor(property?: PropertyBEModel) {
47         if (property) {
48             this.defaultValue = property.defaultValue;
49             this.description = property.description;
50             this.fromDerived = property.fromDerived;
51             this.name = property.name;
52             this.parentUniqueId = property.parentUniqueId;
53             this.password = property.password;
54             this.required = property.required;
55             this.schema = property.schema;
56             this.type = property.type;
57             this.uniqueId = property.uniqueId;
58             this.value = property.value ? property.value : property.defaultValue;
59             this.definition = property.definition;
60             this.getInputValues = property.getInputValues;
61         }
62
63         if (!this.schema || !this.schema.property) {
64             this.schema = new SchemaPropertyGroupModel(new SchemaProperty());
65         } else { //forcing creating new object, so editing different one than the object in the table
66             this.schema = new SchemaPropertyGroupModel(new SchemaProperty(this.schema.property));
67         }
68     }
69
70
71
72     public toJSON = (): any => {
73         let temp = angular.copy(this);
74         temp.value = temp.value === "{}" || temp.value === "[]" ? undefined : temp.value;
75         temp.defaultValue = temp.defaultValue === "{}" || temp.defaultValue === "[]" ? undefined : temp.defaultValue;
76         return temp;
77     };
78
79     public getDerivedPropertyType = () => {
80         if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) {
81             return DerivedPropertyType.SIMPLE;
82         } else if (this.type == PROPERTY_TYPES.LIST) {
83             return DerivedPropertyType.LIST;
84         } else if (this.type == PROPERTY_TYPES.MAP) {
85             return DerivedPropertyType.MAP;
86         } else {
87             return DerivedPropertyType.COMPLEX;
88         }
89     }
90
91 }
92
93
94 // EXTRAS FROM CONSTRUCTOR:
95 //         this.source = property.source;
96 //         this.valueUniqueUid = property.valueUniqueUid;
97 //         this.path = property.path;
98 //         this.rules = property.rules;
99 //         this.resourceInstanceUniqueId = property.resourceInstanceUniqueId;
100 //         this.readonly = property.readonly;
101 //         this.simpleType = property.simpleType;
102 //         this.componentInstanceId = property.componentInstanceId;
103 //         this.parentValue = property.parentValue;
104 //NEW PROPERTIES MAY NEED:
105 // export class PropertyFEModel extends PropertyBEModel {
106 //     componentInstanceId: string;
107 //     isAlreadySelected: boolean;
108 //     filterTerm: string;
109 // }
110 //FOR INPUTS, BE ALSO INCLUDES:
111 //export class InputFEModel extends PropertyBEModel {
112 //     hidden: boolean;
113 //     label: string;
114 //     immutable: boolean;
115 // }