From b310a37a0016cadc86b183e46737c40bf3b9a525 Mon Sep 17 00:00:00 2001 From: snoop Date: Fri, 25 Aug 2017 15:04:19 +0900 Subject: [PATCH] added sensor regist --- src/ts/@overflow/app/config/index.ts | 2 ++ .../sensor/react/SensorConfigStepper.tsx | 10 ++++--- .../react/components/SensorConfigStepper.tsx | 10 ++++--- .../redux/action/regist_sensor_config.ts | 9 +++++++ .../redux/reducer/regist_sensor_config.ts | 26 +++++++++++++++++++ .../sensor/redux/state/RegistSensorConfig.ts | 13 ++++++++++ 6 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 src/ts/@overflow/sensor/redux/action/regist_sensor_config.ts create mode 100644 src/ts/@overflow/sensor/redux/reducer/regist_sensor_config.ts create mode 100644 src/ts/@overflow/sensor/redux/state/RegistSensorConfig.ts diff --git a/src/ts/@overflow/app/config/index.ts b/src/ts/@overflow/app/config/index.ts index 8993559..7724e26 100644 --- a/src/ts/@overflow/app/config/index.ts +++ b/src/ts/@overflow/app/config/index.ts @@ -25,6 +25,7 @@ import sensorReadAllByDomainReducer from '@overflow/sensor/redux/reducer/read_al import SensorReadReducer from '@overflow/sensor/redux/reducer/read'; import SensorItemReadAllBySensorReducer from '@overflow/sensor/redux/reducer/item_read_all_by_sensor'; import readAllTargetByInfraReducer from '@overflow/sensor/redux/reducer/read_all_by_infra'; +import SensorRegistSensorConfigReducer from '@overflow/sensor/redux/reducer/regist_sensor_config'; import readMachineReducer from '@overflow/infra/redux/reducer/machine_read'; import readHostReducer from '@overflow/infra/redux/reducer/host_read'; @@ -110,6 +111,7 @@ const reduxConfig: ReduxConfig = { readAllTargetByInfraReducer, InfraReadServiceReducer, HistoryTypeReadAllReducer, + SensorRegistSensorConfigReducer, ], sagaWatchers: [ AsyncRequest, diff --git a/src/ts/@overflow/sensor/react/SensorConfigStepper.tsx b/src/ts/@overflow/sensor/react/SensorConfigStepper.tsx index 588d850..de18d4a 100644 --- a/src/ts/@overflow/sensor/react/SensorConfigStepper.tsx +++ b/src/ts/@overflow/sensor/react/SensorConfigStepper.tsx @@ -8,12 +8,12 @@ import { import Target from '@overflow/target/api/model/Target'; import Sensor from '@overflow/sensor/api/model/Sensor'; +import SensorItem from '@overflow/sensor/api/model/SensorItem'; import Domain from '@overflow/domain/api/model/Domain'; import MetaSensorItem from '@overflow/meta/api/model/MetaSensorItem'; -import * as CrawlerReadAllByTargetActions from '@overflow/meta/redux/action/crawler_read_all_by_target'; -import * as SensorItemReadAllActions from '@overflow/meta/redux/action/sensor_item_read_all'; -import * as RegistActions from '../redux/action/regist'; + +import * as RegistSensorConfigActions from '../redux/action/regist_sensor_config'; import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; import * as targetListActions from '@overflow/target/redux/action/read_all_by_probe'; @@ -28,6 +28,10 @@ export function mapStateToProps(state: any, props: any): SensorConfigStepperStat export function mapDispatchToProps(dispatch: Dispatch): SensorConfigStepperDispatchProps { return { + onRegistSensorConfig: (sensor: Sensor, sensorItemList: SensorItem[]) => { + dispatch(asyncRequestActions.request('SensorService', 'registSensorConfig', RegistSensorConfigActions.REQUEST, + JSON.stringify(sensor), JSON.stringify(sensorItemList))); + }, }; } diff --git a/src/ts/@overflow/sensor/react/components/SensorConfigStepper.tsx b/src/ts/@overflow/sensor/react/components/SensorConfigStepper.tsx index f32b675..97c281e 100644 --- a/src/ts/@overflow/sensor/react/components/SensorConfigStepper.tsx +++ b/src/ts/@overflow/sensor/react/components/SensorConfigStepper.tsx @@ -47,7 +47,7 @@ export interface SensorConfigStepperStateProps { } export interface SensorConfigStepperDispatchProps { - + onRegistSensorConfig?(sensor: Sensor, sensorItemList: SensorItem[]): void; } export type SensorConfigStepperProps = SensorConfigStepperStateProps & SensorConfigStepperDispatchProps; @@ -122,16 +122,18 @@ export class SensorConfigStepper extends React.Component = new Array; - sensorData.sensorItemMap.forEach( (value: MetaSensorItem[], key: number) => { - for(let msi of value) { + sensorData.sensorItemMap.forEach((value: MetaSensorItem[], key: number) => { + for (let msi of value) { siList.push({ - item: {id: msi.id}, + item: { id: msi.id }, }); } }); console.log(sensor); console.log(siList); + + this.props.onRegistSensorConfig(sensor, siList); } public showContent(): any { diff --git a/src/ts/@overflow/sensor/redux/action/regist_sensor_config.ts b/src/ts/@overflow/sensor/redux/action/regist_sensor_config.ts new file mode 100644 index 0000000..c0856d2 --- /dev/null +++ b/src/ts/@overflow/sensor/redux/action/regist_sensor_config.ts @@ -0,0 +1,9 @@ + +// Action Type +export type REQUEST = '@overflow/sensor/regist_sensor_config/REQUEST'; +export type REQUEST_SUCCESS = '@overflow/sensor/regist_sensor_config/REQUEST/SUCCESS'; +export type REQUEST_FAILURE = '@overflow/sensor/regist_sensor_config/REQUEST/FAILURE'; + +export const REQUEST: REQUEST = '@overflow/sensor/regist_sensor_config/REQUEST'; +export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/sensor/regist_sensor_config/REQUEST/SUCCESS'; +export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/sensor/regist_sensor_config/REQUEST/FAILURE'; diff --git a/src/ts/@overflow/sensor/redux/reducer/regist_sensor_config.ts b/src/ts/@overflow/sensor/redux/reducer/regist_sensor_config.ts new file mode 100644 index 0000000..ea8973c --- /dev/null +++ b/src/ts/@overflow/sensor/redux/reducer/regist_sensor_config.ts @@ -0,0 +1,26 @@ + + +import Action from '@overflow/commons/redux/Action'; +import { ReducersMapObject } from 'redux'; +import Sensor from '@overflow/sensor/api/model/Sensor'; + +import * as RegistSensorConfigActionTypes from '../action/regist_sensor_config'; +import RegistSensorConfigState, { defaultState as RegistSensorConfigDefaultState } from '../state/RegistSensorConfig'; + +const reducer: ReducersMapObject = { + [RegistSensorConfigActionTypes.REQUEST_SUCCESS]: + (state: RegistSensorConfigState = RegistSensorConfigDefaultState, action: Action): RegistSensorConfigState => { + console.log(action); + return { + ...state, + isSensorRegistSuccess:action.payload, + }; + }, + [RegistSensorConfigActionTypes.REQUEST_FAILURE]: + (state: RegistSensorConfigState = RegistSensorConfigDefaultState, action: Action): + RegistSensorConfigState => { + return state; + }, +}; + +export default reducer; diff --git a/src/ts/@overflow/sensor/redux/state/RegistSensorConfig.ts b/src/ts/@overflow/sensor/redux/state/RegistSensorConfig.ts new file mode 100644 index 0000000..769f9a3 --- /dev/null +++ b/src/ts/@overflow/sensor/redux/state/RegistSensorConfig.ts @@ -0,0 +1,13 @@ + + +export interface State { + readonly isSensorRegistSuccess: boolean; + readonly error?: Error; +} + +export const defaultState: State = { + isSensorRegistSuccess: undefined, + error: undefined, +}; + +export default State;