This commit is contained in:
crusader 2018-06-04 19:03:59 +09:00
parent a2021b84e0
commit c47bb4fad5
10 changed files with 215 additions and 111 deletions

View File

@ -30,6 +30,7 @@ export class NoAuthProbeListComponent implements OnInit, OnDestroy {
private noAuthProbeSubscriber: NoAuthProbeSubscriber, private noAuthProbeSubscriber: NoAuthProbeSubscriber,
) { ) {
this.noauthProbes = []; this.noauthProbes = [];
this.noauthProbeSubscription = null;
} }
ngOnInit() { ngOnInit() {
@ -75,8 +76,10 @@ export class NoAuthProbeListComponent implements OnInit, OnDestroy {
} }
ngOnDestroy(): void { ngOnDestroy(): void {
if (null !== this.noauthProbeSubscription) {
this.noauthProbeSubscription.unsubscribe(); this.noauthProbeSubscription.unsubscribe();
} }
}
onAcceptOrDeny(isAccept: boolean, selected: NoAuthProbe) { onAcceptOrDeny(isAccept: boolean, selected: NoAuthProbe) {
const title = isAccept ? const title = isAccept ?

View File

@ -3,7 +3,7 @@
<of-block-progressbar [target]="content" [pending]="pending$ | async"></of-block-progressbar> <of-block-progressbar [target]="content" [pending]="pending$ | async"></of-block-progressbar>
<p-panel #content [showHeader]="false" class="block-panel"> <p-panel #content [showHeader]="false" class="block-panel">
<p-table [value]="probeHosts$ | async" selectionMode="single" (onRowSelect)="onProbeSelect($event)" [resizableColumns]="true"> <p-table [value]="probeHosts" selectionMode="single" (onRowSelect)="onProbeSelect($event)" [resizableColumns]="true">
<ng-template pTemplate="header"> <ng-template pTemplate="header">
<tr> <tr>
<th>Probe Name</th> <th>Probe Name</th>

View File

@ -1,7 +1,7 @@
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core'; import { Component, OnInit, Output, EventEmitter, Input, OnDestroy } from '@angular/core';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { Observable, of } from 'rxjs'; import { Observable, Subscription, of } from 'rxjs';
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators'; import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
import { AuthSelector } from '@overflow/shared/auth/store'; import { AuthSelector } from '@overflow/shared/auth/store';
@ -9,22 +9,27 @@ import { DomainMember } from '@overflow/commons-typescript/model/domain';
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe'; import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
import { ProbeHostService } from '../service/probe-host.service'; import { ProbeHostService } from '../service/probe-host.service';
import { ProbeSubscriber, ProbeNotify } from '../subscriber/probe.subscriber';
@Component({ @Component({
selector: 'of-probe-list', selector: 'of-probe-list',
templateUrl: './probe-list.component.html', templateUrl: './probe-list.component.html',
}) })
export class ProbeListComponent implements OnInit { export class ProbeListComponent implements OnInit, OnDestroy {
@Output() select = new EventEmitter<ProbeHost>();
probeHosts$: Observable<ProbeHost[]>; probeHosts: ProbeHost[];
pending$: Observable<boolean>; pending$: Observable<boolean>;
error$: Observable<any>; error$: Observable<any>;
@Output() select = new EventEmitter<ProbeHost>();
probeSubscription: Subscription;
constructor( constructor(
private store: Store<any>, private store: Store<any>,
private probeHostService: ProbeHostService, private probeHostService: ProbeHostService,
private probeSubscriber: ProbeSubscriber,
) { ) {
this.probeSubscription = null;
} }
ngOnInit(): void { ngOnInit(): void {
@ -37,7 +42,7 @@ export class ProbeListComponent implements OnInit {
this.probeHostService.readAllByDomainID(domainMember.domain.id) this.probeHostService.readAllByDomainID(domainMember.domain.id)
.pipe( .pipe(
map((probeHosts: ProbeHost[]) => { map((probeHosts: ProbeHost[]) => {
this.probeHosts$ = of(probeHosts); this.probeHosts = probeHosts;
}), }),
catchError(error => { catchError(error => {
this.error$ = of(error); this.error$ = of(error);
@ -50,6 +55,28 @@ export class ProbeListComponent implements OnInit {
}), }),
take(1), take(1),
).subscribe(); ).subscribe();
this.probeSubscription = this.probeSubscriber.observable().pipe(
tap((probeNotify: ProbeNotify) => {
const probeHosts = [];
this.probeHosts.forEach(probeHost => {
const n = probeNotify.params;
if (probeHost.probe.id === n.id) {
probeHost.probe = n;
}
probeHosts.push(probeHost);
});
this.probeHosts = probeHosts;
}
),
).subscribe();
}
ngOnDestroy(): void {
if (null !== this.probeSubscription) {
this.probeSubscription.unsubscribe();
}
} }
onProbeSelect(event) { onProbeSelect(event) {
@ -60,7 +87,8 @@ export class ProbeListComponent implements OnInit {
// if (!probe.connectDate) { // if (!probe.connectDate) {
// return 'Not Connected.'; // return 'Not Connected.';
// } // }
// const hours = Math.abs(new Date().getTime() - probe.connectDate.getTime()); // const connectDate = new Date(probe.connectDate);
// const hours = Math.abs(new Date().getTime() - connectDate.getTime());
// return this.convertUptimeString(hours); // return this.convertUptimeString(hours);
} }

View File

@ -0,0 +1,10 @@
import { NgModule } from '@angular/core';
import { LoggerModule } from '@loafer/ng-logger';
@NgModule({
imports: [
LoggerModule.forFeature({}),
],
})
export class ProbeLoggerModule { }

View File

@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { RPCModule } from '@loafer/ng-rpc';
import {
SUBSCRIBERS,
} from './subscriber';
@NgModule({
imports: [
RPCModule.forFeature(SUBSCRIBERS),
],
})
export class ProbeRPCModule { }

View File

@ -4,6 +4,10 @@ import { CommonModule } from '@angular/common';
import { COMPONENTS } from './component'; import { COMPONENTS } from './component';
import { SERVICES } from './service'; import { SERVICES } from './service';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { ProbeRPCModule } from './probe-rpc.module';
import { ProbeLoggerModule } from './probe-logger.module';
import { MetaModule } from '@overflow/meta/meta.module'; import { MetaModule } from '@overflow/meta/meta.module';
// import { InfraModule } from '@overflow/infra/infra.module'; // import { InfraModule } from '@overflow/infra/infra.module';
import { UIModule } from '@overflow/shared/ui/ui.module'; import { UIModule } from '@overflow/shared/ui/ui.module';
@ -15,6 +19,8 @@ import { UIModule } from '@overflow/shared/ui/ui.module';
UIModule, UIModule,
MetaModule, MetaModule,
// InfraModule, // InfraModule,
ProbeRPCModule,
ProbeLoggerModule,
], ],
declarations: [ declarations: [
COMPONENTS, COMPONENTS,

View File

@ -0,0 +1,5 @@
import { ProbeSubscriber } from './probe.subscriber';
export const SUBSCRIBERS = [
ProbeSubscriber,
];

View File

@ -0,0 +1,53 @@
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { RPCSubscriber } from '@loafer/ng-rpc';
import { LoggerService } from '@loafer/ng-logger';
import { Probe } from '@overflow/commons-typescript/model/probe';
export interface ProbeNotify {
method: string;
params: Probe;
}
export class ProbeSubscriberSubject extends Subject<ProbeNotify> {
}
@Injectable()
export class ProbeSubscriber {
private probeSubscriberSubject: ProbeSubscriberSubject;
public constructor(
private loggerService: LoggerService,
) {
this.probeSubscriberSubject = null;
}
public observable(): Observable<ProbeNotify> {
if (null === this.probeSubscriberSubject) {
this.probeSubscriberSubject = new ProbeSubscriberSubject();
}
return this.probeSubscriberSubject.asObservable();
}
private publish(method: string, params: any): void {
this.probeSubscriberSubject.next({ method: method, params: params });
}
@RPCSubscriber({method: 'ProbeService.onConnect'})
public onConnect(probe: Probe): void {
this.loggerService.debug('ProbeService.onConnect probe:', probe);
this.publish('ProbeService.onConnect', probe);
}
@RPCSubscriber({method: 'ProbeService.onDisconnect'})
public onDisconnect(probe: Probe): void {
this.loggerService.debug('ProbeService.onDisconnect noAuthProbe:', probe);
this.publish('ProbeService.onDisconnect', probe);
}
}

186
package-lock.json generated
View File

@ -409,9 +409,9 @@
} }
}, },
"@loafer/ng-rpc": { "@loafer/ng-rpc": {
"version": "0.0.2", "version": "0.0.3",
"resolved": "https://nexus.loafle.net/repository/npm-all/@loafer/ng-rpc/-/ng-rpc-0.0.2.tgz", "resolved": "https://nexus.loafle.net/repository/npm-all/@loafer/ng-rpc/-/ng-rpc-0.0.3.tgz",
"integrity": "sha512-UkCljxw+1DXfug2bLyDoJpUvQCNmtBsx01KO4leBY7zk/afLE69Qq3ZFG2k7VbK0ZIIeBfJLGa4NUX/21J2RqQ==", "integrity": "sha512-OOr1KtD3hPrTzbrJWFDGVpBECEZpQaOGvM8kmbRMaZGxFOaku34TDTo5w22e5tF+MC4wd2Rec5roSY0g3Cj4JQ==",
"requires": { "requires": {
"tslib": "^1.9.0" "tslib": "^1.9.0"
} }
@ -3763,23 +3763,21 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"delegates": "1.0.0", "delegates": "^1.0.0",
"readable-stream": "2.3.6" "readable-stream": "^2.0.6"
} }
}, },
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
} }
}, },
@ -3792,20 +3790,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -3846,7 +3841,7 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"minipass": "2.2.4" "minipass": "^2.2.1"
} }
}, },
"fs.realpath": { "fs.realpath": {
@ -3861,14 +3856,14 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"aproba": "1.2.0", "aproba": "^1.0.3",
"console-control-strings": "1.1.0", "console-control-strings": "^1.0.0",
"has-unicode": "2.0.1", "has-unicode": "^2.0.0",
"object-assign": "4.1.1", "object-assign": "^4.1.0",
"signal-exit": "3.0.2", "signal-exit": "^3.0.0",
"string-width": "1.0.2", "string-width": "^1.0.1",
"strip-ansi": "3.0.1", "strip-ansi": "^3.0.1",
"wide-align": "1.1.2" "wide-align": "^1.1.0"
} }
}, },
"glob": { "glob": {
@ -3877,12 +3872,12 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"fs.realpath": "1.0.0", "fs.realpath": "^1.0.0",
"inflight": "1.0.6", "inflight": "^1.0.4",
"inherits": "2.0.3", "inherits": "2",
"minimatch": "3.0.4", "minimatch": "^3.0.4",
"once": "1.4.0", "once": "^1.3.0",
"path-is-absolute": "1.0.1" "path-is-absolute": "^1.0.0"
} }
}, },
"has-unicode": { "has-unicode": {
@ -3897,7 +3892,7 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"safer-buffer": "2.1.2" "safer-buffer": "^2.1.0"
} }
}, },
"ignore-walk": { "ignore-walk": {
@ -3906,7 +3901,7 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"minimatch": "3.0.4" "minimatch": "^3.0.4"
} }
}, },
"inflight": { "inflight": {
@ -3915,15 +3910,14 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"once": "1.4.0", "once": "^1.3.0",
"wrappy": "1.0.2" "wrappy": "1"
} }
}, },
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -3935,9 +3929,8 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "1.0.1" "number-is-nan": "^1.0.0"
} }
}, },
"isarray": { "isarray": {
@ -3950,25 +3943,22 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "1.1.11" "brace-expansion": "^1.1.7"
} }
}, },
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "5.1.1", "safe-buffer": "^5.1.1",
"yallist": "3.0.2" "yallist": "^3.0.0"
} }
}, },
"minizlib": { "minizlib": {
@ -3977,14 +3967,13 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"minipass": "2.2.4" "minipass": "^2.2.1"
} }
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -4001,9 +3990,9 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"debug": "2.6.9", "debug": "^2.1.2",
"iconv-lite": "0.4.21", "iconv-lite": "^0.4.4",
"sax": "1.2.4" "sax": "^1.2.4"
} }
}, },
"node-pre-gyp": { "node-pre-gyp": {
@ -4012,16 +4001,16 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"detect-libc": "1.0.3", "detect-libc": "^1.0.2",
"mkdirp": "0.5.1", "mkdirp": "^0.5.1",
"needle": "2.2.0", "needle": "^2.2.0",
"nopt": "4.0.1", "nopt": "^4.0.1",
"npm-packlist": "1.1.10", "npm-packlist": "^1.1.6",
"npmlog": "4.1.2", "npmlog": "^4.0.2",
"rc": "1.2.7", "rc": "^1.1.7",
"rimraf": "2.6.2", "rimraf": "^2.6.1",
"semver": "5.5.0", "semver": "^5.3.0",
"tar": "4.4.1" "tar": "^4"
} }
}, },
"nopt": { "nopt": {
@ -4030,8 +4019,8 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"abbrev": "1.1.1", "abbrev": "1",
"osenv": "0.1.5" "osenv": "^0.1.4"
} }
}, },
"npm-bundled": { "npm-bundled": {
@ -4046,8 +4035,8 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"ignore-walk": "3.0.1", "ignore-walk": "^3.0.1",
"npm-bundled": "1.0.3" "npm-bundled": "^1.0.1"
} }
}, },
"npmlog": { "npmlog": {
@ -4056,17 +4045,16 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"are-we-there-yet": "1.1.4", "are-we-there-yet": "~1.1.2",
"console-control-strings": "1.1.0", "console-control-strings": "~1.1.0",
"gauge": "2.7.4", "gauge": "~2.7.3",
"set-blocking": "2.0.0" "set-blocking": "~2.0.0"
} }
}, },
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -4078,9 +4066,8 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1.0.2" "wrappy": "1"
} }
}, },
"os-homedir": { "os-homedir": {
@ -4101,8 +4088,8 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"os-homedir": "1.0.2", "os-homedir": "^1.0.0",
"os-tmpdir": "1.0.2" "os-tmpdir": "^1.0.0"
} }
}, },
"path-is-absolute": { "path-is-absolute": {
@ -4123,10 +4110,10 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"deep-extend": "0.5.1", "deep-extend": "^0.5.1",
"ini": "1.3.5", "ini": "~1.3.0",
"minimist": "1.2.0", "minimist": "^1.2.0",
"strip-json-comments": "2.0.1" "strip-json-comments": "~2.0.1"
}, },
"dependencies": { "dependencies": {
"minimist": { "minimist": {
@ -4143,13 +4130,13 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"core-util-is": "1.0.2", "core-util-is": "~1.0.0",
"inherits": "2.0.3", "inherits": "~2.0.3",
"isarray": "1.0.0", "isarray": "~1.0.0",
"process-nextick-args": "2.0.0", "process-nextick-args": "~2.0.0",
"safe-buffer": "5.1.1", "safe-buffer": "~5.1.1",
"string_decoder": "1.1.1", "string_decoder": "~1.1.1",
"util-deprecate": "1.0.2" "util-deprecate": "~1.0.1"
} }
}, },
"rimraf": { "rimraf": {
@ -4158,7 +4145,7 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"glob": "7.1.2" "glob": "^7.0.5"
} }
}, },
"safe-buffer": { "safe-buffer": {
@ -4200,11 +4187,10 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "1.1.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "1.0.0", "is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "3.0.1" "strip-ansi": "^3.0.0"
} }
}, },
"string_decoder": { "string_decoder": {
@ -4213,7 +4199,7 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"safe-buffer": "5.1.1" "safe-buffer": "~5.1.0"
} }
}, },
"strip-ansi": { "strip-ansi": {
@ -4221,7 +4207,7 @@
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"requires": { "requires": {
"ansi-regex": "2.1.1" "ansi-regex": "^2.0.0"
} }
}, },
"strip-json-comments": { "strip-json-comments": {
@ -4236,13 +4222,13 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"chownr": "1.0.1", "chownr": "^1.0.1",
"fs-minipass": "1.2.5", "fs-minipass": "^1.2.5",
"minipass": "2.2.4", "minipass": "^2.2.4",
"minizlib": "1.1.0", "minizlib": "^1.1.0",
"mkdirp": "0.5.1", "mkdirp": "^0.5.0",
"safe-buffer": "5.1.1", "safe-buffer": "^5.1.1",
"yallist": "3.0.2" "yallist": "^3.0.2"
} }
}, },
"util-deprecate": { "util-deprecate": {
@ -4257,7 +4243,7 @@
"dev": true, "dev": true,
"optional": true, "optional": true,
"requires": { "requires": {
"string-width": "1.0.2" "string-width": "^1.0.2"
} }
}, },
"wrappy": { "wrappy": {

View File

@ -31,7 +31,7 @@
"@loafer/ng-entity": "^0.0.2", "@loafer/ng-entity": "^0.0.2",
"@loafer/ng-logger": "^0.0.1", "@loafer/ng-logger": "^0.0.1",
"@loafer/ng-rest": "^0.0.1", "@loafer/ng-rest": "^0.0.1",
"@loafer/ng-rpc": "^0.0.2", "@loafer/ng-rpc": "^0.0.3",
"@ngrx/core": "^1.2.0", "@ngrx/core": "^1.2.0",
"@ngrx/effects": "^5.2.0", "@ngrx/effects": "^5.2.0",
"@ngrx/router-store": "^5.2.0", "@ngrx/router-store": "^5.2.0",