2018-04-06 11:02:18 +00:00
|
|
|
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';
|
|
|
|
|
2018-05-24 06:44:13 +00:00
|
|
|
import { RPCClientError } from '@loafer/ng-rpc';
|
2018-04-06 11:02:18 +00:00
|
|
|
|
2018-05-02 07:23:35 +00:00
|
|
|
import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';
|
2018-04-06 11:02:18 +00:00
|
|
|
import { TargetDiscoveryService } from '../../service/target-discovery.service';
|
|
|
|
|
|
|
|
import {
|
|
|
|
DiscoverySaveAllTarget,
|
|
|
|
DiscoverySaveAllTargetSuccess,
|
|
|
|
DiscoverySaveAllTargetFailure,
|
|
|
|
ActionType
|
|
|
|
} from './regist.action';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private targetDiscoveryService: TargetDiscoveryService,
|
|
|
|
private router: Router
|
|
|
|
) { }
|
|
|
|
|
|
|
|
@Effect()
|
|
|
|
saveAllTargetResult$: Observable<Action> = this.actions$
|
|
|
|
.ofType(ActionType.SaveAllTarget)
|
|
|
|
.map((action: DiscoverySaveAllTarget) => action.payload)
|
|
|
|
.switchMap(payload => this.targetDiscoveryService.saveAllTarget(payload.hosts, payload.probe))
|
|
|
|
.map(result => {
|
|
|
|
return new DiscoverySaveAllTargetSuccess(result);
|
|
|
|
})
|
|
|
|
.catch((error: RPCClientError) => {
|
|
|
|
console.log(error.response.message);
|
|
|
|
return of(new DiscoverySaveAllTargetFailure(error));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|