/*-------------------------------------------------------------------------------------------------------------- * Copyright (c) insite-gmbh. All rights reserved. * Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------------------------*/ import { Component, ElementRef, Directive, Input, OnInit, Output, ViewChild } from '@angular/core'; import { InaxPlcService, DataChangeEvent, IPlcEventProxy, PlcValidator } from '../../../plc'; import { InaxSignalR, Guid } from '../../../common'; import { PlcItem } from '../../../../app/components/plcviewer/plcviewer.component'; import { InaxLoggerService } from '../../../logger/src/logger'; import { PlcInput, PlcInputType, PlcAddressType } from '../plcInput'; @Component(Object.assign({ selector: 'plc-checkbox', templateUrl: './@inax/plcUi/src/plcCheckbox/plc-checkbox.component.html', styleUrls: ['./@inax/plcUi/src/plcCheckbox/plc-checkbox.component.css'] }, PlcInput.metaData)) export class PlcCheckboxComponent extends PlcInput { public displayMessage: string = ''; constructor(inaxPlc: InaxPlcService) { super(inaxPlc); } /* SPECIFIC INPUTS */ @Input() trueValue: string = 'true'; @Input() falseValue: string = 'false'; @Input() trueValueMessage: string = 'Start'; @Input() falseValueMessage: string = 'Stop'; @ViewChild('plccheckbox') checkbox; public get Value(): string { return (this._value === this.trueValue) ? 'checked' : ''; } public set Value(v: string) { } ngOnInit(): void { this.initializeDefaultProperties(); this.initialize(); this.subscribe(); } ngOnDestroy(): void { this.unsubscribe(); } public initialize(): void { } /** * updates the current value * - if the value equals trueValue, trueValueMessage is displayed in the label * - in all other cases, falseValueMessage is displayed * @param value the value to set */ public updateValue(value: string): void { this._value = value; this.displayMessage = (value === this.trueValue) ? this.trueValueMessage : this.falseValueMessage; } /** * writes the other specified value (different values are treated like falseValue) * if the write operation does return false, the checkbox is set to the current * Value (before the switch) so it does always display the actual value */ public switchValue(): void { let val = (this._value === this.trueValue) ? this.falseValue : this.trueValue; if (this.write(val) !== true) { this.checkbox.nativeElement.checked = this.Value; } } }