wowwwwwwwww

This commit is contained in:
insanity 2017-06-08 21:51:35 +09:00
parent cd7399fd06
commit 924ce5846e

View File

@ -1,4 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import { OFRest } from '../../components/Rest';
import Dialog from 'material-ui/Dialog'; import Dialog from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton'; import FlatButton from 'material-ui/FlatButton';
import RaisedButton from 'material-ui/RaisedButton'; import RaisedButton from 'material-ui/RaisedButton';
@ -8,6 +9,8 @@ import DropDownMenu from 'material-ui/DropDownMenu';
import MenuItem from 'material-ui/MenuItem'; import MenuItem from 'material-ui/MenuItem';
import AppBar from 'material-ui/AppBar'; import AppBar from 'material-ui/AppBar';
import Checkbox from 'material-ui/Checkbox'; import Checkbox from 'material-ui/Checkbox';
import TextField from 'material-ui/TextField';
import { RadioButton, RadioButtonGroup } from 'material-ui/RadioButton';
import { import {
Table, Table,
TableBody, TableBody,
@ -57,6 +60,7 @@ export class SensorConfigPopup extends React.Component<any, any> {
"description": "mem free ", "description": "mem free ",
}, },
]; ];
this.setState({ this.setState({
crawler: c, crawler: c,
sensorItems: items, sensorItems: items,
@ -106,96 +110,149 @@ export class SensorConfigPopup extends React.Component<any, any> {
<div>Version : </div> <div>Version : </div>
<div>Port : </div> <div>Port : </div>
<div>Port Type : </div> <div>Port Type : </div>
<div></div>
</CardText> </CardText>
</Card> </Card>
<Card> <Card>
<CrawlerSelector target={this.props.target} onChange={this.handleCrawlerSelect} /> <CrawlerSelector target={this.props.target} onChange={this.handleCrawlerSelect} />
</Card>
<Card>
<SensorItemSelector items={this.state.sensorItems} onChange={this.handleSensorItemsSelect} /> <SensorItemSelector items={this.state.sensorItems} onChange={this.handleSensorItemsSelect} />
</Card> </Card>
</Dialog> </Dialog>
</div> </div>
); );
} }
} }
const styles = {
title: {
cursor: 'pointer',
},
};
export class CrawlerSelector extends React.Component<any, any> { export class CrawlerSelector extends React.Component<any, any> {
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.state = { this.state = {
value: 0, value: -1,
crawlers: [], crawlers: [],
authOpen: false,
authInputs: [],
}; };
} }
componentWillMount() { componentWillMount() {
var crawlers = [
{ let os: OFRest = new OFRest("Crawler", "List", null);
"id": 0, var that: any = this;
"name": "Protocol", os.Call().then(function (res) {
"description": "Alive check only using protocol.", return res.json();
"type": "Protocol", }).then(function (json) {
}, let list = JSON.parse(json.resultStr);
{ that.setState({
"id": 1, crawlers: list,
"name": "SQL", });
"description": "Query based sensors", }).catch(function (err) {
"type": "SQL", console.log(err);
},
{
"id": 2,
"name": "WMI",
"description": "Windows Management Instrumentation",
"type": "WMI",
},
];
this.setState({
crawlers: crawlers,
}); });
} }
handleCrawlerChange = (event: any, index: any, v: number) => { handleCrawlerChange = (event: any, index: any, v: number) => {
this.setState({ this.setState({
value: v, value: v,
}); });
if (v === 0) { if (v === -1) {
return; return;
} }
this.props.onChange(this.state.crawlers[v]); let selectedCrawler = this.state.crawlers[v];
this.props.onChange(selectedCrawler);
this.checkAuth(selectedCrawler);
}
checkAuth = (c: any) => {
//Todo. validate auth
this.setState({
authOpen: true,
});
let os: OFRest = new OFRest("Crawlerinputitemmapping", "List", c);
var that: any = this;
os.Call().then(function (res) {
return res.json();
}).then(function (json) {
var list = JSON.parse(json.resultStr);
that.setState({
authInputs: list,
});
}).catch(function (err) {
console.log(err);
});
} }
getCrawlerTitle() { getCrawlerTitle() {
if (this.state.value === 0) { if (this.state.value === -1) {
return ""; return "";
} }
return this.state.crawlers[this.state.value].description; var c = this.state.crawlers[this.state.value];
return "[" + c.crawlerType + "] " + c.description;
} }
renderAuthRequester = () => {
if (this.state.authInputs.length === 0) {
return <div></div>;
}
return <div> Connection Info. {
this.state.authInputs.map((data: any, index: number) => {
return <div key={index}>{this.renderInputs(data)}</div>;
})
}</div>;
}
renderInputs = (data: any) => {
let input = data.crawlerInputItem;
if (input.dataType === "String") {
return <div><TextField
hintText={input.description}
floatingLabelText={input.name}
underlineShow={true}
//value={this.state.email}
// onChange={(e, newValue) => this.setState({ email: newValue })}
/></div>;
}
else if (input.dataType === "Select") {
let values = input.description.split('||');
let radios = Array();
for (var i = 0; i < values.length; i++) {
radios.push(<RadioButton key={i} value={i} label={values[i]} />);
}
return <div>
<RadioButtonGroup name={input.name} defaultSelected="not_light">
{radios}
</RadioButtonGroup>
</div>;
}
}
handleExpand = (b: boolean) => {
this.setState({
authOpen: b,
});
}
render() { render() {
return ( return (
<div> <div>
<DropDownMenu value={this.state.value} onChange={this.handleCrawlerChange} style={{ width: 300 }}> <DropDownMenu value={this.state.value} onChange={this.handleCrawlerChange} style={{ width: 300 }}>
<MenuItem value={0} primaryText="Choose a Crawler type" /> <MenuItem value={-1} primaryText="Choose a Crawler type" />
{this.state.crawlers.map((crawler: any, index: number) => { {this.state.crawlers.map((crawler: any, index: number) => {
return (<MenuItem return (<MenuItem
value={crawler.id} value={index}
primaryText={crawler.name} primaryText={crawler.name}
key={index} key={index}
/>); />);
})} })}
</DropDownMenu> </DropDownMenu>
<Card> <Card expanded={this.state.authOpen} onExpandChange={this.handleExpand.bind(this)}>
<CardHeader <CardHeader
title={this.getCrawlerTitle()} title={this.getCrawlerTitle()}
subtitle='' subtitle=''
@ -203,7 +260,7 @@ export class CrawlerSelector extends React.Component<any, any> {
showExpandableButton={true} showExpandableButton={true}
/> />
<CardText expandable={true} > <CardText expandable={true} >
Crawler manual blahblahblah... {this.renderAuthRequester()}
</CardText> </CardText>
</Card> </Card>
@ -218,7 +275,7 @@ export class SensorItemSelector extends React.Component<any, any> {
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
this.state = { this.state = {
selected:[] selected: []
}; };
} }
@ -229,7 +286,7 @@ export class SensorItemSelector extends React.Component<any, any> {
handleRowSelection = (selectedRows: any) => { handleRowSelection = (selectedRows: any) => {
this.setState({ this.setState({
selected : selectedRows, selected: selectedRows,
}); });
this.props.onChange(selectedRows); this.props.onChange(selectedRows);
} }