From e4e6a45238030d165979791a427728a2bb796fd3 Mon Sep 17 00:00:00 2001 From: insanity Date: Thu, 19 Apr 2018 19:26:39 +0900 Subject: [PATCH] arrange pages --- src/packages/infra/service/infra.service.ts | 4 ++ .../infra/store/detail/detail.action.ts | 35 +++++++++++++ .../infra/store/detail/detail.effect.spec.ts | 15 ++++++ .../infra/store/detail/detail.effect.ts | 49 ++++++++++++++++++ .../infra/store/detail/detail.reducer.ts | 38 ++++++++++++++ .../infra/store/detail/detail.state.ts | 16 ++++++ src/packages/infra/store/detail/index.ts | 4 ++ src/packages/infra/store/index.ts | 8 +++ .../component/detail/detail.component.ts | 2 +- .../component/list/list.component.ts | 14 +---- .../sensor/component/list/list.component.html | 13 ++++- .../sensor/component/list/list.component.ts | 51 +++++++++++++++---- .../target/component/list/list.component.html | 27 ++-------- .../target/component/list/list.component.ts | 4 +- src/packages/target/target.module.ts | 4 +- 15 files changed, 235 insertions(+), 49 deletions(-) create mode 100644 src/packages/infra/store/detail/detail.action.ts create mode 100644 src/packages/infra/store/detail/detail.effect.spec.ts create mode 100644 src/packages/infra/store/detail/detail.effect.ts create mode 100644 src/packages/infra/store/detail/detail.reducer.ts create mode 100644 src/packages/infra/store/detail/detail.state.ts create mode 100644 src/packages/infra/store/detail/index.ts diff --git a/src/packages/infra/service/infra.service.ts b/src/packages/infra/service/infra.service.ts index 528fea6..30b3845 100644 --- a/src/packages/infra/service/infra.service.ts +++ b/src/packages/infra/service/infra.service.ts @@ -26,4 +26,8 @@ export class InfraService { public readAllByProbe(probe: Probe, pageParams: PageParams): Observable { return this.rpcService.call('InfraService.readAllByProbe', probe, pageParams); } + + public read(id: string): Observable { + return this.rpcService.call('InfraService.read', id); + } } diff --git a/src/packages/infra/store/detail/detail.action.ts b/src/packages/infra/store/detail/detail.action.ts new file mode 100644 index 0000000..a06e770 --- /dev/null +++ b/src/packages/infra/store/detail/detail.action.ts @@ -0,0 +1,35 @@ +import { Action } from '@ngrx/store'; +import { RPCClientError } from '@loafer/ng-rpc/protocol'; +import { Infra } from '../../model'; + +export enum ActionType { + Read = '[Infra.list] Read', + ReadSuccess = '[Infra.list] ReadSuccess', + ReadFailure = '[Infra.list] ReadFailure', +} + +export class Read implements Action { + readonly type = ActionType.Read; + + constructor(public payload: { id: string }) { } +} + +export class ReadSuccess implements Action { + readonly type = ActionType.ReadSuccess; + + constructor(public payload: Infra) { } +} + +export class ReadFailure implements Action { + readonly type = ActionType.ReadFailure; + + constructor(public payload: RPCClientError) { } +} + + + +export type Actions = + | Read + | ReadSuccess + | ReadFailure + ; diff --git a/src/packages/infra/store/detail/detail.effect.spec.ts b/src/packages/infra/store/detail/detail.effect.spec.ts new file mode 100644 index 0000000..a77b6b1 --- /dev/null +++ b/src/packages/infra/store/detail/detail.effect.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { Effects } from './list.effect'; + +describe('list.Effects', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [Effects] + }); + }); + + it('should be created', inject([Effects], (effects: Effects) => { + expect(effects).toBeTruthy(); + })); +}); diff --git a/src/packages/infra/store/detail/detail.effect.ts b/src/packages/infra/store/detail/detail.effect.ts new file mode 100644 index 0000000..de37117 --- /dev/null +++ b/src/packages/infra/store/detail/detail.effect.ts @@ -0,0 +1,49 @@ +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/map'; +import 'rxjs/add/operator/take'; + +import { RPCClientError } from '@loafer/ng-rpc/protocol'; + +import { Infra } from '../../model'; + +import { + Read, + ReadSuccess, + ReadFailure, + ActionType, +} from './detail.action'; +import { InfraService } from '../../service/infra.service'; + +@Injectable() +export class Effects { + + constructor( + private actions$: Actions, + private infraService: InfraService, + private router: Router + ) { } + + @Effect() + read$: Observable = this.actions$ + .ofType(ActionType.Read) + .map((action: Read) => action.payload) + .switchMap(payload => this.infraService.read(payload.id)) + .map(infra => { + return new ReadSuccess(infra); + }) + .catch((error: RPCClientError) => { + return of(new ReadFailure(error)); + }); + +} diff --git a/src/packages/infra/store/detail/detail.reducer.ts b/src/packages/infra/store/detail/detail.reducer.ts new file mode 100644 index 0000000..d3c93ba --- /dev/null +++ b/src/packages/infra/store/detail/detail.reducer.ts @@ -0,0 +1,38 @@ +import { Actions, ActionType } from './detail.action'; +import { State, initialState } from './detail.state'; + +import { Infra } from '../../model'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.Read: { + return { + ...state, + error: null, + isPending: true, + }; + } + + case ActionType.ReadSuccess: { + return { + ...state, + error: null, + isPending: false, + infra: action.payload + }; + } + + case ActionType.ReadFailure: { + return { + ...state, + error: action.payload, + isPending: false, + infra: null + }; + } + + default: { + return state; + } + } +} diff --git a/src/packages/infra/store/detail/detail.state.ts b/src/packages/infra/store/detail/detail.state.ts new file mode 100644 index 0000000..513a03a --- /dev/null +++ b/src/packages/infra/store/detail/detail.state.ts @@ -0,0 +1,16 @@ +import { RPCClientError } from '@loafer/ng-rpc/protocol'; + +import { Infra } from '../../model'; + +export interface State { + error: RPCClientError | null; + isPending: boolean; + infra: Infra | null; +} + +export const initialState: State = { + error: null, + isPending: false, + infra: null, +}; + diff --git a/src/packages/infra/store/detail/index.ts b/src/packages/infra/store/detail/index.ts new file mode 100644 index 0000000..23ae8ab --- /dev/null +++ b/src/packages/infra/store/detail/index.ts @@ -0,0 +1,4 @@ +export * from './detail.action'; +export * from './detail.effect'; +export * from './detail.reducer'; +export * from './detail.state'; diff --git a/src/packages/infra/store/index.ts b/src/packages/infra/store/index.ts index 25bb7f3..05b6b69 100644 --- a/src/packages/infra/store/index.ts +++ b/src/packages/infra/store/index.ts @@ -7,18 +7,22 @@ import { import { MODULE } from '../infra.constant'; import * as ListStore from './list'; +import * as DetailStore from './detail'; import { StateSelector } from 'packages/core/ngrx/store'; export interface State { list: ListStore.State; + sensor: DetailStore.State; } export const REDUCERS = { list: ListStore.reducer, + sensor: DetailStore.reducer }; export const EFFECTS = [ ListStore.Effects, + DetailStore.Effects ]; export const selectInfraState = createFeatureSelector(MODULE.name); @@ -28,3 +32,7 @@ export const ListSelector = new StateSelector(createSelector( (state: State) => state.list )); +export const DetailSelector = new StateSelector(createSelector( + selectInfraState, + (state: State) => state.sensor +)); diff --git a/src/packages/probe/component/detail/detail.component.ts b/src/packages/probe/component/detail/detail.component.ts index b5899ce..7ac90f2 100644 --- a/src/packages/probe/component/detail/detail.component.ts +++ b/src/packages/probe/component/detail/detail.component.ts @@ -74,7 +74,7 @@ export class DetailComponent implements OnInit, AfterContentInit { icon: 'fa fa-trash', message: 'Are you sure to remove this Probe?', accept: () => { - this.router.navigate(['probes']); + this.router.navigate(['probes/list']); }, reject: () => { } diff --git a/src/packages/sensor-item/component/list/list.component.ts b/src/packages/sensor-item/component/list/list.component.ts index 93241e9..22f7cf7 100644 --- a/src/packages/sensor-item/component/list/list.component.ts +++ b/src/packages/sensor-item/component/list/list.component.ts @@ -1,18 +1,6 @@ import { Component, OnInit, AfterViewInit, AfterContentInit } from '@angular/core'; import { Router } from '@angular/router'; -import { MetaSensorDisplayItem } from '../../../meta/sensor-display-item/model/MetaSensorDisplayItem'; - -export interface Probe { - id: string; - name: string; - ip: string; - os: string; - cidr: string; - targetCnt: number; - date: string; - authBy: string; -} - +import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem'; @Component({ selector: 'of-sensor-item-list', diff --git a/src/packages/sensor/component/list/list.component.html b/src/packages/sensor/component/list/list.component.html index 0eb1729..96d0950 100644 --- a/src/packages/sensor/component/list/list.component.html +++ b/src/packages/sensor/component/list/list.component.html @@ -1,12 +1,23 @@

Sensors

+
+ + Up + + + + + + +
+
- +
diff --git a/src/packages/sensor/component/list/list.component.ts b/src/packages/sensor/component/list/list.component.ts index 19193ec..c16638d 100644 --- a/src/packages/sensor/component/list/list.component.ts +++ b/src/packages/sensor/component/list/list.component.ts @@ -1,12 +1,8 @@ -import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core'; -import { AfterContentInit } from '@angular/core/src/metadata/lifecycle_hooks'; -import { Router } from '@angular/router'; +import { Component, OnInit, AfterViewInit, ViewChild, AfterContentInit } from '@angular/core'; +import { Router, ActivatedRoute } from '@angular/router'; import { Sensor } from '../../model'; - import { Store, select } from '@ngrx/store'; - import * as SensorStore from '../../store'; - import { RPCClientError } from '@loafer/ng-rpc/protocol'; import * as ListStore from '../../store/list'; import { sensorListSelector } from '../../store'; @@ -17,6 +13,11 @@ import { Target } from 'packages/target/model'; import { SettingComponent } from '../setting/setting.component'; import { SelectItem } from 'primeng/primeng'; +import { Infra } from 'packages/infra/model'; +import * as InfraDetailStore from 'packages/infra/store/detail'; +import { DetailSelector as InfraDetailSelector } from 'packages/infra/store'; + + @Component({ selector: 'of-sensor-list', templateUrl: './list.component.html', @@ -29,23 +30,37 @@ export class ListComponent implements OnInit, AfterContentInit { totalLength = 0; sensorSettingDisplay = false; + paramTarget?: Infra = null; + infra$ = this.infraDetailStore.pipe(select(InfraDetailSelector.select('infra'))); + sensors: Sensor[]; target: Target = null; - targetSensor; // filter targetOptions: SelectItem[]; - filteredName: string; selectedTargets: string[] = []; selectedStatus: string[] = []; - constructor(private router: Router, + constructor( + private router: Router, + private route: ActivatedRoute, private store: Store, + private infraDetailStore: Store, ) { } ngOnInit() { + let infraID = null; + this.route.queryParams.subscribe((queryParams: any) => { + infraID = queryParams.target; + if (infraID) { + this.getInfraInfo(infraID); + } else { + this.paramTarget = null; + } + }); + this.sensorList$.subscribe( (page: Page) => { if (page != null) { @@ -59,6 +74,24 @@ export class ListComponent implements OnInit, AfterContentInit { ); } + getInfraInfo(infraID: string) { + this.infraDetailStore.dispatch( + new InfraDetailStore.Read( + { id: infraID } + ) + ); + this.infra$.subscribe( + (infra: Infra) => { + console.log(infra); + this.paramTarget = infra; + }, + (error: RPCClientError) => { + console.log(error.response.message); + } + ); + + } + ngAfterContentInit() { this.getSensors(0); } diff --git a/src/packages/target/component/list/list.component.html b/src/packages/target/component/list/list.component.html index b674866..1232915 100644 --- a/src/packages/target/component/list/list.component.html +++ b/src/packages/target/component/list/list.component.html @@ -1,9 +1,8 @@

Targets

- - + + - No. Status Type @@ -13,13 +12,8 @@ - - - - - - - + + {{rowIndex}} ?? {{infra.infraType.name}} @@ -27,21 +21,10 @@ ?? {{infra.createDate | date: 'dd.MM.yyyy'}} - + - - - - -
-
요기다가 센서 리스트와 상태 출력
-
- - -
-
diff --git a/src/packages/target/component/list/list.component.ts b/src/packages/target/component/list/list.component.ts index 604f741..4119190 100644 --- a/src/packages/target/component/list/list.component.ts +++ b/src/packages/target/component/list/list.component.ts @@ -124,8 +124,7 @@ export class ListComponent implements OnInit, AfterContentInit { } onRowSelect(event) { - console.log(event.data.target); - // this.router.navigate(['notification']); + this.router.navigate(['sensors'], { queryParams: {target: event.data.id}}); } onAddSensor(target: Target) { @@ -136,4 +135,5 @@ export class ListComponent implements OnInit, AfterContentInit { onSensorSettingClose() { this.sensorSettingDisplay = false; } + } diff --git a/src/packages/target/target.module.ts b/src/packages/target/target.module.ts index b34162c..4c0ed51 100644 --- a/src/packages/target/target.module.ts +++ b/src/packages/target/target.module.ts @@ -5,12 +5,14 @@ import { COMPONENTS } from './component'; import { SERVICES } from './service'; import { PrimeNGModules } from '../commons/prime-ng/prime-ng.module'; import { SensorModule } from '../sensor/sensor.module'; +import { KeyValueModule } from 'app/commons/component/key-value/key-value.module'; @NgModule({ imports: [ CommonModule, PrimeNGModules, - SensorModule + SensorModule, + KeyValueModule ], declarations: [ COMPONENTS,