/*-------------------------------------------------------------------------------------------------------------- * 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, ChangeDetectorRef } 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-radio', templateUrl: './@inax/plcUi/src/plcRadio/plc-radio.component.html', styleUrls: ['./@inax/plcUi/src/plcRadio/plc-radio.component.css'] }, PlcInput.metaData)) export class PlcRadioComponent extends PlcInput { public successRadioClass: string = 'basicblue'; // static, can be modified here to alter design of active radio constructor(inaxPlc: InaxPlcService, private _ref: ChangeDetectorRef) { super(inaxPlc) } /* SPECIFIC INPUTS */ @Input() values: Array = []; public get Value(): string { return this._value; } public set Value(v: string) { } ngOnInit(): void { this.initializeDefaultProperties(); this.initialize(); this.subscribe(); } ngOnDestroy(): void { this.unsubscribe(); } public initialize(): void { // console.log(this.values); } /** * updates the current value */ public updateValue(value: string): void { this._value = value; } /** * handles a click on a radio-button by the user * - tries to write the value specified by the radio-button clicked * - if the write-operation completes successfully, the DataChangeEvent will update the value * - on a fail, the previous value is re-set * the ChangeDetector is called in between to ensure the updating of the UI, so * the radio will always display the correct value */ public radioChangeHandler(val: string): void { let temp = this._value; // force change detection this.updateValue(''); this._ref.detectChanges(); if (this.write(val) !== true) { // if writing is unsuccessful (e.g. no permission, set old value and trigger change detection to update UI) this.updateValue(temp); this._ref.detectChanges(); } } }