fixed sensor setup - sensorItemTree

This commit is contained in:
snoop 2017-09-07 12:36:42 +09:00
parent 648f9da64a
commit 9538ec28fa
7 changed files with 109 additions and 10 deletions

View File

@ -48,6 +48,8 @@ import NotificationReadAllUnconfirmedReducer from '@overflow/notification/redux/
import NotificationReadAllReducer from '@overflow/notification/redux/reducer/read_all'; import NotificationReadAllReducer from '@overflow/notification/redux/reducer/read_all';
import NotificationReadCountReducer from '@overflow/notification/redux/reducer/read_unconfirmed_count'; import NotificationReadCountReducer from '@overflow/notification/redux/reducer/read_unconfirmed_count';
import SensorItemKeyReadAllByCrawlerReducer from '@overflow/meta/redux/reducer/sensor_item_key_read_all_by_crawler';
import ForgotPassword from '@overflow/member/redux/reducer/forgotPassword'; import ForgotPassword from '@overflow/member/redux/reducer/forgotPassword';
import AuthCrawlerRegistReducer from '@overflow/auth/redux/reducer/regist'; import AuthCrawlerRegistReducer from '@overflow/auth/redux/reducer/regist';
@ -133,6 +135,7 @@ const reduxConfig: ReduxConfig = {
NotificationReadCountReducer, NotificationReadCountReducer,
AuthCrawlerRegistReducer, AuthCrawlerRegistReducer,
ForgotPassword, ForgotPassword,
SensorItemKeyReadAllByCrawlerReducer,
], ],
sagaWatchers: [ sagaWatchers: [
AsyncRequest, AsyncRequest,

View File

@ -0,0 +1,14 @@
import MetaSensorItem from './MetaSensorItem';
import MetaCrawler from './MetaCrawler';
export interface MetaSensorItemKey {
id: number;
item: MetaSensorItem;
key: string;
froms: string;
option: string;
crawler: MetaCrawler;
createDate: Date;
}
export default MetaSensorItemKey;

View File

@ -9,17 +9,20 @@ import State from '../redux/state/SensorItemReadAll';
import * as SensorItemReadAllByActions from '../redux/action/sensor_item_read_all'; import * as SensorItemReadAllByActions from '../redux/action/sensor_item_read_all';
import * as SensorItemReadAllBySensorActions from '../redux/action/sensor_item_read_all_by_sensor'; import * as SensorItemReadAllBySensorActions from '../redux/action/sensor_item_read_all_by_sensor';
import * as SensorItemTypeReadAllActions from '../redux/action/sensor_item_type_read_all'; import * as SensorItemTypeReadAllActions from '../redux/action/sensor_item_type_read_all';
import * as SensorItemKeyReadAllByCrawlerActions from '../redux/action/sensor_item_key_read_all_by_crawler';
import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest';
import Sensor from '@overflow/sensor/api/model/Sensor'; import Sensor from '@overflow/sensor/api/model/Sensor';
import MetaCrawler from '@overflow/meta/api/model/MetaCrawler';
export function mapStateToProps(state: any, props: any): SensorItemTreeStateProps { export function mapStateToProps(state: any, props: any): SensorItemTreeStateProps {
return { return {
crawlerId: props.crawlerId, crawlerId: props.crawlerId,
metaSensorItemTypeList: state.MetaSensorItemTypeList, // metaSensorItemTypeList: state.MetaSensorItemTypeList,
sensorItemList: state.SensorItemList, // sensorItemList: state.SensorItemList,
metaSensorItemList: state.MetaSensorItemList, // metaSensorItemList: state.MetaSensorItemList,
metaSensorItemKeyList: state.MetaSensorItemKeyList,
}; };
} }
@ -35,6 +38,10 @@ export function mapDispatchToProps(dispatch: Dispatch<any>): SensorItemTreeDispa
onSensorItemTypeReadAll: () => { onSensorItemTypeReadAll: () => {
dispatch(asyncRequestActions.request('MetaSensorItemTypeService', 'readAll', SensorItemTypeReadAllActions.REQUEST)); dispatch(asyncRequestActions.request('MetaSensorItemTypeService', 'readAll', SensorItemTypeReadAllActions.REQUEST));
}, },
onReadAllSensorItemKeyByCrawler: (metaCrawler: MetaCrawler) => {
dispatch(asyncRequestActions.request('MetaSensorItemKeyService', 'readAllByCrawler',
SensorItemKeyReadAllByCrawlerActions.REQUEST, JSON.stringify(metaCrawler)));
},
}; };
} }

View File

@ -16,6 +16,8 @@ import {
import MetaSensorItemType from '../../api/model/MetaSensorItemType'; import MetaSensorItemType from '../../api/model/MetaSensorItemType';
import MetaSensorItem from '../../api/model/MetaSensorItem'; import MetaSensorItem from '../../api/model/MetaSensorItem';
import MetaSensorItemKey from '../../api/model/MetaSensorItemKey';
import MetaCrawler from '../../api/model/MetaCrawler';
import Sensor from '@overflow/sensor/api/model/Sensor'; import Sensor from '@overflow/sensor/api/model/Sensor';
import SensorItem from '@overflow/sensor/api/model/SensorItem'; import SensorItem from '@overflow/sensor/api/model/SensorItem';
@ -28,6 +30,7 @@ export interface SensorItemTreeStateProps {
sensorItemList?: SensorItem[]; sensorItemList?: SensorItem[];
metaSensorItemTypeList?: MetaSensorItemType[]; metaSensorItemTypeList?: MetaSensorItemType[];
metaSensorItemList?: MetaSensorItem[]; metaSensorItemList?: MetaSensorItem[];
metaSensorItemKeyList?: MetaSensorItemKey[];
setSensor?(data: SensorRegistInfo): void; setSensor?(data: SensorRegistInfo): void;
getSensor?(): SensorRegistInfo; getSensor?(): SensorRegistInfo;
} }
@ -36,6 +39,7 @@ export interface SensorItemTreeDispatchProps {
onReadAllBySensor?(sensor: Sensor): void; onReadAllBySensor?(sensor: Sensor): void;
onSensorItemTypeReadAll?(): void; onSensorItemTypeReadAll?(): void;
onReadAll?(): void; onReadAll?(): void;
onReadAllSensorItemKeyByCrawler?(metaCrawler: MetaCrawler): void;
} }
@ -72,9 +76,11 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
}; };
this.props.onReadAll(); // this.props.onReadAll();
this.props.onSensorItemTypeReadAll(); // this.props.onSensorItemTypeReadAll();
// fs.readFile('../../../../../dh.json', this.handlJSONFile); // fs.readFile('../../../../../dh.json', this.handlJSONFile);
this.props.onReadAllSensorItemKeyByCrawler({id: this.props.crawlerId});
} }
@ -83,8 +89,11 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
public ViewSensorItemType(): JSX.Element[] { public ViewSensorItemType(): JSX.Element[] {
if(this.props.metaSensorItemTypeList === undefined // if(this.props.metaSensorItemTypeList === undefined
|| this.props.metaSensorItemList === undefined) { // || this.props.metaSensorItemList === undefined) {
// return null;
// }
if(this.props.metaSensorItemKeyList === undefined) {
return null; return null;
} }
@ -163,8 +172,22 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
return; return;
} }
for(let si of this.props.metaSensorItemList) { // for(let si of this.props.metaSensorItemList) {
let sensorItem: MetaSensorItem = si; // let sensorItem: MetaSensorItem = si;
// if (this.itemMap.has(sensorItem.itemType.id)) {
// this.itemMap.get(sensorItem.itemType.id).metaSensorItemList.push(sensorItem);
// } else {
// let item: TreeItem = { metaSensorItemList: null, metaSensorItemType: null };
// item.metaSensorItemList = [];
// item.metaSensorItemList.push(sensorItem);
// item.metaSensorItemType = this.GetMetaSensorItemType(sensorItem.itemType.id);
// this.itemMap.set(sensorItem.itemType.id, item);
// }
// }
for(let si of this.props.metaSensorItemKeyList) {
let sensorItem: MetaSensorItem = si.item;
if (this.itemMap.has(sensorItem.itemType.id)) { if (this.itemMap.has(sensorItem.itemType.id)) {
this.itemMap.get(sensorItem.itemType.id).metaSensorItemList.push(sensorItem); this.itemMap.get(sensorItem.itemType.id).metaSensorItemList.push(sensorItem);
@ -172,7 +195,7 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
let item: TreeItem = { metaSensorItemList: null, metaSensorItemType: null }; let item: TreeItem = { metaSensorItemList: null, metaSensorItemType: null };
item.metaSensorItemList = []; item.metaSensorItemList = [];
item.metaSensorItemList.push(sensorItem); item.metaSensorItemList.push(sensorItem);
item.metaSensorItemType = this.GetMetaSensorItemType(sensorItem.itemType.id); item.metaSensorItemType = sensorItem.itemType;
this.itemMap.set(sensorItem.itemType.id, item); this.itemMap.set(sensorItem.itemType.id, item);
} }
} }

View File

@ -0,0 +1,9 @@
// Action Type
export type REQUEST = '@overflow/meta_sensor_item_key/read_all_by_crawler/REQUEST';
export type REQUEST_SUCCESS = '@overflow/meta_sensor_item_key/read_all_by_crawler/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/meta_sensor_item_key/read_all_by_crawler/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/meta_sensor_item_key/read_all_by_crawler/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/meta_sensor_item_key/read_all_by_crawler/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/meta_sensor_item_key/read_all_by_crawler/REQUEST/FAILURE';

View File

@ -0,0 +1,30 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import * as SensorItemKeyReadAllByCrawlerActions from '../action/sensor_item_key_read_all_by_crawler';
import SensorItemKeyReadAllByCrawlerState,
{ defaultState as SensorItemKeyReadAllByCrawlerDefaultState }
from '../state/SensorItemKeyReadAllByCrawler';
import MetaSensorItemKey from '../../api/model/MetaSensorItemKey';
const reducer: ReducersMapObject = {
[SensorItemKeyReadAllByCrawlerActions.REQUEST_SUCCESS]:
(state: SensorItemKeyReadAllByCrawlerState = SensorItemKeyReadAllByCrawlerDefaultState, action: Action<MetaSensorItemKey[]>):
SensorItemKeyReadAllByCrawlerState => {
console.log(action);
return {
...state,
MetaSensorItemKeyList: <MetaSensorItemKey[]>action.payload,
};
},
[SensorItemKeyReadAllByCrawlerActions.REQUEST_FAILURE]:
(state: SensorItemKeyReadAllByCrawlerState = SensorItemKeyReadAllByCrawlerDefaultState, action: Action<Error>):
SensorItemKeyReadAllByCrawlerState => {
return state;
},
};
export default reducer;

View File

@ -0,0 +1,13 @@
import MetaSensorItemKey from '../../api/model/MetaSensorItemKey';
export interface State {
readonly MetaSensorIteKeyList: MetaSensorItemKey[];
readonly error?: Error;
}
export const defaultState: State = {
MetaSensorIteKeyList: undefined,
error: undefined,
};
export default State;