diff --git a/package.json b/package.json index 7026de0..bf97a56 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "express-bearer-token": "2.1.0", "http-proxy-middleware": "0.17.4", "lodash": "4.17.4", - "material-ui": "^0.20.0", + "material-ui": "^0.20.1", "material-ui-datetimepicker": "^1.0.6", "react": "15.4.2", "react-dom": "15.4.2", @@ -61,4 +61,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/actions/index.js b/src/actions/index.js index 53bb8c4..d6743b3 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -886,3 +886,13 @@ export const recordsDelete = (deviceId, componentId) => { }) } } + +export const deviceTypesGet = (deviceOverview) => { + return agile.deviceManager.typeof(deviceOverview) + .then(deviceTypes => { + return deviceTypes + }) + .catch(err => { + return err + }); +} \ No newline at end of file diff --git a/src/components/RegisterDeviceManual.js b/src/components/RegisterDeviceManual.js new file mode 100644 index 0000000..75bfbb0 --- /dev/null +++ b/src/components/RegisterDeviceManual.js @@ -0,0 +1,253 @@ + +import React from 'react'; + +import TextField from 'material-ui/TextField'; +import Dialog from 'material-ui/Dialog'; +import { FlatButton } from 'material-ui'; +import SelectField from 'material-ui/SelectField'; +import MenuItem from 'material-ui/MenuItem'; + +import { connect } from 'react-redux'; + +import { Card } from 'material-ui/Card'; + +import { + devicesCreate, + deviceTypesFetch, + protocolsFetch, + deviceTypesGet +} from '../actions'; + +class RegisterDeviceManually extends React.Component { + constructor() { + super(); + + this.state = { + open: false, + deviceStatus: "AVAILABLE", + deviceProtocol: null, + deviceName: null, + deviceId: null, + deviceType: null, + deviceTypesMenuItem: [] + }; + this.handleDeviceValueChange = this.handleDeviceValueChange.bind(this); + this.submitManualDeviceForm = this.submitManualDeviceForm.bind(this); + this.handleChangeDeviceType = this.handleChangeDeviceType.bind(this); + this.handleChangeDeviceProtocol = this.handleChangeDeviceProtocol.bind(this); + this.renderDeviceTypeItems = this.renderDeviceTypeItems.bind(this); + } + + componentDidMount() { + this.props.protocolsFetch() + } + + handleDeviceValueChange(event) { + this.setState({ + [event.target.name]: event.target.value + }); + } + + handleChangeDeviceProtocol(event, index, value) { + this.setState({ + deviceProtocol: value + }) + this.renderDeviceTypesSelectList(false) + this.renderDeviceTypeItems(value) + } + + handleChangeDeviceType (event, index, value) { + this.setState({ + deviceType: value + }) + } + + renderDeviceTypeItems(value) { + let device = { + id: this.state.deviceId, + name: this.state.deviceName, + protocol: value, + status: this.state.deviceStatus + } + console.log(device) + deviceTypesGet(device) + .then(deviceTypes => { + console.log(deviceTypes) + + deviceTypes.map((type, i) => { + return this.state.deviceTypesMenuItem.push()} ) + }) + .catch(err => { + console.log(err) + }); + // this.renderDeviceTypes(device, this.props.deviceTypes[device.id]) + } + + renderDeviceTypesSelectList(disable) { + return( +
+ + + {this.state.deviceTypesMenuItem} + +
) + } + + renderProtocols() { + return( +
+ + + {this.props.protocols.map((protocol, i) => { + return () + })} + +
) + } + + deviceForm() { + return ( +
+
+ +
+
+ +
+
+ {this.renderProtocols()} +
+
+ {this.renderDeviceTypesSelectList(true)} +
+
) + } + + handleOpen = () => { + this.setState({open: true}); + }; + + handleClose = () => { + this.setState({open: false}); + }; + + submitManualDeviceForm() { + console.log(this.state) + let device = { + id: this.state.deviceId, + name: this.state.deviceName, + protocol: this.state.deviceProtocol, + status: this.state.deviceStatus + } + this.props.devicesCreate(device, this.state.deviceType) + this.setState({open: false}); + } + + render() { + const actions = [ + , + , + ]; + return ( + +
+ Register Device +
+ + {this.deviceForm()} + + +
+ ) + } +} + +const modalWinStyle = { + form: { + group: { + width: '100%', + display: 'block', + margin: '5px' + } + }, + label: {fontSize: '1rem', fontWeight: 'bold'}, + btn: {width: '100%', textAligh: 'center'}, + card: { + marginBottom: '10px' + }, +} + +const mapStateToProps = (state) => { + return { + deviceTypes: state.deviceTypes, + protocols: state.protocols + }; +}; + +const mapDispatchToProps = (dispatch) => { + return { + devicesCreate: (device, type) => dispatch(devicesCreate(device, type)), + deviceTypesFetch: (device) => dispatch(deviceTypesFetch(device)), + protocolsFetch: () => dispatch(protocolsFetch()) + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(RegisterDeviceManually); \ No newline at end of file diff --git a/src/components/index.js b/src/components/index.js index 7a2ddd8..8f3984b 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -15,6 +15,7 @@ import SettingsMenu from './SettingsMenu'; import DeviceItem from './DeviceItem'; import EntityItem from './EntityItem'; import SecurityItem from './SecurityItem'; +import RegisterDeviceManual from './RegisterDeviceManual'; import LockItem from './LockItem'; import Form from './Form'; import Stream from './Stream'; @@ -39,5 +40,6 @@ export { SecurityItem, LockItem, Form, - LocalDataOverview + LocalDataOverview, + RegisterDeviceManual } diff --git a/src/containers/Discover.js b/src/containers/Discover.js index e0f0e36..fd653ff 100644 --- a/src/containers/Discover.js +++ b/src/containers/Discover.js @@ -11,7 +11,7 @@ * Resin.io, FBK, Jolocom - initial API and implementation ******************************************************************************/ import React, { Component } from 'react'; -import { DeviceItem } from '../components'; +import { DeviceItem, RegisterDeviceManual } from '../components'; import SelectField from 'material-ui/SelectField'; import MenuItem from 'material-ui/MenuItem'; import { connect } from 'react-redux'; @@ -118,15 +118,21 @@ class Discover extends Component { const {discovery, devices} = this.props if (devices.length === 0 && discovery) { return ( -
- +
+ +
+ +
) } return ( -
- {this.renderItems(this.props.devices)} +
+ +
+ {this.renderItems(this.props.devices)} +
); }