resolved conflicts
|
@ -3,6 +3,7 @@ image: node:latest
|
|||
stages:
|
||||
- build
|
||||
- test
|
||||
- deploy
|
||||
|
||||
cache:
|
||||
paths:
|
||||
|
@ -22,3 +23,22 @@ testing_testing:
|
|||
script:
|
||||
- cd smart-hut
|
||||
- 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
|
||||
|
|
39
Dockerfile
Normal file
|
@ -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;"]
|
BIN
smart-hut/public/avatar.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
smart-hut/public/avatar2.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
1
smart-hut/public/img/dimmer.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg id="icons" enable-background="new 0 0 64 64" height="512" viewBox="0 0 64 64" width="512" xmlns="http://www.w3.org/2000/svg"><path d="m62 6.005v51.99c0 2.2-1.8 4-4 4h-52c-2.2 0-4-1.8-4-4v-51.99c0-2.199 1.8-4 4-4h52c2.2 0 4 1.801 4 4zm-5 50.99v-50h-50v50z" fill="#fff"/><path d="m32 17.025c5.24 0 9.99 2.12 13.43 5.56 3.431 3.44 5.561 8.181 5.561 13.42v.011h-2.991v-.011c0-8.829-7.17-16-16-16s-16 7.171-16 16v.011h-2.98v-.011c0-5.239 2.121-9.979 5.561-13.409 3.429-3.441 8.179-5.571 13.419-5.571z" fill="#94c1ff"/><path d="m32 17.025c-5.24 0-9.99 2.13-13.42 5.57-3.439 3.43-5.561 8.17-5.561 13.409v.011h2.981v-.011c0-8.829 7.17-16 16-16s16 7.171 16 16v.011h2.99v-.011c0-5.239-2.13-9.979-5.561-13.42-3.439-3.438-8.189-5.559-13.429-5.559zm13 18.98c0-7.17-5.82-13-13-13-7.17 0-13 5.83-13 13 0 7.171 5.83 13 13 13 7.18 0 13-5.829 13-13zm12-29.01v50h-50v-50z" fill="#d7e9ff"/><path d="m32 25.995c1.109 0 2 .9 2 2 0 1.101-.891 2-2 2-1.1 0-2-.899-2-2 0-1.099.9-2 2-2z" fill="#d7e9ff"/><path d="m32 25.995c-1.1 0-2 .9-2 2 0 1.101.9 2 2 2 1.109 0 2-.899 2-2 0-1.099-.891-2-2-2zm0-2.99c7.18 0 13 5.83 13 13 0 7.171-5.82 13-13 13-7.17 0-13-5.829-13-13 0-7.17 5.83-13 13-13z" fill="#fff"/><g fill="#116fff"><path d="m57.999 62.999h-51.998c-2.757 0-5-2.243-5-5v-51.998c0-2.757 2.243-5 5-5h51.998c2.757 0 5 2.243 5 5v51.998c0 2.757-2.243 5-5 5zm-51.998-59.998c-1.654 0-3 1.346-3 3v51.998c0 1.654 1.346 3 3 3h51.998c1.654 0 3-1.346 3-3v-51.998c0-1.654-1.346-3-3-3z"/><path d="m57 58h-50c-.553 0-1-.447-1-1v-50c0-.553.447-1 1-1h50c.553 0 1 .447 1 1v50c0 .553-.447 1-1 1zm-49-2h48v-48h-48z"/><path d="m32 50.004c-7.72 0-14-6.281-14-14.001 0-7.719 6.28-13.999 14-13.999s14 6.28 14 13.999c0 7.72-6.28 14.001-14 14.001zm0-26c-6.617 0-12 5.383-12 11.999 0 6.617 5.383 12.001 12 12.001s12-5.384 12-12.001c0-6.616-5.383-11.999-12-11.999z"/><path d="m32 30.995c-1.654 0-3-1.346-3-3s1.346-3 3-3 3 1.346 3 3-1.346 3-3 3zm0-4c-.552 0-1 .448-1 1s.448 1 1 1 1-.448 1-1-.448-1-1-1z"/><path d="m50.983 37.003c-.553 0-1-.447-1-1 0-9.916-8.067-17.982-17.983-17.982s-17.983 8.066-17.983 17.982c0 .553-.447 1-1 1s-1-.447-1-1c0-11.019 8.965-19.982 19.983-19.982s19.983 8.964 19.983 19.982c0 .553-.447 1-1 1z"/><path d="m48 37.003c-.553 0-1-.447-1-1 0-8.271-6.729-14.999-15-14.999s-15 6.729-15 14.999c0 .553-.447 1-1 1s-1-.447-1-1c0-9.373 7.626-16.999 17-16.999s17 7.626 17 16.999c0 .553-.447 1-1 1z"/><path d="m32 19.021c-.553 0-1-.447-1-1v-1.017c0-.553.447-1 1-1s1 .447 1 1v1.017c0 .553-.447 1-1 1z"/><path d="m19.278 24.291c-.256 0-.512-.098-.707-.293l-.719-.719c-.391-.391-.391-1.023 0-1.414s1.023-.391 1.414 0l.719.719c.391.391.391 1.023 0 1.414-.195.195-.451.293-.707.293z"/><path d="m15.998 37.013h-3.006c-.553 0-1-.447-1-1s.447-1 1-1h3.006c.553 0 1 .447 1 1s-.447 1-1 1z"/><path d="m51.007 37.014h-3.007c-.553 0-1-.447-1-1s.447-1 1-1h3.007c.553 0 1 .447 1 1s-.447 1-1 1z"/><path d="m44.721 24.293c-.256 0-.512-.098-.707-.293-.391-.391-.391-1.023 0-1.414l.72-.72c.391-.391 1.023-.391 1.414 0s.391 1.023 0 1.414l-.72.72c-.196.195-.451.293-.707.293z"/><path d="m11.044 12.021c-.553 0-1.005-.447-1.005-1s.442-1 .994-1h.011c.552 0 1 .447 1 1s-.448 1-1 1z"/><path d="m11.044 54.017c-.553 0-1.005-.447-1.005-1s.442-1 .994-1h.011c.552 0 1 .447 1 1s-.448 1-1 1z"/><path d="m53.046 12.021c-.553 0-1.005-.447-1.005-1s.442-1 .994-1h.011c.552 0 1 .447 1 1s-.448 1-1 1z"/><path d="m53.046 54.017c-.553 0-1.005-.447-1.005-1s.442-1 .994-1h.011c.552 0 1 .447 1 1s-.448 1-1 1z"/></g></svg>
|
After Width: | Height: | Size: 3.4 KiB |
1
smart-hut/public/img/humidity-sensor.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg id="Capa_1" enable-background="new 0 0 512 512" height="512" viewBox="0 0 512 512" width="512" xmlns="http://www.w3.org/2000/svg"><g id="XMLID_2040_"><circle id="XMLID_1170_" cx="210" cy="302" fill="#91def5" r="200"/><path id="XMLID_1252_" d="m310.911 116.754 84.079-106.754 84.079 106.754c33.55 42.598 29.941 103.557-8.401 141.899-41.796 41.796-109.561 41.796-151.357 0-38.342-38.342-41.951-99.301-8.4-141.899z" fill="#dff6fc"/><g id="XMLID_759_"><path id="XMLID_760_" d="m174.798 388.747c1.265.531 2.576.782 3.866.782 3.907 0 7.618-2.304 9.225-6.133l64.758-154.303c2.138-5.092-.259-10.953-5.351-13.09-5.095-2.138-10.954.258-13.091 5.351l-64.758 154.303c-2.137 5.092.259 10.953 5.351 13.09z"/><path id="XMLID_763_" d="m199.375 247.585c0-21.81-16.087-39.553-35.859-39.553s-35.858 17.743-35.858 39.553 16.086 39.553 35.858 39.553 35.859-17.744 35.859-39.553zm-35.859 19.552c-8.744 0-15.858-8.771-15.858-19.553s7.114-19.553 15.858-19.553c8.745 0 15.859 8.771 15.859 19.553s-7.114 19.553-15.859 19.553z"/><path id="XMLID_770_" d="m256.484 400.032c19.772 0 35.858-17.743 35.858-39.553s-16.086-39.553-35.858-39.553-35.859 17.743-35.859 39.553 16.087 39.553 35.859 39.553zm0-59.106c8.744 0 15.858 8.771 15.858 19.553s-7.114 19.553-15.858 19.553c-8.745 0-15.859-8.771-15.859-19.553s7.114-19.553 15.859-19.553z"/><path id="XMLID_773_" d="m486.926 110.567-84.079-106.754c-1.897-2.408-4.792-3.813-7.857-3.813s-5.96 1.405-7.855 3.813l-84.081 106.754c-.598.759-1.184 1.524-1.76 2.293-28.294-13.656-59.669-20.86-91.294-20.86-115.794 0-210 94.206-210 210s94.206 210 210 210c39.357 0 77.729-10.955 110.966-31.681 4.687-2.922 6.116-9.09 3.194-13.776-2.922-4.687-9.09-6.117-13.776-3.194-30.06 18.743-64.772 28.651-100.384 28.651-104.767 0-190-85.233-190-190s85.233-190 190-190c27.901 0 55.58 6.193 80.663 17.946-22.563 44.347-14.795 99.405 21.578 135.777 22.103 22.104 51.49 34.277 82.748 34.277 1.665 0 3.324-.042 4.978-.111.008.704.033 1.409.033 2.111 0 35.875-10.045 70.807-29.048 101.018-2.94 4.675-1.534 10.848 3.141 13.789 1.654 1.041 3.495 1.537 5.314 1.537 3.323 0 6.574-1.656 8.475-4.677 21.012-33.405 32.118-72.019 32.118-111.667 0-1.547-.039-3.102-.073-4.655 21.74-4.695 41.71-15.52 57.812-31.621 41.902-41.901 45.851-108.604 9.187-155.157zm-91.937 169.433c-25.916 0-50.281-10.092-68.606-28.418-34.741-34.74-38.016-90.043-7.616-128.64h-.001l76.225-96.779 76.223 96.779c30.399 38.597 27.125 93.9-7.616 128.641-18.327 18.325-42.692 28.417-68.609 28.417z"/><path id="XMLID_799_" d="m351.34 433.5c-2.64 0-5.22 1.07-7.07 2.93-1.859 1.86-2.93 4.44-2.93 7.07 0 2.64 1.07 5.21 2.93 7.08 1.86 1.86 4.431 2.92 7.07 2.92 2.63 0 5.2-1.06 7.07-2.92 1.859-1.87 2.93-4.44 2.93-7.08 0-2.63-1.07-5.21-2.93-7.07s-4.44-2.93-7.07-2.93z"/></g></g></svg>
|
After Width: | Height: | Size: 2.7 KiB |
1
smart-hut/public/img/intensity-light.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg height="512pt" viewBox="-1 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg"><path d="m255.128906 398.359375c-49.757812 0-90.234375-40.480469-90.234375-90.230469v-13.941406c0-8.429688 6.835938-15.265625 15.265625-15.265625h149.933594c8.429688 0 15.265625 6.835937 15.265625 15.265625v13.941406c0 49.75-40.480469 90.230469-90.230469 90.230469zm0 0" fill="#145180"/><path d="m330.089844 278.917969h-74.960938v119.441406c49.753906-.003906 90.230469-40.480469 90.230469-90.230469v-13.941406c0-8.433594-6.835937-15.269531-15.269531-15.269531zm0 0" fill="#082130"/><path d="m164.894531 294.1875v-57.515625c-28.894531-25.75-45.320312-62.191406-45.320312-101.121094 0-74.742187 60.808593-135.550781 135.554687-135.550781 74.742188 0 135.550782 60.808594 135.550782 135.550781 0 38.929688-16.425782 75.371094-45.320313 101.121094v57.515625zm0 0" fill="#fff04a"/><path d="m255.128906 0v294.1875h90.226563v-57.515625c28.898437-25.75 45.320312-62.191406 45.320312-101.121094 0-74.742187-60.804687-135.54687475-135.546875-135.550781zm0 0" fill="#ff961f"/><path d="m308.277344 126.613281c-5.960938-5.960937-15.628906-5.960937-21.589844 0l-31.558594 31.558594-31.558594-31.558594c-5.960937-5.964843-15.628906-5.964843-21.589843 0-5.964844 5.960938-5.964844 15.628907 0 21.589844l37.882812 37.882813v108.101562h30.53125v-108.101562l37.882813-37.882813c5.960937-5.960937 5.960937-15.628906 0-21.589844zm0 0" fill="#fff"/><path d="m286.6875 126.613281-31.558594 31.558594v136.015625h15.265625v-108.101562l37.882813-37.882813c5.960937-5.960937 5.960937-15.628906 0-21.589844-5.960938-5.960937-15.628906-5.960937-21.589844 0zm0 0" fill="#fff04a"/><path d="m494.992188 512h-479.726563c-8.429687 0-15.265625-6.835938-15.265625-15.265625v-51.90625c0-8.429687 6.835938-15.265625 15.265625-15.265625h479.726563c8.429687 0 15.265624 6.835938 15.265624 15.265625v51.90625c0 8.429687-6.832031 15.265625-15.265624 15.265625zm0 0" fill="#9ffeff"/><path d="m494.992188 429.5625h-239.863282v82.4375h239.863282c8.429687 0 15.265624-6.835938 15.265624-15.265625v-51.90625c0-8.429687-6.832031-15.265625-15.265624-15.265625zm0 0" fill="#78e3f6"/><path d="m494.992188 429.5625h-121.882813v82.4375h121.882813c8.429687 0 15.265624-6.835938 15.265624-15.265625v-51.90625c0-8.429687-6.832031-15.265625-15.265624-15.265625zm0 0" fill="#082130"/><path d="m494.992188 370.03125h-56.660157c-8.429687 0-15.265625-6.835938-15.265625-15.269531 0-8.429688 6.835938-15.265625 15.265625-15.265625h56.660157c8.429687 0 15.265624 6.835937 15.265624 15.265625 0 8.433593-6.832031 15.269531-15.265624 15.269531zm0 0" fill="#082130"/><path d="m71.925781 339.496094h-13.0625v-13.0625c0-8.429688-6.835937-15.265625-15.265625-15.265625-8.433594 0-15.269531 6.835937-15.269531 15.265625v13.0625h-13.0625c-8.429687 0-15.265625 6.835937-15.265625 15.265625 0 8.433593 6.835938 15.269531 15.265625 15.269531h13.0625v13.0625c0 8.429688 6.835937 15.265625 15.269531 15.265625 8.429688 0 15.265625-6.835937 15.265625-15.265625v-13.0625h13.0625c8.429688 0 15.265625-6.835938 15.265625-15.269531 0-8.429688-6.832031-15.265625-15.265625-15.265625zm0 0" fill="#145180"/></svg>
|
After Width: | Height: | Size: 3 KiB |
1
smart-hut/public/img/light-sensor.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg height="512pt" viewBox="0 0 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg"><path d="m256 394.414062c-77.425781 0-140.414062-62.988281-140.414062-140.410156 0-77.425781 62.988281-140.414062 140.414062-140.414062s140.414062 62.988281 140.414062 140.414062c0 77.421875-62.988281 140.410156-140.414062 140.410156zm0 0" fill="#ffe645"/><path d="m256 113.589844c-.003906 0-.007812 0-.007812 0v280.824218h.007812c77.425781 0 140.414062-62.988281 140.414062-140.410156 0-77.425781-62.988281-140.414062-140.414062-140.414062zm0 0" fill="#a19d8d"/><path d="m256 512c-8.285156 0-15-6.714844-15-15v-56c0-8.28125 6.714844-15 15-15s15 6.71875 15 15v56c0 8.285156-6.714844 15-15 15zm0 0" fill="#ffe645"/><path d="m497 271h-54.011719c-8.285156 0-15-6.714844-15-15 0-8.28125 6.714844-15 15-15h54.011719c8.285156 0 15 6.71875 15 15 0 8.285156-6.714844 15-15 15zm0 0" fill="#ffcf2c"/><path d="m69.011719 271h-54.011719c-8.285156 0-15-6.714844-15-15 0-8.28125 6.714844-15 15-15h54.011719c8.285156 0 15 6.71875 15 15 0 8.285156-6.714844 15-15 15zm0 0" fill="#ffe645"/><path d="m418.839844 176.996094c-5.183594 0-10.226563-2.691406-13.003906-7.503906-4.140626-7.171876-1.683594-16.347657 5.492187-20.488282l45.882813-26.492187c7.175781-4.144531 16.351562-1.683594 20.492187 5.492187 4.140625 7.171875 1.683594 16.347656-5.492187 20.488282l-45.882813 26.492187c-2.363281 1.363281-4.941406 2.011719-7.488281 2.011719zm0 0" fill="#ffcf2c"/><g fill="#ffe645"><path d="m48.140625 391.019531c-5.183594 0-10.226563-2.691406-13.003906-7.503906-4.144531-7.171875-1.683594-16.347656 5.488281-20.488281l46.785156-27.011719c7.175782-4.144531 16.347656-1.683594 20.488282 5.492187 4.144531 7.171876 1.6875 16.347657-5.488282 20.488282l-46.785156 27.011718c-2.359375 1.363282-4.941406 2.011719-7.484375 2.011719zm0 0"/><path d="m136.332031 478.246094c-2.542969 0-5.121093-.644532-7.484375-2.011719-7.175781-4.140625-9.632812-13.316406-5.492187-20.488281l27.007812-46.777344c4.140625-7.171875 13.316407-9.632812 20.488281-5.488281 7.175782 4.140625 9.632813 13.316406 5.492188 20.488281l-27.007812 46.777344c-2.777344 4.8125-7.820313 7.5-13.003907 7.5zm0 0"/><path d="m93.160156 176.996094c-2.546875 0-5.125-.648438-7.484375-2.011719l-46.78125-27.007813c-7.171875-4.140624-9.632812-13.316406-5.488281-20.492187 4.140625-7.171875 13.3125-9.632813 20.488281-5.488281l46.78125 27.007812c7.171875 4.140625 9.628907 13.316406 5.488281 20.488282-2.777343 4.8125-7.820312 7.503906-13.003906 7.503906zm0 0"/></g><path d="m464.699219 391.503906c-2.546875 0-5.125-.648437-7.488281-2.011718l-47.617188-27.492188c-7.171875-4.144531-9.628906-13.316406-5.488281-20.492188 4.140625-7.171874 13.316406-9.632812 20.488281-5.488281l47.617188 27.492188c7.175781 4.140625 9.632812 13.316406 5.492187 20.488281-2.777344 4.8125-7.820313 7.503906-13.003906 7.503906zm0 0" fill="#ffcf2c"/><path d="m375.667969 478.246094c-5.1875 0-10.226563-2.6875-13.003907-7.5l-27.003906-46.769532c-4.140625-7.175781-1.683594-16.347656 5.492188-20.488281 7.171875-4.144531 16.347656-1.6875 20.488281 5.488281l27.003906 46.769532c4.140625 7.175781 1.683594 16.347656-5.492187 20.488281-2.363282 1.367187-4.941406 2.011719-7.484375 2.011719zm0 0" fill="#ffcf2c"/><path d="m256 84c-8.285156 0-15-6.714844-15-15v-54c0-8.285156 6.714844-15 15-15s15 6.714844 15 15v54c0 8.285156-6.714844 15-15 15zm0 0" fill="#ffe645"/><path d="m348.632812 108.535156c-2.542968 0-5.125-.648437-7.484374-2.015625-7.175782-4.140625-9.632813-13.3125-5.492188-20.488281l27.007812-46.773438c4.140626-7.175781 13.3125-9.636718 20.488282-5.492187 7.175781 4.140625 9.632812 13.316406 5.492187 20.492187l-27.007812 46.773438c-2.777344 4.8125-7.820313 7.503906-13.003907 7.503906zm0 0" fill="#ffcf2c"/><path d="m163.363281 108.527344c-5.183593 0-10.226562-2.691406-13.003906-7.503906l-27.003906-46.765626c-4.140625-7.175781-1.683594-16.351562 5.492187-20.492187 7.171875-4.144531 16.347656-1.683594 20.488282 5.492187l27.003906 46.765626c4.140625 7.175781 1.683594 16.347656-5.492188 20.492187-2.359375 1.363281-4.941406 2.011719-7.484375 2.011719zm0 0" fill="#ffe645"/><path d="m256 426c-.003906 0-.007812 0-.007812 0v86h.007812c8.285156 0 15-6.714844 15-15v-56c0-8.28125-6.714844-15-15-15zm0 0" fill="#ffcf2c"/><path d="m256 0c-.003906 0-.007812 0-.007812 0v84h.007812c8.285156 0 15-6.714844 15-15v-54c0-8.285156-6.714844-15-15-15zm0 0" fill="#ffcf2c"/></svg>
|
After Width: | Height: | Size: 4.3 KiB |
BIN
smart-hut/public/img/room_404_meme/1.jpeg
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
smart-hut/public/img/room_404_meme/10.jpg
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
smart-hut/public/img/room_404_meme/11.jpeg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
smart-hut/public/img/room_404_meme/12.gif
Normal file
After Width: | Height: | Size: 94 KiB |
BIN
smart-hut/public/img/room_404_meme/13.gif
Normal file
After Width: | Height: | Size: 644 KiB |
BIN
smart-hut/public/img/room_404_meme/14.gif
Normal file
After Width: | Height: | Size: 320 KiB |
BIN
smart-hut/public/img/room_404_meme/2.jpeg
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
smart-hut/public/img/room_404_meme/3.png
Normal file
After Width: | Height: | Size: 244 KiB |
BIN
smart-hut/public/img/room_404_meme/4.jpeg
Normal file
After Width: | Height: | Size: 9.6 KiB |
BIN
smart-hut/public/img/room_404_meme/5.jpeg
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
smart-hut/public/img/room_404_meme/6.jpg
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
smart-hut/public/img/room_404_meme/7.jpg
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
smart-hut/public/img/room_404_meme/8.jpg
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
smart-hut/public/img/room_404_meme/9.jpeg
Normal file
After Width: | Height: | Size: 37 KiB |
1
smart-hut/public/img/sensorOff.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg id="Layer_1" enable-background="new 0 0 512 512" height="512" viewBox="0 0 512 512" width="512" xmlns="http://www.w3.org/2000/svg"><g><path d="m437.066 74.981c-5.857-5.858-15.355-5.858-21.213 0s-5.858 15.355 0 21.213c42.656 42.655 66.147 99.409 66.147 159.806s-23.491 117.151-66.147 159.806c-5.858 5.857-5.858 15.355 0 21.213 5.868 5.868 15.365 5.848 21.213 0 48.322-48.321 74.934-112.608 74.934-181.019s-26.612-132.698-74.934-181.019z"/><path d="m391.646 120.4c-5.858-5.857-15.356-5.857-21.213 0-5.857 5.858-5.857 15.355 0 21.213 30.533 30.531 47.349 71.155 47.349 114.387s-16.815 83.855-47.349 114.387c-5.858 5.858-5.858 15.355 0 21.213 5.856 5.856 15.353 5.859 21.213 0 36.2-36.198 56.136-84.355 56.136-135.601s-19.937-99.402-56.136-135.599z"/><path d="m346.193 165.852c-5.858-5.857-15.356-5.857-21.213 0-5.858 5.858-5.857 15.356 0 21.213 18.4 18.398 28.533 42.88 28.533 68.934s-10.133 50.536-28.533 68.934c-5.858 5.857-5.858 15.355 0 21.213 5.857 5.857 15.354 5.859 21.213 0 24.066-24.065 37.32-56.08 37.32-90.148s-13.254-66.081-37.32-90.146z"/><path d="m30 256c0-60.397 23.491-117.151 66.147-159.806 5.858-5.857 5.858-15.355 0-21.213-5.857-5.857-15.354-5.858-21.213 0-48.322 48.321-74.934 112.608-74.934 181.019s26.612 132.698 74.934 181.019c5.856 5.857 15.355 5.859 21.213 0 5.858-5.858 5.858-15.355 0-21.213-42.656-42.655-66.147-99.409-66.147-159.806z"/><path d="m94.219 256c0-43.232 16.815-83.855 47.349-114.387 5.858-5.858 5.858-15.355 0-21.213-5.857-5.858-15.355-5.857-21.213 0-36.2 36.197-56.136 84.355-56.136 135.6s19.936 99.403 56.136 135.601c5.866 5.865 15.363 5.85 21.213 0 5.857-5.858 5.857-15.355 0-21.213-30.534-30.532-47.349-71.156-47.349-114.388z"/><path d="m187.021 165.853c-5.857-5.858-15.355-5.858-21.213 0-24.066 24.065-37.32 56.08-37.32 90.148s13.254 66.083 37.32 90.148c5.866 5.865 15.363 5.85 21.213 0 5.858-5.858 5.857-15.356 0-21.213-18.4-18.398-28.533-42.88-28.533-68.934s10.133-50.536 28.533-68.934c5.857-5.859 5.857-15.357 0-21.215z"/><path d="m256 192.8c-34.849 0-63.2 28.352-63.2 63.2s28.352 63.2 63.2 63.2 63.2-28.352 63.2-63.2-28.351-63.2-63.2-63.2z"/></g></svg>
|
After Width: | Height: | Size: 2.1 KiB |
1
smart-hut/public/img/sensorOn.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<svg id="Layer_1" enable-background="new 0 0 512 512" height="512" viewBox="0 0 512 512" width="512" xmlns="http://www.w3.org/2000/svg"><g><path d="m415.853 437.019c-5.858-5.858-5.858-15.355 0-21.213 42.656-42.655 66.147-99.409 66.147-159.806s-23.491-117.151-66.147-159.806c-5.858-5.857-5.858-15.355 0-21.213 5.857-5.858 15.355-5.858 21.213 0 48.322 48.321 74.934 112.608 74.934 181.019s-26.612 132.698-74.934 181.019c-5.848 5.848-15.345 5.868-21.213 0z" fill="#7affe4"/><path d="m370.432 391.6c-5.857-5.858-5.857-15.355 0-21.213 30.533-30.531 47.349-71.155 47.349-114.387s-16.815-83.855-47.349-114.387c-5.858-5.858-5.858-15.355 0-21.213 5.857-5.857 15.355-5.858 21.213 0 36.2 36.198 56.136 84.355 56.136 135.601s-19.936 99.403-56.136 135.601c-5.86 5.858-15.356 5.855-21.213-.002z" fill="#00ddc1"/><path d="m324.979 346.148c-5.858-5.858-5.857-15.356 0-21.213 18.4-18.398 28.533-42.88 28.533-68.934s-10.133-50.536-28.533-68.934c-5.858-5.857-5.858-15.355 0-21.213 5.857-5.857 15.355-5.858 21.213 0 24.066 24.065 37.32 56.08 37.32 90.148s-13.254 66.083-37.32 90.148c-5.858 5.857-15.356 5.854-21.213-.002z" fill="#7affe4"/><path d="m415.853 437.019c5.868 5.868 15.365 5.848 21.213 0 48.322-48.321 74.934-112.608 74.934-181.019h-30c0 60.397-23.491 117.151-66.147 159.806-5.858 5.858-5.858 15.355 0 21.213z" fill="#00ddc1"/><path d="m370.432 391.6c5.856 5.856 15.353 5.859 21.213 0 36.2-36.198 56.136-84.355 56.136-135.601h-30c0 43.232-16.815 83.855-47.349 114.387-5.857 5.859-5.857 15.356 0 21.214z" fill="#00b4bc"/><path d="m324.979 346.148c5.857 5.857 15.354 5.859 21.213 0 24.066-24.065 37.32-56.08 37.32-90.148h-30c0 26.054-10.133 50.536-28.533 68.934-5.857 5.858-5.857 15.355 0 21.214z" fill="#00ddc1"/><path d="m74.934 437.019c-48.322-48.321-74.934-112.608-74.934-181.019s26.612-132.698 74.934-181.019c5.858-5.858 15.355-5.857 21.213 0 5.858 5.858 5.858 15.355 0 21.213-42.656 42.655-66.147 99.409-66.147 159.806s23.491 117.151 66.147 159.806c5.858 5.857 5.858 15.355 0 21.213-5.858 5.859-15.357 5.857-21.213 0z" fill="#7affe4"/><path d="m120.354 391.601c-36.199-36.198-56.135-84.355-56.135-135.601s19.936-99.403 56.136-135.601c5.858-5.857 15.356-5.857 21.213 0 5.857 5.858 5.857 15.355 0 21.213-30.534 30.533-47.349 71.156-47.349 114.388s16.815 83.855 47.349 114.387c5.858 5.858 5.858 15.355 0 21.213-5.85 5.85-15.347 5.866-21.214.001z" fill="#00ddc1"/><path d="m165.807 346.148c-24.066-24.065-37.32-56.08-37.32-90.148s13.254-66.083 37.32-90.148c5.858-5.858 15.356-5.857 21.213 0 5.858 5.858 5.857 15.356 0 21.213-18.4 18.398-28.533 42.88-28.533 68.934s10.133 50.536 28.533 68.934c5.858 5.857 5.858 15.355 0 21.213-5.85 5.852-15.347 5.867-21.213.002z" fill="#7affe4"/><path d="m96.147 437.019c5.858-5.858 5.858-15.355 0-21.213-42.656-42.655-66.147-99.409-66.147-159.806h-30c0 68.411 26.612 132.698 74.934 181.019 5.856 5.857 15.355 5.859 21.213 0z" fill="#00ddc1"/><path d="m141.568 391.6c5.857-5.858 5.857-15.355 0-21.213-30.534-30.531-47.349-71.155-47.349-114.387h-30c0 51.246 19.936 99.403 56.136 135.601 5.866 5.865 15.363 5.849 21.213-.001z" fill="#00b4bc"/><path d="m187.021 346.148c5.858-5.858 5.857-15.356 0-21.213-18.4-18.398-28.533-42.88-28.533-68.934h-30c0 34.068 13.254 66.083 37.32 90.148 5.865 5.864 15.362 5.849 21.213-.001z" fill="#00ddc1"/><circle cx="256" cy="256" fill="#00ddc1" r="63.2"/><path d="m256 319.2c34.849 0 63.2-28.352 63.2-63.2h-126.4c0 34.849 28.351 63.2 63.2 63.2z" fill="#00b4bc"/></g></svg>
|
After Width: | Height: | Size: 3.3 KiB |
48
smart-hut/public/img/switchOff.svg
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
|
||||
<g>
|
||||
<g>
|
||||
<path d="M336.709,74.843c-10.322-3.944-21.88,1.219-25.825,11.537c-3.945,10.316,1.22,21.879,11.536,25.824
|
||||
C393.115,139.239,442,207.384,442,286c0,102.561-83.439,186-186,186S70,388.561,70,286c0-78.659,48.908-146.766,119.573-173.793
|
||||
c10.317-3.946,15.481-15.509,11.536-25.825c-3.947-10.317-15.512-15.48-25.825-11.536C89.185,107.777,30,190.692,30,286
|
||||
c0,124.922,101.09,226,226,226c124.922,0,226-101.09,226-226C482,190.65,422.778,107.759,336.709,74.843z"/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path d="M256,0c-11.046,0-20,8.954-20,20v195.851c0,11.046,8.954,20,20,20s20-8.955,20-20V20C276,8.954,267.046,0,256,0z"/>
|
||||
</g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
48
smart-hut/public/img/switchOn.svg
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
|
||||
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="30" y1="258" x2="482" y2="258" gradientTransform="matrix(1 0 0 -1 0 514)">
|
||||
<stop offset="0" style="stop-color:#80D8FF"/>
|
||||
<stop offset="0.16" style="stop-color:#88D1FF"/>
|
||||
<stop offset="0.413" style="stop-color:#9FBEFE"/>
|
||||
<stop offset="0.725" style="stop-color:#C4A0FD"/>
|
||||
<stop offset="1" style="stop-color:#EA80FC"/>
|
||||
</linearGradient>
|
||||
<path style="fill:url(#SVGID_1_);" d="M256,512C131.09,512,30,410.922,30,286c0-95.308,59.185-178.223,145.284-211.154
|
||||
c10.313-3.944,21.878,1.219,25.825,11.536c3.945,10.316-1.219,21.879-11.536,25.825C118.908,139.234,70,207.341,70,286
|
||||
c0,102.561,83.439,186,186,186s186-83.439,186-186c0-78.616-48.885-146.761-119.58-173.796
|
||||
c-10.316-3.945-15.481-15.508-11.536-25.824c3.945-10.318,15.503-15.481,25.825-11.537C422.778,107.759,482,190.65,482,286
|
||||
C482,410.91,380.922,512,256,512z M276,215.851V20c0-11.046-8.954-20-20-20s-20,8.954-20,20v195.851c0,11.046,8.954,20,20,20
|
||||
C267.046,235.851,276,226.896,276,215.851z"/>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.5 KiB |
14
smart-hut/public/img/temperature-sensor.svg
Normal file
|
@ -0,0 +1,14 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" height="590pt" version="1.1" viewBox="-193 0 590 590.60879" width="590pt">
|
||||
<g id="surface1">
|
||||
<path d="M 163.433594 407.625 L 163.433594 61.121094 C 163.433594 27.363281 136.070312 0 102.308594 0 C 68.550781 0 41.1875 27.363281 41.1875 61.121094 L 41.1875 407.625 C -3.820312 441.386719 -12.945312 505.238281 20.8125 550.246094 C 54.574219 595.253906 118.425781 604.378906 163.433594 570.621094 C 208.441406 536.859375 217.566406 473.007812 183.808594 428 C 178.019531 420.277344 171.15625 413.421875 163.433594 407.625 Z M 163.433594 407.625 " style=" stroke:none;fill-rule:nonzero;fill:rgb(41.176471%,80%,84.313725%);fill-opacity:1;" />
|
||||
<path d="M 163.433594 407.625 L 163.433594 244.488281 L 41.1875 366.734375 L 41.1875 407.625 C -3.820312 441.386719 -12.945312 505.238281 20.8125 550.246094 C 54.574219 595.253906 118.425781 604.378906 163.433594 570.621094 C 208.441406 536.859375 217.566406 473.007812 183.808594 428 C 178.019531 420.277344 171.15625 413.421875 163.433594 407.625 Z M 163.433594 407.625 " style=" stroke:none;fill-rule:nonzero;fill:rgb(38.039216%,74.117647%,78.039216%);fill-opacity:1;" />
|
||||
<path d="M 143.058594 488.980469 C 143.058594 511.484375 124.816406 529.726562 102.308594 529.726562 C 79.804688 529.726562 61.5625 511.484375 61.5625 488.980469 C 61.5625 466.476562 79.804688 448.230469 102.308594 448.230469 C 124.816406 448.230469 143.058594 466.476562 143.058594 488.980469 Z M 143.058594 488.980469 " style=" stroke:none;fill-rule:nonzero;fill:rgb(92.941176%,19.215686%,14.117647%);fill-opacity:1;" />
|
||||
<path d="M 92.125 81.496094 L 112.496094 81.496094 L 112.496094 478.792969 L 92.125 478.792969 Z M 92.125 81.496094 " style=" stroke:none;fill-rule:nonzero;fill:rgb(92.941176%,19.215686%,14.117647%);fill-opacity:1;" />
|
||||
<path d="M 41.1875 356.546875 L 71.75 356.546875 L 71.75 376.921875 L 41.1875 376.921875 Z M 41.1875 356.546875 " style=" stroke:none;fill-rule:nonzero;fill:rgb(31.764706%,61.568627%,65.098039%);fill-opacity:1;" />
|
||||
<path d="M 41.1875 305.613281 L 71.75 305.613281 L 71.75 325.988281 L 41.1875 325.988281 Z M 41.1875 305.613281 " style=" stroke:none;fill-rule:nonzero;fill:rgb(31.764706%,61.568627%,65.098039%);fill-opacity:1;" />
|
||||
<path d="M 41.1875 254.675781 L 71.75 254.675781 L 71.75 275.050781 L 41.1875 275.050781 Z M 41.1875 254.675781 " style=" stroke:none;fill-rule:nonzero;fill:rgb(31.764706%,61.568627%,65.098039%);fill-opacity:1;" />
|
||||
<path d="M 41.1875 203.742188 L 71.75 203.742188 L 71.75 224.117188 L 41.1875 224.117188 Z M 41.1875 203.742188 " style=" stroke:none;fill-rule:nonzero;fill:rgb(31.764706%,61.568627%,65.098039%);fill-opacity:1;" />
|
||||
<path d="M 41.1875 152.804688 L 71.75 152.804688 L 71.75 173.179688 L 41.1875 173.179688 Z M 41.1875 152.804688 " style=" stroke:none;fill-rule:nonzero;fill:rgb(31.764706%,61.568627%,65.098039%);fill-opacity:1;" />
|
||||
<path d="M 41.1875 101.871094 L 71.75 101.871094 L 71.75 122.246094 L 41.1875 122.246094 Z M 41.1875 101.871094 " style=" stroke:none;fill-rule:nonzero;fill:rgb(31.764706%,61.568627%,65.098039%);fill-opacity:1;" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3 KiB |
BIN
smart-hut/public/smart-home.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
smart-hut/public/title.png
Normal file
After Width: | Height: | Size: 9 KiB |
BIN
smart-hut/public/title3.png
Normal file
After Width: | Height: | Size: 9 KiB |
BIN
smart-hut/public/title4.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
smart-hut/public/user-icon.png
Normal file
After Width: | Height: | Size: 134 KiB |
|
@ -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() {
|
||||
|
@ -113,7 +117,8 @@ class App extends Component {
|
|||
<Route path="/instruction" >
|
||||
<Instruction />
|
||||
</Route>
|
||||
<Route path="/forgot-pass-reset" >
|
||||
<Route path="/forgot-pass-reset" > </Route>
|
||||
<Route path="/password-reset" >
|
||||
<ChangePass query={this.state.query}/>
|
||||
</Route>
|
||||
<Route component={FourOhFour} />
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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 = () => (
|
|||
<Image src='title6.png' size='medium' centered/>
|
||||
)
|
||||
|
||||
const HeaderExampleIconProp = () => (
|
||||
<Header as='h2' icon='plug' color="white" content='Smart Hut' />
|
||||
)
|
||||
|
||||
|
||||
|
||||
const GridExampleInverted = () => (
|
||||
const GridExampleInverted = (props) => (
|
||||
<Grid columns='equal' divided inverted padded >
|
||||
<Grid.Row color='black' textAlign='center'>
|
||||
<Grid.Column width={2}>
|
||||
|
@ -57,7 +52,7 @@ const GridExampleInverted = () => (
|
|||
</Dropdown.Item>
|
||||
<Dropdown.Item>See profile...</Dropdown.Item>
|
||||
<Dropdown.Divider />
|
||||
<Dropdown.Item>Logout</Dropdown.Item>
|
||||
<Dropdown.Item onClick={props.logout }>Logout</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
</Grid.Column>
|
||||
|
@ -69,7 +64,7 @@ export default class MyHeader extends React.Component {
|
|||
render() {
|
||||
return (
|
||||
<div>
|
||||
<GridExampleInverted />
|
||||
<GridExampleInverted logout={this.props.logout} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import _ from "lodash";
|
||||
import React, { Component } from "react";
|
||||
import { render } from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Icon,
|
||||
|
|
|
@ -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 (
|
||||
<Grid centered>
|
||||
{
|
||||
|
|
|
@ -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)){
|
||||
|
@ -89,24 +55,116 @@ class Panel extends Component {
|
|||
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 (
|
||||
<div style={panelStyle}>
|
||||
<button style={editButtonStyle} onClick={this.editModeController}>Edit</button>
|
||||
<Grid doubling columns={5} divided="vertically">
|
||||
<Grid.Column>
|
||||
<Light onChangeData={this.changeDeviceData} device={devices[0]} edit={this.state.editMode}/>
|
||||
<Grid doubling columns={4} divided="vertically">
|
||||
{this.state.openSettingsModal ?
|
||||
<SettingsModal openModal={this.openModal}
|
||||
updateDevice={this.updateDevice}
|
||||
removeDevice={this.removeDevice}
|
||||
device={ds.filter(d => d.id === this.state.settingsDeviceId)[0]}/> : ""
|
||||
}
|
||||
{
|
||||
ds ?
|
||||
ds.map((e, i) => {
|
||||
|
||||
return (
|
||||
<Grid.Column key={i}>
|
||||
<DeviceType type={e.kind} onChangeData={this.changeDeviceData} device={e} edit={edit}/>
|
||||
</Grid.Column>
|
||||
)
|
||||
})
|
||||
:
|
||||
null
|
||||
}
|
||||
{
|
||||
this.props.activeItem !== -1 ?
|
||||
<Grid.Column>
|
||||
<SmartPlug onChangeData={this.changeDeviceData} device={devices[4]} edit={this.state.editMode}/>
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<Sensor onChangeData={this.changeDeviceData} device={devices[5]} edit={this.state.editMode}/>
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<NewDevice/>
|
||||
<NewDevice addDevice={this.addDevice} devices={ds}/>
|
||||
</Grid.Column>
|
||||
:
|
||||
null
|
||||
}
|
||||
</Grid>
|
||||
</div>
|
||||
)
|
||||
|
@ -114,21 +172,3 @@ class Panel extends Component {
|
|||
|
||||
}
|
||||
|
||||
|
||||
export default class DevicePanel extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
shownRoom: "All"
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Panel/>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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 (
|
||||
<StyledDiv onClick={this.props.edit ? () => {
|
||||
} : this.onClickDevice} style={{textAlign: "center"}}>
|
||||
<Settings
|
||||
deviceId={this.props.device.id}
|
||||
edit={this.props.edit}
|
||||
onChangeData={(id, newSettings) => this.props.onChangeData(id, newSettings)}/>
|
||||
<Image src={this.state.icon} style={iconStyle}/>
|
||||
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
||||
</StyledDiv>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,43 +1,12 @@
|
|||
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 (
|
||||
<Form style={formStyle}>
|
||||
<Form.Field>
|
||||
<label style={{color: "white"}}>New Device Name</label>
|
||||
<input name="new-name" placeholder='New name' onChange={this.onChangeHandler}/>
|
||||
</Form.Field>
|
||||
<Button type='submit' onClick={this.saveChanges}>Save</Button>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
import {editModeIconStyle, editModeStyle} from "./styleComponents";
|
||||
|
||||
|
||||
export default class Settings extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
displayForm: false,
|
||||
displayForm: true,
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -47,26 +16,18 @@ export default class Settings extends Component {
|
|||
|
||||
render() {
|
||||
const view = (
|
||||
<div>
|
||||
{this.state.displayForm ? (
|
||||
<SettingsForm id={this.props.deviceId} onChangeData={this.props.onChangeData}/>) : ("")}
|
||||
<div onClick={this.displayForm}>
|
||||
<div onClick={() => this.props.edit.openModal(this.props.deviceId)}>
|
||||
<span style={editModeStyle}>
|
||||
{!this.state.displayForm ? (
|
||||
<img
|
||||
src="/img/settings.svg"
|
||||
alt=""
|
||||
style={editModeIconStyle}/>)
|
||||
:
|
||||
<p style={{color: "white"}}>×</p>
|
||||
}
|
||||
style={editModeIconStyle}/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<React.Fragment>
|
||||
{this.props.edit ? view : ("")}
|
||||
{this.props.edit.mode ? view : ("")}
|
||||
</React.Fragment>
|
||||
)
|
||||
};
|
||||
|
|
|
@ -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 (<Light onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />)
|
||||
case "sensor":
|
||||
return <Sensor onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />
|
||||
case "dimmer":
|
||||
return <DefaultDimmer onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />
|
||||
case "smartplug":
|
||||
return <SmartPlug onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />
|
||||
case "switch":
|
||||
return <Switcher onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />
|
||||
case "light":
|
||||
return (<Light onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
export default DeviceType;
|
58
smart-hut/src/components/dashboard/devices/DigitalSensor.js
Normal file
|
@ -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 (
|
||||
<StyledDiv>
|
||||
<Settings
|
||||
deviceId={this.props.device.id}
|
||||
edit={this.props.edit}
|
||||
onChangeData={(id, newSettings) => this.props.onChangeData(id, newSettings)}/>
|
||||
<Image src={this.getIcon()} style={imageStyle}/>
|
||||
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
||||
</StyledDiv>
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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%)"
|
||||
};
|
|
@ -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);
|
||||
|
|
|
@ -7,18 +7,17 @@
|
|||
*/
|
||||
|
||||
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"
|
||||
|
@ -29,21 +28,20 @@ export default class Light extends Component {
|
|||
};
|
||||
|
||||
setIntensity = (newValue) => {
|
||||
this.setState({intensityLevel : newValue});
|
||||
this.setState({intensity: newValue});
|
||||
};
|
||||
|
||||
getIcon = () => {
|
||||
if(this.state.turnedOn){
|
||||
if (this.state.turnedOn) {
|
||||
return this.iconOn;
|
||||
}
|
||||
return this.iconOff;
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
if(this.props.device.hasOwnProperty("hasIntensity") && this.props.device.hasOwnProperty("intensityLevel")) {
|
||||
if (this.props.device.hasOwnProperty("intensity")) {
|
||||
this.setState({
|
||||
hasIntensity: this.props.device.hasIntensity,
|
||||
intensityLevel: this.props.device.intensityLevel
|
||||
intensity: this.props.device.intensity
|
||||
});
|
||||
}
|
||||
// Get the state and update it
|
||||
|
@ -54,7 +52,7 @@ export default class Light extends Component {
|
|||
render() {
|
||||
const intensityLightView = (
|
||||
<CircularInput
|
||||
value={this.state.intensityLevel}
|
||||
value={this.state.intensity}
|
||||
onChange={this.setIntensity}
|
||||
style={style}
|
||||
>
|
||||
|
@ -63,7 +61,7 @@ export default class Light extends Component {
|
|||
<CircularThumb/>
|
||||
|
||||
<text style={valueStyle} x={100} y={100} textAnchor="middle" dy="0.3em" fontWeight="bold">
|
||||
{Math.round(this.state.intensityLevel*100)}%
|
||||
{Math.round(this.state.intensity * 100)}%
|
||||
</text>
|
||||
<text style={intensityLightStyle} x={100} y={150} textAnchor="middle" dy="0.3em" fontWeight="bold">
|
||||
{this.props.device.name}
|
||||
|
@ -72,21 +70,21 @@ export default class Light extends Component {
|
|||
);
|
||||
|
||||
const normalLightView = (
|
||||
<StyledDiv onClick={this.props.edit ? () => {
|
||||
} : this.onClickDevice} style={{textAlign: "center"}}>
|
||||
<div onClick={this.props.edit.mode ? () => {
|
||||
} : this.onClickDevice}>
|
||||
<Image src={this.getIcon()} style={iconStyle}/>
|
||||
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<StyledDiv>
|
||||
<Settings
|
||||
deviceId={this.props.device.id}
|
||||
edit={this.props.edit}
|
||||
onChangeData={(id, newSettings) => this.props.onChangeData(id, newSettings)}/>
|
||||
<Image src={this.getIcon()} style={iconStyle}/>
|
||||
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
||||
{this.state.intensity ? (intensityLightView) : (normalLightView)}
|
||||
</StyledDiv>
|
||||
);
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
{this.state.hasIntensity ? (intensityLightView) : (normalLightView)}
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
};
|
||||
|
|
|
@ -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 <LightForm/>;
|
||||
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 (
|
||||
<Form style={addDeviceFormStyle}>
|
||||
<Form.Field>
|
||||
<label style={{color: "white"}}>Select the type of device</label>
|
||||
<Dropdown clearable options={options} selection/>
|
||||
</Form.Field>
|
||||
|
||||
<Button type='submit' onClick={this.saveChanges}>Save</Button>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 (
|
||||
<Form.Field>
|
||||
<label style={{color: "white"}}>Type of light</label>
|
||||
<Dropdown clearable options={options} selection/>
|
||||
</Form.Field>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default class NewDevice extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
openForm: false
|
||||
}
|
||||
step: 1,
|
||||
openModal : false
|
||||
};
|
||||
this.baseState = this.state
|
||||
this.createDevice = this.createDevice.bind(this);
|
||||
}
|
||||
|
||||
onClickDevice = (event) => {
|
||||
this.setState((prevState) => ({openForm: !prevState.openForm}));
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
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 = (
|
||||
<Dropdown
|
||||
name="typeOfDevice"
|
||||
placeholder='Select a Type of Device'
|
||||
fluid
|
||||
selection
|
||||
onChange={this.setTypeOfDevice}
|
||||
options={deviceOptions}
|
||||
/>
|
||||
);
|
||||
const step2 = (typeOfDevice) => {
|
||||
const deviceName = (<div>
|
||||
<Form.Field>
|
||||
<label>Device Name: </label>
|
||||
<Input fluid size={"large"} onChange={this.setDeviceName} focus placeholder='Device Name'/>
|
||||
</Form.Field>
|
||||
</div>);
|
||||
const sensorForm = (<Form.Field style={{marginTop : "1rem"}}>
|
||||
<label>Type of Sensor: </label>
|
||||
<Dropdown
|
||||
name="typeOfDevice"
|
||||
placeholder='Select a Type of Sensor'
|
||||
fluid
|
||||
selection
|
||||
onChange={this.setTypeOfSensor}
|
||||
options={sensorOptions}
|
||||
/>
|
||||
</Form.Field>);
|
||||
const switchDimmerOptions = (<Form.Field style={{marginTop : "1rem"}}>
|
||||
<label>Select the Lights You Want to Attach: </label>
|
||||
<Dropdown
|
||||
name="typeOfDevice"
|
||||
placeholder='Select Lights'
|
||||
fluid
|
||||
multiple
|
||||
onChange={this.setLightsDimmerSwitch}
|
||||
options={availableLights}
|
||||
/>
|
||||
</Form.Field>);
|
||||
return (
|
||||
<StyledDiv onClick={this.onClickDevice} style={{textAlign: "center"}}>
|
||||
<Form>
|
||||
{deviceName}
|
||||
{this.state.typeOfDevice === "sensor" ? (sensorForm) : ""}
|
||||
{this.state.typeOfDevice === "switch" || this.state.typeOfDevice === "dimmer" ?
|
||||
(switchDimmerOptions) : ""
|
||||
}
|
||||
</Form>
|
||||
)
|
||||
};
|
||||
const steps = [step1, step2()];
|
||||
return (
|
||||
<Modal closeIcon open={this.state.openModal} onClose={this.resetState} trigger={<StyledDiv onClick={this.handleOpen}>
|
||||
<Image src="/img/add.svg" style={{filter: "invert()"}}/>
|
||||
{this.state.openForm ? (
|
||||
<NewDeviceForm/>
|
||||
</StyledDiv>} centered={true}>
|
||||
<Modal.Header>Add a New Device</Modal.Header>
|
||||
<Modal.Content>
|
||||
{steps[this.state.step -1]}
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
{this.state.step > 1 ? (
|
||||
<Button onClick={this.previousStep} color="blue" icon labelPosition='left'>
|
||||
<Icon name='left arrow'/>
|
||||
Back
|
||||
</Button>
|
||||
) : ""}
|
||||
</StyledDiv>
|
||||
{this.state.step < steps.length ? (
|
||||
<Button color="blue" onClick={this.nextStep} icon labelPosition='right'>
|
||||
Next
|
||||
<Icon name='right arrow'/>
|
||||
</Button>
|
||||
) : ""}
|
||||
{this.state.step === steps.length ? (
|
||||
<Button onClick={this.createDevice} color="blue" icon labelPosition='right'>
|
||||
<Icon name='up arrow'/>
|
||||
Finish
|
||||
</Button>
|
||||
) : ""}
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,21 +9,23 @@
|
|||
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 {
|
||||
export default class Sensor extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
turnedOn: false,
|
||||
value: 20,
|
||||
error : 2.4
|
||||
error: 2.4
|
||||
};
|
||||
this.units = "ºC"
|
||||
}
|
||||
|
||||
setName = () => {
|
||||
if(this.props.device.name.length > 15){
|
||||
return this.props.device.name.slice(0,12) + "..."
|
||||
if (this.props.device.name.length > 15) {
|
||||
return this.props.device.name.slice(0, 12) + "..."
|
||||
}
|
||||
return this.props.device.name;
|
||||
};
|
||||
|
@ -34,13 +36,18 @@ export default class Light extends Component {
|
|||
|
||||
render() {
|
||||
return (
|
||||
<StyledDiv>
|
||||
<Settings
|
||||
deviceId={this.props.device.id}
|
||||
edit={this.props.edit}
|
||||
onChangeData={(id, newSettings) => this.props.onChangeData(id, newSettings)}/>
|
||||
|
||||
<CircularInput
|
||||
value={this.state.value/100}
|
||||
value={this.state.value / 100}
|
||||
style={style}
|
||||
>
|
||||
<CircularTrack/>
|
||||
<CircularProgress/>
|
||||
|
||||
<text style={valueStyle} x={100} y={80} textAnchor="middle" dy="0.3em" fontWeight="bold">
|
||||
{Math.round(this.state.value)}{this.units}
|
||||
</text>
|
||||
|
@ -51,6 +58,7 @@ export default class Light extends Component {
|
|||
{this.setName()}
|
||||
</text>
|
||||
</CircularInput>
|
||||
</StyledDiv>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
90
smart-hut/src/components/dashboard/devices/SettingsModal.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
import React, {Component, useState} from 'react';
|
||||
import {Button, Checkbox, Form, Icon, Header, Modal} from "semantic-ui-react";
|
||||
|
||||
const DeleteModal = (props) => (
|
||||
<Modal trigger={<Button color='red'>Remove</Button>} closeIcon>
|
||||
<Header icon='archive' content='Are you sure ?' />
|
||||
<Modal.Actions>
|
||||
<Button color='red'>
|
||||
<Icon name='remove' /> No
|
||||
</Button>
|
||||
<Button onClick={() => props.removeDevice()} color='green'>
|
||||
<Icon name='checkmark' /> Yes
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
)
|
||||
|
||||
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 (
|
||||
<Form>
|
||||
<Form.Field>
|
||||
<label>New Name: </label>
|
||||
<input autoComplete="off" name="name" onChange={handleInputChange} value={values.name} placeholder='Device name'/>
|
||||
</Form.Field>
|
||||
|
||||
{props.type === "smart-plug" ? (
|
||||
<Form.Field>
|
||||
<Checkbox slider name={"reset"} onClick={handleCheckboxChange} label='Reset Energy Consumption'/>
|
||||
</Form.Field>
|
||||
) : ""}
|
||||
<Form.Field>
|
||||
<DeleteModal removeDevice={() => props.removeDevice(values)} />
|
||||
</Form.Field>
|
||||
<Button onClick={() => props.saveFunction(values)} color="blue" type='submit'>Save</Button>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
|
||||
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 = () => (
|
||||
<Modal open={true} onOpen={this.props.openModal} onClose={this.props.openModal}>
|
||||
<Modal.Header>Settings of {this.props.device.name}</Modal.Header>
|
||||
<Modal.Content>
|
||||
<SettingsForm type={this.props.device.type} removeDevice={this.props.removeDevice} saveFunction={this.saveSettings}/>
|
||||
</Modal.Content>
|
||||
</Modal>
|
||||
);
|
||||
return (
|
||||
<SettingsModal/>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -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 (
|
||||
<StyledDiv onClick={this.props.edit ? () => {} : this.onClickDevice} style={{textAlign: "center"}}>
|
||||
<StyledDiv onClick={this.props.edit.mode ? () => {} : this.onClickDevice}>
|
||||
<Settings
|
||||
deviceId={this.props.device.id}
|
||||
edit={this.props.edit}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {iconStyle} from "./styleComponents";
|
||||
|
||||
export const energyConsumedStyle = {
|
||||
color : "black",
|
||||
fontSize : "1.3rem",
|
||||
position: "absolute",
|
||||
top: "30%",
|
||||
|
@ -17,3 +17,11 @@ export const imageStyle = {
|
|||
transform: "translateX(-50%)",
|
||||
filter: "drop-shadow( 1px 1px 0.5px rgba(0, 0, 0, .25))"
|
||||
};
|
||||
|
||||
export const nameStyle = {
|
||||
color : "black",
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translateX(-50%)"
|
||||
};
|
||||
|
|
52
smart-hut/src/components/dashboard/devices/Switch.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Users can add on-off switches. A on-off switch can turn on (or off) lights.
|
||||
* If a light has an intensity level, when it gets switched back on, it gets the last available
|
||||
* intensity level that was set by the user (or 100% if no such level exists).
|
||||
* The user can change the state of a switch through the SmartHut interface.
|
||||
*/
|
||||
|
||||
import React, {Component} from 'react';
|
||||
import {StyledDiv} from "./styleComponents";
|
||||
import Settings from "./DeviceSettings";
|
||||
import {Image} from "semantic-ui-react";
|
||||
import {imageStyle, nameStyle} from "./SwitchStyle";
|
||||
|
||||
export default class Switch extends Component {
|
||||
constructor(props){
|
||||
super(props);
|
||||
this.state = {
|
||||
turnedOn: false,
|
||||
pointingLights : []
|
||||
};
|
||||
this.iconOn = "/img/switchOn.svg";
|
||||
this.iconOff = "/img/switchOff.svg";
|
||||
}
|
||||
|
||||
onClickDevice = () => {
|
||||
this.setState((prevState) => ({turnedOn: !prevState.turnedOn}));
|
||||
};
|
||||
|
||||
getIcon = () => {
|
||||
if(this.state.turnedOn){
|
||||
return this.iconOn;
|
||||
}
|
||||
return this.iconOff;
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
}
|
||||
|
||||
render(){
|
||||
return (
|
||||
<StyledDiv onClick={this.props.edit.mode ? () => {} : this.onClickDevice}>
|
||||
<Settings
|
||||
deviceId={this.props.device.id}
|
||||
edit={this.props.edit}
|
||||
onChangeData={(id, newSettings) => this.props.onChangeData(id, newSettings)}/>
|
||||
<Image src={this.getIcon()} style={imageStyle}/>
|
||||
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
||||
</StyledDiv>
|
||||
)
|
||||
}
|
||||
}
|
17
smart-hut/src/components/dashboard/devices/SwitchStyle.js
Normal file
|
@ -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%)"
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
<div>
|
||||
|
||||
{this.props.type === "new" ?
|
||||
<Button icon labelPosition='left' inverted onClick={this.openModal}>
|
||||
<Icon name='plus' size='small'/>
|
||||
ADD ROOM
|
||||
</Button>
|
||||
:
|
||||
null
|
||||
}
|
||||
|
||||
<Modal
|
||||
onClose={this.closeModal}
|
||||
open={this.state.openModal}>
|
||||
<Header>{this.props.type == "new" ? "Add new room" : "Modify room" }</Header>
|
||||
<Header>{this.props.type === "new" ? "Add new room" : "Modify room" }</Header>
|
||||
<Modal.Content>
|
||||
<Form>
|
||||
<p>Insert the name of the room:</p>
|
||||
<Form.Field>
|
||||
<Input label='Room name' placeholder='Room Name' name="name" type='text' onChange={this.changeSomething}/>
|
||||
<Input label='Room name' placeholder='Room Name' name="name" type='text' onChange={this.changeSomething}
|
||||
value={this.props.type === "new" ? null : this.props.idRoom.name }/>
|
||||
</Form.Field>
|
||||
<p>Insert an image of the room:</p>
|
||||
<Form.Field>
|
||||
<Input label='Room image' type='file' name="img" onChange={this.changeSomething}/>
|
||||
<Input label='Room image' type='file' name="img" onChange={this.changeSomething}
|
||||
value={this.props.type === "new" ? null : this.props.idRoom.images }/>
|
||||
</Form.Field>
|
||||
</Form>
|
||||
|
||||
<div style={spaceDiv}>
|
||||
<p>Select an icon:</p>
|
||||
<SelectIcons updateIcon={this.updateIcon} currentIcon={this.state.selectedIcon}/>
|
||||
<SelectIcons updateIcon={this.updateIcon} currentIcon={this.props.type === "new" ? "home" : this.props.idRoom.icon }/>
|
||||
</div>
|
||||
|
||||
{this.props.type == "modify" ?
|
||||
{this.props.type === "modify" ?
|
||||
<Button icon labelPosition='left' inverted color='red' onClick={this.deleteRoom}>
|
||||
<Icon name='trash alternate' />
|
||||
Delete room
|
||||
|
@ -98,11 +115,14 @@ export default class ModalWindow extends Component {
|
|||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button color='red' onClick={this.closeModal}>
|
||||
<Icon name='remove' /> {this.props.type == "new" ? "Cancel" : "Discard changes" }
|
||||
<Icon name='remove' /> {this.props.type === "new" ? "Cancel" : "Discard changes" }
|
||||
</Button>
|
||||
<Button color='green' onClick={this.addRoomModal}>
|
||||
<Icon name='checkmark' /> {this.props.type == "new" ? "Add room" : "Save changes" }
|
||||
|
||||
|
||||
<Button color='green' onClick={this.props.type === "new" ? this.addRoomModal : this.modifyRoomModal}>
|
||||
<Icon name='checkmark' /> {this.props.type === "new" ? "Add room" : "Save changes"}
|
||||
</Button>
|
||||
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
</div>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,13 +66,63 @@ 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(
|
||||
|
@ -63,16 +130,16 @@ export default class Dashboard extends Component{
|
|||
<Grid >
|
||||
<Grid.Row color='black'>
|
||||
<Grid.Column>
|
||||
<MyHeader />
|
||||
<MyHeader logout={this.props.logout} />
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row color='black'>
|
||||
<Grid.Column width={3}>
|
||||
<Navbar addRoom={this.addRoom} rooms={this.state.rooms} handleItemClick={this.handleItemClick}/>
|
||||
<Navbar addRoom={this.addRoom} deleteRoom={this.deleteRoom} rooms={this.state.rooms} handleItemClick={this.handleItemClick}/>
|
||||
</Grid.Column>
|
||||
|
||||
<Grid.Column width={13}>
|
||||
<DevicePanel />
|
||||
<DevicePanel tkn={this.props.tkn} activeItem={this.state.activeItem} addDevice={this.addDevice} devices={this.state.devices} />
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
|
|
@ -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 <Redirect to="/" />
|
||||
}
|
||||
// else set a message that an email has been sent
|
||||
}).catch(err => {
|
||||
|
|
107
smart-hut/src/views/ForgotPassword.js
Normal file
|
@ -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 (
|
||||
<Message
|
||||
onDismiss={this.handleDismiss}
|
||||
header='Link has been sent!'
|
||||
content='An e-mail has been sent your address, please follow the
|
||||
instruction to create a new password'
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<p>
|
||||
<br />
|
||||
<i>The message will return in 2s</i>
|
||||
<br />
|
||||
<br />
|
||||
</p>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const MessageReg = () => (
|
||||
<Grid>
|
||||
<HomeNavbar />
|
||||
<Divider />
|
||||
<Grid.Row height={3}>
|
||||
</Grid.Row>
|
||||
<Grid.Row height={3}>
|
||||
</Grid.Row>
|
||||
<Grid.Row height={3}>
|
||||
</Grid.Row>
|
||||
<Grid.Row height={3}>
|
||||
<Grid.Column width={6}>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={10}>
|
||||
<Image src='title5.png' />
|
||||
</Grid.Column>
|
||||
<Grid.Column width={3}>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row height={3}>
|
||||
</Grid.Row>
|
||||
<Grid.Row height={3}>
|
||||
</Grid.Row>
|
||||
<Grid.Column width={3}>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={4}>
|
||||
<Image src='./img/logo.png' />
|
||||
</Grid.Column>
|
||||
<Grid.Column width={6}>
|
||||
<Paragraph />
|
||||
</Grid.Column>
|
||||
<Grid.Column width={4}>
|
||||
</Grid.Column>
|
||||
<Grid.Row height={3}>
|
||||
</Grid.Row>
|
||||
<Grid.Row height={3}>
|
||||
</Grid.Row>
|
||||
<Grid.Row height={3}>
|
||||
<Grid.Column width={3}>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={10}>
|
||||
<Divider />
|
||||
</Grid.Column>
|
||||
<Grid.Column width={3}>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
)
|
||||
|
||||
export default class ForgotPasswrod extends React.Component {
|
||||
render () {
|
||||
return (
|
||||
<MessageReg />
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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 (
|
||||
<div style={{height : "110vh", background: '#1b1c1d'}}>
|
||||
<Grid centered>
|
||||
<Grid.Row>
|
||||
<Header as='h1'>404</Header>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column width={10}>
|
||||
<Message>
|
||||
<Message.Header>404 Page Not Found</Message.Header>
|
||||
<p>
|
||||
Hey what are you doing here?
|
||||
Go back to our homepage <Link to="/"/>
|
||||
Looks like you are lost, this room does not exist.
|
||||
</p>
|
||||
</Message>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={6}>
|
||||
<Button >
|
||||
<Link to="/">Go back to our main room</Link>
|
||||
</Button>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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 (
|
||||
<Responsive getWidth={getWidth} minWidth={Responsive.onlyTablet.minWidth}>
|
||||
|
|
|
@ -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 (<ModalWindow type="new"/>)
|
||||
}
|
||||
}
|
||||
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.props.handleItemClick(e)
|
||||
this.setState({ activeItem: id,
|
||||
activeRoom: obj
|
||||
});
|
||||
this.props.handleItemClick(id)
|
||||
}
|
||||
|
||||
render(){
|
||||
const { activeItem } = this.state
|
||||
//const { activeItem } = this.state
|
||||
return (
|
||||
<div>
|
||||
<Segment.Group>
|
||||
|
@ -40,8 +44,10 @@ class Navbar extends Component {
|
|||
<Grid.Row color='black'>
|
||||
<Menu inverted fluid vertical>
|
||||
<Menu.Item
|
||||
key={-1}
|
||||
id={-1}
|
||||
name='Home'
|
||||
active={activeItem === 'Home'}
|
||||
active={this.state.activeItem === 'Home'}
|
||||
onClick={this.handleClick}
|
||||
>
|
||||
<Grid>
|
||||
|
@ -50,7 +56,7 @@ class Navbar extends Component {
|
|||
<Icon name="home" size="small"/>
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
Home
|
||||
HOME
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
@ -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}
|
||||
>
|
||||
<Grid>
|
||||
<Grid.Row>
|
||||
<Grid.Column width={1}>
|
||||
<Grid.Column>
|
||||
<Icon name={e.icon} size="small"/>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={12}>
|
||||
<Grid.Column width={8}>
|
||||
{e.name}
|
||||
</Grid.Column>
|
||||
<Grid.Column width={1}>
|
||||
<Icon name="pencil" size="small"/>
|
||||
<Grid.Column floated="right">
|
||||
{this.state.edit ?
|
||||
<ModalWindow type="modify" idRoom={e} modifyRoom={this.props.updateRoom} deleteRoom={this.props.deleteRoom}/>
|
||||
: null
|
||||
}
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
||||
</ Menu.Item>
|
||||
|
||||
)
|
||||
}) : null
|
||||
}
|
||||
|
||||
<Menu.Item
|
||||
name='newM'
|
||||
active={activeItem === 'Plus'}
|
||||
active={this.state.activeItem === 'newM'}
|
||||
>
|
||||
|
||||
<Grid>
|
||||
<Grid.Row centered onClick={this.showForm} name='new'>
|
||||
|
||||
<Grid.Row centered name='new'>
|
||||
<ModalWindow type="new" addRoom={this.props.addRoom}/>
|
||||
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
||||
|
@ -105,7 +111,7 @@ class Navbar extends Component {
|
|||
</Grid>
|
||||
</Responsive>
|
||||
<Responsive as={Segment} maxWidth={768}>
|
||||
//dropdown menu
|
||||
|
||||
</Responsive>
|
||||
</Segment.Group>
|
||||
</div>
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
import React, {Component} from 'react';
|
||||
import {Button } from 'semantic-ui-react';
|
||||
|
||||
|
||||
export default class NavbarTest extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<h1>Ciao</h1>
|
||||
)
|
||||
}
|
||||
}
|
11
smart-hut/src/views/TestHeaderController.js
Normal file
|
@ -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 (
|
||||
<HeaderController/>
|
||||
)
|
||||
}
|
||||
}
|