| @@ -1,6 +1,7 @@ | |||
| import { Component, OnDestroy, OnInit } from '@angular/core'; | |||
| import {SocketService} from "../../../shared/services/socket.service"; | |||
| import {Subscription} from "rxjs"; | |||
| import {ToastrService} from "ngx-toastr"; | |||
| @Component({ | |||
| @@ -9,27 +10,25 @@ import {Subscription} from "rxjs"; | |||
| styleUrls: ['./overall-ground.component.scss'] | |||
| }) | |||
| export class OverallGroundComponent implements OnInit, OnDestroy { | |||
| isClicked = false; | |||
| isConnected = false; | |||
| states = Array(6).fill(0); | |||
| state1 = ''; | |||
| state2 = ''; | |||
| state1 = false; | |||
| state2 = false; | |||
| state3 = ''; | |||
| state4 = ''; | |||
| state5 = ''; | |||
| state6 = ''; | |||
| Sstate1 = false; | |||
| Sstate2 = false; | |||
| Sstate3 = false; | |||
| Sstate4 = false; | |||
| imageIcon = 'assets/images/sensor-off.png'; | |||
| title = 'ALARM: SMOKE ALERT' | |||
| state5 = false; | |||
| state6 = false; | |||
| switchArm = false; | |||
| switchWarning = false; | |||
| isReady = true; | |||
| private statusSubscription?: Subscription; | |||
| private messageSubscription?: Subscription; | |||
| private intervalId: any; | |||
| constructor(private socketService$: SocketService) { | |||
| constructor( | |||
| private socketService$: SocketService, | |||
| private toastr: ToastrService | |||
| ) { | |||
| } | |||
| ngOnInit() { | |||
| @@ -65,38 +64,38 @@ export class OverallGroundComponent implements OnInit, OnDestroy { | |||
| } | |||
| toggleState1() { | |||
| this.Sstate1 = !this.Sstate1; | |||
| let str = {id: '0', type: 'cmd', state1: this.Sstate1.toString()}; | |||
| this.switchArm = !this.switchArm; | |||
| let str = {id: '0', type: 'cmd', state1: this.switchArm.toString()}; | |||
| this.socketService$.sendMessage(str); | |||
| } | |||
| toggleState2() { | |||
| this.Sstate2 = !this.Sstate2; | |||
| let str = {id: '0', type: 'cmd', state2: this.Sstate2.toString()}; | |||
| this.switchWarning = !this.switchWarning; | |||
| let str = {id: '0', type: 'cmd', state2: this.switchWarning.toString()}; | |||
| this.socketService$.sendMessage(str); | |||
| } | |||
| getImageSource(): string { | |||
| return (this.Sstate1 && this.Sstate2) || this.Sstate1 ? 'assets/images/sensor-on.png' : 'assets/images/sensor-off.png'; | |||
| return (this.state5 && this.state6) || this.state5 ? 'assets/images/sensor-on.png' : 'assets/images/sensor-off.png'; | |||
| } | |||
| onMessage(message: any) { | |||
| if (message.id == '0' && message.type === 'get') { | |||
| this.state1 = message.state1 === '0' ? 'ON' : 'OFF'; // 1 OFF | |||
| this.state2 = message.state2 === '0' ? 'ON' : 'OFF'; // 1 OFF | |||
| this.state1 = message.state1 === '0'; // 1 OFF // alarm 12h | |||
| this.state2 = message.state2 === '0'; // 1 OFF // alarm 1h | |||
| this.state3 = message.state3 === '1' ? 'ON' : 'OFF'; | |||
| this.state4 = message.state4 === '1' ? 'ON' : 'OFF'; | |||
| this.state5 = message.state5 === '1' ? 'ON' : 'OFF'; | |||
| this.state6 = message.state6 === '1' ? 'ON' : 'OFF'; | |||
| this.Sstate1 = this.state5 === 'ON'; | |||
| this.Sstate2 = this.state6 === 'ON'; | |||
| this.state5 = message.state5 === '1'; // alarm 9h && 6h // 1 ON, 0 OFF | |||
| this.state6 = message.state6 === '1'; // ? 'ON' : 'OFF'; | |||
| this.Sstate3 = this.state1 === 'ON'; | |||
| this.Sstate4 = this.state2 === 'ON'; | |||
| } | |||
| if(this.Sstate1 && this.Sstate2) | |||
| this.title = 'ALARM: VIBRATION ALERT' | |||
| this.switchArm = message.state5 === '1';// alarm 9h && 6h // 1 ON, 0 OFF | |||
| this.switchWarning = message.state6 === '1';// alarm 9h && 6h // 1 ON, 0 OFF | |||
| this.isReady = message.ready === '1'; | |||
| if (message.ready === '0' && this.state5){ // not ready and ON arm | |||
| this.toastr.warning('System not ready', 'Warning', {timeOut: 5000}); | |||
| } | |||
| } | |||
| } | |||
| } | |||