[SDC-29] rebase continue work to align source
[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     isChildOfListOrMap: boolean;
16     canBeDeclared: boolean;
17     mapKey: string;
18
19     constructor(property: PropertyBEModel, parentName?: string, createChildOfListOrMap?: boolean, key?:string, value?:any) {
20         if (!createChildOfListOrMap) { //creating a standard derived prop
21             super(property);
22             this.parentName = parentName ? parentName : null;
23             this.propertiesName = (parentName) ? parentName + '#' + property.name : property.name;
24             this.canBeDeclared = true; //defaults to true
25         } else { //creating a direct child of list or map (ie. Item that can be deleted, with UUID instead of name)
26             super(null);
27             this.isChildOfListOrMap = true;
28             this.canBeDeclared = false;
29             this.name = UUID.UUID();
30             this.parentName = parentName;
31             this.propertiesName = parentName + '#' + this.name;
32
33             
34             if (property.type == PROPERTY_TYPES.LIST) {
35                 this.mapKey = property.schema.property.type.split('.').pop();
36                 this.type = property.schema.property.type;
37             } else { //map
38                 this.mapKey = key || "";
39                 this.type = property.type;
40             }
41             this.valueObj = (this.type == PROPERTY_TYPES.JSON && typeof value == 'object') ? JSON.stringify(value) : value;
42             this.schema = new SchemaPropertyGroupModel(new SchemaProperty(property.schema.property));
43         }
44         this.derivedDataType = this.getDerivedPropertyType();
45     }
46     
47 }
48 export class DerivedFEPropertyMap {
49     [parentPath: string]: Array<DerivedFEProperty>;
50 }
51