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/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/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/smart-home_index.png b/smart-hut/public/smart-home_index.png
new file mode 100644
index 0000000..3b678bc
Binary files /dev/null and b/smart-hut/public/smart-home_index.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 5cc0cd3..efde975 100644
--- a/smart-hut/src/App.js
+++ b/smart-hut/src/App.js
@@ -80,12 +80,12 @@ class App extends Component {
};
logout() {
+ console.log("logout")
this.setState({
loggedIn : false,
});
localStorage.removeItem("token");
- this.props.history.push("/");
};
render() {
diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js
index 18c2ae4..3821dcb 100644
--- a/smart-hut/src/client_server.js
+++ b/smart-hut/src/client_server.js
@@ -59,6 +59,28 @@ export var call = {
return err;
});
},
+ getAllDevices: function(token) {
+ if (!token){
+ token = tkn;
+ }
+ return axios.get(config + 'device', { headers: { Authorization : "Bearer " + token } })
+ .then(res => {
+ return res;
+ }).catch(err => {
+ return err;
+ });
+ },
+ getAllDevicesByRoom: function(id, token) {
+ if (!token){
+ token = tkn;
+ }
+ return axios.get(config + 'room/' + id + '/devices' , { headers: { Authorization : "Bearer " + token } })
+ .then(res => {
+ return res;
+ }).catch(err => {
+ return err;
+ });
+ },
createRoom: function(data, headers) {
return axios.post(config + 'room', data, { headers: { Authorization : "Bearer " + tkn } })
.then(res => {
diff --git a/smart-hut/src/components/HeaderController.js b/smart-hut/src/components/HeaderController.js
index 355d08a..5bf9c9f 100644
--- a/smart-hut/src/components/HeaderController.js
+++ b/smart-hut/src/components/HeaderController.js
@@ -29,7 +29,7 @@ const HeaderExampleIconProp = () => (
-const GridExampleInverted = () => (
+const GridExampleInverted = (props) => (
@@ -57,7 +57,7 @@ const GridExampleInverted = () => (
See profile...
- Logout
+ Logout
@@ -67,9 +67,10 @@ const GridExampleInverted = () => (
export default class MyHeader extends React.Component {
render() {
+ console.log(this.props)
return (
-
+
);
}
diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js
index 0276963..6d046a4 100644
--- a/smart-hut/src/components/dashboard/DevicePanel.js
+++ b/smart-hut/src/components/dashboard/DevicePanel.js
@@ -59,16 +59,42 @@ const devices = [
];
-class Panel extends Component {
+export default class DevicePanel extends Component {
- constructor(props) {
- super(props);
- this.state = {
- devices: devices,
+ constructor(props) {
+ super(props);
+ this.state = {
+ editMode : false,
+ devices : this.props.devices,
+ };
+ }
- editMode: false,
- openSettingsModal: false,
- settingsDeviceId: null,
+ editModeController = (e) => this.setState((prevState) => ({ editMode: !prevState.editMode }));
+
+ changeDeviceData = (deviceId, newSettings) => {
+
+ console.log(newSettings.name, " <-- new name --> ", deviceId );
+ this.state.devices.map(device => {
+ if(device.id === deviceId){
+ for(let prop in newSettings){
+ if(device.hasOwnProperty(prop)){
+ if(prop==="name"){
+ if(checkMaxLength(newSettings[prop])){
+ device[prop] = newSettings[prop];
+ }
+ else{
+ alert("Name must be less than " + DEVICE_NAME_MAX_LENGTH + " characters.");
+ }
+ }else{
+ device[prop] = newSettings[prop];
+ }
+
+ }
+ }
+ }
+ return null;
+ });
+ this.forceUpdate();
};
}
@@ -92,69 +118,31 @@ class Panel extends Component {
device[prop] = newSettings[prop];
}
- }
- }
- }
- return null;
- });
- this.forceUpdate();
- };
- openModal = (settingsDeviceId) => {
- this.setState(prevState => ({
- openSettingsModal: !prevState.openSettingsModal,
- settingsDeviceId: settingsDeviceId
- }));
- };
-
- render() {
- const edit = {
- mode: this.state.editMode,
- openModal: this.openModal,
- };
- return (
-
-
-
- {this.state.openSettingsModal ?
- d.id === this.state.settingsDeviceId)[0]}/> : ""}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- )
- }
-
-}
-
-
-export default class DevicePanel extends Component {
-
- constructor(props) {
- super(props);
- this.state = {
- shownRoom: "All"
+ render() {
+ return (
+
+
+ 0 ? this.props.devices.length : 1} divided="vertically">
+ {
+ this.props.devices ?
+ this.props.devices.map((e, i) => {
+ return (
+
+
+
+ )
+ })
+ :
+ null
+ }
+
+
+
+
+
+ )
}
- }
- render() {
- return (
-
- )
- }
-
-}
+}
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..b67ae7b
--- /dev/null
+++ b/smart-hut/src/components/dashboard/devices/DeviceTypeController.js
@@ -0,0 +1,25 @@
+import React, { Component } from 'react';
+import Light from "./Light";
+import SmartPlug from "./SmartPlug";
+import Sensor from "./Sensor";
+import DefaultDimmer from "./Dimmer";
+import Switcher from "./Switcher";
+
+
+
+const DeviceType = (props) => {
+ switch(props.type) {
+ case "light":
+ return
+ case "sensor":
+ return
+ case "dimmer":
+ return
+ case "smartplug":
+ return
+ case "switch":
+ return
+ }
+}
+
+export default DeviceType;
\ No newline at end of file
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/modalform.js b/smart-hut/src/components/modalform.js
index 3400d42..79ca7da 100644
--- a/smart-hut/src/components/modalform.js
+++ b/smart-hut/src/components/modalform.js
@@ -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,26 @@ 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);
+ let data = {
+ "id" : this.state.id
+ }
+ this.props.deleteRoom(data);
+ this.closeModal();
}
changeSomething = (event) => {
@@ -49,7 +62,6 @@ export default class ModalWindow extends Component {
}
updateIcon(e) {
- console.log(e);
this.setState({selectedIcon : e})
}
@@ -64,10 +76,16 @@ export default class ModalWindow extends Component {
return (
diff --git a/smart-hut/src/views/Dashboard.js b/smart-hut/src/views/Dashboard.js
index 75222fc..5cea3c6 100644
--- a/smart-hut/src/views/Dashboard.js
+++ b/smart-hut/src/views/Dashboard.js
@@ -4,18 +4,24 @@ 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);
@@ -25,11 +31,17 @@ export default class Dashboard extends Component{
componentDidMount() {
call.getAllRooms(this.props.tkn)
.then(res => {
- res.data.forEach((e) => {
- this.setState(state => ({
- rooms: state.rooms.concat([e])
- }));
- });
+ this.setState({
+ rooms: res.data
+ });
+ }).catch(err => {
+ console.log(err);
+ });
+ call.getAllDevices(this.props.tkn)
+ .then(res => {
+ this.setState({
+ devices: res.data
+ });
}).catch(err => {
console.log(err);
});
@@ -50,11 +62,25 @@ export default class Dashboard extends Component{
};
deleteRoom(id) {
-
+ call.deleteRoom(id)
+ .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
+ call.getAllDevicesByRoom(id, this.props.tkn)
+ .then(res => {
+ this.setState({
+ devices: res.data
+ });
+ }).catch(err => {
+ console.log(err);
+ });
}
render () {
@@ -65,8 +91,8 @@ export default class Dashboard extends Component{
{/*TODO change this back
-
- */}
+
+
@@ -74,7 +100,7 @@ export default class Dashboard extends Component{
-
+
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 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/Navbar.js b/smart-hut/src/views/Navbar.js
index c887f59..121d4b7 100644
--- a/smart-hut/src/views/Navbar.js
+++ b/smart-hut/src/views/Navbar.js
@@ -8,27 +8,24 @@ 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);
+ this.setState({ activeItem: id,
});
- this.props.handleItemClick(e)
+ this.props.handleItemClick(id)
}
render(){
- const { activeItem } = this.state
+ //const { activeItem } = this.state
return (
@@ -40,8 +37,9 @@ class Navbar extends Component {
@@ -64,38 +62,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
+ }
-
Menu.Item>
-
)
}) : null
}
+
-
-
+
-
diff --git a/smart-hut/src/views/TestHeaderController.js b/smart-hut/src/views/TestHeaderController.js
new file mode 100644
index 0000000..6293908
--- /dev/null
+++ b/smart-hut/src/views/TestHeaderController.js
@@ -0,0 +1,20 @@
+import _ from "lodash";
+import React, { Component } from "react";
+import HeaderController from "./../components/HeaderController";
+import { render } from "react-dom";
+import {
+ Container,
+ Icon,
+ Image,
+ Menu,
+ Sidebar,
+ Responsive
+} from "semantic-ui-react";
+
+export default class TestHeaderController extends React.Component {
+ render () {
+ return (
+
+ )
+ }
+}
\ No newline at end of file