[SDC-29] catalog 1707 rebase commit.
[sdc.git] / catalog-ui / src / app / models / properties-inputs / derived-fe-property.ts
1 import { SchemaPropertyGroupModel, SchemaProperty } from '../aschema-property';
2 import { PROPERTY_DATA, PROPERTY_TYPES} from 'app/utils';
3 import { PropertyBEModel } from '../../models';
4
5 export enum DerivedPropertyType {
6     SIMPLE,
7     LIST,
8     MAP,
9     COMPLEX //other datatype, list of non-simple, or map of non-simple
10 }
11
12 export class DerivedFEProperty extends PropertyBEModel {
13     parentName: string;
14     propertiesName: string; //"network_assignments#ipv4_subnet#use_ipv4 =  parentPath + name
15     derivedDataType: DerivedPropertyType;
16     isDeclared: boolean;
17     isSelected: boolean;
18     isDisabled: boolean;
19     isChildOfListOrMap: boolean;
20
21     constructor(property: PropertyBEModel, parentName?: string)
22     constructor(name: string, parentName: string, type: string, value: string, isChildOfListOrMap?:boolean, schema?: SchemaPropertyGroupModel);
23     constructor(nameOrPropertyObj?: string | PropertyBEModel, parentName?: string, type?: string, value?: string, isChildOfListOrMap?: boolean, schema?: SchemaPropertyGroupModel) {
24
25         super(typeof nameOrPropertyObj === 'string' ? null : nameOrPropertyObj);
26
27         if (typeof nameOrPropertyObj !== 'string') { //constructor #1
28             this.parentName = parentName ? parentName : null;
29             this.propertiesName = (parentName) ? parentName + '#' + nameOrPropertyObj.name : nameOrPropertyObj.name;
30         } else { //constructor #2
31             this.name = nameOrPropertyObj;
32             this.type = type;
33             this.parentName = parentName;
34             this.propertiesName = parentName + '#' + nameOrPropertyObj;
35             this.value = value;
36             if (schema) {
37                 this.schema = new SchemaPropertyGroupModel(new SchemaProperty(schema.property));
38             }
39         }
40         this.derivedDataType = this.getDerivedPropertyType();
41         this.isChildOfListOrMap = (isChildOfListOrMap) ? isChildOfListOrMap : false;
42     }
43    
44     public getDerivedPropertyType = () => {
45         if (PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1) {
46             return DerivedPropertyType.SIMPLE;
47         } else if (this.type == PROPERTY_TYPES.LIST) {
48             return DerivedPropertyType.LIST;
49         } else if (this.type == PROPERTY_TYPES.MAP) {
50             return DerivedPropertyType.MAP;
51         } else {
52             return DerivedPropertyType.COMPLEX;
53         }
54    } 
55     
56 }
57 export class DerivedFEPropertyMap {
58     [parentPath: string]: Array<DerivedFEProperty>;
59 }
60
61
62
63 // isDataType: boolean;
64
65
66 // canAdd: boolean;
67 // canCollapse: boolean;
68 // canBeDeclared: boolean;
69
70 // derivedValue: string;
71 // derivedValueType: string;
72 // propertiesName: string;