|
|
|
@@ -7,12 +7,13 @@ import { |
|
|
|
} from '@angular/core'; |
|
|
|
import * as L from 'leaflet'; |
|
|
|
import 'leaflet.markercluster'; |
|
|
|
import { Subscription, take } from 'rxjs'; |
|
|
|
import {Subject, Subscription, take} from 'rxjs'; |
|
|
|
import { SocketService } from '../../../shared/services/socket.service'; |
|
|
|
import { MatDialog } from '@angular/material/dialog'; |
|
|
|
import { AlarmSoundService } from '../../../shared/services/alarm-sound.service'; |
|
|
|
import { CameraDialogComponent } from '../../../shared/component/camera-dialog/camera-dialog.component'; |
|
|
|
import { alarmData, alarmDemo } from '../data/fake-data'; |
|
|
|
import {takeUntil} from "rxjs/operators"; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'app-centralized-security-management', |
|
|
|
@@ -24,8 +25,6 @@ export class CentralizedSecurityManagementComponent |
|
|
|
{ |
|
|
|
private map!: L.Map; |
|
|
|
private markers!: L.MarkerClusterGroup; |
|
|
|
private statusSubscription?: Subscription; |
|
|
|
private messageSubscription?: Subscription; |
|
|
|
data = alarmData; |
|
|
|
alarmDemo = alarmDemo; |
|
|
|
state1 = false; |
|
|
|
@@ -35,7 +34,7 @@ export class CentralizedSecurityManagementComponent |
|
|
|
state5 = false; |
|
|
|
state6 = false; |
|
|
|
isReady = true; |
|
|
|
|
|
|
|
private unsubscribeAll = new Subject(); |
|
|
|
constructor( |
|
|
|
private socketService$: SocketService, |
|
|
|
private dialog: MatDialog, |
|
|
|
@@ -44,11 +43,11 @@ export class CentralizedSecurityManagementComponent |
|
|
|
) {} |
|
|
|
|
|
|
|
ngOnInit() { |
|
|
|
this.statusSubscription = this.socketService$.status$.subscribe( |
|
|
|
this.socketService$.status$.pipe(takeUntil(this.unsubscribeAll)).subscribe( |
|
|
|
(isConnected) => { |
|
|
|
if (isConnected) { |
|
|
|
this.socketService$.sendMessage({ id: '0', type: 'get' }); |
|
|
|
this.messageSubscription = this.socketService$.messages$.subscribe( |
|
|
|
this.socketService$.messages$.pipe(takeUntil(this.unsubscribeAll)).subscribe( |
|
|
|
(message) => { |
|
|
|
this.onMessage(message); |
|
|
|
}, |
|
|
|
@@ -70,10 +69,9 @@ export class CentralizedSecurityManagementComponent |
|
|
|
} |
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
|
this.statusSubscription?.unsubscribe(); |
|
|
|
this.messageSubscription?.unsubscribe(); |
|
|
|
this.socketService$.close(); |
|
|
|
this.alarmSoundService$.stopAlarm(); |
|
|
|
this.unsubscribeAll.next(''); |
|
|
|
this.unsubscribeAll.complete(); |
|
|
|
} |
|
|
|
|
|
|
|
initMap(): void { |
|
|
|
@@ -98,13 +96,13 @@ export class CentralizedSecurityManagementComponent |
|
|
|
} |
|
|
|
|
|
|
|
onMessage(message: any) { |
|
|
|
if (message.id == '0' && message.type === 'get') { |
|
|
|
this.state1 = message.state1 === '0'; // 1 OFF // alarm 12h |
|
|
|
this.status1 = message.status1 === '1'; // 0 not, 1 ready, 2 error, 3 bypass |
|
|
|
this.state2 = message.state2 === '0'; // 1 OFF // alarm 1h |
|
|
|
this.status2 = message.status2 === '1'; // 0 not, 1 ready, 2 error, 3 bypass |
|
|
|
this.state5 = message.state5 === '1'; // 1 ON, 0 OFF |
|
|
|
this.isReady = message.ready === '1'; |
|
|
|
if (message.id == '0' && message.type == 'get') { |
|
|
|
this.state1 = message.state1 == '0'; // 1 OFF // alarm 12h |
|
|
|
this.status1 = message.status1 == '1'; // 0 not, 1 ready, 2 error, 3 bypass |
|
|
|
this.state2 = message.state2 == '0'; // 1 OFF // alarm 1h |
|
|
|
this.status2 = message.status2 == '1'; // 0 not, 1 ready, 2 error, 3 bypass |
|
|
|
this.state5 = message.state5 == '1'; // 1 ON, 0 OFF |
|
|
|
this.isReady = message.ready == '1'; |
|
|
|
this.alarmSoundService$.startAlarm(this.state5, this.state1,this.status1, this.state2, this.status2); |
|
|
|
this.updateIcons(); |
|
|
|
} |
|
|
|
@@ -119,7 +117,6 @@ export class CentralizedSecurityManagementComponent |
|
|
|
} |
|
|
|
|
|
|
|
addMarker(item: any, isDemo: boolean = false): void { |
|
|
|
console.log(this.state5, this.state1, this.status1) |
|
|
|
const icon = isDemo |
|
|
|
? this.getIcon(this.state5, this.state1, this.status1, this.state2, this.status2) |
|
|
|
: this.createIcon(item.warning); |
|
|
|
@@ -163,7 +160,7 @@ export class CentralizedSecurityManagementComponent |
|
|
|
<div><strong>Địa điểm:</strong> ${item.detail.position}</div> |
|
|
|
<div><strong>Tọa độ:</strong> ${item.detail.coordinates.lat}, ${item.detail.coordinates.lng}</div> |
|
|
|
<div><strong>Thời gian:</strong> ${item.detail.time}</div> |
|
|
|
<a href="/overview/security-system-details" target="_blank">Xem chi tiết</a> |
|
|
|
<a href="/homepage/security-system-details" target="_blank">Xem chi tiết</a> |
|
|
|
</div>`; |
|
|
|
} |
|
|
|
|