diff --git a/src/ts/containers/config/SensorConfigPopup.tsx b/src/ts/containers/config/SensorConfigPopup.tsx index 56aa815..23cf4a0 100644 --- a/src/ts/containers/config/SensorConfigPopup.tsx +++ b/src/ts/containers/config/SensorConfigPopup.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import { OFRest } from '../../components/Rest'; import Dialog from 'material-ui/Dialog'; import FlatButton from 'material-ui/FlatButton'; import RaisedButton from 'material-ui/RaisedButton'; @@ -8,6 +9,8 @@ import DropDownMenu from 'material-ui/DropDownMenu'; import MenuItem from 'material-ui/MenuItem'; import AppBar from 'material-ui/AppBar'; import Checkbox from 'material-ui/Checkbox'; +import TextField from 'material-ui/TextField'; +import { RadioButton, RadioButtonGroup } from 'material-ui/RadioButton'; import { Table, TableBody, @@ -57,6 +60,7 @@ export class SensorConfigPopup extends React.Component { "description": "mem free ", }, ]; + this.setState({ crawler: c, sensorItems: items, @@ -106,96 +110,149 @@ export class SensorConfigPopup extends React.Component {
Version :
Port :
Port Type :
-
+ + - ); } } -const styles = { - title: { - cursor: 'pointer', - }, -}; export class CrawlerSelector extends React.Component { constructor(props: any, context: any) { super(props, context); this.state = { - value: 0, + value: -1, crawlers: [], + authOpen: false, + authInputs: [], }; } componentWillMount() { - var crawlers = [ - { - "id": 0, - "name": "Protocol", - "description": "Alive check only using protocol.", - "type": "Protocol", - }, - { - "id": 1, - "name": "SQL", - "description": "Query based sensors", - "type": "SQL", - }, - { - "id": 2, - "name": "WMI", - "description": "Windows Management Instrumentation", - "type": "WMI", - }, - ]; - this.setState({ - crawlers: crawlers, + + let os: OFRest = new OFRest("Crawler", "List", null); + var that: any = this; + os.Call().then(function (res) { + return res.json(); + }).then(function (json) { + let list = JSON.parse(json.resultStr); + that.setState({ + crawlers: list, + }); + }).catch(function (err) { + console.log(err); }); + + } handleCrawlerChange = (event: any, index: any, v: number) => { this.setState({ value: v, }); - if (v === 0) { + if (v === -1) { 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() { - if (this.state.value === 0) { + if (this.state.value === -1) { 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
; + } + return
Connection Info. { + this.state.authInputs.map((data: any, index: number) => { + return
{this.renderInputs(data)}
; + }) + }
; + } + + renderInputs = (data: any) => { + let input = data.crawlerInputItem; + if (input.dataType === "String") { + return
this.setState({ email: newValue })} + />
; + } + else if (input.dataType === "Select") { + let values = input.description.split('||'); + let radios = Array(); + for (var i = 0; i < values.length; i++) { + radios.push(); + } + return
+ + {radios} + +
; + } + } + + handleExpand = (b: boolean) => { + this.setState({ + authOpen: b, + }); + } render() { return (
- + {this.state.crawlers.map((crawler: any, index: number) => { return (); })} - + { showExpandableButton={true} /> - Crawler manual blahblahblah... + {this.renderAuthRequester()} @@ -218,7 +275,7 @@ export class SensorItemSelector extends React.Component { constructor(props: any, context: any) { super(props, context); this.state = { - selected:[] + selected: [] }; } @@ -229,7 +286,7 @@ export class SensorItemSelector extends React.Component { handleRowSelection = (selectedRows: any) => { this.setState({ - selected : selectedRows, + selected: selectedRows, }); this.props.onChange(selectedRows); }