#15 features/dialog-camera

Merged
trungnd merged 6 commits from features/dialog-camera into master 1 year ago
  1. +6
    -0
      Dockerfile
  2. +20
    -1
      src/app/app.component.ts
  3. +22
    -25
      src/app/modules/homepage/centralized-security-management/centralized-security-management.component.ts
  4. +8
    -6
      src/app/modules/homepage/homepage/home-page.component.ts
  5. +1
    -1
      src/app/modules/homepage/security-system-details/security-system-details.component.scss
  6. +9
    -14
      src/app/modules/homepage/security-system-details/security-system-details.component.ts
  7. +11
    -5
      src/app/shared/component/slider-range/slider-range.component.ts
  8. +5
    -4
      src/app/shared/services/mqtt-client.service.ts

+ 6
- 0
Dockerfile View File

@@ -4,3 +4,9 @@ FROM nginx:1.15.8-alpine
RUN sed -i 's/index index.html index.htm;/try_files $uri \/index.html;/' /etc/nginx/conf.d/default.conf

COPY /dist/lot-web-ui /usr/share/nginx/html

#FROM node:18-alpine
#WORKDIR /app
#COPY dist/ots-landing-page-ssr .
#EXPOSE 80
#CMD node server/server.mjs

+ 20
- 1
src/app/app.component.ts View File

@@ -8,6 +8,8 @@ import {
import { SocketService } from './shared/services/socket.service';
import { AlarmSoundService } from './shared/services/alarm-sound.service';
import {MqttClientService} from "./shared/services/mqtt-client.service";
import {takeUntil} from "rxjs/operators";
import {filter, Subject} from "rxjs";

@Component({
selector: 'app-root',
@@ -16,11 +18,28 @@ import {MqttClientService} from "./shared/services/mqtt-client.service";
})
export class AppComponent implements OnInit {
title = 'Iot-web-ui';

private unsubscribeAll = new Subject();
isConnected = false;
constructor(private socketService$: SocketService, private mqtt$: MqttClientService) {}

ngOnInit() {
// this.socketService$.connect();
this.mqtt$.createConnection();
this.mqtt$.status$.pipe(takeUntil(this.unsubscribeAll)).subscribe(
(isConnected: boolean) => {
this.isConnected = isConnected;
this.mqtt$.getLog();
this.mqtt$.sendPublish({ id: '0', type: 'get', whistletime: ''});
this.mqtt$.sendPublish({ id: '0', type: 'get', arlamtime: ''});
this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe((message: any) => {
if (message.id == '0' && message.whistletime) {
localStorage.setItem('whistletime', message.whistletime);
}
if (message.id == '0' && message.arlamtime) {
localStorage.setItem('alarmtime', message.arlamtime);
}
});
},
);
}
}

+ 22
- 25
src/app/modules/homepage/centralized-security-management/centralized-security-management.component.ts View File

@@ -7,12 +7,14 @@ import {
} from '@angular/core';
import * as L from 'leaflet';
import 'leaflet.markercluster';
import { Subscription, take } from 'rxjs';
import {filter, 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";
import {MqttClientService} from "../../../shared/services/mqtt-client.service";

@Component({
selector: 'app-centralized-security-management',
@@ -24,8 +26,6 @@ export class CentralizedSecurityManagementComponent
{
private map!: L.Map;
private markers!: L.MarkerClusterGroup;
private statusSubscription?: Subscription;
private messageSubscription?: Subscription;
data = alarmData;
alarmDemo = alarmDemo;
state1 = false;
@@ -34,25 +34,25 @@ export class CentralizedSecurityManagementComponent
status2 = false;
state5 = false;
state6 = false;
isReady = true;

private unsubscribeAll = new Subject();
constructor(
private socketService$: SocketService,
private dialog: MatDialog,
private renderer: Renderer2,
private alarmSoundService$: AlarmSoundService,
private mqtt$: MqttClientService
) {}

ngOnInit() {
this.statusSubscription = this.socketService$.status$.subscribe(
this.mqtt$.status$.pipe(takeUntil(this.unsubscribeAll)).subscribe(
(isConnected) => {
if (isConnected) {
this.socketService$.sendMessage({ id: '0', type: 'get' });
this.messageSubscription = this.socketService$.messages$.subscribe(
(message) => {
this.onMessage(message);
},
);
this.mqtt$.getLog();
this.mqtt$.sendPublish({ id: '0', type: 'get' });
this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe(message => {
console.log('map:',message);
this.onMessage(message);
});
}
},
);
@@ -70,10 +70,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,14 +97,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';
this.alarmSoundService$.startAlarm(this.state5, this.state1,this.status1, this.state2, this.status2);
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.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>`;
}


+ 8
- 6
src/app/modules/homepage/homepage/home-page.component.ts View File

@@ -1,6 +1,6 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
import {SocketService} from "../../../shared/services/socket.service";
import {Subscription, Subject} from "rxjs";
import {Subscription, Subject, filter, take} from "rxjs";
import {MqttClientService} from "../../../shared/services/mqtt-client.service";
import {takeUntil} from "rxjs/operators";

@@ -28,10 +28,13 @@ export class HomePageComponent implements OnInit,OnDestroy{
(isConnected: boolean) => {
this.isConnected = isConnected;
this.mqtt$.getLog();
this.mqtt$.sendPublish({ id: '0', type: 'get', whistletime: ''});
this.mqtt$.sendPublish({ id: '0', type: 'get', arlamtime: ''});
this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll)).subscribe((message: any) => {
console.log(message);
setTimeout(() => {
this.mqtt$.sendPublish({ id: '0', type: 'get', whistletime: ''});
}, 500);
setTimeout(() => {
this.mqtt$.sendPublish({ id: '0', type: 'get', arlamtime: ''});
}, 1000);
this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe((message: any) => {
if (message.id == '0' && message.whistletime) {
this.whistle.time = Number(message.whistletime);
}
@@ -47,7 +50,6 @@ export class HomePageComponent implements OnInit,OnDestroy{

emitSetting(type: string, event: any){
if (this.isConnected) {
console.log(event);
if (type === 'whistle') {
this.whistle.time = event;
this.mqtt$.sendPublish({ id: '0', type: 'set', whistletime: event.toString()});

+ 1
- 1
src/app/modules/homepage/security-system-details/security-system-details.component.scss View File

@@ -142,7 +142,7 @@ p {
.sensor-on {
width: 30px;
height: 30px;
position: absolute;
position: relative;
background: linear-gradient(#ff0000, #c70039);
display: flex !important;
justify-content: center;

+ 9
- 14
src/app/modules/homepage/security-system-details/security-system-details.component.ts View File

@@ -1,11 +1,12 @@
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from "rxjs";
import {debounceTime, filter, Subject, Subscription} from "rxjs";
import {SocketService} from "../../../shared/services/socket.service";
import {CameraDialogComponent} from "../../../shared/component/camera-dialog/camera-dialog.component";
import {MatDialog} from "@angular/material/dialog";
import { ConfirmDialogService } from '../../../shared/services/confirm-dialog.service';
import { AlarmSoundService } from "../../../shared/services/alarm-sound.service";
import { MqttClientService } from "../../../shared/services/mqtt-client.service";
import {takeUntil} from "rxjs/operators";

@Component({
selector: 'app-security-system-details',
@@ -25,10 +26,8 @@ export class SecuritySystemDetailsComponent implements OnInit, OnDestroy {
switchArm = false;
switchWarning = false;
isReady = true;
private statusSubscription?: Subscription;
private messageSubscription?: Subscription;
private intervalId: any;
private unsubscribeAll = new Subject();

constructor(
private socketService$: SocketService,
@@ -39,12 +38,13 @@ export class SecuritySystemDetailsComponent implements OnInit, OnDestroy {
) {}

ngOnInit() {
this.statusSubscription = this.mqtt$.status$.subscribe((isConnected) => {
this.mqtt$.status$.pipe(takeUntil(this.unsubscribeAll)).subscribe((isConnected) => {
this.isConnected = isConnected;
if (isConnected){
this.mqtt$.getLog();
this.messageSubscription = this.mqtt$.messages$.subscribe(message => {
console.log('MQTT sup msg: ',message);
this.mqtt$.sendPublish({ id: '0', type: 'get'});
this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe(message => {
console.log('detail:',message);
this.onMessage(message);
});
}
@@ -52,16 +52,11 @@ export class SecuritySystemDetailsComponent implements OnInit, OnDestroy {
}

ngOnDestroy(): void {
if (this.statusSubscription) {
this.statusSubscription.unsubscribe();
}
if (this.messageSubscription) {
this.messageSubscription.unsubscribe();
}
this.unsubscribeAll.next('');
this.unsubscribeAll.complete();
if (this.intervalId) {
clearInterval(this.intervalId);
}
this.socketService$.close();
this.alarmSoundService$.stopAlarm();
}


+ 11
- 5
src/app/shared/component/slider-range/slider-range.component.ts View File

@@ -6,6 +6,7 @@ import {
Output,
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import {debounceTime, Subject} from 'rxjs';

@Component({
selector: 'app-slider-range',
@@ -25,11 +26,15 @@ export class SliderRangeComponent implements ControlValueAccessor {
@Input() icon: string = '';
@Input() disable: boolean = false;
@Output() valueChange = new EventEmitter<number>();

onChange = (value: number) => {};
onTouched = () => {};
private valueChangeSubject = new Subject<number>();

constructor() {}
constructor() {
this.valueChangeSubject.pipe(debounceTime(500)).subscribe(value => {
this.valueChange.emit(value);
});
}

writeValue(value: number): void {
this.value = value;
@@ -51,7 +56,7 @@ export class SliderRangeComponent implements ControlValueAccessor {
this.value = event.target.value;
this.onChange(this.value);
this.onTouched();
this.valueChange.emit(this.value);
this.valueChangeSubject.next(this.value);
}

onSliderChangeBackground() {
@@ -89,7 +94,8 @@ export class SliderRangeComponent implements ControlValueAccessor {
this.value += 10;
this.onChange(this.value);
this.onTouched();
this.valueChange.emit(this.value);
this.valueChangeSubject.next(this.value);

}
}

@@ -98,7 +104,7 @@ export class SliderRangeComponent implements ControlValueAccessor {
this.value -= 10;
this.onChange(this.value);
this.onTouched();
this.valueChange.emit(this.value);
this.valueChangeSubject.next(this.value);
}
}
}

+ 5
- 4
src/app/shared/services/mqtt-client.service.ts View File

@@ -30,7 +30,7 @@ export class MqttClientService {
isConnection = false;
private statusSubject = new BehaviorSubject<boolean>(this.isConnection);
public status$ = this.statusSubject.asObservable();
private messagesSubject$ = new Subject();
private messagesSubject$ = new BehaviorSubject(null);
public messages$ = this.messagesSubject$.asObservable();

// 创建连接
@@ -63,13 +63,13 @@ export class MqttClientService {
topic: 'isoft/node 4/log4',
qos: 0,
};
this.client?.observe(topic, { qos } as IClientSubscribeOptions).subscribe((message: IMqttMessage) => {
this.client?.observe(topic, { qos, dup: false } as IClientSubscribeOptions).subscribe((message: IMqttMessage) => {
try {
console.log('Subscribe to topics res', message.payload.toString());
var plainMessage = "";
let plainMessage = "";
for (var i = 0; i < message.payload.length; i++) {
plainMessage += String.fromCharCode(parseInt(String(message.payload[i])));
}
console.log(JSON.parse(plainMessage));
this.messagesSubject$.next(JSON.parse(plainMessage));
}catch (e) {
console.log(e);
@@ -88,6 +88,7 @@ export class MqttClientService {
// 发送消息
sendPublish(data: any) {
this.client?.unsafePublish("isoft/node 4/in4", JSON.stringify(data), {qos: 0} as IPublishOptions);
// this.client?.publish("isoft/node 4/in4", JSON.stringify(data), {qos: 0} as IPublishOptions).subscribe();
}
// 断开连接
destroyConnection() {

Loading…
Cancel
Save