[sdc] update code of sdc
[sdc.git] / catalog-ui / src / app / models / properties-inputs / derived-fe-property.ts
1 import { SchemaPropertyGroupModel, SchemaProperty } from '../aschema-property';
2 import { DerivedPropertyType, PropertyBEModel } from '../../models';
3 import { PROPERTY_TYPES } from 'app/utils';
4 import { UUID } from "angular2-uuid";
5
6
7 export class DerivedFEProperty extends PropertyBEModel {
8     valueObj: any; 
9     parentName: string;
10     propertiesName: string; //"network_assignments#ipv4_subnet#use_ipv4 =  parentPath + name
11     derivedDataType: DerivedPropertyType;
12     isDeclared: boolean;
13     isSelected: boolean;
14     isDisabled: boolean;
15     hidden: boolean;
16     isChildOfListOrMap: boolean;
17     canBeDeclared: boolean;
18     mapKey: string;
19
20     constructor(property: PropertyBEModel, parentName?: string, createChildOfListOrMap?: boolean, key?:string, value?:any) {
21         if (!createChildOfListOrMap) { //creating a standard derived prop
22             super(property);
23             this.parentName = parentName ? parentName : null;
24             this.propertiesName = (parentName) ? parentName + '#' + property.name : property.name;
25             this.canBeDeclared = true; //defaults to true
26         } else { //creating a direct child of list or map (ie. Item that can be deleted, with UUID instead of name)
27             super(null);
28             this.isChildOfListOrMap = true;
29             this.canBeDeclared = false;
30             this.name = UUID.UUID();
31             this.parentName = parentName;
32             this.propertiesName = parentName + '#' + this.name;
33
34             
35             if (property.type == PROPERTY_TYPES.LIST) {
36                 this.mapKey = property.schema.property.type.split('.').pop();
37                 this.type = property.schema.property.type;
38             } else { //map
39                 this.mapKey = key || "";
40                 this.type = property.type;
41             }
42             this.valueObj = (this.type == PROPERTY_TYPES.JSON && typeof value == 'object') ? JSON.stringify(value) : value;
43             this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property));
44         }
45         this.derivedDataType = this.getDerivedPropertyType();
46     }
47     
48 }
49 export class DerivedFEPropertyMap {
50     [parentPath: string]: Array<DerivedFEProperty>;
51 }
52