2018-05-04 04:11:59 +00:00
|
|
|
import { Component, OnInit, AfterContentInit, Output, EventEmitter,
|
|
|
|
Input, OnDestroy, OnChanges, SimpleChanges, ViewChild } from '@angular/core';
|
2018-05-03 11:45:49 +00:00
|
|
|
import { Store, select, StateObservable } from '@ngrx/store';
|
2018-04-10 10:20:44 +00:00
|
|
|
import { RPCClientError } from '@loafer/ng-rpc/protocol';
|
|
|
|
import {
|
|
|
|
DiscoveryStartInfo,
|
2018-04-27 16:29:54 +00:00
|
|
|
DiscoverZone,
|
2018-04-10 10:20:44 +00:00
|
|
|
Zone,
|
2018-04-27 16:29:54 +00:00
|
|
|
DiscoverPort,
|
|
|
|
DiscoverService
|
2018-05-02 07:23:35 +00:00
|
|
|
} from '@overflow/commons-typescript/model/discovery';
|
2018-04-10 10:20:44 +00:00
|
|
|
import * as CIDR from 'ip-cidr';
|
|
|
|
import * as DiscoveredStore from '../../store/setting';
|
|
|
|
import { SettingSelector, DiscoverSelector } from '../../store';
|
|
|
|
import * as DiscoverStore from '../../store/discover';
|
|
|
|
import * as RegistStore from '../../store/regist';
|
2018-05-02 07:23:35 +00:00
|
|
|
import { Host } from '@overflow/commons-typescript/model/discovery';
|
|
|
|
import { Port } from '@overflow/commons-typescript/model/discovery';
|
|
|
|
import { Service } from '@overflow/commons-typescript/model/discovery';
|
2018-04-10 10:20:44 +00:00
|
|
|
import * as ProbeDetailStore from 'packages/probe/store';
|
2018-05-02 07:23:35 +00:00
|
|
|
import { Probe } from '@overflow/commons-typescript/model/probe';
|
2018-04-10 10:20:44 +00:00
|
|
|
import { TreeNode } from 'primeng/primeng';
|
2018-05-03 11:45:49 +00:00
|
|
|
import { ListSelector as ProbeListSelector } from 'packages/probe/store';
|
|
|
|
import * as ProbeListStore from 'packages/probe/store/list';
|
|
|
|
import { AuthSelector } from 'packages/member/store';
|
|
|
|
import { Domain } from '@overflow/commons-typescript/model/domain';
|
|
|
|
import { Subscription } from 'rxjs/Subscription';
|
2018-05-04 04:11:59 +00:00
|
|
|
import { ResultComponent } from './result/result.component';
|
|
|
|
import { ProbeSelectorComponent } from './probe-selector/probe-selector.component';
|
|
|
|
import { FilterComponent } from './filter/filter.component';
|
2018-04-10 10:20:44 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-discovery-setting',
|
|
|
|
templateUrl: './setting.component.html',
|
|
|
|
})
|
2018-05-03 11:45:49 +00:00
|
|
|
export class SettingComponent implements OnInit, AfterContentInit, OnDestroy, OnChanges {
|
2018-04-10 10:20:44 +00:00
|
|
|
|
2018-05-04 02:20:07 +00:00
|
|
|
@Input() visible: boolean;
|
2018-05-03 11:45:49 +00:00
|
|
|
@Input() probe: Probe;
|
2018-04-13 10:32:17 +00:00
|
|
|
@Output() close = new EventEmitter();
|
2018-05-03 11:45:49 +00:00
|
|
|
private requestStart = false;
|
|
|
|
private started = false;
|
2018-04-10 10:20:44 +00:00
|
|
|
|
2018-05-03 11:45:49 +00:00
|
|
|
private selectedProbe: Probe;
|
2018-05-03 13:27:11 +00:00
|
|
|
private height: number;
|
2018-04-10 10:20:44 +00:00
|
|
|
|
2018-05-04 04:11:59 +00:00
|
|
|
@ViewChild('probeSelectorComponent') probeSelectorComponent: ProbeSelectorComponent;
|
|
|
|
@ViewChild('filterComponent') filterComponent: FilterComponent;
|
|
|
|
@ViewChild('resultComponent') resultComponent: ResultComponent;
|
|
|
|
|
2018-04-10 10:20:44 +00:00
|
|
|
constructor(
|
2018-05-03 11:45:49 +00:00
|
|
|
private discoverStore: Store<DiscoverStore.State>,
|
2018-04-10 10:20:44 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-05-04 04:11:59 +00:00
|
|
|
this.selectedProbe = this.probe;
|
|
|
|
this.height = window.innerHeight * 0.9;
|
2018-04-10 10:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterContentInit() {
|
|
|
|
}
|
|
|
|
|
2018-05-03 11:45:49 +00:00
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
2018-05-04 04:11:59 +00:00
|
|
|
if (changes['visible']) {
|
|
|
|
const change = changes['visible'];
|
|
|
|
if (!change.previousValue && change.currentValue) {
|
|
|
|
this.initAll();
|
|
|
|
} else if (change.previousValue && !change.currentValue) {
|
|
|
|
this.destroyAll();
|
|
|
|
}
|
2018-04-10 10:20:44 +00:00
|
|
|
}
|
2018-04-16 08:13:25 +00:00
|
|
|
}
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-05-03 11:45:49 +00:00
|
|
|
ngOnDestroy() {
|
2018-05-04 04:11:59 +00:00
|
|
|
this.selectedProbe = null;
|
|
|
|
this.started = false;
|
|
|
|
this.close.emit();
|
|
|
|
this.requestStart = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
initAll() {
|
|
|
|
this.ngOnInit();
|
|
|
|
if (this.probeSelectorComponent) {
|
|
|
|
this.probeSelectorComponent.ngOnInit();
|
|
|
|
}
|
|
|
|
if (this.filterComponent) {
|
|
|
|
this.filterComponent.ngOnInit();
|
|
|
|
}
|
|
|
|
if (this.resultComponent) {
|
|
|
|
this.resultComponent.ngOnInit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
destroyAll() {
|
|
|
|
this.ngOnDestroy();
|
|
|
|
if (this.probeSelectorComponent) {
|
|
|
|
this.probeSelectorComponent.ngOnDestroy();
|
|
|
|
}
|
|
|
|
if (this.filterComponent) {
|
|
|
|
this.filterComponent.ngOnDestroy();
|
|
|
|
}
|
|
|
|
if (this.resultComponent) {
|
|
|
|
this.resultComponent.ngOnDestroy();
|
|
|
|
}
|
2018-04-16 08:13:25 +00:00
|
|
|
}
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-05-03 11:45:49 +00:00
|
|
|
onProbeSelect(probe: Probe) {
|
|
|
|
this.selectedProbe = probe;
|
2018-04-10 10:20:44 +00:00
|
|
|
}
|
|
|
|
|
2018-05-03 11:45:49 +00:00
|
|
|
onDiscoveryStart(discoverZone: DiscoverZone) {
|
2018-05-04 04:11:59 +00:00
|
|
|
console.log('DiscoveryStart requested');
|
2018-05-04 02:20:07 +00:00
|
|
|
this.discoverStore.dispatch(new DiscoverStore.DiscoverZone(
|
|
|
|
{ probeID: this.selectedProbe.probeKey, discoverZone: discoverZone }));
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-05-03 11:45:49 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
this.started = true;
|
|
|
|
this.requestStart = false;
|
2018-04-10 10:20:44 +00:00
|
|
|
});
|
|
|
|
}
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-05-03 11:45:49 +00:00
|
|
|
onCancel() {
|
2018-05-04 04:11:59 +00:00
|
|
|
this.destroyAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
onSave() {
|
|
|
|
this.resultComponent.save();
|
2018-04-10 10:20:44 +00:00
|
|
|
}
|
2018-05-03 11:55:14 +00:00
|
|
|
|
2018-04-10 10:20:44 +00:00
|
|
|
}
|