sensor setup item

This commit is contained in:
snoop 2017-08-16 16:38:57 +09:00
parent 99724e10ce
commit 8692555516
14 changed files with 310 additions and 118 deletions

View File

@ -24,6 +24,9 @@ import readHostReducer from '@overflow/infra/redux/reducer/host_read';
import CrawlerReadAllByTargetReducer from '@overflow/meta/redux/reducer/crawler_read_all_by_target';
import CrawlerAuthInputsReducer from '@overflow/meta/redux/reducer/crawler_auth_inputs';
import MetaSensorItemReadAllReducer from '@overflow/meta/redux/reducer/sensor_item_read_all';
import MetaSensorItemTypeReadAllReducer from '@overflow/meta/redux/reducer/sensor_item_type_read_all';
import AsyncRequest from '@overflow/app/redux/saga/AsyncRequest';
// Container Configuration
@ -74,6 +77,8 @@ const reduxConfig: ReduxConfig = {
readHostReducer,
CrawlerReadAllByTargetReducer,
CrawlerAuthInputsReducer,
MetaSensorItemReadAllReducer,
MetaSensorItemTypeReadAllReducer,
],
sagaWatchers: [
AsyncRequest,

View File

@ -20,10 +20,11 @@ import * as asyncRequestActions from '@overflow/commons/redux/action/asyncReques
// FIXME::....
export function mapStateToProps(state: any): CrawlerSelectorStateProps {
export function mapStateToProps(state: any, props: any): CrawlerSelectorStateProps {
return {
metaCralwerList: state.MetaCrawlerList,
metaCrawlerInputItemList:state.MetaCrawlerInputItemList,
onSelectCrawlerId: props.onSelectCrawlerId,
};
}

View File

@ -6,18 +6,34 @@ import {
} from './components/SensorItemTree';
import State from '../redux/state/SensorItemReadAll';
import * as SensorItemReadAllActions 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 SensorItemTypeReadAllActions from '../redux/action/sensor_item_type_read_all';
import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest';
export function mapStateToProps(state: any): SensorItemTreeStateProps {
import Sensor from '@overflow/sensor/api/model/Sensor';
export function mapStateToProps(state: any, props: any): SensorItemTreeStateProps {
return {
crawlerId: props.crawlerId,
metaSensorItemTypeList: state.MetaSensorItemTypeList,
sensorItemList: state.SensorItemList,
metaSensorItemList: state.MetaSensorItemList,
};
}
export function mapDispatchToProps(dispatch: Dispatch<any>): SensorItemTreeDispatchProps {
return {
onReadAll: () => {
dispatch(SensorItemReadAllActions.request());
dispatch(asyncRequestActions.request('MetaSensorItemService', 'readAll', SensorItemReadAllByActions.REQUEST));
},
onReadAllBySensor: (sensor: Sensor) => {
dispatch(asyncRequestActions.request('SensorItemService', 'readAllBySensor',
SensorItemReadAllBySensorActions.REQUEST, JSON.stringify(sensor)));
},
onSensorItemTypeReadAll: () => {
dispatch(asyncRequestActions.request('MetaSensorItemTypeService', 'readAll', SensorItemTypeReadAllActions.REQUEST));
},
};
}

View File

@ -15,11 +15,13 @@ export interface CrawlerSelectorStateProps {
metaCralwerList?: MetaCrawler[];
targetId?: number;
metaCrawlerInputItemList?: MetaCrawlerInputItem[];
onSelectCrawlerId?(id: number): void;
}
export interface CrawlerSelectorDispatchProps {
onCrawlerReadAllByTarget?(target: Target): void;
onCrawlerReadAllByMetaCrawler?(crawler: MetaCrawler): void;
}
export type CrawlerSelectorProps = CrawlerSelectorStateProps & CrawlerSelectorDispatchProps;

View File

@ -17,13 +17,22 @@ import {
import MetaSensorItemType from '../../api/model/MetaSensorItemType';
import MetaSensorItem from '../../api/model/MetaSensorItem';
import Sensor from '@overflow/sensor/api/model/Sensor';
import SensorItem from '@overflow/sensor/api/model/SensorItem';
import * as Utils from '@overflow/commons/util/Utils';
export interface SensorItemTreeStateProps {
crawlerId?: number;
sensorItemList?: SensorItem[];
metaSensorItemTypeList?: MetaSensorItemType[];
metaSensorItemList?: MetaSensorItem[];
}
export interface SensorItemTreeDispatchProps {
onReadAllBySensor?(sensor: Sensor): void;
onSensorItemTypeReadAll?(): void;
onReadAll?(): void;
}
@ -58,8 +67,10 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
categoryCheckState: new Map(),
itemState: new Map(),
};
this.sortItemMap();
this.props.onReadAll();
this.props.onSensorItemTypeReadAll();
// fs.readFile('../../../../../dh.json', this.handlJSONFile);
}
@ -68,6 +79,14 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
public ViewSensorItemType(): JSX.Element[] {
if(this.props.metaSensorItemTypeList === undefined
|| this.props.metaSensorItemList === undefined) {
return null;
}
this.sortItemMap();
let elems: JSX.Element[] = new Array();
this.itemMap.forEach((data: TreeItem, key: number) => {
@ -83,7 +102,7 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
this.onTypeCheckCBox(key, checkProps, data);
}} />
</List.Header>
<List.Description style={{marginLeft:'26px'}}>Category</List.Description>
<List.Description style={{ marginLeft: '26px' }}>Category</List.Description>
{this.state.categoryState[key] ? this.ViewSensorItem(data.metaSensorItemList, key) : ''}
</List.Content>
</List.Item>,
@ -112,7 +131,7 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
this.onItemCheckCBox(parentKey, checkProps, item);
}} /></List.Header>
<List.Description style={{marginLeft:'26px'}}>Sensor Item</List.Description>
<List.Description style={{ marginLeft: '26px' }}>Sensor Item</List.Description>
</List.Content>
</List.Item>
</List.List>,
@ -137,8 +156,12 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
private sortItemMap(): void {
SensorJsonData.map((data: any, idx: number) => {
let sensorItem: MetaSensorItem = data;
if(this.itemMap.size > 0) {
return;
}
for(let si of this.props.metaSensorItemList) {
let sensorItem: MetaSensorItem = si;
if (this.itemMap.has(sensorItem.itemType.id)) {
this.itemMap.get(sensorItem.itemType.id).metaSensorItemList.push(sensorItem);
@ -149,7 +172,21 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
item.metaSensorItemType = this.GetMetaSensorItemType(sensorItem.itemType.id);
this.itemMap.set(sensorItem.itemType.id, item);
}
});
}
// SensorJsonData.map((data: any, idx: number) => {
// let sensorItem: MetaSensorItem = data;
// 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);
// }
// });
}
private onItemClick = (parentKey: number, idx: number) => {
@ -207,93 +244,91 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
private GetMetaSensorItemType(id: number): MetaSensorItemType {
for (let i: number = 0; i < SensorTypeJsonData.length; ++i) {
let msit: MetaSensorItemType = SensorTypeJsonData[i];
if (msit.id === id) {
return msit;
for(let sit of this.props.metaSensorItemTypeList) {
if(sit.id === id) {
return sit;
}
}
return null;
// SensorTypeJsonData.map((data: any, idx: number) => {
// let msit: MetaSensorItemType = data;
// for (let i: number = 0; i < SensorTypeJsonData.length; ++i) {
// let msit: MetaSensorItemType = SensorTypeJsonData[i];
// if (msit.id === id) {
// return msit;
// }
// return null;
// });
// return null;
// }
return null;
}
}
const SensorTypeJsonData: any = [
{
'id': 1,
'create_date': '2017-06-26T10:49:39Z',
'description': 'CPU blah blah blah',
'name': 'CPU',
},
{
'id': 2,
'create_date': '2017-06-26T10:49:39Z',
'description': 'MEMORY blah blah blah',
'name': 'MEMORY',
},
{
'id': 3,
'create_date': '2017-06-26T10:49:39Z',
'description': 'DISK blah blah blah',
'name': 'DISK',
},
];
// const SensorTypeJsonData: any = [
// {
// 'id': 1,
// 'create_date': '2017-06-26T10:49:39Z',
// 'description': 'CPU blah blah blah',
// 'name': 'CPU',
// },
// {
// 'id': 2,
// 'create_date': '2017-06-26T10:49:39Z',
// 'description': 'MEMORY blah blah blah',
// 'name': 'MEMORY',
// },
// {
// 'id': 3,
// 'create_date': '2017-06-26T10:49:39Z',
// 'description': 'DISK blah blah blah',
// 'name': 'DISK',
// },
// ];
const SensorJsonData = [{
'id': 1,
'itemType': {
'id': 1,
'name': 'CPU',
'description': 'CPU blah blah blah',
'createDate': 1498474179690,
},
'key': 'cpu.usage',
'name': 'CPU USAGE',
'createDate': 1498475408269,
},
{
'id': 2,
'itemType': {
'id': 1,
'name': 'CPU',
'description': 'CPU blah blah blah',
'createDate': 1498474179690,
},
'key': 'cpu.free',
'name': 'CPU FREE',
'createDate': 1498475408361,
},
{
'id': 3,
'itemType': {
'id': 2,
'name': 'MEMORY',
'description': 'MEMORY blah blah blah',
'createDate': 1498474179811,
},
'key': 'mem.usage',
'name': 'MEMORY USAGE',
'createDate': 1498475408376,
},
{
'id': 4,
'itemType': {
'id': 2,
'name': 'MEMORY',
'description': 'MEMORY blah blah blah',
'createDate': 1498474179811,
},
'key': 'mem.free',
'name': 'MEMORY FREE',
'createDate': 1498475408394,
}];
// const SensorJsonData = [{
// 'id': 1,
// 'itemType': {
// 'id': 1,
// 'name': 'CPU',
// 'description': 'CPU blah blah blah',
// 'createDate': 1498474179690,
// },
// 'key': 'cpu.usage',
// 'name': 'CPU USAGE',
// 'createDate': 1498475408269,
// },
// {
// 'id': 2,
// 'itemType': {
// 'id': 1,
// 'name': 'CPU',
// 'description': 'CPU blah blah blah',
// 'createDate': 1498474179690,
// },
// 'key': 'cpu.free',
// 'name': 'CPU FREE',
// 'createDate': 1498475408361,
// },
// {
// 'id': 3,
// 'itemType': {
// 'id': 2,
// 'name': 'MEMORY',
// 'description': 'MEMORY blah blah blah',
// 'createDate': 1498474179811,
// },
// 'key': 'mem.usage',
// 'name': 'MEMORY USAGE',
// 'createDate': 1498475408376,
// },
// {
// 'id': 4,
// 'itemType': {
// 'id': 2,
// 'name': 'MEMORY',
// 'description': 'MEMORY blah blah blah',
// 'createDate': 1498474179811,
// },
// 'key': 'mem.free',
// 'name': 'MEMORY FREE',
// 'createDate': 1498475408394,
// }];
export default SensorItemTree;

View File

@ -6,39 +6,39 @@ import SensorItemReadAllPayload from '../payload/SensorItemReadAllPayload';
// Action Type
export type REQUEST = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST';
export type REQUEST_SUCCESS = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST_SUCCESS';
export type REQUEST_FAILURE = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST_FAILURE';
export type REQUEST_SUCCESS = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST_SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST_FAILURE';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/meta_sensor_item/sensor_item_read_all/REQUEST/FAILURE';
// Action Creater
export type request = () => Action<SensorItemReadAllPayload>;
export type requestSuccess = (metaSensorItemList: MetaSensorItem[]) => Action<MetaSensorItem[]>;
export type requestFailure = (error: Error) => Action;
// // Action Creater
// export type request = () => Action<SensorItemReadAllPayload>;
// export type requestSuccess = (metaSensorItemList: MetaSensorItem[]) => Action<MetaSensorItem[]>;
// export type requestFailure = (error: Error) => Action;
export const request: request = (): Action<SensorItemReadAllPayload> => {
return {
type: REQUEST,
payload: {
// export const request: request = (): Action<SensorItemReadAllPayload> => {
// return {
// type: REQUEST,
// payload: {
},
};
};
// },
// };
// };
export const requestSuccess: requestSuccess = (metaSensorItemList: MetaSensorItem[]): Action<MetaSensorItem[]> => {
return {
type: REQUEST_SUCCESS,
payload: metaSensorItemList,
};
};
// export const requestSuccess: requestSuccess = (metaSensorItemList: MetaSensorItem[]): Action<MetaSensorItem[]> => {
// return {
// type: REQUEST_SUCCESS,
// payload: metaSensorItemList,
// };
// };
export const requestFailure: requestFailure = (error: Error): Action => {
return {
type: REQUEST_FAILURE,
error: error,
};
};
// export const requestFailure: requestFailure = (error: Error): Action => {
// return {
// type: REQUEST_FAILURE,
// error: error,
// };
// };

View File

@ -0,0 +1,10 @@
// Action Type
export type REQUEST = '@overflow/meta_sensor_item/read_all_by_sensor/REQUEST';
export type REQUEST_SUCCESS = '@overflow/meta_sensor_item/read_all_by_sensor/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/meta_sensor_item/read_all_by_sensor/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/meta_sensor_item/read_all_by_sensor/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/meta_sensor_item/read_all_by_sensor/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/meta_sensor_item/read_all_by_sensor/REQUEST/FAILURE';

View File

@ -0,0 +1,10 @@
// Action Type
export type REQUEST = '@overflow/meta_sensor_item_type/read_all/REQUEST';
export type REQUEST_SUCCESS = '@overflow/meta_sensor_item_type/read_all/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/meta_sensor_item_type/read_all/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/meta_sensor_item_type/read_all/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/meta_sensor_item_type/read_all/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/meta_sensor_item_type/read_all/REQUEST/FAILURE';

View File

@ -0,0 +1,28 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import SensorItem from '@overflow/sensor/api/model/SensorItem';
import * as SensorItemReadAllActions from '../action/sensor_item_read_all';
import SensorItemReadAllState, { defaultState as SensorItemReadAllDefaultState } from '../state/SensorItemReadAll';
import MetaSensorItem from '../../api/model/MetaSensorItem';
const reducer: ReducersMapObject = {
[SensorItemReadAllActions.REQUEST_SUCCESS]:
(state: SensorItemReadAllState = SensorItemReadAllDefaultState, action: Action<MetaSensorItem[]>):
SensorItemReadAllState => {
console.log(action);
return {
...state,
MetaSensorItemList: <MetaSensorItem[]>action.payload,
};
},
[SensorItemReadAllActions.REQUEST_FAILURE]:
(state: SensorItemReadAllState = SensorItemReadAllDefaultState, action: Action<Error>):
SensorItemReadAllState => {
return state;
},
};
export default reducer;

View File

@ -0,0 +1,28 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import SensorItem from '@overflow/sensor/api/model/SensorItem';
import * as SensorItemReadAllBySensorActions from '../action/sensor_item_read_all_by_sensor';
import SensorItemReadAllBySensorState, { defaultState as SensorItemReadAllBySensorDefaultState } from '../state/SensorItemReadAllBySensor';
import MetaCrawler from '../../api/model/MetaCrawler';
const reducer: ReducersMapObject = {
[SensorItemReadAllBySensorActions.REQUEST_SUCCESS]:
(state: SensorItemReadAllBySensorState = SensorItemReadAllBySensorDefaultState, action: Action<SensorItem[]>):
SensorItemReadAllBySensorState => {
console.log(action);
return {
...state,
SensorItemList: <SensorItem[]>action.payload,
};
},
[SensorItemReadAllBySensorActions.REQUEST_FAILURE]:
(state: SensorItemReadAllBySensorState = SensorItemReadAllBySensorDefaultState, action: Action<Error>):
SensorItemReadAllBySensorState => {
return state;
},
};
export default reducer;

View File

@ -0,0 +1,28 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import SensorItem from '@overflow/sensor/api/model/SensorItem';
import * as SensorItemTypeReadAllActions from '../action/sensor_item_type_read_all';
import SensorItemTypeReadAllState, { defaultState as SensorItemTypeReadAllDefaultState } from '../state/SensorItemTypeReadAll';
import MetaSensorItemType from '../../api/model/MetaSensorItemType';
const reducer: ReducersMapObject = {
[SensorItemTypeReadAllActions.REQUEST_SUCCESS]:
(state: SensorItemTypeReadAllState = SensorItemTypeReadAllDefaultState, action: Action<MetaSensorItemType[]>):
SensorItemTypeReadAllState => {
console.log(action);
return {
...state,
MetaSensorItemTypeList: <MetaSensorItemType[]>action.payload,
};
},
[SensorItemTypeReadAllActions.REQUEST_FAILURE]:
(state: SensorItemTypeReadAllState = SensorItemTypeReadAllDefaultState, action: Action<Error>):
SensorItemTypeReadAllState => {
return state;
},
};
export default reducer;

View File

@ -1,11 +1,12 @@
import MetaSensorItem from '../../api/model/MetaSensorItem';
export interface State {
readonly isGetSensorItemAll: boolean;
readonly MetaSensorItemList: MetaSensorItem[];
readonly error?: Error;
}
export const defaultState: State = {
isGetSensorItemAll: undefined,
MetaSensorItemList: undefined,
error: undefined,
};

View File

@ -0,0 +1,14 @@
import SensorItem from '@overflow/sensor/api/model/SensorItem';
export interface State {
readonly SensorItemList: SensorItem[];
readonly error?: Error;
}
export const defaultState: State = {
SensorItemList: undefined,
error: undefined,
};
export default State;

View File

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