2018-04-18 11:28:53 +00:00
|
|
|
import { Component, OnInit, Inject, AfterContentInit } from '@angular/core';
|
2018-04-16 06:00:05 +00:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2018-04-18 11:28:53 +00:00
|
|
|
import { ConfirmationService } from 'primeng/primeng';
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import { RPCClientError } from '@loafer/ng-rpc/protocol';
|
|
|
|
import * as DetailStore from '../../store/detail';
|
|
|
|
import { sensorSelector } from '../../store';
|
|
|
|
import { Sensor } from '../../model';
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-04-16 06:00:05 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'of-sensor-detail',
|
|
|
|
templateUrl: './detail.component.html',
|
2018-04-18 11:28:53 +00:00
|
|
|
providers: [ConfirmationService]
|
2018-04-16 06:00:05 +00:00
|
|
|
})
|
2018-04-18 11:28:53 +00:00
|
|
|
export class DetailComponent implements OnInit, AfterContentInit {
|
|
|
|
|
|
|
|
sensor$ = this.detailStore.pipe(select(sensorSelector.select('sensor')));
|
|
|
|
sensor: Sensor;
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-04-16 06:00:05 +00:00
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
2018-04-18 11:28:53 +00:00
|
|
|
private confirmationService: ConfirmationService,
|
|
|
|
private detailStore: Store<DetailStore.State>,
|
2018-04-16 06:00:05 +00:00
|
|
|
) { }
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-04-16 06:00:05 +00:00
|
|
|
ngOnInit() {
|
2018-04-18 11:28:53 +00:00
|
|
|
this.sensor$.subscribe(
|
|
|
|
(sensor: Sensor) => {
|
|
|
|
console.log(sensor);
|
|
|
|
this.sensor = sensor;
|
|
|
|
},
|
|
|
|
(error: RPCClientError) => {
|
|
|
|
console.log(error.response.message);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterContentInit() {
|
|
|
|
const sensorId = this.route.snapshot.paramMap.get('id');
|
|
|
|
this.detailStore.dispatch(
|
|
|
|
new DetailStore.Read(
|
|
|
|
{ id: sensorId }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onStartOrStop() { }
|
|
|
|
|
|
|
|
onEdit() { }
|
|
|
|
|
|
|
|
onRemove() {
|
|
|
|
this.confirmationService.confirm({
|
|
|
|
header: 'Are you sure to remove this Sensor?',
|
|
|
|
icon: 'fa fa-trash',
|
|
|
|
message: 'All the related data will be deleted. ',
|
|
|
|
accept: () => {
|
|
|
|
alert('으앙 안돼 지우지마ㅠㅠ');
|
|
|
|
},
|
|
|
|
reject: () => {
|
|
|
|
}
|
|
|
|
});
|
2018-04-16 06:00:05 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-06 11:02:18 +00:00
|
|
|
|