|
|
@ -1,8 +1,15 @@ |
|
|
|
import React from 'react' |
|
|
|
import RGBLamp from './rgbLamp' |
|
|
|
import { Grid, Switch, Typography, Dialog, Select, MenuItem, TextField, Button } from '@material-ui/core'; |
|
|
|
import { DialogTitle, DialogContent, DialogActions } from '@material-ui/core'; |
|
|
|
import { Grid, Switch, Typography, Dialog, Select, MenuItem, TextField } from '@material-ui/core'; |
|
|
|
import DialogTitle from '@material-ui/core/DialogTitle'; |
|
|
|
import DialogContent from '@material-ui/core/DialogContent'; |
|
|
|
import DialogActions from '@material-ui/core/DialogActions'; |
|
|
|
import Button from '@material-ui/core/Button'; |
|
|
|
import api from '../../static'; |
|
|
|
|
|
|
|
const SelectStyle = { |
|
|
|
minWidth: 120 |
|
|
|
} |
|
|
|
|
|
|
|
const styles= { |
|
|
|
dropdown: { |
|
|
@ -19,20 +26,20 @@ class LampList extends React.Component { |
|
|
|
super(props) |
|
|
|
this.state = { |
|
|
|
dialogOpen: false, |
|
|
|
createLightType: 'rgb', |
|
|
|
textFieldCreateLightName: "", |
|
|
|
textFieldCreateLightDescription: "", |
|
|
|
textFieldCreateLightBoardred: "", |
|
|
|
textFieldCreateLightChannelred: "", |
|
|
|
textFieldCreateLightBoardgreen: "", |
|
|
|
textFieldCreateLightChannelgreen: "", |
|
|
|
textFieldCreateLightBoardblue: "", |
|
|
|
textFieldCreateLightChannelblue: "" |
|
|
|
createLightType: 1, |
|
|
|
createBoardAddress: 1, |
|
|
|
types: [], |
|
|
|
boards: [] |
|
|
|
} |
|
|
|
|
|
|
|
api.getBoardnType() |
|
|
|
.then(res => { |
|
|
|
this.setState(res) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
addLamp = (onChange, lamp, adminMode) => { |
|
|
|
console.log(adminMode) |
|
|
|
switch (lamp.type) { |
|
|
|
case 'rgb': |
|
|
|
return (<RGBLamp key={lamp.id} lamp={lamp} adminMode={adminMode} onChange={onChange} />) |
|
|
@ -41,6 +48,7 @@ class LampList extends React.Component { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
handleClose = () => { |
|
|
|
this.setState({ dialogOpen: false }) |
|
|
@ -56,6 +64,12 @@ class LampList extends React.Component { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
handleCreateBoardAddress = (event) => { |
|
|
|
this.setState({ |
|
|
|
createBoardAddress: event.target.value |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
handleTextField = (event) => { |
|
|
|
console.log(event.target.value) |
|
|
|
this.setState({ |
|
|
@ -63,42 +77,73 @@ class LampList extends React.Component { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
createRGBChannel = (name) => { |
|
|
|
return ( |
|
|
|
<Grid container> |
|
|
|
<Grid item xs={12}> |
|
|
|
<Typography variant="h6" style={styles.caption}>{name}</Typography> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6} md={4}> |
|
|
|
<TextField id={"textFieldCreateLightChannel" + name} label="Board" value={this.state.textFieldCreateLightChannel} onChange={this.handleTextField} /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6} md={4}> |
|
|
|
<TextField id={"textFieldCreateLightBoard" + name} label="Channel" value={this.state.textFieldCreateLightChannel} onChange={this.handleTextField} /> |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
) |
|
|
|
handleSave = () => { |
|
|
|
let light = { |
|
|
|
title: this.state.createTitle, |
|
|
|
description: this.state.createDescription, |
|
|
|
typeID: this.state.createLightType, |
|
|
|
boardID: this.state.createBoardAddress |
|
|
|
} |
|
|
|
switch (this.state.createLightType) { |
|
|
|
case 1: |
|
|
|
light.channels = { |
|
|
|
r: this.state.createR, |
|
|
|
g: this.state.createG, |
|
|
|
b: this.state.createB |
|
|
|
} |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
light.channels = { |
|
|
|
s: this.state.createS |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
} |
|
|
|
api.createLamp(light) |
|
|
|
console.log(light) |
|
|
|
} |
|
|
|
|
|
|
|
createChannel = () => { |
|
|
|
addChannels() { |
|
|
|
switch (this.state.createLightType) { |
|
|
|
case 'rgb': |
|
|
|
case 1: |
|
|
|
return ( |
|
|
|
<Grid item xs={12}> |
|
|
|
<Typography variant="h5" style={styles.caption}>Channels</Typography> |
|
|
|
{this.createRGBChannel('red')} |
|
|
|
{this.createRGBChannel('green')} |
|
|
|
{this.createRGBChannel('blue')} |
|
|
|
<Grid item xs={12} style={{marginTop:20}}> |
|
|
|
<Grid container> |
|
|
|
<Grid item xs={6} > |
|
|
|
<Typography style={{marginTop:16}}>Channel red</Typography> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6}> |
|
|
|
<TextField id="createR" label="Channel red" value={this.state.colorR} onChange={this.handleTextField} /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6}> |
|
|
|
<Typography style={{marginTop:16}}>Channel green</Typography> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6}> |
|
|
|
<TextField id="createG" label="Channel green" value={this.state.colorG} onChange={this.handleTextField} /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6}> |
|
|
|
<Typography style={{marginTop:16}}>Channel blue</Typography> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6}> |
|
|
|
<TextField id="createB" label="Channel blue" value={this.state.colorB} onChange={this.handleTextField} /> |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
) |
|
|
|
|
|
|
|
case 'light': |
|
|
|
default: |
|
|
|
return ( |
|
|
|
<div></div> |
|
|
|
<Grid container> |
|
|
|
<Grid item xs={6}> |
|
|
|
<Typography>Switch</Typography> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6}> |
|
|
|
<TextField id="createS" label="Switch" value={this.state.colorB} onChange={this.handleTextField} /> |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addNewLightDialog = (open) => { |
|
|
|
return ( |
|
|
|
<Dialog onClose={this.handleClose} aria-labelledby="customized-dialog-title" open={this.state.dialogOpen}> |
|
|
@ -107,24 +152,43 @@ class LampList extends React.Component { |
|
|
|
</DialogTitle> |
|
|
|
<DialogContent dividers> |
|
|
|
<Grid container> |
|
|
|
<Grid item xs={12}> |
|
|
|
<Select style={styles.dropdown} value={this.state.createLightType} onChange={this.handleCreateLightType}> |
|
|
|
<MenuItem value={'rgb'}>RGB-Stripe</MenuItem> |
|
|
|
<MenuItem value={'light'}>Light</MenuItem> |
|
|
|
</Select> |
|
|
|
<Grid item xs={6} md={3}> |
|
|
|
<Typography>Typ</Typography> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6}> |
|
|
|
<TextField id="textFieldCreateLightName" label="Name" value={this.state.textFieldCreateLightName} onChange={this.handleTextField} /> |
|
|
|
<Grid item xs={6} md={3}> |
|
|
|
<Select style={SelectStyle} value={this.state.createLightType} onChange={this.handleCreateLightType}> |
|
|
|
{ |
|
|
|
this.state.types.map(type => { |
|
|
|
return <MenuItem id={type.typeID} key={type.typeID} value={type.typeID}>{type.name}</MenuItem> |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
</Select> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6}> |
|
|
|
<TextField id="textFieldCreateLightDescription" label="Beschreibung" value={this.state.textFieldCreateLightDescription} onChange={this.handleTextField} /> |
|
|
|
<Grid item xs={6} md={3}> |
|
|
|
<Typography>Board-Address</Typography> |
|
|
|
</Grid> |
|
|
|
{this.createChannel()} |
|
|
|
<Grid item xs={6} md={3}> |
|
|
|
<Select style={SelectStyle} value={this.state.createBoardAddress} onChange={this.handleCreateBoardAddress}> |
|
|
|
{ |
|
|
|
this.state.boards.map(board => { |
|
|
|
return <MenuItem id={board.boardID} key={board.boardID} value={board.boardID}>{board.address}</MenuItem> |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
</Select> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={6} style={{marginTop:10}}> |
|
|
|
<TextField id="createTitle" label="Titel" value={this.state.createName} onChange={this.handleTextField} /> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={4} style={{marginTop:10}}> |
|
|
|
<TextField id="createDescription" label="Beschreibung" value={this.state.createName} onChange={this.handleTextField} /> |
|
|
|
</Grid> |
|
|
|
{this.addChannels()} |
|
|
|
</Grid> |
|
|
|
</DialogContent> |
|
|
|
<DialogActions> |
|
|
|
<Button autoFocus onClick={this.handleClose} color="primary"> |
|
|
|
<Button autoFocus onClick={this.handleSave} color="primary"> |
|
|
|
Save changes |
|
|
|
</Button> |
|
|
|
</DialogActions> |
|
|
@ -149,7 +213,7 @@ class LampList extends React.Component { |
|
|
|
</div> |
|
|
|
</Grid> |
|
|
|
<Grid item xs={4}> |
|
|
|
<Button onClick={this.handleDialogOpen}>Create light</Button> |
|
|
|
<Button onClick={this.handleDialogOpen}>Create new light</Button> |
|
|
|
</Grid> |
|
|
|
</Grid> |
|
|
|
) |
|
|
@ -170,7 +234,15 @@ class LampList extends React.Component { |
|
|
|
this.props.lamps.map(lamp => { |
|
|
|
switch (lamp.type) { |
|
|
|
case 'rgb': |
|
|
|
return (<RGBLamp key={lamp.id} lamp={lamp} adminMode={this.props.adminMode} colorMode={this.props.colorMode} onChange={this.props.onChangeColor} />) |
|
|
|
return ( |
|
|
|
<RGBLamp |
|
|
|
key={lamp.id} |
|
|
|
lamp={lamp} |
|
|
|
adminMode={this.props.adminMode} |
|
|
|
colorMode={this.props.colorMode} |
|
|
|
onChange={this.props.onChangeColor} |
|
|
|
/> |
|
|
|
) |
|
|
|
default: |
|
|
|
return "" |
|
|
|
} |
|
|
|