sensor setup ing

This commit is contained in:
snoop 2017-08-25 13:02:59 +09:00
parent 33d0b896aa
commit 7cc5082a50
7 changed files with 79 additions and 113 deletions

View File

@ -4,10 +4,10 @@ import MetaSensorItemType from './MetaSensorItemType';
interface MetaSensorItem { interface MetaSensorItem {
id?: number; id?: number;
itemType: MetaSensorItemType; itemType?: MetaSensorItemType;
key: string; key?: string;
name: string; name?: string;
createDate: Date; createDate?: Date;
} }
export default MetaSensorItem; export default MetaSensorItem;

View File

@ -1,7 +1,7 @@
interface MetaSensorStatus { interface MetaSensorStatus {
id?: number; id?: number;
name: string; name?: string;
} }
export enum MetaSensorStatus_ID { export enum MetaSensorStatus_ID {

View File

@ -69,7 +69,7 @@ export class CrawlerSelector extends React.Component<CrawlerSelectorProps, Crawl
let option = { let option = {
// key: crawler.id, // key: crawler.id,
text: crawler.name, text: crawler.name,
value: crawler.id, value: JSON.stringify(crawler),
icon: 'check', // or close? icon: 'check', // or close?
}; };
crawlerOptions.push(option); crawlerOptions.push(option);
@ -83,15 +83,18 @@ export class CrawlerSelector extends React.Component<CrawlerSelectorProps, Crawl
// selected: data.key, // selected: data.key,
// }); // });
this.checkInstall(); this.checkInstall();
let vCrawler: MetaCrawler = JSON.parse(String(data.value));
let crawler: MetaCrawler = { let crawler: MetaCrawler = {
id: Number(data.value), id: vCrawler.id,
}; };
this.props.onCrawlerReadAllByMetaCrawler(crawler); this.props.onCrawlerReadAllByMetaCrawler(crawler);
this.props.onSelectCrawlerId(Number(data.value)); this.props.onSelectCrawlerId(vCrawler.id);
let sd = this.props.getSensor(); let sd = this.props.getSensor();
sd.crawlerId = Number(data.value); sd.crawler = vCrawler;
this.props.setSensor(sd); this.props.setSensor(sd);
} }

View File

@ -177,19 +177,6 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
} }
} }
// 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) => { private onItemClick = (parentKey: number, idx: number) => {
@ -199,17 +186,17 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
} }
private onItemCheckCBox = (parentKey: number, checkProps: CheckboxProps, item: MetaSensorItem) => { private onItemCheckCBox = (parentKey: number, checkProps: CheckboxProps, item: MetaSensorItem) => {
if (this.selectedItemMap[parentKey] === undefined) { if (this.selectedItemMap.get(parentKey) === undefined) {
this.selectedItemMap[parentKey] = []; this.selectedItemMap.set(parentKey, []);
} }
if (checkProps.checked) { if (checkProps.checked) {
this.selectedItemMap[parentKey].push(item); this.selectedItemMap.get(parentKey).push(item);
} else { } else {
let index: number = this.selectedItemMap[parentKey].indexOf(item); let index: number = this.selectedItemMap.get(parentKey).indexOf(item);
if (index >= 0) { if (index >= 0) {
this.selectedItemMap[parentKey].splice(index, 1); this.selectedItemMap.get(parentKey).splice(index, 1);
} }
if (this.selectedItemMap[parentKey].length <= 0) { if (this.selectedItemMap.get(parentKey).length <= 0) {
let newCheckState: Map<number, boolean> = _.clone(this.state.categoryCheckState); let newCheckState: Map<number, boolean> = _.clone(this.state.categoryCheckState);
newCheckState[parentKey] = false; newCheckState[parentKey] = false;
this.setState({ categoryCheckState: newCheckState }); this.setState({ categoryCheckState: newCheckState });
@ -234,11 +221,15 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
} }
newItemState[key].fill(checkProps.checked); newItemState[key].fill(checkProps.checked);
if (checkProps.checked) { if (checkProps.checked) {
this.selectedItemMap[key] = _.clone(data.metaSensorItemList); this.selectedItemMap.set(key, _.clone(data.metaSensorItemList));
} else { } else {
this.selectedItemMap[key].length = 0; this.selectedItemMap.get(key).length = 0;
} }
this.setState({ itemState: newItemState }); this.setState({ itemState: newItemState });
let sd = this.props.getSensor();
sd.sensorItemMap = this.selectedItemMap;
this.props.setSensor(sd);
} }
private checkUnCheckParent(metaSensorItemList: Array<MetaSensorItem>): boolean { private checkUnCheckParent(metaSensorItemList: Array<MetaSensorItem>): boolean {
@ -267,74 +258,4 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
} }
// 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,
// }];
export default SensorItemTree; export default SensorItemTree;

View File

@ -1,11 +1,15 @@
import MetaSensorItem from '@overflow/meta/api/model/MetaSensorItem'; import MetaSensorItem from '@overflow/meta/api/model/MetaSensorItem';
import Infra from '@overflow/infra/api/model/Infra';
import Crawler from '@overflow/meta/api/model/MetaCrawler';
interface SensorRegistInfo { interface SensorRegistInfo {
sensorItemMap: Map<number, Array<MetaSensorItem>>; sensorItemMap: Map<number, Array<MetaSensorItem>>;
crawlerId: number; crawler: Crawler;
targetId: number; // targetId: number;
interval: number; interval: number;
// type: string;
infra: Infra;
} }
export default SensorRegistInfo; export default SensorRegistInfo;

View File

@ -28,11 +28,13 @@ import Domain from '@overflow/domain/api/model/Domain';
import Page from '@overflow/commons/api/model/Page'; import Page from '@overflow/commons/api/model/Page';
import SensorRegistInfo from '../../api/model/SensorRegistInfo'; import SensorRegistInfo from '../../api/model/SensorRegistInfo';
import Sensor from '../../api/model/Sensor';
import SensorItem from '../../api/model/SensorItem';
import MetaSensorItem from '@overflow/meta/api/model/MetaSensorItem';
import SensorItemTree from '@overflow/meta/react/SensorItemTree'; import SensorItemTree from '@overflow/meta/react/SensorItemTree';
import CrawlerSelectorContainer from '@overflow/meta/react/CrawlerSelector'; import CrawlerSelectorContainer from '@overflow/meta/react/CrawlerSelector';
import { MetaSensorStatus_ID } from '@overflow/meta/api/model/MetaSensorStatus';
export interface SensorConfigStepperStateProps { export interface SensorConfigStepperStateProps {
@ -105,9 +107,40 @@ export class SensorConfigStepper extends React.Component<SensorConfigStepperProp
if (step === this.props.steps.length + 1) { if (step === this.props.steps.length + 1) {
console.log('Done'); console.log('Done');
console.log(this.props.getSensor()); console.log(this.props.getSensor());
this.registSensor();
} }
} }
public registSensor(): void {
let sensorData = this.props.getSensor();
let sensor: Sensor = {};
sensor.crawler = { id: sensorData.crawler.id };
sensor.target = { id: sensorData.infra.target.id };
sensor.status = { id: MetaSensorStatus_ID.RUNNING };
sensor.description = sensorData.infra.infraType.name + '-' + sensorData.crawler.name;
let msiList: Array<MetaSensorItem> = new Array;
// let msiArray: MetaSensorItem[];
// let msi: MetaSensorItem;
// for (let key of Array.from(sensorData.sensorItemMap.keys())) {
// msiArray = sensorData.sensorItemMap[key];
// for (let msi of msiArray) {
// msiList.push(msi);
// }
// }
sensorData.sensorItemMap.forEach( (value: MetaSensorItem[], key: number) => {
for(let msi of value) {
msiList.push(msi);
}
});
console.log(sensor);
console.log(msiList);
}
public showContent(): any { public showContent(): any {
return this.props.steps[this.state.currentStep - 1]; return this.props.steps[this.state.currentStep - 1];
} }
@ -154,7 +187,9 @@ export class SensorConfigStepper extends React.Component<SensorConfigStepperProp
this.selectOptions = selectionOptions; this.selectOptions = selectionOptions;
let sd = this.props.getSensor(); let sd = this.props.getSensor();
sd.targetId = this.props.infra.target.id; // sd.targetId = this.props.infra.target.id;
// sd.type = this.props.infra.infraType.name;
sd.infra = this.props.infra;
this.props.setSensor(sd); this.props.setSensor(sd);
} }
@ -162,7 +197,8 @@ export class SensorConfigStepper extends React.Component<SensorConfigStepperProp
let option = { let option = {
key: infra.id, key: infra.id,
text: infra.infraType.name + '-' + infra.target.displayName, text: infra.infraType.name + '-' + infra.target.displayName,
value: infra.target.id, // value: infra.target.id,
value: JSON.stringify(infra),
// icon: 'check', // or close? // icon: 'check', // or close?
}; };
return option; return option;
@ -177,8 +213,10 @@ export class SensorConfigStepper extends React.Component<SensorConfigStepperProp
public onChangeTarget(event: React.SyntheticEvent<HTMLElement>, data: DropdownProps): void { public onChangeTarget(event: React.SyntheticEvent<HTMLElement>, data: DropdownProps): void {
let sd = this.props.getSensor(); let sd = this.props.getSensor();
// let infra: Infra = JSON.parse(String(data.value));
sd.targetId = Number(data.value); // sd.targetId = infra.target.id;
// sd.type = infra.infraType.name;
sd.infra = JSON.parse(String(data.value));
this.props.setSensor(sd); this.props.setSensor(sd);
} }

View File

@ -113,14 +113,14 @@ export interface ETCSelectorProps {
} }
export interface ETCSelectorState { export interface ETCSelectorState {
interval: number; interval: string;
} }
export class ETCSelector extends React.Component<ETCSelectorProps, ETCSelectorState> { export class ETCSelector extends React.Component<ETCSelectorProps, ETCSelectorState> {
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.state = { this.state = {
interval: 5, interval: '5',
}; };
} }
public handleIntervalChange = (e: any, { value }: any) => { public handleIntervalChange = (e: any, { value }: any) => {
@ -145,21 +145,21 @@ export class ETCSelector extends React.Component<ETCSelectorProps, ETCSelectorSt
label='5 seconds' label='5 seconds'
name='radioGroup' name='radioGroup'
value='5' value='5'
checked={this.state.interval === 5} checked={this.state.interval === '5'}
onChange={this.handleIntervalChange} onChange={this.handleIntervalChange}
/> />
<Form.Radio <Form.Radio
label='10 seconds' label='10 seconds'
name='radioGroup' name='radioGroup'
value='10' value='10'
checked={this.state.interval === 10} checked={this.state.interval === '10'}
onChange={this.handleIntervalChange} onChange={this.handleIntervalChange}
/> />
<Form.Radio <Form.Radio
label='15 seconds' label='15 seconds'
name='radioGroup' name='radioGroup'
value='15' value='15'
checked={this.state.interval === 15} checked={this.state.interval === '15'}
onChange={this.handleIntervalChange} onChange={this.handleIntervalChange}
/> />
</Form.Group> </Form.Group>