diff --git a/src/packages/infra/service/infra.service.ts b/src/packages/infra/service/infra.service.ts index cebe6c8..528fea6 100644 --- a/src/packages/infra/service/infra.service.ts +++ b/src/packages/infra/service/infra.service.ts @@ -6,9 +6,9 @@ import 'rxjs/add/operator/map'; import { RPCService } from '@loafer/ng-rpc/service'; import { Infra } from '../model'; -import { Page, PageParams } from '../../../app/commons/model'; -import { Domain } from '../../domain/model'; -import { Probe } from '../../probe/model'; +import { Page, PageParams } from 'app/commons/model'; +import { Domain } from 'packages/domain/model'; +import { Probe } from 'packages/probe/model'; @Injectable() export class InfraService { diff --git a/src/packages/infra/store/index.ts b/src/packages/infra/store/index.ts index 5c1dd3f..25bb7f3 100644 --- a/src/packages/infra/store/index.ts +++ b/src/packages/infra/store/index.ts @@ -7,8 +7,7 @@ import { import { MODULE } from '../infra.constant'; import * as ListStore from './list'; -import { StateSelector } from '../../core/ngrx/store'; - +import { StateSelector } from 'packages/core/ngrx/store'; export interface State { list: ListStore.State; diff --git a/src/packages/infra/store/list/list.reducer.ts b/src/packages/infra/store/list/list.reducer.ts index 698b9d4..ca23bee 100644 --- a/src/packages/infra/store/list/list.reducer.ts +++ b/src/packages/infra/store/list/list.reducer.ts @@ -32,6 +32,32 @@ export function reducer(state = initialState, action: Actions): State { }; } + case ActionType.ReadAllByProbe: { + return { + ...state, + error: null, + isPending: true, + }; + } + + case ActionType.ReadAllByProbeSuccess: { + return { + ...state, + error: null, + isPending: false, + page: action.payload + }; + } + + case ActionType.ReadAllByProbeFailure: { + return { + ...state, + error: action.payload, + isPending: false, + page: null + }; + } + default: { return state; } diff --git a/src/packages/infra/store/list/list.state.ts b/src/packages/infra/store/list/list.state.ts index 4af6fdb..a720536 100644 --- a/src/packages/infra/store/list/list.state.ts +++ b/src/packages/infra/store/list/list.state.ts @@ -1,12 +1,7 @@ -import { - createSelector, - MemoizedSelector, -} from '@ngrx/store'; - import { RPCClientError } from '@loafer/ng-rpc/protocol'; import { Infra } from '../../model'; -import { Page } from '../../../../app/commons/model'; +import { Page } from 'app/commons/model'; export interface State { error: RPCClientError | null; @@ -20,11 +15,3 @@ export const initialState: State = { page: null, }; -export class StateSelector { - public constructor(private _selector: MemoizedSelector) { - } - - public getInfraList = createSelector(this._selector, (state: State) => state.page); - public getError = createSelector(this._selector, (state: State) => state.error); - public isPending = createSelector(this._selector, (state: State) => state.isPending); -} diff --git a/src/packages/probe/component/list/list.component.ts b/src/packages/probe/component/list/list.component.ts index fa9f56d..1a5d642 100644 --- a/src/packages/probe/component/list/list.component.ts +++ b/src/packages/probe/component/list/list.component.ts @@ -28,7 +28,6 @@ export class ListComponent implements OnInit, AfterContentInit { ngOnInit() { this.probes$.subscribe( (probes: Probe[]) => { - console.log(probes); this.probes = probes; }, (error: RPCClientError) => { diff --git a/src/packages/probe/store/list/list.state.ts b/src/packages/probe/store/list/list.state.ts index 3d283bc..34309cc 100644 --- a/src/packages/probe/store/list/list.state.ts +++ b/src/packages/probe/store/list/list.state.ts @@ -13,7 +13,3 @@ export const initialState: State = { isPending: false, probes: null, }; - -export const getProbes = (state: State) => state.probes; -export const getError = (state: State) => state.error; -export const isPending = (state: State) => state.isPending; diff --git a/src/packages/sensor/component/setting/target-selector/target-selector.component.html b/src/packages/sensor/component/setting/target-selector/target-selector.component.html index 3fe9451..8db91c7 100644 --- a/src/packages/sensor/component/setting/target-selector/target-selector.component.html +++ b/src/packages/sensor/component/setting/target-selector/target-selector.component.html @@ -1,9 +1,9 @@ -
+
-
{{target.displayName}}
+
{{ target.displayName }}
diff --git a/src/packages/target/component/list/list.component.html b/src/packages/target/component/list/list.component.html index 5f10d31..f811849 100644 --- a/src/packages/target/component/list/list.component.html +++ b/src/packages/target/component/list/list.component.html @@ -1,5 +1,5 @@

Targets

- + No. @@ -11,7 +11,7 @@ - + {{rowIndex}} ?? @@ -20,8 +20,12 @@ ?? {{infra.createDate | date: 'dd.MM.yyyy'}} - + - \ No newline at end of file + + + + + diff --git a/src/packages/target/component/list/list.component.ts b/src/packages/target/component/list/list.component.ts index c9e23a2..30be636 100644 --- a/src/packages/target/component/list/list.component.ts +++ b/src/packages/target/component/list/list.component.ts @@ -3,50 +3,136 @@ import { Router, ActivatedRoute } from '@angular/router'; import { Infra } from 'packages/infra/model'; import { Store, select } from '@ngrx/store'; import { ListSelector } from 'packages/infra/store'; -import * as ListStore from 'packages/infra/store/list'; -import { Page } from 'app/commons/model'; +import * as InfraListStore from 'packages/infra/store/list'; +import { Page, PageParams } from 'app/commons/model'; import { RPCClientError } from '@loafer/ng-rpc/protocol'; import { Probe } from 'packages/probe/model'; +import * as ProbeDetailStore from 'packages/probe/store/detail'; +import { DetailSelector as ProbeDetailSelector } from 'packages/probe/store'; +import { Target } from '../../model'; + + @Component({ selector: 'of-target-list', templateUrl: './list.component.html', }) export class ListComponent implements OnInit, AfterContentInit { - infras$ = this.store.pipe(select(ListSelector.select('page'))); + probe$ = this.probeDetailStore.pipe(select(ProbeDetailSelector.select('probe'))); + infras$ = this.infraListStore.pipe(select(ListSelector.select('page'))); infras: Infra[]; probe: Probe; + target: Target = null; + sensorSettingDisplay = false; constructor( private route: ActivatedRoute, private router: Router, - private store: Store + private infraListStore: Store, + private probeDetailStore: Store, ) { - console.log('PROBE ID: ' + this.route.snapshot.paramMap.get('id')); - this.getProbe(); } ngOnInit() { - this.infras$.subscribe( - (page: Page) => { - if (page) { - this.infras = page.content; - } - }, - (error: RPCClientError) => { - console.log(error.response.message); - } - ); + // this.probe$.subscribe( + // (probe: Probe) => { + // if (probe) { + // console.log(probe); + // this.probe = probe; + // this.getInfras(probe); + // } + // }, + // (error: RPCClientError) => { + // console.log(error.response.message); + // } + // ); + + // this.infras$.subscribe( + // (page: Page) => { + // if (!page) { + // return; + // } + // this.infras = page.content; + // }, + // (error: RPCClientError) => { + // console.log(error); + // } + // ); } ngAfterContentInit() { - // if (this.probe) { - // this.store.dispatch(new ListStore.ReadAllByProbe(this.probe)); - // } + const probeId = this.route.snapshot.paramMap.get('id'); + this.getProbe(probeId); + + // Temporary + const infra1 = { + id: 1, + infraType: { + id: 1 + }, + target: { + id: 1, + displayName: 'FakeTarget1', + }, + }; + const infra2 = { + id: 2, + infraType: { + id: 3 + }, + target: { + id: 2, + displayName: 'FakeTarget2', + }, + }; + const infra3 = { + id: 3, + infraType: { + id: 2 + }, + target: { + id: 3, + displayName: 'FakeTarget3', + }, + }; + this.infras = []; + this.infras.push(infra1); + this.infras.push(infra2); + this.infras.push(infra3); } - getProbe() { + getProbe(probeId: string) { + this.probeDetailStore.dispatch( + new ProbeDetailStore.Read( + { id: probeId } + ) + ); + } + getInfras(probe) { + const pageParams: PageParams = { + pageNo: '0', + countPerPage: '10', + sortCol: 'id', + sortDirection: 'descending' + }; + this.infraListStore.dispatch( + new InfraListStore.ReadAllByProbe( + { probe, pageParams } + ) + ); + } + onRowSelect(event) { + console.log(event.data); + } + + onAddSensor(target: Target) { + this.target = target; + this.sensorSettingDisplay = true; + } + + onSensorSettingClose() { + this.sensorSettingDisplay = false; } } diff --git a/src/packages/target/target.module.ts b/src/packages/target/target.module.ts index 02e8ddf..b34162c 100644 --- a/src/packages/target/target.module.ts +++ b/src/packages/target/target.module.ts @@ -4,11 +4,13 @@ import { CommonModule } from '@angular/common'; import { COMPONENTS } from './component'; import { SERVICES } from './service'; import { PrimeNGModules } from '../commons/prime-ng/prime-ng.module'; +import { SensorModule } from '../sensor/sensor.module'; @NgModule({ imports: [ CommonModule, - PrimeNGModules + PrimeNGModules, + SensorModule ], declarations: [ COMPONENTS,