2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import * as _ from "lodash";
22 import { SchemaPropertyGroupModel, SchemaProperty } from "../aschema-property";
23 import {PropertyFEModel} from "../../models";
24 import {PROPERTY_DATA} from "../../utils/constants";
25 import {InputBEModel} from "./input-be-model";
26 import {DerivedPropertyType} from "./property-be-model";
28 export class InputFEModel extends InputBEModel {
29 isSimpleType: boolean;
30 relatedPropertyValue: any;
31 relatedPropertyName: string;
33 defaultValueObjIsValid:boolean;
34 defaultValueObjOrig:any;
35 defaultValueObjIsChanged:boolean;
36 derivedDataType: DerivedPropertyType;
38 constructor(input?: InputBEModel) {
41 this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1;
42 let relatedProperty = input.properties && input.properties[0] || input.inputs && input.inputs[0];
43 if (relatedProperty) {
44 this.relatedPropertyValue = relatedProperty.value;
45 this.relatedPropertyName = relatedProperty.name;
47 this.derivedDataType = this.getDerivedPropertyType();
48 this.resetDefaultValueObjValidation();
49 this.updateDefaultValueObjOrig();
53 public updateDefaultValueObj(defaultValueObj:any, isValid:boolean) {
54 this.defaultValueObj = PropertyFEModel.cleanValueObj(defaultValueObj);
55 this.defaultValueObjIsValid = isValid;
56 this.defaultValueObjIsChanged = this.hasDefaultValueChanged();
59 public updateDefaultValueObjOrig() {
60 this.defaultValueObjOrig = _.cloneDeep(this.defaultValueObj);
61 this.defaultValueObjIsChanged = false;
64 public getJSONDefaultValue(): string {
65 return PropertyFEModel.stringifyValueObj(this.defaultValueObj, this.schema.property.type, this.derivedDataType);
68 public getDefaultValueObj(): any {
69 return PropertyFEModel.parseValueObj(this.defaultValue, this.type, this.derivedDataType);
72 public resetDefaultValueObjValidation() {
73 this.defaultValueObjIsValid = true;
76 hasDefaultValueChanged(): boolean {
77 return !_.isEqual(this.defaultValueObj, this.defaultValueObjOrig);