diff --git a/src/ts/components/Rest.tsx b/src/ts/components/Rest.tsx index 15abeae..3ee07ce 100644 --- a/src/ts/components/Rest.tsx +++ b/src/ts/components/Rest.tsx @@ -17,9 +17,6 @@ export class OFRest { } }; - - - } public Call() { @@ -28,10 +25,9 @@ export class OFRest { method: 'POST', headers: { 'Accept': 'application/json', - // mode: 'no-cors' }, body: JSON.stringify(this.obj) - }) + }); } } diff --git a/src/ts/containers/target/TargetList.tsx b/src/ts/containers/target/TargetList.tsx index a0dba91..2c9abb0 100644 --- a/src/ts/containers/target/TargetList.tsx +++ b/src/ts/containers/target/TargetList.tsx @@ -1,152 +1,125 @@ import * as React from 'react'; - import { List, ListItem, makeSelectable } from 'material-ui/List'; import Subheader from 'material-ui/Subheader'; import Paper from 'material-ui/Paper'; - import { OFRest } from '../../components/Rest'; import * as Utils from '../../components/Utils'; - import RaisedButton from 'material-ui/RaisedButton'; +import { + Table, + TableBody, + TableHeader, + TableHeaderColumn, + TableFooter, + TableRow, + TableRowColumn, +} from 'material-ui/Table'; -const styles = { - test: { - display: 'inline-block', - float: 'left', - width: '50%', - height: 550, - }, - container: { - width: '80%', - - } -} - -let SelectableList = makeSelectable(List); - -function wrapState(ComposedComponent: any, par: any) { - return class SelectableList extends React.Component { - - componentWillMount() { - this.setState({ - selectedIndex: -1, - }); - } - - handleRequestChange = (event: any, index: any) => { - this.setState({ - selectedIndex: index, - }); - par.handleSelect(index); - }; - - render() { - return ( - - {this.props.children} - - ); - } - }; -} - -var testRes = "[{\"id\":1,\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL\",\"version\":\"9.5.0\",\"createDate\":1496631864025,\"member\":{\"id\":1,\"email\":\"insanity33@loafle.com\",\"pwSalt\":\"salktttt\",\"digest\":\"bbbbbbbbb\",\"name\":\"insanity3\",\"company\":\"loafle\",\"phone\":\"000-000-0000\",\"authorizedDate\":null}}]"; - -var RES = JSON.parse(testRes); export class TargetList extends React.Component { constructor(props: any, context: any) { - super(props, context) - SelectableList = wrapState(SelectableList, this); - - this.componentWillMount = this.componentWillMount.bind(this) - - this.getTargetList = this.getTargetList.bind(this); - - + super(props, context); + this.state = { + selected: [], + targets: [], + }; } componentWillMount() { - + this.getTargetList(); } getTargetList() { - - let obj: any - + let obj: any; obj = { - "id":"0", - "member":{ - "id":"1" + "id": "0", + "member": { + "id": "1" } }; let os: OFRest = new OFRest("Target", "List", obj); - + var that: any = this; os.Call().then(function (res) { return res.json(); }).then(function (json) { - - RES = JSON.parse(json) - + let targetList = JSON.parse(json.resultStr); + that.setState({ + targets: targetList, + }); }).catch(function (err) { console.log(err); }); } - handleSelect(idx: any) { - this.props.onChange(idx); + + handleRowSelection = (selectedRows: any) => { + this.setState({ + selected: selectedRows, + }); } - handleSignUp() { - this.getTargetList() + handleNext = () => { + if (this.state.selected.length === 0) { + alert('Select a target to monitor'); + }else { + alert("ID: "+ this.state.targets[this.state.selected[0]].id); + } } + + isSelected = (index: any) => { + if (this.state.selected.indexOf(index) === -1) { + return false; + } else { + return true; + } + } + + render() { - let num: number; - num = 1; return ( -
+
- - Select a target to monitor - + + + Host + Port + Type + Kind + Name + Version + + + + displayRowCheckbox={true} + > + {this.state.targets.map((row: any, index: number) => ( + + {Utils.int2ip(row.ip)} + {row.port} + {row.targetType} + {row.kinds} + {row.vendorName} + {row.version} + + ))}; + + - RES.map(function (item: any, index: number) { - - let port: string; - port = "Port : " - - - return ( - , - - ]} - /> - ) - }) - ]} - /> - - +
); diff --git a/tslint.json b/tslint.json index 9530e59..b0596c4 100644 --- a/tslint.json +++ b/tslint.json @@ -1,5 +1,4 @@ { - "extends": "tslint:recommended", "rules": { "indent": [ true, @@ -12,7 +11,7 @@ "only-arrow-functions": [ false, "allow-declarations", "allow-named-functions" ], - "no-console": false, + "no-console": [false], "prefer-const": false, "member-access": false, "no-unused-expression": true,