From 3af1550821ccaeb11cd840ae562b4d29f5e4afce Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 24 May 2018 19:50:43 +0900 Subject: [PATCH] probe store arranging --- .../probe-selector.component.ts | 24 ++--- .../component/setting/setting.component.html | 4 +- @overflow/infra/component/index.ts | 4 +- .../probe-summary/probe-summary.component.ts | 84 ++++++++--------- .../component/detail/detail.component.ts | 90 +++++++++---------- .../probe/component/list/list.component.ts | 71 ++++++++------- @overflow/probe/service/probe-host.service.ts | 12 ++- @overflow/probe/store/index.ts | 44 ++------- @overflow/probe/store/probe/index.ts | 4 + @overflow/probe/store/probe/probe.action.ts | 58 ++++++++++++ @overflow/probe/store/probe/probe.effect.ts | 64 +++++++++++++ @overflow/probe/store/probe/probe.reducer.ts | 68 ++++++++++++++ @overflow/probe/store/probe/probe.state.ts | 12 +++ .../store/{ => trash}/detail/detail.action.ts | 0 .../{ => trash}/detail/detail.effect.spec.ts | 0 .../store/{ => trash}/detail/detail.effect.ts | 0 .../{ => trash}/detail/detail.reducer.ts | 0 .../store/{ => trash}/detail/detail.state.ts | 0 .../probe/store/{ => trash}/detail/index.ts | 0 .../probe/store/{ => trash}/list/index.ts | 0 .../store/{ => trash}/list/list.action.ts | 0 .../{ => trash}/list/list.effect.spec.ts | 0 .../store/{ => trash}/list/list.effect.ts | 0 .../store/{ => trash}/list/list.reducer.ts | 0 .../store/{ => trash}/list/list.state.ts | 0 .../probe/store/{ => trash}/modify/index.ts | 0 .../store/{ => trash}/modify/modify.action.ts | 0 .../{ => trash}/modify/modify.effect.spec.ts | 0 .../store/{ => trash}/modify/modify.effect.ts | 0 .../{ => trash}/modify/modify.reducer.ts | 0 .../store/{ => trash}/modify/modify.state.ts | 0 .../{ => trash}/probe-host-list/index.ts | 0 .../probe-host-list/list.action.ts | 0 .../probe-host-list/list.effect.spec.ts | 0 .../probe-host-list/list.effect.ts | 0 .../probe-host-list/list.reducer.ts | 0 .../{ => trash}/probe-host-list/list.state.ts | 0 .../store/{ => trash}/probe-host/index.ts | 0 .../probe-host/probe-host.action.ts | 0 .../probe-host/probe-host.effect.spec.ts | 0 .../probe-host/probe-host.effect.ts | 0 .../probe-host/probe-host.reducer.ts | 0 .../probe-host/probe-host.state.ts | 0 .../probe/store/{ => trash}/remove/index.ts | 0 .../store/{ => trash}/remove/remove.action.ts | 0 .../{ => trash}/remove/remove.effect.spec.ts | 0 .../store/{ => trash}/remove/remove.effect.ts | 0 .../{ => trash}/remove/remove.reducer.ts | 0 .../store/{ => trash}/remove/remove.state.ts | 0 49 files changed, 358 insertions(+), 181 deletions(-) create mode 100644 @overflow/probe/store/probe/index.ts create mode 100644 @overflow/probe/store/probe/probe.action.ts create mode 100644 @overflow/probe/store/probe/probe.effect.ts create mode 100644 @overflow/probe/store/probe/probe.reducer.ts create mode 100644 @overflow/probe/store/probe/probe.state.ts rename @overflow/probe/store/{ => trash}/detail/detail.action.ts (100%) rename @overflow/probe/store/{ => trash}/detail/detail.effect.spec.ts (100%) rename @overflow/probe/store/{ => trash}/detail/detail.effect.ts (100%) rename @overflow/probe/store/{ => trash}/detail/detail.reducer.ts (100%) rename @overflow/probe/store/{ => trash}/detail/detail.state.ts (100%) rename @overflow/probe/store/{ => trash}/detail/index.ts (100%) rename @overflow/probe/store/{ => trash}/list/index.ts (100%) rename @overflow/probe/store/{ => trash}/list/list.action.ts (100%) rename @overflow/probe/store/{ => trash}/list/list.effect.spec.ts (100%) rename @overflow/probe/store/{ => trash}/list/list.effect.ts (100%) rename @overflow/probe/store/{ => trash}/list/list.reducer.ts (100%) rename @overflow/probe/store/{ => trash}/list/list.state.ts (100%) rename @overflow/probe/store/{ => trash}/modify/index.ts (100%) rename @overflow/probe/store/{ => trash}/modify/modify.action.ts (100%) rename @overflow/probe/store/{ => trash}/modify/modify.effect.spec.ts (100%) rename @overflow/probe/store/{ => trash}/modify/modify.effect.ts (100%) rename @overflow/probe/store/{ => trash}/modify/modify.reducer.ts (100%) rename @overflow/probe/store/{ => trash}/modify/modify.state.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host-list/index.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host-list/list.action.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host-list/list.effect.spec.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host-list/list.effect.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host-list/list.reducer.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host-list/list.state.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host/index.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host/probe-host.action.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host/probe-host.effect.spec.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host/probe-host.effect.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host/probe-host.reducer.ts (100%) rename @overflow/probe/store/{ => trash}/probe-host/probe-host.state.ts (100%) rename @overflow/probe/store/{ => trash}/remove/index.ts (100%) rename @overflow/probe/store/{ => trash}/remove/remove.action.ts (100%) rename @overflow/probe/store/{ => trash}/remove/remove.effect.spec.ts (100%) rename @overflow/probe/store/{ => trash}/remove/remove.effect.ts (100%) rename @overflow/probe/store/{ => trash}/remove/remove.reducer.ts (100%) rename @overflow/probe/store/{ => trash}/remove/remove.state.ts (100%) diff --git a/@overflow/discovery/component/setting/probe-selector/probe-selector.component.ts b/@overflow/discovery/component/setting/probe-selector/probe-selector.component.ts index 714b921..3a3f0fa 100644 --- a/@overflow/discovery/component/setting/probe-selector/probe-selector.component.ts +++ b/@overflow/discovery/component/setting/probe-selector/probe-selector.component.ts @@ -4,8 +4,8 @@ import { } from '@angular/core'; import { Store, select, StateObservable } from '@ngrx/store'; import { RPCClientError } from '@loafer/ng-rpc'; -import * as ListStore from '@overflow/probe/store/list'; -import { ListSelector } from '@overflow/probe/store'; +// import * as ListStore from '@overflow/probe/store/list'; +// import { ListSelector } from '@overflow/probe/store'; import { Subscription } from 'rxjs/Subscription'; import { Probe } from '@overflow/commons-typescript/model/probe'; import { AuthSelector } from '@overflow/member/store'; @@ -27,9 +27,9 @@ export class ProbeSelectorComponent implements OnInit, AfterContentInit, OnDestr @Output() probeSelected = new EventEmitter(); constructor( - private listStore: Store, + // private listStore: Store, ) { - this.probes$ = listStore.pipe(select(ListSelector.select('probes'))); + // this.probes$ = listStore.pipe(select(ListSelector.select('probes'))); } ngOnInit() { @@ -58,14 +58,14 @@ export class ProbeSelectorComponent implements OnInit, AfterContentInit, OnDestr } getProbes() { - this.listStore.select(AuthSelector.select('domain')).subscribe( - (domain: Domain) => { - this.listStore.dispatch(new ListStore.ReadAllByDomain(domain)); - }, - (error) => { - console.log(error); - } - ); + // this.listStore.select(AuthSelector.select('domain')).subscribe( + // (domain: Domain) => { + // this.listStore.dispatch(new ListStore.ReadAllByDomain(domain)); + // }, + // (error) => { + // console.log(error); + // } + // ); } onProbeSelect(event) { diff --git a/@overflow/discovery/component/setting/setting.component.html b/@overflow/discovery/component/setting/setting.component.html index b616aa4..3592ffd 100644 --- a/@overflow/discovery/component/setting/setting.component.html +++ b/@overflow/discovery/component/setting/setting.component.html @@ -1,4 +1,4 @@ -
+ diff --git a/@overflow/infra/component/index.ts b/@overflow/infra/component/index.ts index 9894e82..6d2d9cb 100644 --- a/@overflow/infra/component/index.ts +++ b/@overflow/infra/component/index.ts @@ -1,11 +1,11 @@ import { MapComponent } from './map/map.component'; -import { ProbeSummaryComponent } from './probe-summary/probe-summary.component'; +// import { ProbeSummaryComponent } from './probe-summary/probe-summary.component'; import { HostSummaryComponent } from './host-summary/host-summary.component'; import { ServiceSummaryComponent } from './service-summary/service-summary.component'; export const COMPONENTS = [ MapComponent, - ProbeSummaryComponent, + // ProbeSummaryComponent, HostSummaryComponent, ServiceSummaryComponent ]; diff --git a/@overflow/infra/component/probe-summary/probe-summary.component.ts b/@overflow/infra/component/probe-summary/probe-summary.component.ts index 5825705..b51b476 100644 --- a/@overflow/infra/component/probe-summary/probe-summary.component.ts +++ b/@overflow/infra/component/probe-summary/probe-summary.component.ts @@ -1,53 +1,53 @@ -import { Component, OnInit, AfterContentInit, Input, OnChanges } from '@angular/core'; -import { Store, select } from '@ngrx/store'; -import { RPCClientError } from '@loafer/ng-rpc'; +// import { Component, OnInit, AfterContentInit, Input, OnChanges } from '@angular/core'; +// import { Store, select } from '@ngrx/store'; +// import { RPCClientError } from '@loafer/ng-rpc'; -import * as DetailStore from '@overflow/probe/store/probe-host'; -import { ProbeHostSelector } from '@overflow/probe/store'; -import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe'; +// import * as DetailStore from '@overflow/probe/store/probe-host'; +// import { ProbeHostSelector } from '@overflow/probe/store'; +// import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe'; -@Component({ - selector: 'of-probe-summary', - templateUrl: './probe-summary.component.html', -}) -export class ProbeSummaryComponent implements OnInit, AfterContentInit, OnChanges { +// @Component({ +// selector: 'of-probe-summary', +// templateUrl: './probe-summary.component.html', +// }) +// export class ProbeSummaryComponent implements OnInit, AfterContentInit, OnChanges { - @Input() probe: Object; - @Input() visible: boolean; +// @Input() probe: Object; +// @Input() visible: boolean; - probeHost$ = this.detailStore.pipe(select(ProbeHostSelector.select('probeHost'))); - probeHost: ProbeHost; +// probeHost$ = this.detailStore.pipe(select(ProbeHostSelector.select('probeHost'))); +// probeHost: ProbeHost; - constructor( - private detailStore: Store, - ) { } +// constructor( +// private detailStore: Store, +// ) { } - ngOnInit() { - this.probeHost$.subscribe( - (probeHost: ProbeHost) => { - if (probeHost) { - console.log(probeHost); - this.probeHost = probeHost; - } - }, - (error: RPCClientError) => { - console.log(error.response.message); - } - ); - } +// ngOnInit() { +// this.probeHost$.subscribe( +// (probeHost: ProbeHost) => { +// if (probeHost) { +// console.log(probeHost); +// this.probeHost = probeHost; +// } +// }, +// (error: RPCClientError) => { +// console.log(error.response.message); +// } +// ); +// } - ngAfterContentInit() { - console.log('$$$$$$$$$$'); - console.log(this.probe); - console.log('$$$$$$$$$$'); - // this.detailStore.dispatch( - // new DetailStore.ReadByProbe(this.probe) - // ); - } +// ngAfterContentInit() { +// console.log('$$$$$$$$$$'); +// console.log(this.probe); +// console.log('$$$$$$$$$$'); +// // this.detailStore.dispatch( +// // new DetailStore.ReadByProbe(this.probe) +// // ); +// } - ngOnChanges() { - } +// ngOnChanges() { +// } -} +// } diff --git a/@overflow/probe/component/detail/detail.component.ts b/@overflow/probe/component/detail/detail.component.ts index f5e9505..679cc82 100644 --- a/@overflow/probe/component/detail/detail.component.ts +++ b/@overflow/probe/component/detail/detail.component.ts @@ -2,9 +2,9 @@ import { Component, OnInit, Inject, AfterContentInit, OnDestroy } from '@angular import { ActivatedRoute, Router } from '@angular/router'; import { Store, select } from '@ngrx/store'; import { RPCClientError } from '@loafer/ng-rpc'; -import * as DetailStore from '../../store/detail'; -import * as ModifyStore from '../../store/modify'; -import { DetailSelector, ModifySelector } from '../../store'; +// import * as DetailStore from '../../store/detail'; +// import * as ModifyStore from '../../store/modify'; +// import { DetailSelector, ModifySelector } from '../../store'; import { Probe } from '@overflow/commons-typescript/model/probe'; import { ConfirmationService, Message } from 'primeng/primeng'; import * as CIDR from 'ip-cidr'; @@ -21,8 +21,8 @@ import { MessageService } from 'primeng/components/common/messageservice'; export class ProbeDetailComponent implements OnInit, AfterContentInit, OnDestroy { probeSubscription$: Subscription; - probe$ = this.detailStore.pipe(select(DetailSelector.select('probe'))); - modifySuccess$ = this.modifyStore.pipe(select(ModifySelector.select('modifiedProbe'))); + // probe$ = this.detailStore.pipe(select(DetailSelector.select('probe'))); + // modifySuccess$ = this.modifyStore.pipe(select(ModifySelector.select('modifiedProbe'))); probe: Probe = null; IPRange: string; display = false; @@ -30,24 +30,24 @@ export class ProbeDetailComponent implements OnInit, AfterContentInit, OnDestroy constructor( private route: ActivatedRoute, - private detailStore: Store, - private modifyStore: Store, + // private detailStore: Store, + // private modifyStore: Store, private confirmationService: ConfirmationService, private messageService: MessageService ) { } ngOnInit() { - this.probeSubscription$ = this.probe$.subscribe( - (probe: Probe) => { - if (probe) { - this.probe = probe; - this.arrangeInfo(); - } - }, - (error: RPCClientError) => { - console.log(error.response.message); - } - ); + // this.probeSubscription$ = this.probe$.subscribe( + // (probe: Probe) => { + // if (probe) { + // this.probe = probe; + // this.arrangeInfo(); + // } + // }, + // (error: RPCClientError) => { + // console.log(error.response.message); + // } + // ); } ngOnDestroy() { @@ -57,12 +57,12 @@ export class ProbeDetailComponent implements OnInit, AfterContentInit, OnDestroy } ngAfterContentInit() { - const probeId = this.route.snapshot.paramMap.get('id'); - this.detailStore.dispatch( - new DetailStore.Read( - { id: probeId } - ) - ); + // const probeId = this.route.snapshot.paramMap.get('id'); + // this.detailStore.dispatch( + // new DetailStore.Read( + // { id: probeId } + // ) + // ); } arrangeInfo() { @@ -95,28 +95,28 @@ export class ProbeDetailComponent implements OnInit, AfterContentInit, OnDestroy } onDisplayNameChange(value: string) { - if (value === this.probe.displayName) { - return; - } - this.probe.displayName = value; - this.modifyStore.dispatch( - new ModifyStore.Modify(this.probe) - ); + // if (value === this.probe.displayName) { + // return; + // } + // this.probe.displayName = value; + // this.modifyStore.dispatch( + // new ModifyStore.Modify(this.probe) + // ); - const modifySuccessSubscription$: Subscription = this.modifySuccess$.subscribe( - (probe: Probe) => { - if (probe) { - this.msgs = []; - this.msgs.push({ severity: 'success', summary: 'Succeed', detail: 'Probe name has changed.' }); - } - if (modifySuccessSubscription$) { - modifySuccessSubscription$.unsubscribe(); - } - }, - (error: RPCClientError) => { - console.log(error.response.message); - } - ); + // const modifySuccessSubscription$: Subscription = this.modifySuccess$.subscribe( + // (probe: Probe) => { + // if (probe) { + // this.msgs = []; + // this.msgs.push({ severity: 'success', summary: 'Succeed', detail: 'Probe name has changed.' }); + // } + // if (modifySuccessSubscription$) { + // modifySuccessSubscription$.unsubscribe(); + // } + // }, + // (error: RPCClientError) => { + // console.log(error.response.message); + // } + // ); } onDisplayNameChangeKeypress(event, value) { diff --git a/@overflow/probe/component/list/list.component.ts b/@overflow/probe/component/list/list.component.ts index 53e648b..803899e 100644 --- a/@overflow/probe/component/list/list.component.ts +++ b/@overflow/probe/component/list/list.component.ts @@ -6,8 +6,8 @@ import { Domain } from '@overflow/commons-typescript/model/domain'; import { AuthSelector } from '@overflow/member/store'; import { Probe, ProbeHost } from '@overflow/commons-typescript/model/probe'; -import * as ListStore from '../../store/probe-host-list'; -import { ProbeHostListSelector } from '../../store'; +import * as ProbeStore from '../../store/probe'; +import { ProbeSelector } from '../../store'; import { Subscription } from 'rxjs/Subscription'; @Component({ @@ -16,14 +16,13 @@ import { Subscription } from 'rxjs/Subscription'; }) export class ProbeListComponent implements OnInit, AfterContentInit, OnDestroy { probeHostsSubscription$: Subscription; - probeHosts$ = this.store.pipe(select(ProbeHostListSelector.select('probeHosts'))); + probeHosts$ = this.store.pipe(select(ProbeSelector.select('probes'))); probeHosts: ProbeHost[]; @Output() select = new EventEmitter(); - val; constructor( - private store: Store + private store: Store ) { } @@ -39,39 +38,39 @@ export class ProbeListComponent implements OnInit, AfterContentInit, OnDestroy { } ngAfterContentInit() { - // this.store.select(AuthSelector.select('domain')).subscribe( - // (domain: Domain) => { - // this.store.dispatch(new ListStore.ReadAllByDomain(domain)); - // }, - // (error) => { - // console.log(error); - // } - // ); + this.store.select(AuthSelector.select('domain')).subscribe( + (domain: Domain) => { + this.store.dispatch(new ProbeStore.ReadAllByDomainID(domain.id)); + }, + (error) => { + console.log(error); + } + ); // temp - const probeHost: ProbeHost = { - id: 1, - probe: { - id: 1, - displayName: 'ddd', - cidr: 'dddd', - authorizeDate: new Date(), - authorizeMember: { - name: 'ddd' - } - }, - host: { - id: 1, - ipv4: 'aaaa', - os: { - vendor: { - name: 'dd' - } - }, - } - }; - this.probeHosts = []; - this.probeHosts.push(probeHost); + // const probeHost: ProbeHost = { + // id: 1, + // probe: { + // id: 1, + // displayName: 'ddd', + // cidr: 'dddd', + // authorizeDate: new Date(), + // authorizeMember: { + // name: 'ddd' + // } + // }, + // host: { + // id: 1, + // ipv4: 'aaaa', + // os: { + // vendor: { + // name: 'dd' + // } + // }, + // } + // }; + // this.probeHosts = []; + // this.probeHosts.push(probeHost); } diff --git a/@overflow/probe/service/probe-host.service.ts b/@overflow/probe/service/probe-host.service.ts index 4783dd8..c63c3f2 100644 --- a/@overflow/probe/service/probe-host.service.ts +++ b/@overflow/probe/service/probe-host.service.ts @@ -15,12 +15,16 @@ export class ProbeHostService { } - public readByProbe(probe: Probe): Observable { - return this.rpcService.call('ProbeHostService.readByProbe', probe); + public readByProbeID(probeID: number): Observable { + return this.rpcService.call('ProbeHostService.readByProbeID', probeID); } - public readAllByDomain(domain: Domain): Observable { - return this.rpcService.call('ProbeHostService.readAllByDomain', domain); + public readAllByDomainID(domainID: number): Observable { + return this.rpcService.call('ProbeHostService.readAllByDomainID', domainID); + } + + public read(id: number): Observable { + return this.rpcService.call('ProbeHostService.read', id); } } diff --git a/@overflow/probe/store/index.ts b/@overflow/probe/store/index.ts index b787b53..526b25e 100644 --- a/@overflow/probe/store/index.ts +++ b/@overflow/probe/store/index.ts @@ -8,55 +8,23 @@ import { StateSelector } from '@overflow/core/ngrx/store'; import { MODULE } from '../probe.constant'; -import * as ProbeListStore from './list'; -import * as ProbeDetailStore from './detail'; -import * as ProbeHostStore from './probe-host'; -import * as ProbeHostListStore from './probe-host-list'; -import * as ProbeModifyStore from './modify'; +import * as ProbeStore from './probe'; export interface State { - list: ProbeListStore.State; - detail: ProbeDetailStore.State; - probeHost: ProbeHostStore.State; - probeHosts: ProbeHostListStore.State; - modify: ProbeModifyStore.State; + probes: ProbeStore.State; } export const REDUCERS = { - list: ProbeListStore.reducer, - detail: ProbeDetailStore.reducer, - probeHost: ProbeHostStore.reducer, - probeHosts: ProbeHostListStore.reducer, - modify: ProbeModifyStore.reducer + probes: ProbeStore.reducer, }; export const EFFECTS = [ - ProbeListStore.Effects, - ProbeDetailStore.Effects, - ProbeHostStore.Effects, - ProbeHostListStore.Effects, - ProbeModifyStore.Effects + ProbeStore.Effects, ]; export const selectProbeState = createFeatureSelector(MODULE.name); -export const ListSelector = new StateSelector(createSelector( +export const ProbeSelector = new StateSelector(createSelector( selectProbeState, - (state: State) => state.list -)); -export const DetailSelector = new StateSelector(createSelector( - selectProbeState, - (state: State) => state.detail -)); -export const ModifySelector = new StateSelector(createSelector( - selectProbeState, - (state: State) => state.modify -)); -export const ProbeHostSelector = new StateSelector(createSelector( - selectProbeState, - (state: State) => state.probeHost -)); -export const ProbeHostListSelector = new StateSelector(createSelector( - selectProbeState, - (state: State) => state.probeHosts + (state: State) => state.probes )); diff --git a/@overflow/probe/store/probe/index.ts b/@overflow/probe/store/probe/index.ts new file mode 100644 index 0000000..d8f12e5 --- /dev/null +++ b/@overflow/probe/store/probe/index.ts @@ -0,0 +1,4 @@ +export * from './probe.action'; +export * from './probe.effect'; +export * from './probe.reducer'; +export * from './probe.state'; diff --git a/@overflow/probe/store/probe/probe.action.ts b/@overflow/probe/store/probe/probe.action.ts new file mode 100644 index 0000000..368bccb --- /dev/null +++ b/@overflow/probe/store/probe/probe.action.ts @@ -0,0 +1,58 @@ +import { Action } from '@ngrx/store'; +import { RPCClientError } from '@loafer/ng-rpc'; +import { ProbeHost } from '@overflow/commons-typescript/model/probe'; + +export enum ActionType { + ReadAllByDomainID = '[probe.list] ReadAllByDomainID', + ReadAllByDomainIDSuccess = '[probe.list] ReadAllByDomainIDSuccess', + ReadAllByDomainIDFailure = '[probe.list] ReadAllByDomainIDFailure', + + Read = '[probe.detail] Read', + ReadSuccess = '[probe.detail] ReadSuccess', + ReadFailure = '[probe.detail] ReadFailure', +} + +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: ProbeHost[]) {} +} + +export class ReadAllByDomainIDFailure implements Action { + readonly type = ActionType.ReadAllByDomainIDFailure; + + constructor(public payload: RPCClientError) {} +} + +export class Read implements Action { + readonly type = ActionType.Read; + + constructor(public payload: number) {} +} + +export class ReadSuccess implements Action { + readonly type = ActionType.ReadSuccess; + + constructor(public payload: ProbeHost) {} +} + +export class ReadFailure implements Action { + readonly type = ActionType.ReadFailure; + + constructor(public payload: RPCClientError) {} +} + +export type Actions = + | ReadAllByDomainID + | ReadAllByDomainIDSuccess + | ReadAllByDomainIDFailure + | Read + | ReadSuccess + | ReadFailure +; diff --git a/@overflow/probe/store/probe/probe.effect.ts b/@overflow/probe/store/probe/probe.effect.ts new file mode 100644 index 0000000..9d8faba --- /dev/null +++ b/@overflow/probe/store/probe/probe.effect.ts @@ -0,0 +1,64 @@ +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 { Domain } from '@overflow/commons-typescript/model/domain'; +import { Probe } from '@overflow/commons-typescript/model/probe'; + +import { + ReadAllByDomainID, + ReadAllByDomainIDFailure, + ReadAllByDomainIDSuccess, + Read, + ReadSuccess, + ReadFailure, + ActionType +} from './probe.action'; +import { ProbeHostService } from '../../service/probe-host.service'; + +@Injectable() +export class Effects { + + constructor( + private actions$: Actions, + private probeHostService: ProbeHostService, + private router: Router + ) { } + + @Effect() + ReadAllByDomainID$: Observable = this.actions$ + .ofType(ActionType.ReadAllByDomainID) + .map((action: ReadAllByDomainID) => action.payload) + .switchMap(payload => this.probeHostService.readAllByDomainID(payload)) + .map(probeHosts => { + return new ReadAllByDomainIDSuccess(probeHosts); + }) + .catch((error: RPCClientError) => { + return of(new ReadAllByDomainIDFailure(error)); + }); + + @Effect() + Read$: Observable = this.actions$ + .ofType(ActionType.Read) + .map((action: Read) => action.payload) + .switchMap(payload => this.probeHostService.read(payload)) + .map(probeHost => { + return new ReadSuccess(probeHost); + }) + .catch((error: RPCClientError) => { + return of(new ReadAllByDomainIDFailure(error)); + }); +} diff --git a/@overflow/probe/store/probe/probe.reducer.ts b/@overflow/probe/store/probe/probe.reducer.ts new file mode 100644 index 0000000..c74f63d --- /dev/null +++ b/@overflow/probe/store/probe/probe.reducer.ts @@ -0,0 +1,68 @@ +import { + ReadAllByDomainID, + ReadAllByDomainIDFailure, + ReadAllByDomainIDSuccess, + ActionType, + Actions, +} from './probe.action'; + +import { + State, + initialState, +} from './probe.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, + error: null, + }; + } + + case ActionType.ReadAllByDomainIDSuccess: { + return { + ...state, + error: null, + probeHosts: action.payload, + }; + } + + case ActionType.ReadAllByDomainIDFailure: { + return { + ...state, + error: action.payload, + probeHosts: null, + }; + } + + case ActionType.Read: { + return { + ...state, + error: null, + }; + } + + case ActionType.ReadSuccess: { + return { + ...state, + error: null, + probeHosts: [action.payload], + }; + } + + case ActionType.ReadFailure: { + return { + ...state, + error: action.payload, + probeHosts: null, + }; + } + + default: { + return state; + } + } +} diff --git a/@overflow/probe/store/probe/probe.state.ts b/@overflow/probe/store/probe/probe.state.ts new file mode 100644 index 0000000..42e8885 --- /dev/null +++ b/@overflow/probe/store/probe/probe.state.ts @@ -0,0 +1,12 @@ +import { RPCClientError } from '@loafer/ng-rpc'; +import { ProbeHost } from '@overflow/commons-typescript/model/probe'; + +export interface State { + error: RPCClientError | null; + probeHosts: ProbeHost[] | null; +} + +export const initialState: State = { + error: null, + probeHosts: null, +}; diff --git a/@overflow/probe/store/detail/detail.action.ts b/@overflow/probe/store/trash/detail/detail.action.ts similarity index 100% rename from @overflow/probe/store/detail/detail.action.ts rename to @overflow/probe/store/trash/detail/detail.action.ts diff --git a/@overflow/probe/store/detail/detail.effect.spec.ts b/@overflow/probe/store/trash/detail/detail.effect.spec.ts similarity index 100% rename from @overflow/probe/store/detail/detail.effect.spec.ts rename to @overflow/probe/store/trash/detail/detail.effect.spec.ts diff --git a/@overflow/probe/store/detail/detail.effect.ts b/@overflow/probe/store/trash/detail/detail.effect.ts similarity index 100% rename from @overflow/probe/store/detail/detail.effect.ts rename to @overflow/probe/store/trash/detail/detail.effect.ts diff --git a/@overflow/probe/store/detail/detail.reducer.ts b/@overflow/probe/store/trash/detail/detail.reducer.ts similarity index 100% rename from @overflow/probe/store/detail/detail.reducer.ts rename to @overflow/probe/store/trash/detail/detail.reducer.ts diff --git a/@overflow/probe/store/detail/detail.state.ts b/@overflow/probe/store/trash/detail/detail.state.ts similarity index 100% rename from @overflow/probe/store/detail/detail.state.ts rename to @overflow/probe/store/trash/detail/detail.state.ts diff --git a/@overflow/probe/store/detail/index.ts b/@overflow/probe/store/trash/detail/index.ts similarity index 100% rename from @overflow/probe/store/detail/index.ts rename to @overflow/probe/store/trash/detail/index.ts diff --git a/@overflow/probe/store/list/index.ts b/@overflow/probe/store/trash/list/index.ts similarity index 100% rename from @overflow/probe/store/list/index.ts rename to @overflow/probe/store/trash/list/index.ts diff --git a/@overflow/probe/store/list/list.action.ts b/@overflow/probe/store/trash/list/list.action.ts similarity index 100% rename from @overflow/probe/store/list/list.action.ts rename to @overflow/probe/store/trash/list/list.action.ts diff --git a/@overflow/probe/store/list/list.effect.spec.ts b/@overflow/probe/store/trash/list/list.effect.spec.ts similarity index 100% rename from @overflow/probe/store/list/list.effect.spec.ts rename to @overflow/probe/store/trash/list/list.effect.spec.ts diff --git a/@overflow/probe/store/list/list.effect.ts b/@overflow/probe/store/trash/list/list.effect.ts similarity index 100% rename from @overflow/probe/store/list/list.effect.ts rename to @overflow/probe/store/trash/list/list.effect.ts diff --git a/@overflow/probe/store/list/list.reducer.ts b/@overflow/probe/store/trash/list/list.reducer.ts similarity index 100% rename from @overflow/probe/store/list/list.reducer.ts rename to @overflow/probe/store/trash/list/list.reducer.ts diff --git a/@overflow/probe/store/list/list.state.ts b/@overflow/probe/store/trash/list/list.state.ts similarity index 100% rename from @overflow/probe/store/list/list.state.ts rename to @overflow/probe/store/trash/list/list.state.ts diff --git a/@overflow/probe/store/modify/index.ts b/@overflow/probe/store/trash/modify/index.ts similarity index 100% rename from @overflow/probe/store/modify/index.ts rename to @overflow/probe/store/trash/modify/index.ts diff --git a/@overflow/probe/store/modify/modify.action.ts b/@overflow/probe/store/trash/modify/modify.action.ts similarity index 100% rename from @overflow/probe/store/modify/modify.action.ts rename to @overflow/probe/store/trash/modify/modify.action.ts diff --git a/@overflow/probe/store/modify/modify.effect.spec.ts b/@overflow/probe/store/trash/modify/modify.effect.spec.ts similarity index 100% rename from @overflow/probe/store/modify/modify.effect.spec.ts rename to @overflow/probe/store/trash/modify/modify.effect.spec.ts diff --git a/@overflow/probe/store/modify/modify.effect.ts b/@overflow/probe/store/trash/modify/modify.effect.ts similarity index 100% rename from @overflow/probe/store/modify/modify.effect.ts rename to @overflow/probe/store/trash/modify/modify.effect.ts diff --git a/@overflow/probe/store/modify/modify.reducer.ts b/@overflow/probe/store/trash/modify/modify.reducer.ts similarity index 100% rename from @overflow/probe/store/modify/modify.reducer.ts rename to @overflow/probe/store/trash/modify/modify.reducer.ts diff --git a/@overflow/probe/store/modify/modify.state.ts b/@overflow/probe/store/trash/modify/modify.state.ts similarity index 100% rename from @overflow/probe/store/modify/modify.state.ts rename to @overflow/probe/store/trash/modify/modify.state.ts diff --git a/@overflow/probe/store/probe-host-list/index.ts b/@overflow/probe/store/trash/probe-host-list/index.ts similarity index 100% rename from @overflow/probe/store/probe-host-list/index.ts rename to @overflow/probe/store/trash/probe-host-list/index.ts diff --git a/@overflow/probe/store/probe-host-list/list.action.ts b/@overflow/probe/store/trash/probe-host-list/list.action.ts similarity index 100% rename from @overflow/probe/store/probe-host-list/list.action.ts rename to @overflow/probe/store/trash/probe-host-list/list.action.ts diff --git a/@overflow/probe/store/probe-host-list/list.effect.spec.ts b/@overflow/probe/store/trash/probe-host-list/list.effect.spec.ts similarity index 100% rename from @overflow/probe/store/probe-host-list/list.effect.spec.ts rename to @overflow/probe/store/trash/probe-host-list/list.effect.spec.ts diff --git a/@overflow/probe/store/probe-host-list/list.effect.ts b/@overflow/probe/store/trash/probe-host-list/list.effect.ts similarity index 100% rename from @overflow/probe/store/probe-host-list/list.effect.ts rename to @overflow/probe/store/trash/probe-host-list/list.effect.ts diff --git a/@overflow/probe/store/probe-host-list/list.reducer.ts b/@overflow/probe/store/trash/probe-host-list/list.reducer.ts similarity index 100% rename from @overflow/probe/store/probe-host-list/list.reducer.ts rename to @overflow/probe/store/trash/probe-host-list/list.reducer.ts diff --git a/@overflow/probe/store/probe-host-list/list.state.ts b/@overflow/probe/store/trash/probe-host-list/list.state.ts similarity index 100% rename from @overflow/probe/store/probe-host-list/list.state.ts rename to @overflow/probe/store/trash/probe-host-list/list.state.ts diff --git a/@overflow/probe/store/probe-host/index.ts b/@overflow/probe/store/trash/probe-host/index.ts similarity index 100% rename from @overflow/probe/store/probe-host/index.ts rename to @overflow/probe/store/trash/probe-host/index.ts diff --git a/@overflow/probe/store/probe-host/probe-host.action.ts b/@overflow/probe/store/trash/probe-host/probe-host.action.ts similarity index 100% rename from @overflow/probe/store/probe-host/probe-host.action.ts rename to @overflow/probe/store/trash/probe-host/probe-host.action.ts diff --git a/@overflow/probe/store/probe-host/probe-host.effect.spec.ts b/@overflow/probe/store/trash/probe-host/probe-host.effect.spec.ts similarity index 100% rename from @overflow/probe/store/probe-host/probe-host.effect.spec.ts rename to @overflow/probe/store/trash/probe-host/probe-host.effect.spec.ts diff --git a/@overflow/probe/store/probe-host/probe-host.effect.ts b/@overflow/probe/store/trash/probe-host/probe-host.effect.ts similarity index 100% rename from @overflow/probe/store/probe-host/probe-host.effect.ts rename to @overflow/probe/store/trash/probe-host/probe-host.effect.ts diff --git a/@overflow/probe/store/probe-host/probe-host.reducer.ts b/@overflow/probe/store/trash/probe-host/probe-host.reducer.ts similarity index 100% rename from @overflow/probe/store/probe-host/probe-host.reducer.ts rename to @overflow/probe/store/trash/probe-host/probe-host.reducer.ts diff --git a/@overflow/probe/store/probe-host/probe-host.state.ts b/@overflow/probe/store/trash/probe-host/probe-host.state.ts similarity index 100% rename from @overflow/probe/store/probe-host/probe-host.state.ts rename to @overflow/probe/store/trash/probe-host/probe-host.state.ts diff --git a/@overflow/probe/store/remove/index.ts b/@overflow/probe/store/trash/remove/index.ts similarity index 100% rename from @overflow/probe/store/remove/index.ts rename to @overflow/probe/store/trash/remove/index.ts diff --git a/@overflow/probe/store/remove/remove.action.ts b/@overflow/probe/store/trash/remove/remove.action.ts similarity index 100% rename from @overflow/probe/store/remove/remove.action.ts rename to @overflow/probe/store/trash/remove/remove.action.ts diff --git a/@overflow/probe/store/remove/remove.effect.spec.ts b/@overflow/probe/store/trash/remove/remove.effect.spec.ts similarity index 100% rename from @overflow/probe/store/remove/remove.effect.spec.ts rename to @overflow/probe/store/trash/remove/remove.effect.spec.ts diff --git a/@overflow/probe/store/remove/remove.effect.ts b/@overflow/probe/store/trash/remove/remove.effect.ts similarity index 100% rename from @overflow/probe/store/remove/remove.effect.ts rename to @overflow/probe/store/trash/remove/remove.effect.ts diff --git a/@overflow/probe/store/remove/remove.reducer.ts b/@overflow/probe/store/trash/remove/remove.reducer.ts similarity index 100% rename from @overflow/probe/store/remove/remove.reducer.ts rename to @overflow/probe/store/trash/remove/remove.reducer.ts diff --git a/@overflow/probe/store/remove/remove.state.ts b/@overflow/probe/store/trash/remove/remove.state.ts similarity index 100% rename from @overflow/probe/store/remove/remove.state.ts rename to @overflow/probe/store/trash/remove/remove.state.ts