member_webapp/@overflow/probe/component/list/list.component.ts

95 lines
2.4 KiB
TypeScript
Raw Normal View History

2018-05-18 08:30:20 +00:00
import { Component, OnInit, AfterViewInit, AfterContentInit, ViewChild, OnDestroy, Output, EventEmitter } from '@angular/core';
2018-04-06 13:02:46 +00:00
import { Store, select } from '@ngrx/store';
2018-04-06 11:02:18 +00:00
2018-05-24 06:44:13 +00:00
import { RPCClientError } from '@loafer/ng-rpc';
2018-05-02 08:09:39 +00:00
import { Domain } from '@overflow/commons-typescript/model/domain';
2018-05-24 06:44:13 +00:00
import { AuthSelector } from '@overflow/member/store';
2018-04-06 11:02:18 +00:00
2018-05-02 08:09:39 +00:00
import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe';
2018-05-24 10:50:43 +00:00
import * as ProbeStore from '../../store/probe';
import { ProbeSelector } from '../../store';
2018-04-29 10:43:14 +00:00
import { Subscription } from 'rxjs/Subscription';
2018-04-06 11:02:18 +00:00
2018-04-06 13:02:46 +00:00
@Component({
selector: 'of-probe-list',
templateUrl: './list.component.html',
})
2018-05-18 08:30:20 +00:00
export class ProbeListComponent implements OnInit, AfterContentInit, OnDestroy {
2018-04-29 10:43:14 +00:00
probeHostsSubscription$: Subscription;
2018-05-24 10:50:43 +00:00
probeHosts$ = this.store.pipe(select(ProbeSelector.select('probes')));
2018-04-25 09:04:47 +00:00
probeHosts: ProbeHost[];
2018-04-11 06:20:23 +00:00
2018-05-18 08:30:20 +00:00
@Output() select = new EventEmitter<Probe>();
2018-04-06 13:02:46 +00:00
constructor(
2018-05-24 10:50:43 +00:00
private store: Store<ProbeStore.State>
2018-04-06 13:02:46 +00:00
) {
}
2018-04-06 11:02:18 +00:00
2018-04-16 08:28:39 +00:00
ngOnInit() {
2018-04-29 10:43:14 +00:00
this.probeHostsSubscription$ = this.probeHosts$.subscribe(
2018-04-25 09:04:47 +00:00
(probeHosts: ProbeHost[]) => {
this.probeHosts = probeHosts;
2018-04-16 03:52:51 +00:00
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
2018-04-16 08:28:39 +00:00
}
ngAfterContentInit() {
2018-05-24 10:50:43 +00:00
this.store.select(AuthSelector.select('domain')).subscribe(
(domain: Domain) => {
this.store.dispatch(new ProbeStore.ReadAllByDomainID(domain.id));
2018-04-16 08:28:39 +00:00
},
2018-05-24 10:50:43 +00:00
(error) => {
console.log(error);
2018-04-16 08:28:39 +00:00
}
2018-05-24 10:50:43 +00:00
);
// 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);
2018-05-18 08:30:20 +00:00
2018-04-29 10:43:14 +00:00
}
2018-04-06 11:02:18 +00:00
2018-04-29 10:43:14 +00:00
ngOnDestroy() {
if (this.probeHostsSubscription$) {
this.probeHostsSubscription$.unsubscribe();
}
2018-04-06 13:02:46 +00:00
}
2018-04-06 11:02:18 +00:00
2018-04-09 11:03:15 +00:00
onRowSelect(event) {
2018-05-18 08:30:20 +00:00
this.select.emit(event.data.probe);
2018-04-06 13:02:46 +00:00
}
2018-05-14 09:02:48 +00:00
getUptime(probe: Probe) {
// if (probe.connectDate === null || probe.connectDate ==== undefined) {
// return 'Not Connected.';
// }
// const currentDate = new Date();
2018-05-18 08:30:20 +00:00
return 'Uptime';
2018-05-14 09:02:48 +00:00
}
2018-04-06 13:02:46 +00:00
}