[sdc] rebase update
[sdc.git] / catalog-ui / src / app / models / properties-inputs / derived-fe-property.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 { SchemaPropertyGroupModel, SchemaProperty } from '../aschema-property';
22 import { DerivedPropertyType, PropertyBEModel } from '../../models';
23 import { PROPERTY_TYPES } from 'app/utils';
24 import { UUID } from "angular2-uuid";
25
26
27 export class DerivedFEProperty extends PropertyBEModel {
28     valueObj: any; 
29     parentName: string;
30     propertiesName: string; //"network_assignments#ipv4_subnet#use_ipv4 =  parentPath + name
31     derivedDataType: DerivedPropertyType;
32     isDeclared: boolean;
33     isSelected: boolean;
34     isDisabled: boolean;
35     hidden: boolean;
36     isChildOfListOrMap: boolean;
37     canBeDeclared: boolean;
38     mapKey: string;
39
40     constructor(property: PropertyBEModel, parentName?: string, createChildOfListOrMap?: boolean, key?:string, value?:any) {
41         if (!createChildOfListOrMap) { //creating a standard derived prop
42             super(property);
43             this.parentName = parentName ? parentName : null;
44             this.propertiesName = (parentName) ? parentName + '#' + property.name : property.name;
45             this.canBeDeclared = true; //defaults to true
46         } else { //creating a direct child of list or map (ie. Item that can be deleted, with UUID instead of name)
47             super(null);
48             this.isChildOfListOrMap = true;
49             this.canBeDeclared = false;
50             this.name = UUID.UUID();
51             this.parentName = parentName;
52             this.propertiesName = parentName + '#' + this.name;
53
54             
55             if (property.type == PROPERTY_TYPES.LIST) {
56                 this.mapKey = property.schema.property.type.split('.').pop();
57                 this.type = property.schema.property.type;
58             } else { //map
59                 this.mapKey = key || "";
60                 this.type = property.type;
61             }
62             this.valueObj = (this.type == PROPERTY_TYPES.JSON && typeof value == 'object') ? JSON.stringify(value) : value;
63             this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property));
64         }
65         this.derivedDataType = this.getDerivedPropertyType();
66     }
67     
68 }
69 export class DerivedFEPropertyMap {
70     [parentPath: string]: Array<DerivedFEProperty>;
71 }
72