summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/models/property-fe-model.ts
blob: f83d6d6b51d4090a4e950845881e6f6e8f407bf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import {SchemaPropertyGroupModel, SchemaProperty} from './aschema-property';
import { PROPERTY_DATA } from 'app/utils';
import { FilterPropertiesAssignmentData, PropertyBEModel } from 'app/models';

export class PropertyFEModel extends PropertyBEModel {
    public static filterData:FilterPropertiesAssignmentData;
    childrenProperties: Array<PropertyFEModel>;
    expandedChildPropertyId: string;
    isAllChildrenLevelsCalculated: boolean;
    isDataType: boolean;
    isDisabled: boolean;
    isSelected: boolean;
    isSimpleType: boolean;
    parent: PropertyFEModel;
    treeNodeId: string;
    valueObjectRef: any;
    private _derivedFromSimpleTypeName:string;
    get derivedFromSimpleTypeName():string {
        return this._derivedFromSimpleTypeName;
    }
    set derivedFromSimpleTypeName(derivedFromSimpleTypeName:string) {
        this._derivedFromSimpleTypeName = derivedFromSimpleTypeName;
    }

    constructor(property?: PropertyBEModel);
    constructor(name: string, type: string, treeNodeId: string, parent: PropertyFEModel, valueObjectRef: any, schema?: SchemaPropertyGroupModel);
    constructor(nameOrPropertyObj?: string | PropertyBEModel, type?: string, treeNodeId?: string, parent?: PropertyFEModel, valueObjectRef?: any, schema?: SchemaPropertyGroupModel) {

        super(typeof nameOrPropertyObj === 'string' ? null : nameOrPropertyObj);

        if (typeof nameOrPropertyObj === 'string') {
            this.name = nameOrPropertyObj;
            this.type = type;
            this.treeNodeId = treeNodeId;
            this.parent = parent;
            this.valueObjectRef = valueObjectRef;
            this.value = this.value || this.defaultValue;
            if(schema){
                this.schema = new SchemaPropertyGroupModel(new SchemaProperty(schema.property));
            }
        }
        this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1;
        this.isDataType = PROPERTY_DATA.TYPES.indexOf(this.type) == -1;
        this.setNonDeclared();
    }


    public setNonDeclared = (): void => {
        this.isSelected = false;
        this.isDisabled = false;
    }

    public setAsDeclared = (): void => {
        this.isSelected = true;
        this.isDisabled = true;
    }

    //For expand-collapse functionality
    public updateExpandedChildPropertyId = (childPropertyId: string): void => {
        this.expandedChildPropertyId = (this.expandedChildPropertyId == childPropertyId) ? '' : childPropertyId;
    }

    public convertToServerObject: Function = (): any => { //TODO: Idan, Rachel, Nechama: Decide what we need to do here
        // let serverObject = {};
        // let mapData = {
        //     'type': this.type,
        //     'required': this.required || false,
        //     'defaultValue': this.defaultValue != '' && this.defaultValue != '[]' && this.defaultValue != '{}' ? this.defaultValue : null,
        //     'description': this.description,
        //     'isPassword': this.password || false,
        //     'schema': this.schema,
        //     'name': this.name
        // };
        // serverObject[this.name] = mapData;

        //return JSON.stringify(serverObject);
    };
}