From 43582c7199c2d28d4866d31d08fe30421f4690ce Mon Sep 17 00:00:00 2001 From: insanity Date: Mon, 12 Mar 2018 20:05:05 +0900 Subject: [PATCH] test --- .../noauth/component/list/list.component.ts | 1 + .../probe/component/list/list.component.html | 4 +- .../probe/component/list/list.component.ts | 78 ++++++++++--------- src/packages/probe/model/Probe.ts | 2 +- .../probe/store/detail/detail.reducer.ts | 2 + .../probe/store/detail/detail.state.ts | 35 +++++++-- src/packages/probe/store/index.ts | 4 + 7 files changed, 78 insertions(+), 48 deletions(-) diff --git a/src/packages/noauth/component/list/list.component.ts b/src/packages/noauth/component/list/list.component.ts index 7170c2c..12b3390 100644 --- a/src/packages/noauth/component/list/list.component.ts +++ b/src/packages/noauth/component/list/list.component.ts @@ -35,6 +35,7 @@ export class ListComponent implements OnInit, AfterContentInit { ngAfterContentInit() { this.store.select(AuthSelector.select('domain')).subscribe( (domain: Domain) => { + console.log(domain); this.store.dispatch(new ListStore.ReadAllByDomain(domain)); } ); diff --git a/src/packages/probe/component/list/list.component.html b/src/packages/probe/component/list/list.component.html index f489401..1840b9b 100644 --- a/src/packages/probe/component/list/list.component.html +++ b/src/packages/probe/component/list/list.component.html @@ -8,12 +8,12 @@ IP - {{element.host.ip}} + OS - {{element.host.os.meta}} + diff --git a/src/packages/probe/component/list/list.component.ts b/src/packages/probe/component/list/list.component.ts index 6e17d60..0a6178c 100644 --- a/src/packages/probe/component/list/list.component.ts +++ b/src/packages/probe/component/list/list.component.ts @@ -19,8 +19,8 @@ import { ListSelector } from '../../store'; }) export class ListComponent implements OnInit, AfterContentInit { probes$ = this.store.pipe(select(ListSelector.select('probes'))); - pageSize = '25'; - length = '100'; + // pageSize = '25'; + // length = '100'; displayedColumns = ['name', 'ip', 'os', 'cidr', 'targetCnt', 'date', 'authBy']; dataSource: MatTableDataSource; @@ -33,15 +33,6 @@ export class ListComponent implements OnInit, AfterContentInit { } ngAfterContentInit() { - this.probes$.subscribe( - (probes: Probe[]) => { - this.dataSource = new MatTableDataSource(probes); - this.dataSource.sort = this.sort; - }, - (error: RPCError) => { - console.log(error); - } - ); this.store.select(AuthSelector.select('domain')).subscribe( (domain: Domain) => { @@ -52,34 +43,45 @@ export class ListComponent implements OnInit, AfterContentInit { } ); - // temporary data - const data: Probe[] = new Array(); - for (let i = 0; i < 100; i++) { - const p: Probe = { - id: i, - displayName: String('displayName' + i), - host: { - ip: i, - os: { - meta: 'blahblahblah' - }, - }, - cidr: String('cidr' + i), - targets: [ - { - id: i, - }, - ], - authorizeDate: new Date(), - authorizeMember: { - 'name': String('insanity') - }, - }; - data.push(p); - } + this.probes$.subscribe( + (probes: Probe[]) => { + console.log(probes); + this.dataSource = new MatTableDataSource(probes); + this.dataSource.sort = this.sort; + }, + (error: RPCError) => { + console.log(error.message); + } + ); - this.dataSource = new MatTableDataSource(data); - this.dataSource.sort = this.sort; + // // temporary data + // const data: Probe[] = new Array(); + // for (let i = 0; i < 100; i++) { + // const p: Probe = { + // id: i, + // displayName: String('displayName' + i), + // host: { + // ip: i, + // os: { + // meta: 'blahblahblah' + // }, + // }, + // cidr: String('cidr' + i), + // targets: [ + // { + // id: i, + // }, + // ], + // authorizeDate: new Date(), + // authorizeMember: { + // 'name': String('insanity') + // }, + // }; + // data.push(p); + // } + + // this.dataSource = new MatTableDataSource(data); + // this.dataSource.sort = this.sort; } ngOnInit() { diff --git a/src/packages/probe/model/Probe.ts b/src/packages/probe/model/Probe.ts index f7189bd..0c943f2 100644 --- a/src/packages/probe/model/Probe.ts +++ b/src/packages/probe/model/Probe.ts @@ -16,6 +16,6 @@ export interface Probe { cidr?: string; authorizeDate?: Date; authorizeMember?: Member; - host?: InfraHost; + // host?: InfraHost; targets?: Target[]; } diff --git a/src/packages/probe/store/detail/detail.reducer.ts b/src/packages/probe/store/detail/detail.reducer.ts index 21dccad..90bca24 100644 --- a/src/packages/probe/store/detail/detail.reducer.ts +++ b/src/packages/probe/store/detail/detail.reducer.ts @@ -9,10 +9,12 @@ import { import { State, initialState, + adapter, } from './detail.state'; import { Probe } from '../../model'; + export function reducer(state = initialState, action: Actions): State { switch (action.type) { case ActionType.Read: { diff --git a/src/packages/probe/store/detail/detail.state.ts b/src/packages/probe/store/detail/detail.state.ts index 4218697..3b614ab 100644 --- a/src/packages/probe/store/detail/detail.state.ts +++ b/src/packages/probe/store/detail/detail.state.ts @@ -2,18 +2,39 @@ import { RPCError } from 'packages/core/rpc/error'; import { Probe } from '../../model'; -export interface State { +// export interface State { +// error: RPCError | null; +// isPending: boolean; +// probe: Probe | null; +// } + +// export const initialState: State = { +// error: null, +// isPending: false, +// probe: null, +// }; + +// export const getProbe = (state: State) => state.probe; +// export const getError = (state: State) => state.error; +// export const isPending = (state: State) => state.isPending; + +import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity'; + +export interface State extends EntityState { error: RPCError | null; isPending: boolean; probe: Probe | null; } - -export const initialState: State = { +export const adapter: EntityAdapter = createEntityAdapter(); +export const initialState: State = adapter.getInitialState({ error: null, isPending: false, probe: null, -}; +}); -export const getProbe = (state: State) => state.probe; -export const getError = (state: State) => state.error; -export const isPending = (state: State) => state.isPending; +// export const { +// selectIds, +// selectEntities, +// selectAll, +// selectTotal, +// } = adapter.getSelectors(); diff --git a/src/packages/probe/store/index.ts b/src/packages/probe/store/index.ts index 1aa0543..60ac10c 100644 --- a/src/packages/probe/store/index.ts +++ b/src/packages/probe/store/index.ts @@ -32,3 +32,7 @@ export const ListSelector = new StateSelector(createSelect selectProbeState, (state: State) => state.list )); +export const DetailSelector = new StateSelector(createSelector( + selectProbeState, + (state: State) => state.detail +));