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

96 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-04-25 09:04:47 +00:00
import * as ListStore from '../../store/probe-host-list';
import { ProbeHostListSelector } 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-04-25 09:04:47 +00:00
probeHosts$ = this.store.pipe(select(ProbeHostListSelector.select('probeHosts')));
probeHosts: ProbeHost[];
2018-04-11 06:20:23 +00:00
2018-05-18 08:30:20 +00:00
@Output() select = new EventEmitter<Probe>();
val;
2018-04-06 13:02:46 +00:00
constructor(
private store: Store<ListStore.State>
) {
}
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-18 08:30:20 +00:00
// this.store.select(AuthSelector.select('domain')).subscribe(
// (domain: Domain) => {
// this.store.dispatch(new ListStore.ReadAllByDomain(domain));
// },
// (error) => {
// console.log(error);
// }
// );
// temp
const probeHost: ProbeHost = {
id: 1,
probe: {
id: 1,
displayName: 'ddd',
cidr: 'dddd',
authorizeDate: new Date(),
authorizeMember: {
name: 'ddd'
}
2018-04-16 08:28:39 +00:00
},
2018-05-18 08:30:20 +00:00
host: {
id: 1,
ipv4: 'aaaa',
os: {
vendor: {
name: 'dd'
}
},
2018-04-16 08:28:39 +00:00
}
2018-05-18 08:30:20 +00:00
};
this.probeHosts = [];
this.probeHosts.push(probeHost);
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
}