probe store container components
This commit is contained in:
parent
7852cd0081
commit
5893e35095
|
@ -1,87 +1,19 @@
|
||||||
import { Component, OnInit, AfterViewInit, AfterContentInit, ViewChild, OnDestroy, Output, EventEmitter } from '@angular/core';
|
import { Component, OnInit, AfterViewInit, AfterContentInit, ViewChild, OnDestroy, Output, EventEmitter, Input } from '@angular/core';
|
||||||
import { Store, select } from '@ngrx/store';
|
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
|
||||||
|
|
||||||
import { RPCClientError } from '@loafer/ng-rpc';
|
|
||||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
|
||||||
import { AuthSelector } from '@overflow/member/store';
|
|
||||||
|
|
||||||
import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe';
|
|
||||||
import * as ProbeStore from '../../store/probe';
|
|
||||||
import { ProbeSelector } from '../../store';
|
|
||||||
import { Subscription } from 'rxjs/Subscription';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'of-probe-list',
|
selector: 'of-probe-list',
|
||||||
templateUrl: './list.component.html',
|
templateUrl: './list.component.html',
|
||||||
})
|
})
|
||||||
export class ProbeListComponent implements OnInit, AfterContentInit, OnDestroy {
|
export class ProbeListComponent {
|
||||||
probeHostsSubscription$: Subscription;
|
@Output() select = new EventEmitter<ProbeHost>();
|
||||||
probeHosts$ = this.store.pipe(select(ProbeSelector.select('probes')));
|
@Input() probeHosts: ProbeHost[];
|
||||||
probeHosts: ProbeHost[];
|
|
||||||
|
|
||||||
@Output() select = new EventEmitter<Probe>();
|
constructor() {
|
||||||
|
|
||||||
constructor(
|
|
||||||
private store: Store<ProbeStore.State>
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
this.probeHostsSubscription$ = this.probeHosts$.subscribe(
|
|
||||||
(probeHosts: ProbeHost[]) => {
|
|
||||||
this.probeHosts = probeHosts;
|
|
||||||
},
|
|
||||||
(error: RPCClientError) => {
|
|
||||||
console.log(error.response.message);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngAfterContentInit() {
|
|
||||||
this.store.select(AuthSelector.select('domain')).subscribe(
|
|
||||||
(domain: Domain) => {
|
|
||||||
this.store.dispatch(new ProbeStore.ReadAllByDomainID(domain.id));
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// temp
|
|
||||||
// const probeHost: ProbeHost = {
|
|
||||||
// id: 1,
|
|
||||||
// probe: {
|
|
||||||
// id: 1,
|
|
||||||
// displayName: 'ddd',
|
|
||||||
// cidr: 'dddd',
|
|
||||||
// authorizeDate: new Date(),
|
|
||||||
// authorizeMember: {
|
|
||||||
// name: 'ddd'
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// host: {
|
|
||||||
// id: 1,
|
|
||||||
// ipv4: 'aaaa',
|
|
||||||
// os: {
|
|
||||||
// vendor: {
|
|
||||||
// name: 'dd'
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// this.probeHosts = [];
|
|
||||||
// this.probeHosts.push(probeHost);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy() {
|
|
||||||
if (this.probeHostsSubscription$) {
|
|
||||||
this.probeHostsSubscription$.unsubscribe();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onRowSelect(event) {
|
onRowSelect(event) {
|
||||||
this.select.emit(event.data.probe);
|
this.select.emit(event.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
getUptime(probe: Probe) {
|
getUptime(probe: Probe) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<of-probe-list (select)="onSelect($event)"></of-probe-list>
|
<of-probe-list (select)="onSelect($event)" [probeHosts]="probeHosts$ | async"></of-probe-list>
|
|
@ -1,14 +1,41 @@
|
||||||
import { Component, EventEmitter, Output } from '@angular/core';
|
import { Component, EventEmitter, Output, OnInit, AfterContentInit } from '@angular/core';
|
||||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
import { ProbeHost } from '@overflow/commons-typescript/model/probe';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { Store, select } from '@ngrx/store';
|
||||||
|
import * as ProbeStore from '../store/probe';
|
||||||
|
import { ProbeSelector } from '../store';
|
||||||
|
import { AuthSelector } from '@overflow/member/store';
|
||||||
|
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'of-probe-list-container',
|
selector: 'of-probe-list-container',
|
||||||
templateUrl: './probe-list-container.html',
|
templateUrl: './probe-list-container.html',
|
||||||
})
|
})
|
||||||
export class ProbeListContainerComponent {
|
export class ProbeListContainerComponent implements OnInit, AfterContentInit {
|
||||||
|
|
||||||
|
probeHosts$: Observable<ProbeHost[]>;
|
||||||
@Output() select = new EventEmitter();
|
@Output() select = new EventEmitter();
|
||||||
|
|
||||||
onSelect(probe: Probe) {
|
constructor(private store: Store<ProbeStore.State>) {
|
||||||
this.select.emit(probe);
|
this.probeHosts$ = store.pipe(select(ProbeSelector.select('probeHosts')));
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelect(probeHost: ProbeHost) {
|
||||||
|
this.select.emit(probeHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.store.select(AuthSelector.select('domain')).subscribe(
|
||||||
|
(domain: Domain) => {
|
||||||
|
this.store.dispatch(new ProbeStore.ReadAllByDomainID(domain.id));
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngAfterContentInit() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,3 +28,4 @@ export const ProbeSelector = new StateSelector<ProbeStore.State>(createSelector(
|
||||||
selectProbeState,
|
selectProbeState,
|
||||||
(state: State) => state.probes
|
(state: State) => state.probes
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
restBaseURL: 'http://192.168.1.50:19080/webapp',
|
restBaseURL: 'http://192.168.1.50:19080/webapp',
|
||||||
webappRPCConfig: {
|
webappRPCConfig: {
|
||||||
url: 'ws://192.168.1.50:19090/webapp',
|
url: 'ws://192.168.1.101:19090/webapp',
|
||||||
reconnectInterval: 5000,
|
reconnectInterval: 5000,
|
||||||
reconnectRetry: 10,
|
reconnectRetry: 10,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user