diff --git a/src/packages/sensor/model/SensorItem.ts b/src/packages/sensor-item/model/SensorItem.ts similarity index 82% rename from src/packages/sensor/model/SensorItem.ts rename to src/packages/sensor-item/model/SensorItem.ts index 440f8a9..7fe21b9 100644 --- a/src/packages/sensor/model/SensorItem.ts +++ b/src/packages/sensor-item/model/SensorItem.ts @@ -1,5 +1,5 @@ -import { Sensor } from './Sensor'; import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem'; +import { Sensor } from 'packages/sensor/model'; export interface SensorItem { id?: number; diff --git a/src/packages/sensor-item/model/SensorItemDependency.ts b/src/packages/sensor-item/model/SensorItemDependency.ts new file mode 100644 index 0000000..7db5ef3 --- /dev/null +++ b/src/packages/sensor-item/model/SensorItemDependency.ts @@ -0,0 +1,8 @@ +import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem'; +import { MetaSensorItemKey } from '../../meta/sensor-item-key/model/MetaSensorItemKey'; + +export interface SensorItemDependency { + id?: number; + item?: MetaSensorDisplayItem; + sensorItem?: MetaSensorItemKey; +} diff --git a/src/packages/sensor-item/sensor-item-store.module.ts b/src/packages/sensor-item/sensor-item-store.module.ts new file mode 100644 index 0000000..2080777 --- /dev/null +++ b/src/packages/sensor-item/sensor-item-store.module.ts @@ -0,0 +1,24 @@ +import { NgModule } from '@angular/core'; +import { StoreModule } from '@ngrx/store'; +import { StoreDevtoolsModule } from '@ngrx/store-devtools'; +import { + StoreRouterConnectingModule, + RouterStateSerializer, +} from '@ngrx/router-store'; +import { EffectsModule } from '@ngrx/effects'; +import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; + +import { + REDUCERS, + EFFECTS, +} from './store'; + +import { MODULE } from './sensor-item.constant'; + +@NgModule({ + imports: [ + StoreModule.forFeature(MODULE.name, REDUCERS), + EffectsModule.forFeature(EFFECTS), + ], +}) +export class SensorItemStoreModule { } diff --git a/src/packages/sensor-item/sensor-item.constant.ts b/src/packages/sensor-item/sensor-item.constant.ts new file mode 100644 index 0000000..1f3af81 --- /dev/null +++ b/src/packages/sensor-item/sensor-item.constant.ts @@ -0,0 +1,3 @@ +export const MODULE = { + name: 'sensorItem' +}; diff --git a/src/packages/sensor-item/sensor-item.module.ts b/src/packages/sensor-item/sensor-item.module.ts index bf301c5..aceb754 100644 --- a/src/packages/sensor-item/sensor-item.module.ts +++ b/src/packages/sensor-item/sensor-item.module.ts @@ -2,12 +2,15 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MaterialModule } from 'packages/commons/material/material.module'; import { COMPONENTS } from './component'; - +import { SensorItemStoreModule } from './sensor-item-store.module'; +import { MetaSensorDisplayItemModule } from '../meta/sensor-display-item/sensor-display-item.module'; +import { SERVICES } from './service'; @NgModule({ imports: [ CommonModule, MaterialModule, + SensorItemStoreModule, ], declarations: [ COMPONENTS, @@ -15,5 +18,8 @@ import { COMPONENTS } from './component'; exports: [ COMPONENTS, ], + providers: [ + SERVICES, + ], }) export class SensorItemModule { } diff --git a/src/packages/sensor-item/service/index.ts b/src/packages/sensor-item/service/index.ts new file mode 100644 index 0000000..f92c8a5 --- /dev/null +++ b/src/packages/sensor-item/service/index.ts @@ -0,0 +1,7 @@ +import { SensorItemDependencyService } from './sensor-item-dependency.service'; +import { SensorItemService } from './sensor-item.service'; + +export const SERVICES = [ + SensorItemDependencyService, + SensorItemService +]; diff --git a/src/packages/sensor-item/service/sensor-item-dependency.service.ts b/src/packages/sensor-item/service/sensor-item-dependency.service.ts new file mode 100644 index 0000000..b338b49 --- /dev/null +++ b/src/packages/sensor-item/service/sensor-item-dependency.service.ts @@ -0,0 +1,29 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; +import { SensorItemDependency } from '../model/SensorItemDependency'; +import { MetaSensorItemKey } from 'packages/meta/sensor-item-key/model/MetaSensorItemKey'; +import { MetaSensorDisplayItem } from '../../meta/sensor-display-item/model/MetaSensorDisplayItem'; + + + +@Injectable() +export class SensorItemDependencyService { + + public constructor( + private rpcClient: RPCClient, + ) { + + } + + public regist(dependency: SensorItemDependency): Observable { + return this.rpcClient.call('SensorItemDependencyService.regist', dependency); + } + + public readAllByDisplayItem(displayItem: MetaSensorDisplayItem): Observable { + return this.rpcClient.call('SensorItemDependencyService.readAllByDisplayItem', displayItem); + } + + +} diff --git a/src/packages/sensor-item/service/sensor-item.service.ts b/src/packages/sensor-item/service/sensor-item.service.ts new file mode 100644 index 0000000..36e377a --- /dev/null +++ b/src/packages/sensor-item/service/sensor-item.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; + +import { RPCClient } from 'packages/core/rpc/client/RPCClient'; + + + +@Injectable() +export class SensorItemService { + + public constructor( + private rpcClient: RPCClient, + ) { + + } + + // public regist(dependency: SensorItemDependency): Observable { + // return this.rpcClient.call('SensorItemDependencyService.regist', dependency); + // } + + +} diff --git a/src/packages/sensor-item/store/index.ts b/src/packages/sensor-item/store/index.ts new file mode 100644 index 0000000..7104a63 --- /dev/null +++ b/src/packages/sensor-item/store/index.ts @@ -0,0 +1,30 @@ +import { + createSelector, + createFeatureSelector, + ActionReducerMap, +} from '@ngrx/store'; + +import { StateSelector } from 'packages/core/ngrx/store'; + + +import * as ListStore from './key-list'; +import { MODULE } from '../sensor-item.constant'; + +export interface State { + list: ListStore.State; +} + +export const REDUCERS = { + list: ListStore.reducer, +}; + +export const EFFECTS = [ + ListStore.Effects, +]; + +export const selectState = createFeatureSelector(MODULE.name); + +export const ReadSensorItemKeySelector = new StateSelector(createSelector( + selectState, + (state: State) => state.list +)); diff --git a/src/packages/sensor-item/store/key-list/index.ts b/src/packages/sensor-item/store/key-list/index.ts new file mode 100644 index 0000000..7fd86e0 --- /dev/null +++ b/src/packages/sensor-item/store/key-list/index.ts @@ -0,0 +1,4 @@ +export * from './list.action'; +export * from './list.effect'; +export * from './list.reducer'; +export * from './list.state'; diff --git a/src/packages/sensor-item/store/key-list/list.action.ts b/src/packages/sensor-item/store/key-list/list.action.ts new file mode 100644 index 0000000..d6c8c0b --- /dev/null +++ b/src/packages/sensor-item/store/key-list/list.action.ts @@ -0,0 +1,37 @@ +import { Action } from '@ngrx/store'; + +import { RPCError } from 'packages/core/rpc/error'; +import { MetaSensorItemKey } from 'packages/meta/sensor-item-key/model/MetaSensorItemKey'; +import { MetaSensorDisplayItem } from 'packages/meta/sensor-display-item/model/MetaSensorDisplayItem'; + + +export enum ActionType { + ReadAllByDisplayItem = '[meta.sensor-display-key-list] ReadAllByDisplayItem', + ReadAllByDisplayItemSuccess = '[meta.sensor-display-key-list] ReadAllByDisplayItemSuccess', + ReadAllByDisplayItemFailure = '[meta.sensor-display-key-list] ReadAllByDisplayItemFailure', +} + +export class ReadAllByDisplayItem implements Action { + readonly type = ActionType.ReadAllByDisplayItem; + + constructor(public payload: MetaSensorDisplayItem) {} +} + +export class ReadAllByDisplayItemSuccess implements Action { + readonly type = ActionType.ReadAllByDisplayItemSuccess; + + constructor(public payload: MetaSensorItemKey[]) {} +} + +export class ReadAllByDisplayItemFailure implements Action { + readonly type = ActionType.ReadAllByDisplayItemFailure; + + constructor(public payload: RPCError) {} +} + +export type Actions = + | ReadAllByDisplayItem + | ReadAllByDisplayItemSuccess + | ReadAllByDisplayItemFailure + +; diff --git a/src/packages/sensor-item/store/key-list/list.effect.spec.ts b/src/packages/sensor-item/store/key-list/list.effect.spec.ts new file mode 100644 index 0000000..d8f6227 --- /dev/null +++ b/src/packages/sensor-item/store/key-list/list.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/sensor-item/store/key-list/list.effect.ts b/src/packages/sensor-item/store/key-list/list.effect.ts new file mode 100644 index 0000000..d7ac6a7 --- /dev/null +++ b/src/packages/sensor-item/store/key-list/list.effect.ts @@ -0,0 +1,51 @@ +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 { RPCError } from 'packages/core/rpc/error'; + +import { DomainMember } from 'packages/domain/model'; + + +import { + ReadAllByDisplayItem, + ReadAllByDisplayItemSuccess, + ReadAllByDisplayItemFailure, + ActionType, +} from './list.action'; +import { SensorItemDependencyService } from '../../service/sensor-item-dependency.service'; + +@Injectable() +export class Effects { + + constructor( + private actions$: Actions, + private service: SensorItemDependencyService, + private router: Router + ) { } + + @Effect() + readAllByDisplayItem$: Observable = this.actions$ + .ofType(ActionType.ReadAllByDisplayItem) + .map((action: ReadAllByDisplayItem) => action.payload) + .switchMap(payload => this.service.readAllByDisplayItem(payload)) + .map(list => { + return new ReadAllByDisplayItemSuccess(list); + }) + .catch((error: RPCError) => { + return of(new ReadAllByDisplayItemFailure(error)); + }); + +} diff --git a/src/packages/sensor-item/store/key-list/list.reducer.ts b/src/packages/sensor-item/store/key-list/list.reducer.ts new file mode 100644 index 0000000..769743b --- /dev/null +++ b/src/packages/sensor-item/store/key-list/list.reducer.ts @@ -0,0 +1,43 @@ +import { + Actions, + ActionType, +} from './list.action'; + +import { + State, + initialState, +} from './list.state'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.ReadAllByDisplayItem: { + return { + ...state, + error: null, + pending: true, + }; + } + + case ActionType.ReadAllByDisplayItemSuccess: { + return { + ...state, + error: null, + pending: false, + list: action.payload + }; + } + + case ActionType.ReadAllByDisplayItemFailure: { + return { + ...state, + error: action.payload, + pending: false, + list: null, + }; + } + + default: { + return state; + } + } +} diff --git a/src/packages/sensor-item/store/key-list/list.state.ts b/src/packages/sensor-item/store/key-list/list.state.ts new file mode 100644 index 0000000..058ef5a --- /dev/null +++ b/src/packages/sensor-item/store/key-list/list.state.ts @@ -0,0 +1,15 @@ +import { RPCError } from 'packages/core/rpc/error'; +import { MetaSensorItemKey } from 'packages/meta/sensor-item-key/model/MetaSensorItemKey'; + + +export interface State { + error: RPCError | null; + pending: boolean; + list: MetaSensorItemKey[] | null; +} + +export const initialState: State = { + error: null, + pending: false, + list: null, +}; diff --git a/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.html b/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.html index 798cb00..61b5255 100644 --- a/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.html +++ b/src/packages/sensor/component/setting/crawler-auth/crawler-auth.component.html @@ -8,6 +8,12 @@ 크롤러 인증해야 됨 +
+ + + + +
diff --git a/src/packages/sensor/component/setting/setting.component.ts b/src/packages/sensor/component/setting/setting.component.ts index be29521..705b718 100644 --- a/src/packages/sensor/component/setting/setting.component.ts +++ b/src/packages/sensor/component/setting/setting.component.ts @@ -1,10 +1,15 @@ import { Component, OnInit, Input, Inject, DoCheck } from '@angular/core'; import { Target } from '../../../target/model'; -import { MAT_DIALOG_DATA } from '@angular/material'; +import { MAT_DIALOG_DATA, MatSnackBar } from '@angular/material'; import { Infra } from '../../../infra/model'; import { MetaCrawler } from '../../../meta/crawler/model/MetaCrawler'; import { MetaSensorDisplayItem } from '../../../meta/sensor-display-item/model/MetaSensorDisplayItem'; +import { Store, select } from '@ngrx/store'; +import { RPCError } from 'packages/core/rpc/error'; +import * as SensorItemKeyListStore from 'packages/sensor-item/store/key-list'; +import { ReadSensorItemKeySelector } from 'packages/sensor-item/store'; +import { MetaSensorItemKey } from '../../../meta/sensor-item-key/model/MetaSensorItemKey'; @Component({ selector: 'of-sensor-setting', @@ -19,8 +24,12 @@ export class SettingComponent implements OnInit, DoCheck { step = 1; nextable = false; + sensorItemKeys$ = this.keyListStore.pipe(select(ReadSensorItemKeySelector.select('list'))); + constructor( - @Inject(MAT_DIALOG_DATA) public data: any + @Inject(MAT_DIALOG_DATA) public data: any, + public snackBar: MatSnackBar, + private keyListStore: Store, ) { if (data !== null) { this.selectedTarget = data.infra.target; @@ -28,6 +37,18 @@ export class SettingComponent implements OnInit, DoCheck { } ngOnInit() { + this.sensorItemKeys$.subscribe( + (list: MetaSensorItemKey[]) => { + if (list !== null) { + console.log('#############################'); + console.log(list); + console.log('#############################'); + } + }, + (error: RPCError) => { + console.log(error.response.message); + } + ); } ngDoCheck() { @@ -52,7 +73,19 @@ export class SettingComponent implements OnInit, DoCheck { } onDone() { - // SensorService.registSensorConfig(Sensor sensor, List sensorItemList, String etcJson) + this.openSnackBar('센서 등록해야되는데 아직 못함'); + // List SensorItemDependencyService.readAllByDisplayItem(MetaSensorDisplayItem displayItem) + for (const displayItem of Array.from(this.selectedSensorDisplayItems)) { + this.keyListStore.dispatch(new SensorItemKeyListStore.ReadAllByDisplayItem(displayItem)); + } + + // Sensor SensorService.registSensorConfig(Sensor sensor, List sensorItemList, String etcJson) + } + + openSnackBar(message: string) { + this.snackBar.open(message, 'OK', { + duration: 2000, + }); } handleTargetSelection(t: Target) { diff --git a/src/packages/sensor/model/index.ts b/src/packages/sensor/model/index.ts index 82781a6..c814e10 100644 --- a/src/packages/sensor/model/index.ts +++ b/src/packages/sensor/model/index.ts @@ -1,3 +1,2 @@ export * from './Sensor'; -export * from './SensorItem'; export * from './SensorRegistInfo'; diff --git a/src/packages/sensor/sensor.module.ts b/src/packages/sensor/sensor.module.ts index 4a9d512..d53f839 100644 --- a/src/packages/sensor/sensor.module.ts +++ b/src/packages/sensor/sensor.module.ts @@ -14,6 +14,7 @@ import { MetaCrawlerModule } from '../meta/crawler/crawler.module'; import { MetaCrawlerInputItemModule } from '../meta/crawler-input-item/crawler-input.module'; import { MetaSensorDisplayItemModule } from '../meta/sensor-display-item/sensor-display-item.module'; import { InfoTableModule } from '../commons/component/info-table/info-table.module'; +import { SensorItemModule } from '../sensor-item/sensor-item.module'; @NgModule({ imports: [ @@ -26,7 +27,8 @@ import { InfoTableModule } from '../commons/component/info-table/info-table.modu PerfectScrollbarModule, MetaCrawlerModule, MetaCrawlerInputItemModule, - MetaSensorDisplayItemModule + MetaSensorDisplayItemModule, + SensorItemModule ], declarations: [ COMPONENTS, diff --git a/src/packages/sensor/service/sensor.service.ts b/src/packages/sensor/service/sensor.service.ts index 8c35a9f..c3fbac4 100644 --- a/src/packages/sensor/service/sensor.service.ts +++ b/src/packages/sensor/service/sensor.service.ts @@ -19,10 +19,6 @@ export class SensorService { } public readAllByDomain(domain: Domain): Observable { - const body = { - domain: domain, - }; - return this.rpcClient.call('SensorService.readAllByDomain', domain); }