2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 Nordix Foundation. 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 {PROPERTY_DATA} from "../../utils/constants";
23 import {OutputBEModel} from "./output-be-model";
24 import {AttributeFEModel} from "./attribute-fe-model";
25 import {DerivedAttributeType} from "./attribute-be-model";
27 export class OutputFEModel extends OutputBEModel {
28 isSimpleType: boolean;
29 relatedAttributeValue: any;
30 relatedAttributeName: string;
32 defaultValueObjIsValid: boolean;
33 defaultValueObjOrig: any;
34 defaultValueObjIsChanged: boolean;
35 derivedDataType: DerivedAttributeType;
37 constructor(output?: OutputBEModel) {
40 this.isSimpleType = PROPERTY_DATA.SIMPLE_TYPES.indexOf(this.type) > -1;
41 let relatedAttribute = output.attributes && output.attributes[0] || output.outputs && output.outputs[0];
42 if (relatedAttribute) {
43 this.relatedAttributeValue = relatedAttribute.value;
44 this.relatedAttributeName = relatedAttribute.name;
46 this.derivedDataType = this.getDerivedAttributeType();
47 this.resetDefaultValueObjValidation();
48 this.updateDefaultValueObjOrig();
52 public updateDefaultValueObjOrig() {
53 this.defaultValueObjOrig = _.cloneDeep(this.defaultValueObj);
54 this.defaultValueObjIsChanged = false;
57 public getJSONDefaultValue(): string {
58 return AttributeFEModel.stringifyValueObj(this.defaultValueObj, this.schema.property.type, this.derivedDataType);
61 public getDefaultValueObj(): any {
62 return AttributeFEModel.parseValueObj(this.defaultValueObj, this.type, this.derivedDataType);
65 public resetDefaultValueObjValidation() {
66 this.defaultValueObjIsValid = true;
69 hasDefaultValueChanged(): boolean {
70 return !_.isEqual(this.defaultValueObj, this.defaultValueObjOrig);
73 hasChanged(): boolean {
74 return this.hasDefaultValueChanged() ;