diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a033693..66f9d91 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,7 @@ image: node:latest stages: - build - test + - deploy cache: paths: @@ -19,6 +20,25 @@ install_dependencies: testing_testing: stage: test - script: + script: - cd smart-hut - - yarn test \ No newline at end of file + - yarn test + +smartHut_deploy: + stage: deploy + tags: + - dind + image: docker:latest + services: + - docker:dind + variables: + DOCKER_DRIVER: overlay + before_script: + - docker version + - docker info + - docker login -u smarthutsm -p $CI_DOCKER_PASS #GiovanniRoberto + script: + - "docker build -t smarthutsm/smarthut:${CI_COMMIT_BRANCH} ." + - "docker push smarthutsm/smarthut:${CI_COMMIT_BRANCH}" + after_script: + - docker logout diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..18cd721 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +#FROM mhart/alpine-node:11 AS pleaseGodWork +#WORKDIR /app +#COPY . /app +#RUN ls +#RUN yarn run build +# +#RUN yarn global add serve +# +# +#CMD ["serve", "-p", "8080", "-s", "."] + +# base image +FROM node:9.6.1 +RUN mkdir /usr/src/app +WORKDIR /usr/src/app +ENV PATH /usr/src/app/node_modules/.bin:$PATH + + +COPY smart-hut/package.json /usr/src/app/package.json +RUN npm install --silent +RUN npm install react-scripts@1.1.1 -g --silent + + +CMD ["npm", "start"] + +FROM node:9.6.1 as builder +RUN mkdir /usr/src/app +WORKDIR /usr/src/app +ENV PATH /usr/src/app/node_modules/.bin:$PATH +COPY smart-hut/package.json /usr/src/app/package.json +RUN npm install --silent +RUN npm install react-scripts@1.1.1 -g --silent +COPY smart-hut/. /usr/src/app +RUN npm run build + +FROM nginx:1.13.9-alpine +COPY --from=builder /usr/src/app/build /usr/share/nginx/html +EXPOSE 8080 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/smart-hut/public/avatar.png b/smart-hut/public/avatar.png new file mode 100644 index 0000000..86ce723 Binary files /dev/null and b/smart-hut/public/avatar.png differ diff --git a/smart-hut/public/avatar2.png b/smart-hut/public/avatar2.png new file mode 100644 index 0000000..97ac118 Binary files /dev/null and b/smart-hut/public/avatar2.png differ diff --git a/smart-hut/public/img/dimmer.svg b/smart-hut/public/img/dimmer.svg new file mode 100644 index 0000000..587066c --- /dev/null +++ b/smart-hut/public/img/dimmer.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/smart-hut/public/img/humidity-sensor.svg b/smart-hut/public/img/humidity-sensor.svg new file mode 100644 index 0000000..3f2aee8 --- /dev/null +++ b/smart-hut/public/img/humidity-sensor.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/smart-hut/public/img/intensity-light.svg b/smart-hut/public/img/intensity-light.svg new file mode 100644 index 0000000..8a726f9 --- /dev/null +++ b/smart-hut/public/img/intensity-light.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/smart-hut/public/img/light-sensor.svg b/smart-hut/public/img/light-sensor.svg new file mode 100644 index 0000000..7c01850 --- /dev/null +++ b/smart-hut/public/img/light-sensor.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/smart-hut/public/img/room_404_meme/1.jpeg b/smart-hut/public/img/room_404_meme/1.jpeg new file mode 100644 index 0000000..b039f37 Binary files /dev/null and b/smart-hut/public/img/room_404_meme/1.jpeg differ diff --git a/smart-hut/public/img/room_404_meme/10.jpg b/smart-hut/public/img/room_404_meme/10.jpg new file mode 100644 index 0000000..d1b2abd Binary files /dev/null and b/smart-hut/public/img/room_404_meme/10.jpg differ diff --git a/smart-hut/public/img/room_404_meme/11.jpeg b/smart-hut/public/img/room_404_meme/11.jpeg new file mode 100644 index 0000000..0675dac Binary files /dev/null and b/smart-hut/public/img/room_404_meme/11.jpeg differ diff --git a/smart-hut/public/img/room_404_meme/12.gif b/smart-hut/public/img/room_404_meme/12.gif new file mode 100644 index 0000000..575dbac Binary files /dev/null and b/smart-hut/public/img/room_404_meme/12.gif differ diff --git a/smart-hut/public/img/room_404_meme/13.gif b/smart-hut/public/img/room_404_meme/13.gif new file mode 100644 index 0000000..94b389c Binary files /dev/null and b/smart-hut/public/img/room_404_meme/13.gif differ diff --git a/smart-hut/public/img/room_404_meme/14.gif b/smart-hut/public/img/room_404_meme/14.gif new file mode 100644 index 0000000..575599e Binary files /dev/null and b/smart-hut/public/img/room_404_meme/14.gif differ diff --git a/smart-hut/public/img/room_404_meme/2.jpeg b/smart-hut/public/img/room_404_meme/2.jpeg new file mode 100644 index 0000000..eb71f0b Binary files /dev/null and b/smart-hut/public/img/room_404_meme/2.jpeg differ diff --git a/smart-hut/public/img/room_404_meme/3.png b/smart-hut/public/img/room_404_meme/3.png new file mode 100644 index 0000000..8c2b210 Binary files /dev/null and b/smart-hut/public/img/room_404_meme/3.png differ diff --git a/smart-hut/public/img/room_404_meme/4.jpeg b/smart-hut/public/img/room_404_meme/4.jpeg new file mode 100644 index 0000000..413c5f3 Binary files /dev/null and b/smart-hut/public/img/room_404_meme/4.jpeg differ diff --git a/smart-hut/public/img/room_404_meme/5.jpeg b/smart-hut/public/img/room_404_meme/5.jpeg new file mode 100644 index 0000000..294fcb4 Binary files /dev/null and b/smart-hut/public/img/room_404_meme/5.jpeg differ diff --git a/smart-hut/public/img/room_404_meme/6.jpg b/smart-hut/public/img/room_404_meme/6.jpg new file mode 100644 index 0000000..e830719 Binary files /dev/null and b/smart-hut/public/img/room_404_meme/6.jpg differ diff --git a/smart-hut/public/img/room_404_meme/7.jpg b/smart-hut/public/img/room_404_meme/7.jpg new file mode 100644 index 0000000..358bec2 Binary files /dev/null and b/smart-hut/public/img/room_404_meme/7.jpg differ diff --git a/smart-hut/public/img/room_404_meme/8.jpg b/smart-hut/public/img/room_404_meme/8.jpg new file mode 100644 index 0000000..0f63a46 Binary files /dev/null and b/smart-hut/public/img/room_404_meme/8.jpg differ diff --git a/smart-hut/public/img/room_404_meme/9.jpeg b/smart-hut/public/img/room_404_meme/9.jpeg new file mode 100644 index 0000000..db5935a Binary files /dev/null and b/smart-hut/public/img/room_404_meme/9.jpeg differ diff --git a/smart-hut/public/img/sensorOff.svg b/smart-hut/public/img/sensorOff.svg new file mode 100644 index 0000000..dbea9ab --- /dev/null +++ b/smart-hut/public/img/sensorOff.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/smart-hut/public/img/sensorOn.svg b/smart-hut/public/img/sensorOn.svg new file mode 100644 index 0000000..2dacf1c --- /dev/null +++ b/smart-hut/public/img/sensorOn.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/smart-hut/public/img/switchOff.svg b/smart-hut/public/img/switchOff.svg new file mode 100644 index 0000000..5978110 --- /dev/null +++ b/smart-hut/public/img/switchOff.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/smart-hut/public/img/switchOn.svg b/smart-hut/public/img/switchOn.svg new file mode 100644 index 0000000..9046281 --- /dev/null +++ b/smart-hut/public/img/switchOn.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/smart-hut/public/img/temperature-sensor.svg b/smart-hut/public/img/temperature-sensor.svg new file mode 100644 index 0000000..678696b --- /dev/null +++ b/smart-hut/public/img/temperature-sensor.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/smart-hut/public/smart-home.png b/smart-hut/public/smart-home.png new file mode 100644 index 0000000..d2681ce Binary files /dev/null and b/smart-hut/public/smart-home.png differ diff --git a/smart-hut/public/title.png b/smart-hut/public/title.png new file mode 100644 index 0000000..0e288cf Binary files /dev/null and b/smart-hut/public/title.png differ diff --git a/smart-hut/public/title3.png b/smart-hut/public/title3.png new file mode 100644 index 0000000..635a665 Binary files /dev/null and b/smart-hut/public/title3.png differ diff --git a/smart-hut/public/title4.png b/smart-hut/public/title4.png new file mode 100644 index 0000000..8a39bf1 Binary files /dev/null and b/smart-hut/public/title4.png differ diff --git a/smart-hut/public/user-icon.png b/smart-hut/public/user-icon.png new file mode 100644 index 0000000..7c2a03c Binary files /dev/null and b/smart-hut/public/user-icon.png differ diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index 5be1c89..f27fe21 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -26,7 +26,7 @@ class App extends Component { super(props); let loggedIn = false; - + try { let userJsonString = localStorage.getItem("token"); if (userJsonString) { @@ -45,20 +45,25 @@ class App extends Component { } componentDidMount() { - if (this.props.location) { - const values = queryString.parse(this.props.location.search); + if (window.location) { + const values = queryString.parse(window.location.search); + console.log(values); this.setState({ query : values }); + } else { + this.setState({ + query : "ciao" + }); } } auth(data) { return call.login(data.params) .then(res => { - console.log(res); if (res.data && res.status === 200) { localStorage.setItem("token", res.data.jwttoken); + call.setToken(res.data.jwttoken); this.setState( { user: data.params.user, @@ -86,7 +91,6 @@ class App extends Component { }); localStorage.removeItem("token"); - this.props.history.push("/"); }; render() { @@ -95,11 +99,11 @@ class App extends Component { - { this.state.loggedIn && this.state.token ? : } + { this.state.loggedIn && this.state.token ? : } - {this.state.loggedIn ? : } + {this.state.loggedIn ? : } @@ -113,7 +117,8 @@ class App extends Component { - + + diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js index 18c2ae4..6df5b30 100644 --- a/smart-hut/src/client_server.js +++ b/smart-hut/src/client_server.js @@ -1,7 +1,7 @@ import axios from 'axios'; let config = 'http://localhost:8080/'; -const tkn = localStorage.getItem("token"); +var tkn = localStorage.getItem("token"); // requests data devices /* @@ -12,115 +12,75 @@ const tkn = localStorage.getItem("token"); id: se serve } + + device routes: + - buttonDimmer + - dimmableLight + - knobDimmer + - motionSensor + - regularLight + - sensor + - smartPlug + - switch + */ export var call = { + setToken: function(token) { + tkn = token; + }, login: function(data, headers) { return axios.post(config +'auth/login', data) - .then(res => { - return res; - }).catch(err => { - return {status : "Errore"}; - }); }, register: function(data, headers) { return axios.post(config + 'register', data) - .then(res => { - return res; - }).catch(err => { - //console.error(err); - return {status : "Errore"}; - }); }, initResetPassword: function(data, headers) { return axios.post(config + 'register/init-reset-password', data) - .then(res => { - return res; - }).catch(err => { - return {status : "Errore"}; - }); }, resetPassword: function(data, headers) { return axios.put(config + 'register/reset-password', data) - .then(res => { - return res; - }).catch(err => { - return {status : "Errore"}; - }); }, getAllRooms: function(token) { if (!token){ token = tkn; } return axios.get(config + 'room', { headers: { Authorization : "Bearer " + token } }) - .then(res => { - return res; - }).catch(err => { - return err; - }); + }, + getAllDevices: function(token) { + if (!token){ + token = tkn; + } + return axios.get(config + 'device', { headers: { Authorization : "Bearer " + token } }); + }, + getAllDevicesByRoom: function(id, token) { + if (!token){ + token = tkn; + } + return axios.get(config + 'room/' + id + '/devices' , { headers: { Authorization : "Bearer " + token } }); }, createRoom: function(data, headers) { return axios.post(config + 'room', data, { headers: { Authorization : "Bearer " + tkn } }) - .then(res => { - return res; - }).catch(err => { - return err; - }); }, updateRoom: function(data, headers) { return axios.put(config + 'room/'+data.id) - .then(res => { - return res; - }).catch(err => { - return err; - }); }, deleteRoom: function(data, headers) { - return axios.delete(config + 'room/'+data.id) - .then(res => { - return res; - }).catch(err => { - return err; - }); + return axios.delete(config + 'room/'+data.id, { headers: { Authorization : "Bearer " + tkn } }); }, devicePost: function(data, headers) { - return axios.post(config + data.device, data.params) - .then(res => { - return res; - }).catch(err => { - return err; - }); + return axios.post(config + data.device, data.params, { headers: { Authorization : "Bearer " + tkn } }) }, deviceUpdate: function(data, headers) { - return axios.put(config + data.device, data.params) - .then(res => { - return res; - }).catch(err => { - return err; - }); + return axios.put(config + 'device', data, { headers: { Authorization : "Bearer " + tkn } }) }, deviceDelete: function(data, headers) { - return axios.delete(config + data.device + '/' + data.id, data.params) - .then(res => { - return res; - }).catch(err => { - return err; - }); + return axios.delete(config + data.device + '/' + data.id, {}, { headers: { Authorization : "Bearer " + tkn } }) }, deviceGetById: function(data, headers) { return axios.get(config + data.device + '/' + data.id) - .then(res => { - return res; - }).catch(err => { - return err; - }); }, deviceGetAll: function(data, headers) { return axios.get(config + data.device) - .then(res => { - return res; - }).catch(err => { - return err; - }); } }; diff --git a/smart-hut/src/components/HeaderController.js b/smart-hut/src/components/HeaderController.js index e5d8d08..8ec24a5 100644 --- a/smart-hut/src/components/HeaderController.js +++ b/smart-hut/src/components/HeaderController.js @@ -1,6 +1,5 @@ -import React, { Component } from "react"; -import { render } from "react-dom"; -import { Button, Menu, Header, Dropdown, Icon, Grid, Divider} from 'semantic-ui-react' +import React from "react"; +import { Dropdown, Icon, Grid, Divider} from 'semantic-ui-react' import { Segment, Image } from 'semantic-ui-react' const ImageExampleWrapped = () => ( @@ -23,13 +22,9 @@ const ImageExampleWrapped3 = () => ( ) -const HeaderExampleIconProp = () => ( -
-) - -const GridExampleInverted = () => ( +const GridExampleInverted = (props) => ( @@ -57,7 +52,7 @@ const GridExampleInverted = () => ( See profile... - Logout + Logout @@ -69,7 +64,7 @@ export default class MyHeader extends React.Component { render() { return (
- +
); } diff --git a/smart-hut/src/components/HomeNavbar.js b/smart-hut/src/components/HomeNavbar.js index 5bcafb5..651e1a0 100644 --- a/smart-hut/src/components/HomeNavbar.js +++ b/smart-hut/src/components/HomeNavbar.js @@ -1,6 +1,5 @@ import _ from "lodash"; import React, { Component } from "react"; -import { render } from "react-dom"; import { Container, Icon, diff --git a/smart-hut/src/components/SelectIcons.js b/smart-hut/src/components/SelectIcons.js index e9d23f6..f1a7994 100644 --- a/smart-hut/src/components/SelectIcons.js +++ b/smart-hut/src/components/SelectIcons.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { Button, Header, Image, Modal, Checkbox, Form, Grid, Input, Icon } from 'semantic-ui-react' +import { Button, Grid } from 'semantic-ui-react' export default class SelectIcons extends Component { @@ -29,7 +29,6 @@ export default class SelectIcons extends Component { ['trophy', 'wrench', 'image', 'book', 'university', 'medkit'], ['paw', 'tree', 'utensils', 'male', 'female', 'life ring outline']]; - var colums = 0; return ( { diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js index 52c877e..52466d6 100644 --- a/smart-hut/src/components/dashboard/DevicePanel.js +++ b/smart-hut/src/components/dashboard/DevicePanel.js @@ -2,71 +2,37 @@ import React, {Component} from 'react'; import { Grid, } from "semantic-ui-react"; -import Device from "./devices/Device"; -import NewDevice from "./devices/NewDevice"; -import {LightDevice, SmartPlugDevice} from "./devices/TypesOfDevices"; import {editButtonStyle, panelStyle} from "./devices/styleComponents"; import {checkMaxLength, DEVICE_NAME_MAX_LENGTH} from "./devices/constants"; -import Light from "./devices/Light"; -import SmartPlug from "./devices/SmartPlug"; -import Sensor from "./devices/Sensor"; +import DeviceType from './devices/DeviceTypeController'; +import NewDevice from "./devices/NewDevice"; +import SettingsModal from "./devices/SettingsModal"; +import { call } from '../../client_server'; - -const devices = [ - { - "id" : 1, - "name": "Bedroom Light", - "type" : "light", - "hasIntensity" : true, - "intensityLevel" : 0.20, - ...LightDevice - }, - { - "id" : 2, - "name": "Bathroom Light", - "type" : "light", - ...LightDevice - }, - { - "id" : 3, - "name": "Desktop Light", - "type" : "light", - ...LightDevice - }, - { - "id" : 4, - "name": "Entrance Light", - "type" : "light", - ...LightDevice - }, - { - "id" : 5, - "name": "Smart Plug", - "type" : "smartplug", - ...SmartPlugDevice - }, - { - "id" : 6, - "name": "Bedroom Thermometer", - "type" : "temperature-sensor", - }, -]; - -class Panel extends Component { +export default class DevicePanel extends Component { constructor(props) { super(props); this.state = { editMode : false, - devices : devices, }; + + this.addDevice = this.addDevice.bind(this); } editModeController = (e) => this.setState((prevState) => ({ editMode: !prevState.editMode })); + openModal = (settingsDeviceId) => { + this.setState(prevState => ({ + openSettingsModal: !prevState.openSettingsModal, + settingsDeviceId: settingsDeviceId + })) + } + changeDeviceData = (deviceId, newSettings) => { + console.log(newSettings.name, " <-- new name --> ", deviceId ); - this.state.devices.map(device => { + this.props.devices.map(device => { if(device.id === deviceId){ for(let prop in newSettings){ if(device.hasOwnProperty(prop)){ @@ -85,50 +51,124 @@ class Panel extends Component { } } return null; - }); + }); this.forceUpdate(); }; + getDevices() { + if (this.props.activeItem === -1) { + call.getAllDevices() + .then(res => { + if ( res.status === 200) { + this.setState({ + devices: res.data + }); + } + }).catch(err => { + console.log(err); + }); + } else { + call.getAllDevicesByRoom(this.state.settingsDeviceId) + .then(res => { + if (res.status === 200) { + this.setState({ + devices: res.data + }); + } + }).catch(err => { + + }); + } + } + + async addDevice(data) { + const ds = await this.props.addDevice(data); + this.setState({ + devices: ds + }); + this.forceUpdate(); + } + + updateDevice = (data) => { + const roomId = this.props.devices.filter(d => d.id === this.state.settingsDeviceId)[0].roomId; + console.log(roomId) + data["id"] = this.state.settingsDeviceId; + data["roomId"] = roomId; + call.deviceUpdate(data) + .then(res => { + if (res.status === 200) { + this.getDevices(); + } + }).catch(err => { + + }) + } + + removeDevice = () => { + const item = this.props.devices.filter(d => d.id === this.state.settingsDeviceId)[0]; + console.log(item) + const data = { + device: item.kind, + id: this.state.settingsDeviceId + }; + + call.deviceDelete(data) + .then(res => { + console.log(res) + if (res.status === 200) { + this.getDevices(); + } + }).catch(err => { + + }); + } + + + + + render() { + const edit = { + mode: this.state.editMode, + openModal: this.openModal, + }; + const ds = this.state.devices ? this.state.devices : this.props.devices; return (
- - - - - - - - - - - - - + + {this.state.openSettingsModal ? + d.id === this.state.settingsDeviceId)[0]}/> : "" + } + { + ds ? + ds.map((e, i) => { + + return ( + + + + ) + }) + : + null + } + { + this.props.activeItem !== -1 ? + + + + : + null + }
) } -} - - -export default class DevicePanel extends Component { - - constructor(props) { - super(props); - this.state = { - shownRoom: "All" - } - } - - render() { - return ( - - ) - } - -} +} diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js deleted file mode 100644 index d1fb1f0..0000000 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ /dev/null @@ -1,48 +0,0 @@ -import React, {Component} from 'react'; -import {Image} from "semantic-ui-react"; -import {iconStyle, nameStyle, StyledDiv} from "./styleComponents"; -import Settings from './DeviceSettings'; - - -export default class Device extends Component { - constructor(props) { - super(props); - this.state = { - turnOnOff: "off", - icon: this.props.device.img - } - } - - onClickDevice = () => { - if (!this.props.edit) { - if (this.props.device.type === "light") { - if (this.state.turnOnOff === "on") { - this.setState({ - turnOnOff: "off", - icon: this.props.device.img - }); - } else { - this.setState({ - turnOnOff: "on", - icon: this.props.device.imgClick - }); - } - } - } - }; - render() { - return ( - { - } : this.onClickDevice} style={{textAlign: "center"}}> - this.props.onChangeData(id, newSettings)}/> - -
{this.props.device.name}
-
- ) - } -} - - diff --git a/smart-hut/src/components/dashboard/devices/DeviceSettings.js b/smart-hut/src/components/dashboard/devices/DeviceSettings.js index 7fe9884..c8e2fce 100644 --- a/smart-hut/src/components/dashboard/devices/DeviceSettings.js +++ b/smart-hut/src/components/dashboard/devices/DeviceSettings.js @@ -1,73 +1,34 @@ import React, {Component} from "react"; -import {Button, Form} from "semantic-ui-react"; -import {editModeIconStyle, editModeStyle, formStyle} from "./styleComponents"; - -class SettingsForm extends Component { - constructor(props) { - super(props); - this.state = {} - }; - - onChangeHandler = (event) => { - let nam = event.target.name; - let val = event.target.value; - this.setState({[nam]: val}); - }; - - saveChanges = () => { - let newName = this.state["new-name"]; - this.props.onChangeData(this.props.id, {"name": newName}); - }; - - render() { - return ( -
- - - - - -
- ) - } -} +import {editModeIconStyle, editModeStyle} from "./styleComponents"; export default class Settings extends Component { - constructor(props) { - super(props); - this.state = { - displayForm: false, - } - }; + constructor(props) { + super(props); + this.state = { + displayForm: true, + } + }; - displayForm = () => { - this.setState((prevState) => ({displayForm: !prevState.displayForm})); - }; + displayForm = () => { + this.setState((prevState) => ({displayForm: !prevState.displayForm})); + }; - render() { - const view = ( -
- {this.state.displayForm ? ( - ) : ("")} -
- - {!this.state.displayForm ? ( - ) - : -

×

- } -
-
-
- ); - return ( - - {this.props.edit ? view : ("")} - - ) - }; + render() { + const view = ( +
this.props.edit.openModal(this.props.deviceId)}> + + + +
+ ); + return ( + + {this.props.edit.mode ? view : ("")} + + ) + }; } diff --git a/smart-hut/src/components/dashboard/devices/DeviceTypeController.js b/smart-hut/src/components/dashboard/devices/DeviceTypeController.js new file mode 100644 index 0000000..9049fd6 --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/DeviceTypeController.js @@ -0,0 +1,28 @@ +import React from 'react'; +import Light from "./Light"; +import SmartPlug from "./SmartPlug"; +import Sensor from "./Sensor"; +import DefaultDimmer from "./Dimmer"; +import Switcher from "./Switch"; + + +const DeviceType = (props) => { + switch(props.type) { + case "regular-light": + return () + case "sensor": + return + case "dimmer": + return + case "smartplug": + return + case "switch": + return + case "light": + return () + default: + return "" + } +} + +export default DeviceType; diff --git a/smart-hut/src/components/dashboard/devices/DigitalSensor.js b/smart-hut/src/components/dashboard/devices/DigitalSensor.js new file mode 100644 index 0000000..cbc026c --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/DigitalSensor.js @@ -0,0 +1,58 @@ +/** + * Users can add sensors in their rooms. + * Sensors typically measure physical quantities in a room. + * You must support temperature sensors, humidity sensors, light sensors (which measure luminosity1). + * Sensors have an internal state that cannot be changed by the user. + * For this story, make the sensors return a constant value with some small random error. + */ + +import React, {Component} from "react"; +import {CircularInput, CircularProgress, CircularTrack} from "react-circular-input"; +import {errorStyle, sensorText, style, valueStyle} from "./SensorStyle"; +import {StyledDiv} from "./styleComponents"; +import Settings from "./DeviceSettings"; +import {Image} from "semantic-ui-react"; +import {imageStyle, nameStyle} from "./DigitalSensorStyle"; + +export default class DigitalSensor extends Component { + constructor(props) { + super(props); + this.state = { + value: false, // This value is a boolean, was this type of sensor returns presence/absence + }; + + this.iconOn = "/img/sensorOn.svg"; + this.iconOff = "/img/sensorOff.svg" + } + + setName = () => { + if(this.props.device.name.length > 15){ + return this.props.device.name.slice(0,12) + "..." + } + return this.props.device.name; + }; + + getIcon = () => { + if(this.state.value){ + return this.iconOn; + } + return this.iconOff; + }; + + componentDidMount() { + } + + + render() { + return ( + + this.props.onChangeData(id, newSettings)}/> + +
{this.props.device.name}
+
+ ) + } +} diff --git a/smart-hut/src/components/dashboard/devices/DigitalSensorStyle.js b/smart-hut/src/components/dashboard/devices/DigitalSensorStyle.js new file mode 100644 index 0000000..f0fdf12 --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/DigitalSensorStyle.js @@ -0,0 +1,17 @@ +export const imageStyle = { + width: "3.5rem", + height: "auto", + position: "absolute", + top: "20%", + left: "50%", + transform: "translateX(-50%)", + filter: "drop-shadow( 1px 1px 0.5px rgba(0, 0, 0, .25))" +}; + +export const nameStyle = { + color : "black", + position: "absolute", + top: "40%", + left: "50%", + transform: "translateX(-50%)" +}; diff --git a/smart-hut/src/components/dashboard/devices/Dimmer.js b/smart-hut/src/components/dashboard/devices/Dimmer.js index 078fe94..862095a 100644 --- a/smart-hut/src/components/dashboard/devices/Dimmer.js +++ b/smart-hut/src/components/dashboard/devices/Dimmer.js @@ -30,7 +30,7 @@ export class StatefulDimmer extends Component{ } } -export class DefaultDimmer extends Component{ +export default class DefaultDimmer extends Component{ // As far as I am concern, even though this dimmer doesn't have state, internally it's needed constructor(props){ super(props); diff --git a/smart-hut/src/components/dashboard/devices/Light.js b/smart-hut/src/components/dashboard/devices/Light.js index 69a7df8..c307da6 100644 --- a/smart-hut/src/components/dashboard/devices/Light.js +++ b/smart-hut/src/components/dashboard/devices/Light.js @@ -7,86 +7,84 @@ */ import React, {Component} from "react"; -import {iconStyle, StyledDiv, nameStyle} from "./styleComponents"; +import {iconStyle, StyledDiv} from "./styleComponents"; import Settings from "./DeviceSettings"; import {Image} from "semantic-ui-react"; import {CircularInput, CircularProgress, CircularThumb, CircularTrack} from "react-circular-input"; -import {valueStyle, intensityLightStyle, style} from "./LightStyle"; +import {valueStyle, intensityLightStyle, style, nameStyle} from "./LightStyle"; export default class Light extends Component { - constructor(props) { - super(props); - this.state = { - turnedOn: false, - hasIntensity : false - }; - this.iconOn = "/img/lightOn.svg"; - this.iconOff = "/img/lightOff.svg" - } - - onClickDevice = () => { - this.setState((prevState) => ({turnedOn: !prevState.turnedOn})); + constructor(props) { + super(props); + this.state = { + turnedOn: false, }; + this.iconOn = "/img/lightOn.svg"; + this.iconOff = "/img/lightOff.svg" + } - setIntensity = (newValue) => { - this.setState({intensityLevel : newValue}); - }; + onClickDevice = () => { + this.setState((prevState) => ({turnedOn: !prevState.turnedOn})); + }; - getIcon = () => { - if(this.state.turnedOn){ - return this.iconOn; - } - return this.iconOff; - }; - - componentDidMount() { - if(this.props.device.hasOwnProperty("hasIntensity") && this.props.device.hasOwnProperty("intensityLevel")) { - this.setState({ - hasIntensity: this.props.device.hasIntensity, - intensityLevel: this.props.device.intensityLevel - }); - } - // Get the state and update it + setIntensity = (newValue) => { + this.setState({intensity: newValue}); + }; + getIcon = () => { + if (this.state.turnedOn) { + return this.iconOn; } + return this.iconOff; + }; - - render() { - const intensityLightView = ( - - - - - - - {Math.round(this.state.intensityLevel*100)}% - - - {this.props.device.name} - - - ); - - const normalLightView = ( - { - } : this.onClickDevice} style={{textAlign: "center"}}> - this.props.onChangeData(id, newSettings)}/> - -
{this.props.device.name}
-
- ); - - return ( - - {this.state.hasIntensity ? (intensityLightView) : (normalLightView)} - - ) + componentDidMount() { + if (this.props.device.hasOwnProperty("intensity")) { + this.setState({ + intensity: this.props.device.intensity + }); } + // Get the state and update it + + } + + + render() { + const intensityLightView = ( + + + + + + + {Math.round(this.state.intensity * 100)}% + + + {this.props.device.name} + + + ); + + const normalLightView = ( +
{ + } : this.onClickDevice}> + +
{this.props.device.name}
+
+ ); + + return ( + + this.props.onChangeData(id, newSettings)}/> + {this.state.intensity ? (intensityLightView) : (normalLightView)} + + ) + } } diff --git a/smart-hut/src/components/dashboard/devices/LightStyle.js b/smart-hut/src/components/dashboard/devices/LightStyle.js index 046abee..a6e672d 100644 --- a/smart-hut/src/components/dashboard/devices/LightStyle.js +++ b/smart-hut/src/components/dashboard/devices/LightStyle.js @@ -8,7 +8,16 @@ export const valueStyle = { export const intensityLightStyle = { fill: "#3e99ff", - fontSize: "1.5rem", + fontSize: "1.2rem", fontFamily: "Lato", textShadow: "1px 1px 0.5px rgba(0, 0, 0, .2)", }; + +export const nameStyle = { + fontSize : "1rem", + position: "absolute", + top: "50%", + left: "50%", + transform: "translateX(-50%)", + color : "black" +}; diff --git a/smart-hut/src/components/dashboard/devices/NewDevice.js b/smart-hut/src/components/dashboard/devices/NewDevice.js index ddf4e4d..e3ddf2a 100644 --- a/smart-hut/src/components/dashboard/devices/NewDevice.js +++ b/smart-hut/src/components/dashboard/devices/NewDevice.js @@ -1,8 +1,6 @@ import React, {Component} from 'react'; import styled from 'styled-components'; -import {Button, Dropdown, Form, Image} from "semantic-ui-react"; -import {addDeviceFormStyle} from "./styleComponents"; -import {deviceList} from "./TypesOfDevices"; +import {Button, Dropdown, Form, Icon, Image, Input, Modal} from "semantic-ui-react"; const StyledDiv = styled.div` background-color : #ff4050; @@ -19,90 +17,230 @@ const StyledDiv = styled.div` } `; -class NewDeviceForm extends Component { - constructor(props) { - super(props); - } - - formSelector = (option) => { - switch (option) { - case "Light": - return ; - case "Sensor": - return "This is a sensor form"; - default: - return "This is a default text" - } - }; - - render() { - let options = []; - deviceList.forEach((e, i) => { - options.push({key: i, text: e, value: e}) - }); - - return ( -
- - - - - - -
- ); - } -} - - -class LightForm extends Component { - constructor(props) { - super(props); - this.state = {} - } - - render() { - let options = [ - { - key: 1, - value: "common", - text: "Normal Light" - }, - { - key: 1, - value: "intensity", - text: "Supports intensity level" - } - ] - return ( - - - - - ); - }; -}; - export default class NewDevice extends Component { - constructor(props) { - super(props); - this.state = { - openForm: false - } - } - - onClickDevice = (event) => { - this.setState((prevState) => ({openForm: !prevState.openForm})); + constructor(props) { + super(props); + this.state = { + step: 1, + openModal : false }; + this.baseState = this.state + this.createDevice = this.createDevice.bind(this); + } + + handleOpen = () => {this.setState({openModal : true})}; + handleClose = () => {this.setState({openModal : false})}; + + + resetState = () => { + this.setState(this.baseState); + this.handleClose(); + }; + + nextStep = () => { + this.setState((prevState) => ({step: prevState.step + 1})); + }; + previousStep = () => { + this.setState((prevState) => ({step: prevState.step - 1})); + }; + + setTypeOfDevice = (e, d) => { + if (d.value === "dimmableLight"){ + this.setState({typeOfDevice: d.value, + intensity: 0,}); + } else { + this.setState({typeOfDevice: d.value,}); + } + }; + + setDeviceName = (e, d) => { + this.setState({deviceName: d.value}); + }; + + setTypeOfSensor = (e, d) => { + this.setState({typeOfSensor: d.value}); + }; + + setLightsDimmerSwitch = (e, d) => { + this.setState({lightsAttached : d.value}); + }; + + createDevice() { + // Connect to the backend and create device here. + const data = { + params: { + "name": this.state.deviceName, + }, + device: this.state.typeOfDevice - render() { - return ( - - - {this.state.openForm ? ( - - ) : ""} - - ) } + + switch(this.state.typeOfDevice) { + case "dimmableLight": + data.params["intensity"] = 1; + break; + default: + break; + } + this.props.addDevice(data); + this.resetState(); + }; + + + render() { + const deviceOptions = [ + { + key: 'light', + text: 'Normal Light', + value: 'regularLight', + image: {avatar: true, src: '/img/lightOn.svg'}, + }, + { + key: 'intensity-light', + text: 'Intensity Light', + value: 'dimmableLight', + image: {avatar: true, src: '/img/intensity-light.svg'}, + }, + { + key: 'smart-plug', + text: 'Smart Plug', + value: 'smartPlug', + image: {avatar: true, src: '/img/smart-plug.svg'}, + }, + { + key: 'sensor', + text: 'Sensor', + value: 'sensor', + image: {avatar: true, src: '/img/sensorOn.svg'}, + }, + { + key: 'switch', + text: 'Switch', + value: 'switch', + image: {avatar: true, src: '/img/switchOn.svg'}, + }, + { + key: 'dimmer', + text: 'Dimmer', + value: 'dimmer', + image: {avatar: true, src: '/img/dimmer.svg'}, + }, + ]; + const sensorOptions = [ + { + key: "temperature", + text: "Temperature Sensor", + value: "TEMPERATURE", + image: {avatar: true, src: '/img/temperature-sensor.svg'}, + }, + { + key: "humidity", + text: "Humidity Sensor", + value: "HUMIDITY", + image: {avatar: true, src: '/img/humidity-sensor.svg'}, + }, + { + key: "light", + text: "Light Sensor", + value: "LIGHT", + image: {avatar: true, src: '/img/light-sensor.svg'}, + }, + { + key: "motion", + text: "Motion Sensor", + value: "motionSensor", + image: {avatar: true, src: '/img/sensorOn.svg'}, + } + ]; + const availableLights = []; + this.props.devices.forEach(d => { + availableLights.push( + { + key: d.id, + text: d.name, + value: d.id, + } + ) + }); + const step1 = ( + + ); + const step2 = (typeOfDevice) => { + const deviceName = (
+ + + + +
); + const sensorForm = ( + + + ); + const switchDimmerOptions = ( + + + ); + return ( +
+ {deviceName} + {this.state.typeOfDevice === "sensor" ? (sensorForm) : ""} + {this.state.typeOfDevice === "switch" || this.state.typeOfDevice === "dimmer" ? + (switchDimmerOptions) : "" + } +
+ ) + }; + const steps = [step1, step2()]; + return ( + + + } centered={true}> + Add a New Device + + {steps[this.state.step -1]} + + + {this.state.step > 1 ? ( + + ) : ""} + {this.state.step < steps.length ? ( + + ) : ""} + {this.state.step === steps.length ? ( + + ) : ""} + + + ) + } } diff --git a/smart-hut/src/components/dashboard/devices/Sensor.js b/smart-hut/src/components/dashboard/devices/Sensor.js index 5aaa7e5..23cbc51 100644 --- a/smart-hut/src/components/dashboard/devices/Sensor.js +++ b/smart-hut/src/components/dashboard/devices/Sensor.js @@ -9,48 +9,56 @@ import React, {Component} from "react"; import {CircularInput, CircularProgress, CircularTrack} from "react-circular-input"; import {errorStyle, sensorText, style, valueStyle} from "./SensorStyle"; +import Settings from "./DeviceSettings"; +import {StyledDiv} from "./styleComponents"; -export default class Light extends Component { - constructor(props) { - super(props); - this.state = { - turnedOn: false, - value: 20, - error : 2.4 - }; - this.units = "ºC" - } - - setName = () => { - if(this.props.device.name.length > 15){ - return this.props.device.name.slice(0,12) + "..." - } - return this.props.device.name; +export default class Sensor extends Component { + constructor(props) { + super(props); + this.state = { + turnedOn: false, + value: 20, + error: 2.4 }; + this.units = "ºC" + } - componentDidMount() { + setName = () => { + if (this.props.device.name.length > 15) { + return this.props.device.name.slice(0, 12) + "..." } + return this.props.device.name; + }; + + componentDidMount() { + } - render() { - return ( - - - + render() { + return ( + + this.props.onChangeData(id, newSettings)}/> - - {Math.round(this.state.value)}{this.units} - - - ±{this.state.error} - - - {this.setName()} - - - ) - } + + + + + {Math.round(this.state.value)}{this.units} + + + ±{this.state.error} + + + {this.setName()} + + + + ) + } } diff --git a/smart-hut/src/components/dashboard/devices/SettingsModal.js b/smart-hut/src/components/dashboard/devices/SettingsModal.js new file mode 100644 index 0000000..3166cc2 --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/SettingsModal.js @@ -0,0 +1,90 @@ +import React, {Component, useState} from 'react'; +import {Button, Checkbox, Form, Icon, Header, Modal} from "semantic-ui-react"; + +const DeleteModal = (props) => ( + Remove} closeIcon> +
+ + + + + +) + +const SettingsForm = (props) => { + + const handleInputChange = e => { + const {name, value} = e.target; + setValues({...values, [name]: value}) + }; + + const handleCheckboxChange = (e,d) => { + const {name, checked} = d; + setValues({...values, [name]: checked}) + }; + + const [values, setValues] = useState({name: ''}); + + return ( +
+ + + + + + {props.type === "smart-plug" ? ( + + + + ) : ""} + + props.removeDevice(values)} /> + + +
+ ) +} + +export default class SettingsModal extends Component { + + constructor(props) { + super(props); + this.state = { + open: true, + }; + } + + handleClose = () => { + this.setState({open: false}); + }; + + saveSettings = (device) => { + // TODO Here there should be all the connections to save the data in the backend + console.log("SAVED: ", device); + if (device.name.length > 0) { + this.props.updateDevice(device); + } + + this.props.openModal(); + }; + + + render() { + const SettingsModal = () => ( + + Settings of {this.props.device.name} + + + + + ); + return ( + + ) + } + +} diff --git a/smart-hut/src/components/dashboard/devices/SmartPlug.js b/smart-hut/src/components/dashboard/devices/SmartPlug.js index cd175c1..0c07ba4 100644 --- a/smart-hut/src/components/dashboard/devices/SmartPlug.js +++ b/smart-hut/src/components/dashboard/devices/SmartPlug.js @@ -1,18 +1,14 @@ /** - A smart plug is a plug that has a boolean internal state, i.e., that can be turned on or off, either with the SmartHut interface or by a switch. - The smart plug also stores the total energy consumed while the plug is active, in terms of kilowatt-hours - 2 - (kWh) . The user can reset this value. - + The smart plug also stores the total energy consumed while the plug is active, in terms of kilowatt-hours 2(kWh) . + The user can reset this value. **/ - import React, {Component} from 'react'; -import {iconStyle, nameStyle, StyledDiv} from "./styleComponents"; +import {StyledDiv} from "./styleComponents"; import Settings from "./DeviceSettings"; import {Image} from "semantic-ui-react"; -import {energyConsumedStyle, imageStyle} from "./SmartPlugStyle"; +import {energyConsumedStyle, imageStyle, nameStyle} from "./SmartPlugStyle"; export default class SmartPlug extends Component { constructor(props){ @@ -36,17 +32,12 @@ export default class SmartPlug extends Component { return this.iconOff; }; - resetEnergyConsumedValue = () => { - // In the settings form there must be an option to restore this value - // along with the rename feature. - } - componentDidMount() { } render(){ return ( - {} : this.onClickDevice} style={{textAlign: "center"}}> + {} : this.onClickDevice}> { + this.setState((prevState) => ({turnedOn: !prevState.turnedOn})); + }; + + getIcon = () => { + if(this.state.turnedOn){ + return this.iconOn; + } + return this.iconOff; + }; + + componentDidMount() { + + } + + render(){ + return ( + {} : this.onClickDevice}> + this.props.onChangeData(id, newSettings)}/> + +
{this.props.device.name}
+
+ ) + } +} diff --git a/smart-hut/src/components/dashboard/devices/SwitchStyle.js b/smart-hut/src/components/dashboard/devices/SwitchStyle.js new file mode 100644 index 0000000..98e75c2 --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/SwitchStyle.js @@ -0,0 +1,17 @@ +export const imageStyle = { + width: "4.5rem", + height: "auto", + position: "absolute", + top: "15%", + left: "50%", + transform: "translateX(-50%)", + filter: "drop-shadow( 1px 1px 0.5px rgba(0, 0, 0, .25))" +}; + +export const nameStyle = { + color : "black", + position: "absolute", + top: "45%", + left: "50%", + transform: "translateX(-50%)" +}; diff --git a/smart-hut/src/components/dashboard/devices/Switcher.js b/smart-hut/src/components/dashboard/devices/Switcher.js deleted file mode 100644 index e69de29..0000000 diff --git a/smart-hut/src/components/dashboard/devices/styleComponents.js b/smart-hut/src/components/dashboard/devices/styleComponents.js index 01c4083..7ac67c2 100644 --- a/smart-hut/src/components/dashboard/devices/styleComponents.js +++ b/smart-hut/src/components/dashboard/devices/styleComponents.js @@ -16,9 +16,9 @@ export const editButtonStyle = { export const panelStyle = { position : "relative", backgroundColor: "#fafafa", - height: "100%", + height: "100vh", width: "auto", - padding: "3rem", + padding: "0rem 3rem", }; export const editModeStyle = { @@ -29,7 +29,8 @@ export const editModeStyle = { height : "1.5rem", backgroundColor : "black", borderRadius: "100%", - zIndex : "100" + zIndex : "1000", + cursor : "pointer", }; export const editModeIconStyle = { @@ -88,6 +89,7 @@ export const StyledDiv = styled.div` position : relative; box-shadow: 3px 2px 10px 5px #ccc; transition : all .3s ease-out; + text-align : center; :hover{ background-color : #f2f2f2; } diff --git a/smart-hut/src/components/modalform.js b/smart-hut/src/components/modalform.js index 3400d42..682bd12 100644 --- a/smart-hut/src/components/modalform.js +++ b/smart-hut/src/components/modalform.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { Button, Header, Image, Modal, Checkbox, Form, Grid, Input, Icon } from 'semantic-ui-react' +import { Button, Header, Modal, Form, Input, Icon } from 'semantic-ui-react' import SelectIcons from "./SelectIcons"; export default class ModalWindow extends Component { @@ -7,7 +7,8 @@ export default class ModalWindow extends Component { constructor(props) { super(props); this.state = { - selectedIcon: 'home', + id : "", + selectedIcon: "", name: "", img: "", openModal: false @@ -23,14 +24,23 @@ export default class ModalWindow extends Component { "name" : this.state.name, "images" : this.state.img } - - console.log(this.props, data); this.props.addRoom(data); this.closeModal(); } + modifyRoomModal = (e) => { + let data = { + "icon" : this.state.selectedIcon, + "name" : this.state.name, + "images" : this.state.img + } + this.props.updateRoom(data); + this.closeModal(); + } + deleteRoom = (e) => { - console.log(e); + this.props.deleteRoom(); + this.closeModal(); } changeSomething = (event) => { @@ -49,7 +59,6 @@ export default class ModalWindow extends Component { } updateIcon(e) { - console.log(e); this.setState({selectedIcon : e}) } @@ -64,32 +73,40 @@ export default class ModalWindow extends Component { return (
+ + {this.props.type === "new" ? + : + null + } + -
{this.props.type == "new" ? "Add new room" : "Modify room" }
+
{this.props.type === "new" ? "Add new room" : "Modify room" }

Insert the name of the room:

- +

Insert an image of the room:

- +

Select an icon:

- +
- {this.props.type == "modify" ? + {this.props.type === "modify" ? - +
diff --git a/smart-hut/src/views/ConfirmForgotPassword.js b/smart-hut/src/views/ConfirmForgotPassword.js index e364f0d..7de5e16 100644 --- a/smart-hut/src/views/ConfirmForgotPassword.js +++ b/smart-hut/src/views/ConfirmForgotPassword.js @@ -1,14 +1,7 @@ import React, { Component } from "react"; -import { render } from "react-dom"; import HomeNavbar from "./../components/HomeNavbar"; import { - Container, - Icon, Image, - Menu, - Sidebar, - Responsive, - Header, Divider, Message, Grid diff --git a/smart-hut/src/views/ConfirmRegistration.js b/smart-hut/src/views/ConfirmRegistration.js index 9bec496..b1c5652 100644 --- a/smart-hut/src/views/ConfirmRegistration.js +++ b/smart-hut/src/views/ConfirmRegistration.js @@ -1,14 +1,7 @@ import React, { Component } from "react"; -import { render } from "react-dom"; import HomeNavbar from "./../components/HomeNavbar"; import { - Container, - Icon, Image, - Menu, - Sidebar, - Responsive, - Header, Divider, Message, Grid diff --git a/smart-hut/src/views/Dashboard.js b/smart-hut/src/views/Dashboard.js index 30f36e0..f84c813 100644 --- a/smart-hut/src/views/Dashboard.js +++ b/smart-hut/src/views/Dashboard.js @@ -4,32 +4,50 @@ import Navbar from './Navbar' import MyHeader from '../components/HeaderController' import { call } from '../client_server'; -import {Button} from 'semantic-ui-react'; -import { Menu } from 'semantic-ui-react' -import { Grid, Image, Icon } from 'semantic-ui-react' +import { Grid } from 'semantic-ui-react' +/* + rooms -> actual rooms + activeItem -> the current room in view + devices -> current device in current room view + id of Home is -1 +*/ + export default class Dashboard extends Component{ constructor(props) { super(props); this.state = { rooms: [], - activeItem: "Home", - tkn: this.props.tkn + activeItem: -1, + devices: [], + tkn: this.props.tkn, }; this.addRoom = this.addRoom.bind(this); + this.deleteRoom = this.deleteRoom.bind(this); + this.addDevice = this.addDevice.bind(this); this.handleItemClick = this.handleItemClick.bind(this); } componentDidMount() { call.getAllRooms(this.props.tkn) .then(res => { - res.data.forEach((e) => { - this.setState(state => ({ - rooms: state.rooms.concat([e]) - })); - }); + if (res.status === 200){ + this.setState({ + rooms: res.data + }); + } + }).catch(err => { + console.log(err); + }); + call.getAllDevices(this.props.tkn) + .then(res => { + if (res.status === 200) { + this.setState({ + devices: res.data + }); + } }).catch(err => { console.log(err); }); @@ -38,7 +56,6 @@ export default class Dashboard extends Component{ addRoom(data) { call.createRoom(data) .then(res => { - console.log(res); if (res.status === 200 && res.data) { this.setState(state => ({ rooms: state.rooms.concat([res.data]) @@ -49,30 +66,80 @@ export default class Dashboard extends Component{ }); }; - deleteRoom(id) { - + deleteRoom() { + let data = { + id : this.state.activeItem + } + call.deleteRoom(data) + .then(res => { + //remove room in state.rooms + }).catch(err => { + console.log(err); + }); } - handleItemClick(el) { + handleItemClick(id) { + // el -> obj of name and id //da fare richiesta get della room e settare activeItem + this.setState({ + activeItem: id + }); + if ( id === -1) { + call.getAllDevices(this.props.tkn) + .then(res => { + if ( res.status === 200) { + this.setState({ + devices: res.data + }); + } + }).catch(err => { + console.log(err); + }); + } else { + call.getAllDevicesByRoom(id, this.props.tkn) + .then(res => { + if (res.status === 200) { + console.log(res.data); + this.setState({ + devices: res.data + }); + } + }).catch(err => { + console.log(err); + }); + } } - + + addDevice(data) { + data.params["roomId"] = this.state.activeItem; + call.devicePost(data, this.props.tkn) + .then(res => { + this.setState(state => ({ + devices: state.devices.concat([res.data]) + })); + return this.state.devices; + }).catch(err => { + + }); + } + + render () { return(
- - - - - - - - + + + - + + + + + + - + diff --git a/smart-hut/src/views/Forgot-pass-reset.js b/smart-hut/src/views/Forgot-pass-reset.js index 170bf1d..0989b91 100644 --- a/smart-hut/src/views/Forgot-pass-reset.js +++ b/smart-hut/src/views/Forgot-pass-reset.js @@ -1,6 +1,7 @@ import React, {Component} from 'react'; import {Button, Form, Grid, Header, Image, Icon, Message} from 'semantic-ui-react'; import { call } from '../client_server'; +import { Redirect } from "react-router-dom"; export default class ChangePass extends Component { @@ -13,6 +14,7 @@ export default class ChangePass extends Component { message: "", } } + this.handleChangePassword = this.handleChangePassword.bind(this); } onChangeHandler = (event) => { @@ -32,14 +34,16 @@ export default class ChangePass extends Component { handleChangePassword = (e) => { const params = { - "confirmationToken" : this.props.query.confirmationToken , + "confirmationToken" : this.props.query.token , "password" : this.state.password } call.resetPassword(params) .then(res => { - if (res.status === "Errore") { + if (res.status !== 200){ this.setState({ error: { state: true, message: "Errore"}}); + } else { + return } // else set a message that an email has been sent }).catch(err => { diff --git a/smart-hut/src/views/ForgotPassword.js b/smart-hut/src/views/ForgotPassword.js new file mode 100644 index 0000000..7b3a2bd --- /dev/null +++ b/smart-hut/src/views/ForgotPassword.js @@ -0,0 +1,107 @@ +import React, { Component } from "react"; +import { render } from "react-dom"; +import HomeNavbar from "./../components/HomeNavbar"; +import { + Container, + Icon, + Image, + Menu, + Sidebar, + Responsive, + Header, + Divider, + Message, + Grid +} from "semantic-ui-react"; + +class Paragraph extends Component { + state = { visible: true } + + handleDismiss = () => { + this.setState({ visible: false }) + + setTimeout(() => { + this.setState({ visible: true }) + }, 2000) + } + + render() { + if (this.state.visible) { + return ( + + ) + } + + return ( +

+
+ The message will return in 2s +
+
+

+ ) + } + } + + + const MessageReg = () => ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ) + +export default class ForgotPasswrod extends React.Component { + render () { + return ( + + ) + } +} \ No newline at end of file diff --git a/smart-hut/src/views/FourOhFour.js b/smart-hut/src/views/FourOhFour.js index 99cca6c..2aa89f5 100644 --- a/smart-hut/src/views/FourOhFour.js +++ b/smart-hut/src/views/FourOhFour.js @@ -1,5 +1,5 @@ import React, {Component} from 'react'; -import { Message} from 'semantic-ui-react'; +import { Header, Grid, Message, Button} from 'semantic-ui-react'; import {Link } from "react-router-dom"; @@ -7,13 +7,29 @@ export default class FourOhFour extends Component { render() { return ( - - 404 Page Not Found -

- Hey what are you doing here? - Go back to our homepage -

-
+
+ + +
404
+
+ + + + 404 Page Not Found +

+ Hey what are you doing here? + Looks like you are lost, this room does not exist. +

+
+
+ + + +
+
+
) } } \ No newline at end of file diff --git a/smart-hut/src/views/Home.js b/smart-hut/src/views/Home.js index 3566a33..2d03a91 100644 --- a/smart-hut/src/views/Home.js +++ b/smart-hut/src/views/Home.js @@ -4,7 +4,6 @@ import HomeNavbar from './../components/HomeNavbar'; import { Button, Container, - Divider, Grid, Header, Icon, @@ -70,7 +69,6 @@ class DesktopContainer extends Component { render() { const { children } = this.props - const { fixed } = this.state return ( diff --git a/smart-hut/src/views/Navbar.js b/smart-hut/src/views/Navbar.js index c887f59..de3f183 100644 --- a/smart-hut/src/views/Navbar.js +++ b/smart-hut/src/views/Navbar.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { Menu, Grid, Icon, Button, Header, Image, Modal, Responsive, Segment } from "semantic-ui-react"; +import { Menu, Grid, Icon, Responsive, Segment } from "semantic-ui-react"; import {editButtonStyle} from "../components/dashboard/devices/styleComponents"; import ModalWindow from "../components/modalform"; @@ -8,27 +8,31 @@ class Navbar extends Component { super(props); this.state = { activeItem: 'Home', - edited: "" + edited: "", + editMode : false } } - showForm = (event) => { - console.log(event); - if (event === "new"){ - console.log("funziona"); - return () - } - } + editModeController = (e) => { + this.setState((prevState) => ({ editMode: !prevState.editMode })); + }; - handleClick = (e, { i }) => { - this.setState({ activeItem: e.name, - edited: i + handleClick = (e, {id}) => { + console.log(id); + let obj = undefined; + this.props.rooms.forEach((e) => { + if (e.id === id) { + obj = e; + } + }); + this.setState({ activeItem: id, + activeRoom: obj }); - this.props.handleItemClick(e) + this.props.handleItemClick(id) } render(){ - const { activeItem } = this.state + //const { activeItem } = this.state return (
@@ -40,8 +44,10 @@ class Navbar extends Component { @@ -50,7 +56,7 @@ class Navbar extends Component { - Home + HOME @@ -64,38 +70,38 @@ class Navbar extends Component { id={e.id} key={i} name={e.name} - active={activeItem === e.name} + active={this.state.activeItem === e.id} onClick={this.handleClick} > - + - + {e.name} - - + + {this.state.edit ? + + : null + } - - ) }) : null } + - - + - @@ -105,7 +111,7 @@ class Navbar extends Component { - //dropdown menu +
diff --git a/smart-hut/src/views/NavbarTest.js b/smart-hut/src/views/NavbarTest.js deleted file mode 100644 index c108c20..0000000 --- a/smart-hut/src/views/NavbarTest.js +++ /dev/null @@ -1,12 +0,0 @@ -import React, {Component} from 'react'; -import {Button } from 'semantic-ui-react'; - - -export default class NavbarTest extends Component { - - render() { - return ( -

Ciao

- ) - } -} \ No newline at end of file diff --git a/smart-hut/src/views/TestHeaderController.js b/smart-hut/src/views/TestHeaderController.js new file mode 100644 index 0000000..b0afedb --- /dev/null +++ b/smart-hut/src/views/TestHeaderController.js @@ -0,0 +1,11 @@ +import _ from "lodash"; +import React from "react"; +import HeaderController from "./../components/HeaderController"; + +export default class TestHeaderController extends React.Component { + render () { + return ( + + ) + } +} \ No newline at end of file