rino 3 years ago
parent
commit
c18329056c
11 changed files with 339 additions and 171 deletions
  1. +39
    -101
      package-lock.json
  2. +1
    -0
      package.json
  3. +108
    -0
      src/components/ManualView/CustomPicker.js
  4. +122
    -50
      src/components/ManualView/lampList.js
  5. +25
    -14
      src/components/ManualView/rgbLamp.js
  6. +0
    -0
      src/components/Manual_Backup.js
  7. +0
    -0
      src/components/Presets_Backup.js
  8. +0
    -0
      src/components/Unit_Backup.js
  9. +33
    -2
      src/containers/ManualTab.js
  10. +1
    -1
      src/redux/actions.js
  11. +10
    -3
      src/static.js

+ 39
- 101
package-lock.json View File

@ -1467,9 +1467,9 @@
}
},
"acorn": {
"version": "6.4.2",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.2.tgz",
"integrity": "sha512-XtGIhXwF8YM8bJhGxG5kXgjkEuNGLTkoYqVE+KMR+aspr4KGYmKYg7yUe3KghyQ9yheNwLnjmzh/7+gfDBmHCQ=="
"version": "6.4.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz",
"integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA=="
},
"acorn-dynamic-import": {
"version": "3.0.0",
@ -3159,8 +3159,7 @@
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"optional": true
"bundled": true
},
"aproba": {
"version": "1.2.0",
@ -3525,8 +3524,7 @@
},
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"optional": true
"bundled": true
},
"safer-buffer": {
"version": "2.1.2",
@ -3574,7 +3572,6 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -3613,13 +3610,11 @@
},
"wrappy": {
"version": "1.0.2",
"bundled": true,
"optional": true
"bundled": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"optional": true
"bundled": true
}
}
},
@ -3853,6 +3848,11 @@
"simple-swizzle": "^0.2.2"
}
},
"colorconverter": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/colorconverter/-/colorconverter-0.1.1.tgz",
"integrity": "sha1-+VgC/vVO/r9Nl8QsZsg/xtflyjs="
},
"combined-stream": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz",
@ -6715,8 +6715,7 @@
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"optional": true
"bundled": true
},
"aproba": {
"version": "1.2.0",
@ -6753,8 +6752,7 @@
},
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"optional": true
"bundled": true
},
"concat-map": {
"version": "0.0.1",
@ -6763,8 +6761,7 @@
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"optional": true
"bundled": true
},
"core-util-is": {
"version": "1.0.2",
@ -6867,8 +6864,7 @@
},
"inherits": {
"version": "2.0.3",
"bundled": true,
"optional": true
"bundled": true
},
"ini": {
"version": "1.3.5",
@ -6878,7 +6874,6 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -6904,7 +6899,6 @@
"minipass": {
"version": "2.3.5",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -6921,7 +6915,6 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -7005,7 +6998,6 @@
"once": {
"version": "1.4.0",
"bundled": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -7081,8 +7073,7 @@
},
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"optional": true
"bundled": true
},
"safer-buffer": {
"version": "2.1.2",
@ -7112,7 +7103,6 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -7130,7 +7120,6 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -7169,13 +7158,11 @@
},
"wrappy": {
"version": "1.0.2",
"bundled": true,
"optional": true
"bundled": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"optional": true
"bundled": true
}
}
},
@ -9557,12 +9544,12 @@
}
},
"loader-fs-cache": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/loader-fs-cache/-/loader-fs-cache-1.0.2.tgz",
"integrity": "sha512-70IzT/0/L+M20jUlEqZhZyArTU6VKLRTYRDAYN26g4jfzpJqjipLL3/hgYpySqI9PwsVRHHFja0LfEmsx9X2Cw==",
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/loader-fs-cache/-/loader-fs-cache-1.0.3.tgz",
"integrity": "sha512-ldcgZpjNJj71n+2Mf6yetz+c9bM4xpKtNds4LbqXzU/PTdeAX0g3ytnU1AJMEcTk2Lex4Smpe3Q/eCTsvUBxbA==",
"requires": {
"find-cache-dir": "^0.1.1",
"mkdirp": "0.5.1"
"mkdirp": "^0.5.1"
},
"dependencies": {
"find-cache-dir": {
@ -13729,8 +13716,7 @@
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"optional": true
"bundled": true
},
"aproba": {
"version": "1.2.0",
@ -13767,8 +13753,7 @@
},
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"optional": true
"bundled": true
},
"concat-map": {
"version": "0.0.1",
@ -13777,8 +13762,7 @@
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"optional": true
"bundled": true
},
"core-util-is": {
"version": "1.0.2",
@ -13881,8 +13865,7 @@
},
"inherits": {
"version": "2.0.3",
"bundled": true,
"optional": true
"bundled": true
},
"ini": {
"version": "1.3.5",
@ -13892,7 +13875,6 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -13912,13 +13894,11 @@
},
"minimist": {
"version": "0.0.8",
"bundled": true,
"optional": true
"bundled": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@ -13935,7 +13915,6 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -14008,8 +13987,7 @@
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"optional": true
"bundled": true
},
"object-assign": {
"version": "4.1.1",
@ -14019,7 +13997,6 @@
"once": {
"version": "1.4.0",
"bundled": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -14095,8 +14072,7 @@
},
"safe-buffer": {
"version": "5.1.1",
"bundled": true,
"optional": true
"bundled": true
},
"safer-buffer": {
"version": "2.1.2",
@ -14126,7 +14102,6 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -14144,7 +14119,6 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -14183,13 +14157,11 @@
},
"wrappy": {
"version": "1.0.2",
"bundled": true,
"optional": true
"bundled": true
},
"yallist": {
"version": "3.0.2",
"bundled": true,
"optional": true
"bundled": true
}
}
},
@ -16055,16 +16027,10 @@
"has": "^1.0.3",
"has-symbols": "^1.0.1",
"is-callable": "^1.2.2",
"is-regex": "^1.1.1",
"object-inspect": "^1.8.0",
"is-regex": "^1.1.0",
"object-inspect": "^1.7.0",
"object-keys": "^1.1.1",
"object.assign": "^4.1.1",
"string.prototype.trimend": "^1.0.1",
"string.prototype.trimstart": "^1.0.1"
}
},
"es-to-primitive": {
"version": "1.2.1",
"object.assign": "^4.1.0",
"resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz",
"integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==",
"requires": {
@ -16148,39 +16114,11 @@
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.1",
"is-callable": "^1.2.2",
"is-regex": "^1.1.1",
"object-inspect": "^1.8.0",
"is-callable": "^1.2.0",
"is-regex": "^1.1.0",
"object-inspect": "^1.7.0",
"object-keys": "^1.1.1",
"object.assign": "^4.1.1",
"string.prototype.trimend": "^1.0.1",
"string.prototype.trimstart": "^1.0.1"
}
},
"es-to-primitive": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz",
"integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==",
"requires": {
"is-callable": "^1.1.4",
"is-date-object": "^1.0.1",
"is-symbol": "^1.0.2"
}
},
"has-symbols": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz",
"integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg=="
},
"is-callable": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.2.tgz",
"integrity": "sha512-dnMqspv5nU3LoewK2N/y7KLtxtakvTuaCsU9FU50/QDmdbHNy/4/JuRtMHqRU22o3q+W89YQndQEeCVwK+3qrA=="
},
"is-regex": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.1.tgz",
"integrity": "sha512-1+QkEcxiLlB7VEyFtyBg94e08OAsvq7FUBgApTq/w2ymCLyKJgDPsybBENVtA7XCQEgEXxKPonG+mvYRxh/LIg==",
"object.assign": "^4.1.0",
"requires": {
"has-symbols": "^1.0.1"
}

+ 1
- 0
package.json View File

@ -8,6 +8,7 @@
"@material-ui/styles": "^4.5.0",
"axios": "^0.18.1",
"clsx": "^1.0.4",
"colorconverter": "^0.1.1",
"react": "^16.10.2",
"react-color": "^2.17.3",
"react-dom": "^16.10.2",

+ 108
- 0
src/components/ManualView/CustomPicker.js View File

@ -0,0 +1,108 @@
import React from 'react';
import { CustomPicker } from 'react-color';
const { Hue, Alpha } = require('react-color/lib/components/common');
const colors= ['#ffffff', '#ff0000','#ff8000','#ffff00','#80ff00','#00ff00','#00ff80','#00ffff',
'#0080ff','#0000ff','#8000ff','#ff00ff','#ff0080']
const inlineStyles = {
container: {
boxShadow: 'rgba(0, 0, 0, 0.2) 0px 3px 1px -2px, rgba(0, 0, 0, 0.14) 0px 2px 2px 0px, rgba(0, 0, 0, 0.12) 0px 1px 5px 0px',
display: 'flex',
flexDirection: 'column',
height: 282,
width: 200,
},
pointer: {
width: '18px',
height: '18px',
borderRadius: '50%',
transform: 'translate(-9px, -1px)',
backgroundColor: 'rgb(248, 248, 248)',
boxShadow: '0 1px 4px 0 rgba(0, 0, 0, 0.37)',
},
slider: {
marginTop: '1px',
width: '4px',
borderRadius: '1px',
height: '20px',
boxShadow: '0 0 2px rgba(0, 0, 0, .6)',
background: '#fff',
transform: 'translateX(-2px)'
},
saturation: {
width: '100%',
paddingBottom: '75%',
position: 'relative',
overflow: 'hidden',
},
swatchSquare: {
minWidth: 20,
minHeight: 20,
margin: '1px 2px',
cursor: 'pointer',
boxShadow: '0 0 2px rgba(0, 0, 0, .6)',
},
preview: {
minHeight: 50,
minWidth: 100
}
}
const CustomSlider = () => {
return (
<div style={ inlineStyles.slider } />
)
}
class CustomColorPicker extends React.Component {
displayColorSwatches = colors => {
return colors.map(color => {
return (
<div
onClick={() => this.props.onChange(color)}
key={color}
style={{ ...inlineStyles.swatchSquare, backgroundColor: color, }}
/>
);
})
}
render() {
return (
<div style={inlineStyles.container}>
<div style={{ backgroundColor: this.props.colorHex, minHeight: 50 }}></div>
<div style={{ minHeight: 20, position: 'relative', margin: 2 }}>
<Hue
hsl={this.props.colorHsl}
pointer={CustomSlider}
onChange={(color) => this.props.onChange(color)}
direction={'horizontal'}
/>
</div>
<div style={{ position: 'relative', minHeight:20}}>
<Alpha
hsl={this.props.colorHsl}
rgb={this.props.colorRgb}
pointer={CustomSlider}
onChange={(color) => this.props.onChange(color)}
/>
</div>
<div style={{ display: 'flex', width: '100%', flexWrap: 'wrap', padding: 3 }}>
{this.displayColorSwatches(colors)
}
</div>
</div>
);
}
}
export default CustomPicker(CustomColorPicker);

+ 122
- 50
src/components/ManualView/lampList.js View File

@ -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 ""
}

+ 25
- 14
src/components/ManualView/rgbLamp.js View File

@ -1,6 +1,6 @@
import React from 'react'
import Popover from '@material-ui/core/Popover';
import { ChromePicker, SwatchesPicker } from 'react-color';
import { SketchPicker } from 'react-color';
import { Grid } from '@material-ui/core';
import Card from '@material-ui/core/Card';
@ -8,9 +8,8 @@ import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button'
// var { Hue } = require('react-color/lib/components/common');
import api from '../../static'
import CustomPicker from './CustomPicker'
class RGBLamp extends React.Component {
@ -34,35 +33,47 @@ class RGBLamp extends React.Component {
});
};
onDelete = (lampID) => {
console.log(lampID)
api.deleteLamp(lampID)
.then(res => {
this.setState()
})
.catch(err => {
console.log(err)
})
}
colorPicker() {
if (this.props.colorMode) {
return (
<ChromePicker
<SketchPicker
disableAlpha={false}
color={this.props.lamp.color}
disableAlpha={true}
onChange={(color) => { this.props.onChange(this.props.lamp.id, color) }}
/>
)
} else {
return (
<SwatchesPicker
width="100%"
height="50%"
color={this.props.lamp.color}
<CustomPicker
colorHex={this.props.lamp.color.hex}
colorHsl={this.props.lamp.color.hsl}
colorRgb={this.props.lamp.color.rgb}
onChange={(color) => { this.props.onChange(this.props.lamp.id, color) }}
/>
)
}
}
adminModeActions() {
adminModeActions(lampID) {
if (this.props.adminMode) {
return (
<CardActions>
<Button color="primary">Edit</Button>
<Button color="primary">Delete</Button>
<Button color="primary" onClick={() => {this.onEdit(lampID)}} >Edit</Button>
<Button color="primary" onClick={() => {this.onDelete(lampID)}} >Delete</Button>
</CardActions>
)
}
@ -83,7 +94,7 @@ class RGBLamp extends React.Component {
{this.props.lamp.description}
</Typography>
</CardContent>
{this.adminModeActions()}
{this.adminModeActions(this.props.lamp.id)}
</Card>
<Popover

src/components/Manual.js → src/components/Manual_Backup.js View File


src/components/Presets.js → src/components/Presets_Backup.js View File


src/components/Unit.js → src/components/Unit_Backup.js View File


+ 33
- 2
src/containers/ManualTab.js View File

@ -12,19 +12,50 @@ const mapStateToProps = state => {
}
function hslToHex(h, s, l, a) {
h /= 360;
let r, g, b;
if (s === 0) {
r = g = b = l; // achromatic
} else {
const hue2rgb = (p, q, t) => {
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1 / 6) return p + (q - p) * 6 * t;
if (t < 1 / 2) return q;
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
return p;
};
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q;
r = hue2rgb(p, q, h + 1 / 3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1 / 3);
}
const toHex = x => {
const hex = Math.round(x * 255 * a).toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
}
const mapDispatchToProps = dispatch => {
return {
onChangeColor: (id, color) => {
api.setLampColor(id, color.rgb)
.then(()=>{
dispatch(setColor(color.rgb, id))
color.hex = hslToHex(color.hsl.h,color.hsl.s,color.hsl.l,color.hsl.a)
dispatch(setColor(color, id))
})
.catch(err=>{
console.log(err)
})
},
onChangeColorMode: (colorMode) => {
console.log(colorMode.target.checked)
dispatch(toggleColorMode(colorMode.target.checked))
}
}

+ 1
- 1
src/redux/actions.js View File

@ -22,7 +22,7 @@ export function addPreset(preset) {
}
export function addRGBLamp(lamp) {
return { type: ADD_LAMP, lamp, color: {r: 0,g: 0,b: 0} }
return { type: ADD_LAMP, lamp, color: {rgb: {r: 255,g: 0,b: 0,a: 1}, hex: '#ff0000', hsl: {h: 0, s: 1, l: 0.5}, hsv: {h: 0, s: 0, v: 0} }}
}
export function addNormalLamp(lamp) {

+ 10
- 3
src/static.js View File

@ -16,12 +16,19 @@ class API {
return axios.get(this.url+'/getLamps')
}
deleteLamp(id){
return axios.post(this.url+'/deleteLamp', {id: id})
}
createLamp(light){
return axios.post(this.url+'/createLamp', {light: light})
}
setByPreset(id){
return axios.post(this.url+'/setByPreset', {id: id})
}
setLampColor(id, color){
console.log(color)
return axios.post(this.url+'/setLamp', {id: id, color: color})
}
@ -29,9 +36,9 @@ class API {
let boards = axios.get(this.url+'/getBoards')
let types = axios.get(this.url + '/getTypes')
Promise.all([boards, types])
return Promise.all([boards, types])
.then(values => {
return {boards: boards, types: types}
return {boards: values[0].data, types: values[1].data}
})
}

Loading…
Cancel
Save