This commit is contained in:
crusader 2018-05-31 16:38:44 +09:00
parent 163ca1134d
commit e8ad7b6716
20 changed files with 125 additions and 360 deletions

View File

@ -46,6 +46,9 @@
<div class="ui-g-12"> <div class="ui-g-12">
<b>HostID:</b> {{rowData.descriptions.host.hostID}} <b>HostID:</b> {{rowData.descriptions.host.hostID}}
</div> </div>
<div class="ui-g-12">
<b>Connected:</b> {{rowData.connectDate | date: 'dd/MM/yyyy'}} ({{rowData.connectAddress}})
</div>
</div> </div>
<div class="ui-g-12 ui-md-6"> <div class="ui-g-12 ui-md-6">
@ -62,6 +65,8 @@
<div class="ui-g-12"> <div class="ui-g-12">
<b>Mac Address:</b> {{rowData.descriptions.network.macAddress}} <b>Mac Address:</b> {{rowData.descriptions.network.macAddress}}
</div> </div>
<div class="ui-g-12">
</div>
</div> </div>
</div> </div>
<div class="ui-g-12" dir="rtl"> <div class="ui-g-12" dir="rtl">

View File

@ -1,6 +1,6 @@
import { Component, Input, Output, EventEmitter, AfterContentInit, OnInit } from '@angular/core'; import { Component, Input, Output, EventEmitter, AfterContentInit, OnInit, OnDestroy } from '@angular/core';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { Observable, of } from 'rxjs'; import { Observable, of, Subscription } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators'; import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { ConfirmationService, Message } from 'primeng/primeng'; import { ConfirmationService, Message } from 'primeng/primeng';
@ -9,17 +9,21 @@ import { AuthContainerSelector } from '@overflow/shared/auth/store';
import { DomainMember } from '@overflow/commons-typescript/model/domain'; import { DomainMember } from '@overflow/commons-typescript/model/domain';
import { NoAuthProbeService } from '../service/noauth-probe.service'; import { NoAuthProbeService } from '../service/noauth-probe.service';
import { NoAuthProbeConnectingSelector } from '../store';
@Component({ @Component({
selector: 'of-noauth-probe-list', selector: 'of-noauth-probe-list',
templateUrl: './noauth-probe-list.component.html', templateUrl: './noauth-probe-list.component.html',
providers: [ConfirmationService] providers: [ConfirmationService]
}) })
export class NoAuthProbeListComponent implements OnInit { export class NoAuthProbeListComponent implements OnInit, OnDestroy {
noauthProbes$: Observable<NoAuthProbe[]>; noauthProbes$: Observable<NoAuthProbe[]>;
pending$: Observable<boolean>; pending$: Observable<boolean>;
error$: Observable<any>; error$: Observable<any>;
noauthProbes: NoAuthProbe[];
connectingSubscription$: Subscription;
constructor( constructor(
private confirmationService: ConfirmationService, private confirmationService: ConfirmationService,
private store: Store<any>, private store: Store<any>,
@ -50,6 +54,24 @@ export class NoAuthProbeListComponent implements OnInit {
}), }),
).take(1).subscribe(); ).take(1).subscribe();
this.connectingSubscription$ = this.store.pipe(
select(NoAuthProbeConnectingSelector.selectEntities),
tap((entities: { [id: number]: NoAuthProbe }) => {
const noauthProbes = [];
this.noauthProbes.forEach(noauthProbe => {
const t = entities[noauthProbe.id];
if (undefined !== t) {
noauthProbes.push(t);
} else {
noauthProbes.push(noauthProbe);
}
});
this.setNoauthProbes$(noauthProbes);
}
),
).subscribe();
// this.noauthProbes$ = this.store.pipe( // this.noauthProbes$ = this.store.pipe(
// select(AuthContainerSelector.selectDomainMember), // select(AuthContainerSelector.selectDomainMember),
// exhaustMap((domainMember: DomainMember) => // exhaustMap((domainMember: DomainMember) =>
@ -77,6 +99,11 @@ export class NoAuthProbeListComponent implements OnInit {
} }
ngOnDestroy(): void {
this.connectingSubscription$.unsubscribe();
}
onAcceptOrDeny(isAccept: boolean, selected: NoAuthProbe) { onAcceptOrDeny(isAccept: boolean, selected: NoAuthProbe) {
const title = isAccept ? const title = isAccept ?
'Are you sure to accept this Probe?' : 'Are you sure to deny this Probe'; 'Are you sure to accept this Probe?' : 'Are you sure to deny this Probe';
@ -136,6 +163,7 @@ export class NoAuthProbeListComponent implements OnInit {
noauthProbes.forEach(noauthProbe => { noauthProbes.forEach(noauthProbe => {
noauthProbe.descriptions = JSON.parse(noauthProbe.description); noauthProbe.descriptions = JSON.parse(noauthProbe.description);
}); });
this.noauthProbes = noauthProbes;
this.noauthProbes$ = of(noauthProbes); this.noauthProbes$ = of(noauthProbes);
} }

View File

@ -1,5 +0,0 @@
import { NoAuthProbeListContainerComponent } from './noauth-probe-list-container.component';
export const CONTAINER_COMPONENTS = [
NoAuthProbeListContainerComponent,
];

View File

@ -1,7 +0,0 @@
<!-- <of-noauth-probe-list
[noauthProbes]="noauthProbes$ | async"
[pending]="pending$ | async"
[error]="error$ | async"
(accept)="accept($event)"
(deny)="deny($event)">
</of-noauth-probe-list> -->

View File

@ -1,25 +0,0 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NoAuthProbeListContainerComponent } from './noauth-probe-list-container.component';
describe('NoAuthProbeListContainerComponent', () => {
let component: NoAuthProbeListContainerComponent;
let fixture: ComponentFixture<NoAuthProbeListContainerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NoAuthProbeListContainerComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NoAuthProbeListContainerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -1,56 +0,0 @@
import { Component, OnInit } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { AuthContainerSelector } from '@overflow/shared/auth/store';
import { DomainMember } from '@overflow/commons-typescript/model/domain';
import * as NoAuthProbeEntityStore from '../store/entity/noauth-probe';
import { NoAuthProbeListContainerSelector } from '../store';
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { ConfirmationService } from 'primeng/primeng';
import { MessageService } from 'primeng/components/common/messageservice';
import { RPCClientError } from '@loafer/ng-rpc';
@Component({
selector: 'of-noauth-probe-list-container',
templateUrl: './noauth-probe-list-container.component.html',
})
export class NoAuthProbeListContainerComponent implements OnInit {
noauthProbes$: Observable<NoAuthProbe[]>;
pending$: Observable<boolean>;
error$: Observable<any>;
constructor(
private store: Store<any>,
) {
}
ngOnInit() {
this.pending$ = this.store.pipe(select(NoAuthProbeListContainerSelector.selectPending));
this.error$ = this.store.pipe(select(NoAuthProbeListContainerSelector.selectError));
this.noauthProbes$ = this.store.pipe(select(NoAuthProbeListContainerSelector.selectAll)).map((_noauthProbes: NoAuthProbe[]) => {
if (null === _noauthProbes) {
return null;
}
_noauthProbes.forEach(_noauthProbe => {
_noauthProbe.descriptions = JSON.parse(_noauthProbe.description);
});
return _noauthProbes;
});
this.store.select(AuthContainerSelector.selectDomainMember).subscribe(
(domainMember: DomainMember) => {
this.store.dispatch(new NoAuthProbeEntityStore.ReadAllByDomainID(domainMember.domain.id));
}
);
}
accept(noAuthProbe: NoAuthProbe) {
this.store.dispatch(new NoAuthProbeEntityStore.Accept({aa: noAuthProbe.id} as any));
}
deny(noAuthProbe: NoAuthProbe) {
this.store.dispatch(new NoAuthProbeEntityStore.Deny(noAuthProbe.id));
}
}

View File

@ -7,7 +7,6 @@ import { NoAuthProbeStoreModule } from './noauth-probe-store.module';
import { NoAuthProbeRPCModule } from './noauth-probe-rpc.module'; import { NoAuthProbeRPCModule } from './noauth-probe-rpc.module';
import { NoAuthProbeLoggerModule } from './noauth-probe-logger.module'; import { NoAuthProbeLoggerModule } from './noauth-probe-logger.module';
import { COMPONENTS } from './component'; import { COMPONENTS } from './component';
import { CONTAINER_COMPONENTS } from './container';
import { SERVICES } from './service'; import { SERVICES } from './service';
@ -21,11 +20,9 @@ import { SERVICES } from './service';
], ],
declarations: [ declarations: [
COMPONENTS, COMPONENTS,
CONTAINER_COMPONENTS,
], ],
exports: [ exports: [
COMPONENTS, COMPONENTS,
CONTAINER_COMPONENTS,
], ],
providers: [ providers: [
SERVICES, SERVICES,

View File

@ -0,0 +1,4 @@
export * from './noauth-probe-connecting.action';
export * from './noauth-probe-connecting.effect';
export * from './noauth-probe-connecting.reducer';
export * from './noauth-probe-connecting.state';

View File

@ -0,0 +1,26 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
export enum ActionType {
OnConnect = '[noauth-probe.connecting] OnConnect',
OnDisconnect = '[noauth-probe.connecting] OnDisconnect',
}
export class OnConnect implements Action {
readonly type = ActionType.OnConnect;
constructor(public payload: NoAuthProbe) {}
}
export class OnDisconnect implements Action {
readonly type = ActionType.OnDisconnect;
constructor(public payload: NoAuthProbe) {}
}
export type Actions =
| OnConnect
| OnDisconnect
;

View File

@ -1,8 +1,8 @@
import { TestBed, inject } from '@angular/core/testing'; import { TestBed, inject } from '@angular/core/testing';
import { Effects } from './noauth-probe.effect'; import { Effects } from './noauth-probe-connecting.effect';
describe('NoAuth-Probe.Effects', () => { describe('noauth-probe-connecting.Effects', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [Effects] providers: [Effects]

View File

@ -0,0 +1,23 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { NoAuthProbeService } from '../../service/noauth-probe.service';
import {
ActionType,
} from './noauth-probe-connecting.action';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private noAuthProbeService: NoAuthProbeService,
private router: Router
) { }
}

View File

@ -0,0 +1,21 @@
import { ActionType, Actions } from './noauth-probe-connecting.action';
import {
State,
initialState,
noAuthProbeConnectingAdapter,
} from './noauth-probe-connecting.state';
export function reducer(state = initialState, action: Actions): State {
switch (action.type) {
case ActionType.OnConnect: {
return noAuthProbeConnectingAdapter.upsertOne(action.payload, state);
}
case ActionType.OnDisconnect: {
return noAuthProbeConnectingAdapter.upsertOne(action.payload, state);
}
default: {
return state;
}
}
}

View File

@ -4,17 +4,14 @@ import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { Selector, createSelector } from '@ngrx/store'; import { Selector, createSelector } from '@ngrx/store';
import { createEntityAdapter, EntityState } from '@loafer/ng-entity'; import { createEntityAdapter, EntityState } from '@loafer/ng-entity';
export const noAuthProbeListContainerAdapter = createEntityAdapter<NoAuthProbe, RPCClientError>(); export const noAuthProbeConnectingAdapter = createEntityAdapter<NoAuthProbe, RPCClientError>();
export interface State extends EntityState<NoAuthProbe, RPCClientError> { export interface State extends EntityState<NoAuthProbe, RPCClientError> {
pending: boolean;
} }
export const initialState: State = noAuthProbeListContainerAdapter.getInitialState({ export const initialState: State = noAuthProbeConnectingAdapter.getInitialState({
pending: false,
}); });
export function getSelectors(selector: Selector<any, State>) { export function getSelectors(selector: Selector<any, State>) {
return { return {
...noAuthProbeListContainerAdapter.getSelectors(selector), ...noAuthProbeConnectingAdapter.getSelectors(selector),
selectPending: createSelector(selector, (state: State) => state.pending),
}; };
} }

View File

@ -1,2 +0,0 @@
export * from './noauth-probe-list.reducer';
export * from './noauth-probe-list.state';

View File

@ -1,55 +0,0 @@
import { ActionType, Actions } from '../../entity/noauth-probe';
import {
State,
initialState,
noAuthProbeListContainerAdapter,
} from './noauth-probe-list.state';
import { Probe } from '@overflow/commons-typescript/model/probe';
export function reducer(state = initialState, action: Actions): State {
switch (action.type) {
case ActionType.ReadAllByDomainID: {
return {
...state,
pending: true,
};
}
case ActionType.ReadAllByDomainIDSuccess: {
return noAuthProbeListContainerAdapter.setAll(action.payload, {...state, pending: false});
}
case ActionType.ReadAllByDomainIDFailure: {
return noAuthProbeListContainerAdapter.setError(action.payload, {...state, pending: false});
}
case ActionType.Accept: {
return {
...state,
pending: true,
};
}
case ActionType.AcceptSuccess: {
return noAuthProbeListContainerAdapter.setAll(action.payload, {...state, pending: false});
}
case ActionType.AcceptFailure: {
return noAuthProbeListContainerAdapter.setError(action.payload, {...state, pending: false});
}
case ActionType.Deny: {
return {
...state,
pending: true,
};
}
case ActionType.DenySuccess: {
return noAuthProbeListContainerAdapter.setAll(action.payload, {...state, pending: false});
}
case ActionType.DenyFailure: {
return noAuthProbeListContainerAdapter.setError(action.payload, {...state, pending: false});
}
default: {
return state;
}
}
}

View File

@ -1,2 +0,0 @@
export * from './noauth-probe.action';
export * from './noauth-probe.effect';

View File

@ -1,102 +0,0 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc';
import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
export enum ActionType {
ReadAllByDomainID = '[noauth-probe.noauth-probe] ReadAllByDomainID',
ReadAllByDomainIDSuccess = '[noauth-probe.noauth-probe] ReadAllByDomainIDSuccess',
ReadAllByDomainIDFailure = '[noauth-probe.noauth-probe] ReadAllByDomainIDFailure',
Accept = '[noauth-probe.noauth-probe] Accept',
AcceptSuccess = '[noauth-probe.noauth-probe] AcceptSuccess',
AcceptFailure = '[noauth-probe.noauth-probe] AcceptFailure',
Deny = '[noauth-probe.noauth-probe] Deny',
DenySuccess = '[noauth-probe.noauth-probe] DenySuccess',
DenyFailure = '[noauth-probe.noauth-probe] DenyFailure',
OnConnect = '[noauth-probe.noauth-probe] OnConnect',
OnDisconnect = '[noauth-probe.noauth-probe] OnDisconnect',
}
export class ReadAllByDomainID implements Action {
readonly type = ActionType.ReadAllByDomainID;
constructor(public payload: number) {}
}
export class ReadAllByDomainIDSuccess implements Action {
readonly type = ActionType.ReadAllByDomainIDSuccess;
constructor(public payload: NoAuthProbe[]) {}
}
export class ReadAllByDomainIDFailure implements Action {
readonly type = ActionType.ReadAllByDomainIDFailure;
constructor(public payload: RPCClientError) {}
}
export class Accept implements Action {
readonly type = ActionType.Accept;
constructor(public payload: number) {}
}
export class AcceptSuccess implements Action {
readonly type = ActionType.AcceptSuccess;
constructor(public payload: NoAuthProbe[]) {}
}
export class AcceptFailure implements Action {
readonly type = ActionType.AcceptFailure;
constructor(public payload: RPCClientError) {}
}
export class Deny implements Action {
readonly type = ActionType.Deny;
constructor(public payload: number) {}
}
export class DenySuccess implements Action {
readonly type = ActionType.DenySuccess;
constructor(public payload: NoAuthProbe[]) {}
}
export class DenyFailure implements Action {
readonly type = ActionType.DenyFailure;
constructor(public payload: RPCClientError) {}
}
export class OnConnect implements Action {
readonly type = ActionType.OnConnect;
constructor(public payload: NoAuthProbe) {}
}
export class OnDisconnect implements Action {
readonly type = ActionType.OnDisconnect;
constructor(public payload: NoAuthProbe) {}
}
export type Actions =
| ReadAllByDomainID
| ReadAllByDomainIDSuccess
| ReadAllByDomainIDFailure
| Accept
| AcceptSuccess
| AcceptFailure
| Deny
| DenySuccess
| DenyFailure
| OnConnect
| OnDisconnect
;

View File

@ -1,78 +0,0 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/exhaustMap';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
import { RPCClientError } from '@loafer/ng-rpc';
import { NoAuthProbeService } from '../../../service/noauth-probe.service';
import {
ReadAllByDomainID,
ReadAllByDomainIDFailure,
ReadAllByDomainIDSuccess,
Accept,
AcceptSuccess,
AcceptFailure,
Deny,
DenySuccess,
DenyFailure,
ActionType,
} from './noauth-probe.action';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private noAuthProbeService: NoAuthProbeService,
private router: Router
) { }
@Effect()
readAllByDomain$: Observable<Action> = this.actions$
.ofType(ActionType.ReadAllByDomainID)
.map((action: ReadAllByDomainID) => action.payload)
.switchMap(payload => this.noAuthProbeService.readAllByDomainID(payload))
.map(noAuthProbes => {
return new ReadAllByDomainIDSuccess(noAuthProbes);
})
.catch((error: RPCClientError) => {
return of(new ReadAllByDomainIDFailure(error));
});
@Effect()
accept$: Observable<Action> = this.actions$
.ofType(ActionType.Accept)
.map((action: Accept) => action.payload)
.switchMap(payload => this.noAuthProbeService.acceptNoAuthProbe(payload))
.map(noAuthProbes => {
return new AcceptSuccess(noAuthProbes);
})
.catch((error: RPCClientError) => {
return of(new AcceptFailure(error));
});
@Effect()
deny$: Observable<Action> = this.actions$
.ofType(ActionType.Deny)
.map((action: Deny) => action.payload)
.switchMap(payload => this.noAuthProbeService.denyNoauthProbe(payload))
.map(noAuthProbes => {
return new DenySuccess(noAuthProbes);
})
.catch((error: RPCClientError) => {
return of(new DenyFailure(error));
});
}

View File

@ -5,25 +5,23 @@ import {
import { MODULE } from '../noauth-probe.constant'; import { MODULE } from '../noauth-probe.constant';
import * as NoAuthProbeEntityStore from './entity/noauth-probe'; import * as NoAuthProbeConnectingStore from './connecting';
import * as NoAuthProbeListContainerStore from './container/noauth-probe-list';
export interface State { export interface State {
noauth_probe_list: NoAuthProbeListContainerStore.State; connecting: NoAuthProbeConnectingStore.State;
} }
export const REDUCERS = { export const REDUCERS = {
noauth_probe_list: NoAuthProbeListContainerStore.reducer, connecting: NoAuthProbeConnectingStore.reducer,
}; };
export const EFFECTS = [ export const EFFECTS = [
NoAuthProbeEntityStore.Effects, NoAuthProbeConnectingStore.Effects,
]; ];
export const selectState = createFeatureSelector<State>(MODULE.name); export const selectState = createFeatureSelector<State>(MODULE.name);
export const NoAuthProbeListContainerSelector = NoAuthProbeListContainerStore.getSelectors(createSelector( export const NoAuthProbeConnectingSelector = NoAuthProbeConnectingStore.getSelectors(createSelector(
selectState, selectState,
(state: State) => state.noauth_probe_list (state: State) => state.connecting
)); ));

View File

@ -4,11 +4,9 @@ import { Store, select } from '@ngrx/store';
import { RPCSubscriber } from '@loafer/ng-rpc'; import { RPCSubscriber } from '@loafer/ng-rpc';
import { LoggerService } from '@loafer/ng-logger'; import { LoggerService } from '@loafer/ng-logger';
import * as NoAuthProbeStore from '../store/entity/noauth-probe'; import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import { import * as NoAuthProbeConnectingStore from '../store/connecting';
NoAuthProbe,
} from '@overflow/commons-typescript/model/noauth';
@Injectable() @Injectable()
export class NoAuthProbeSubscriber { export class NoAuthProbeSubscriber {
@ -23,13 +21,13 @@ export class NoAuthProbeSubscriber {
public onConnect(noAuthProbe: NoAuthProbe): void { public onConnect(noAuthProbe: NoAuthProbe): void {
this.loggerService.debug('NoAuthProbeService.onConnect noAuthProbe:', noAuthProbe); this.loggerService.debug('NoAuthProbeService.onConnect noAuthProbe:', noAuthProbe);
this.store.dispatch(new NoAuthProbeStore.OnConnect(noAuthProbe)); this.store.dispatch(new NoAuthProbeConnectingStore.OnConnect(noAuthProbe));
} }
@RPCSubscriber({method: 'NoAuthProbeService.onDisconnect'}) @RPCSubscriber({method: 'NoAuthProbeService.onDisconnect'})
public onDisconnect(noAuthProbe: NoAuthProbe): void { public onDisconnect(noAuthProbe: NoAuthProbe): void {
this.loggerService.debug('NoAuthProbeService.onDisconnect noAuthProbe:', noAuthProbe); this.loggerService.debug('NoAuthProbeService.onDisconnect noAuthProbe:', noAuthProbe);
this.store.dispatch(new NoAuthProbeStore.OnDisconnect(noAuthProbe)); this.store.dispatch(new NoAuthProbeConnectingStore.OnDisconnect(noAuthProbe));
} }
} }