aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/models/properties-inputs/input-fe-model.ts
blob: 3af4431b55de9e4cd5ac0b45600ce01fc0f529ed (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
import { SchemaPropertyGroupModel, SchemaProperty } from "../aschema-property";
import { PropertyBEModel } from "../../models";
import {PROPERTY_DATA} from "../../utils/constants";
import {InputBEModel} from "./input-be-model";

export class InputFEModel extends InputBEModel {
    isSimpleType: boolean;
    relatedProperty: SimpleRelatedProperty;

    constructor(input?: InputBEModel) {
        super(input);
        if (input) {
            this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1;
            this.relatedProperty = new SimpleRelatedProperty(input);
        }
    }

}

export class SimpleRelatedProperty {
    name: string;
    value: string;
    nestedPath: string;

    constructor(input: InputBEModel) {
       if(!input.instanceUniqueId){
           return;
       }
        //Check if input is on DerivedFEProperty level, in which case we want to set a nested path
        let instanceName = input.instanceUniqueId.split('.').pop();
        if (input.inputPath && input.inputPath.indexOf('#') > -1
            && instanceName + "_" + input.inputPath.split('#').join('_') == input.name) {  //Ignore inputPath for a complex child on VL that was declared within VF, that was then dragged into service. For that case, input.name will be missing the vl name, so we'll know to ignore the path and fall into else case.
            this.nestedPath = input.inputPath;
            this.name = input.inputPath.substring(0, input.inputPath.indexOf('#'));
        } else { //PropertyFEModel level. Can parse input name to get prop name.
            let propNameLength = input.name.length - instanceName.length + 1;
            this.name = input.name.substr(instanceName.length + 1, propNameLength);
        }

        //In declare response, input contains nested property, and we need to extract value so we can update our prop.
        let nestedProperty = input.properties && input.properties[0] || input.inputs && input.inputs[0];
        if (nestedProperty) {
            this.value = nestedProperty.value;
        }
    }
};