diff --git a/imports/ui/About.jsx b/imports/ui/About.jsx
index 100ac31..10557eb 100644
--- a/imports/ui/About.jsx
+++ b/imports/ui/About.jsx
@@ -1,9 +1,36 @@
import React from 'react'
+import { Container, Row, Col} from 'react-bootstrap';
+
export default function About() {
return (
-
- About
-
+ <>
+
+
+
+ About
+
+
+
+ This is the frontend for the SmartGarden project in Embedded Systems.
+
+
+
+
+
+ Created by
+
+
+ Timo Volkmann, Andrés Uribe Stengel, Sebastian Herzog and Maximilian Seyfried
+
+
+
+
+ >
)
}
diff --git a/imports/ui/ActivatePlant.jsx b/imports/ui/ActivatePlant.jsx
new file mode 100644
index 0000000..f953b03
--- /dev/null
+++ b/imports/ui/ActivatePlant.jsx
@@ -0,0 +1,85 @@
+import React from 'react'
+import { Button, Form} from 'react-bootstrap';
+
+class ActivatePlant extends React.Component{
+
+ constructor(props){
+ super(props);
+ this.state = {
+ name: '',
+ isActivationButtonDisabled: false,
+ }
+ }
+
+ handleChange = (e) => {
+ // console.log(e.target.id, e.target.value);
+
+ /*
+ if (activePlant !== 'undefined'){
+ if (activePlant !== this.state.name) {
+ this.setState({
+ isActivationButtonDisabled: false
+ })
+ }
+ }*/
+
+ this.setState({
+ [e.target.id]: e.target.value
+ });
+ }
+
+ // search for arrow function for further syntax knowledge
+ handleActivation = (e) => {
+ e.preventDefault();
+
+ let activatedPlant
+ this.props.plants.map(plant =>{
+ if (plant.name === this.state.name){
+ activatedPlant = plant
+ }
+ })
+
+ // activePlant = activatedPlant.name
+
+ this.props.activatePlant(activatedPlant)
+
+ /*
+ this.setState({
+ isActivationButtonDisabled: true
+ })*/
+ }
+
+
+
+ render (){
+ return (
+ <>
+ {
+ this.props.plants.length !== 0 ?
+
+ Active plant:
+
+
+ {this.props.plants.map((plant, index) =>{
+ return
+ })}
+
+
+
+
+ :null
+ }
+ >
+ );
+ }
+}
+
+export default ActivatePlant;
+
diff --git a/imports/ui/AddPlant.jsx b/imports/ui/AddPlant.jsx
new file mode 100644
index 0000000..0121cc4
--- /dev/null
+++ b/imports/ui/AddPlant.jsx
@@ -0,0 +1,73 @@
+import React from 'react'
+import { Button, Form, Container, Row, Col, Table } from 'react-bootstrap';
+
+class AddPlant extends React.Component{
+
+ constructor(props){
+ super(props);
+ this.state = {
+ name: '',
+ type: ''
+ }
+ }
+
+ handleChange = (e) => {
+ // console.log(e.target.id, e.target.value); // e.target.id reference to the state which is changed
+ this.setState({
+ [e.target.id]: e.target.value
+ });
+ }
+
+ // search for arrow function for further syntax knowledge
+ handleSubmit = (e) => {
+ e.preventDefault();
+ //console.log(this.state)
+
+ this.props.addPlant(this.state)
+
+ this.setState({ // reset state
+ name: '',
+ type: ''
+ })
+ }
+
+
+
+ render (){
+ return (
+ <>
+
+ Name:
+ {this.nameInput=(input)}}
+ placeholder="plant"
+ onChange={this.handleChange} />
+
+
+ Type:
+
+
+ {this.props.typeArray.map((type, index) =>{
+ return
+ })}
+
+
+
+
+ >
+ );
+ }
+}
+
+export default AddPlant;
+
diff --git a/imports/ui/App.jsx b/imports/ui/App.jsx
index 5bb61bd..7069c24 100644
--- a/imports/ui/App.jsx
+++ b/imports/ui/App.jsx
@@ -24,7 +24,9 @@ function App() {
-
+
+
+
diff --git a/imports/ui/NavigationBar.jsx b/imports/ui/NavigationBar.jsx
index b6ae2f0..4bd216c 100644
--- a/imports/ui/NavigationBar.jsx
+++ b/imports/ui/NavigationBar.jsx
@@ -1,18 +1,23 @@
import React from 'react'
import { Navbar, Nav, NavDropdown } from 'react-bootstrap';
+//import logo from '../../client/public/SmartGarden.svg';
+
export default function NavigationBar() {
return (
-
https://forums.meteor.com/t/importing-assets-image/30266/2
+
+
{' '}
+ />{' '}
+ */}
SmartGarden
@@ -20,13 +25,16 @@ export default function NavigationBar() {
diff --git a/imports/ui/Plants.jsx b/imports/ui/Plants.jsx
new file mode 100644
index 0000000..17fce26
--- /dev/null
+++ b/imports/ui/Plants.jsx
@@ -0,0 +1,37 @@
+import React from 'react'
+import { Table, Button } from 'react-bootstrap';
+
+const Plants = ({plants, deletePlant}) => {
+
+ return (
+ <>
+ {
+ plants.length !== 0 ?
+
+
+
+ | Plant name |
+ Plant type |
+ |
+
+
+
+ {
+ plants.map((plant, index) => {
+ return
+ | {plant.name} |
+ {plant.type} |
+ |
+
+ })
+ }
+
+
+ : null
+ }
+ >
+ );
+
+}
+
+export default Plants
\ No newline at end of file
diff --git a/imports/ui/Settings.jsx b/imports/ui/Settings.jsx
index e1cad0c..a06b24f 100644
--- a/imports/ui/Settings.jsx
+++ b/imports/ui/Settings.jsx
@@ -1,26 +1,43 @@
import React from 'react'
+import { Container, Row, Col} from 'react-bootstrap';
-import { Button, Form, Container, Row, Col, Table } from 'react-bootstrap';
+import AddPlant from './AddPlant'
+import Plants from './Plants'
+import ActivatePlant from './ActivatePlant'
class Settings extends React.Component{
constructor(props){
super(props);
this.state = {
- name: '',
- type: '',
- dirt: '',
plants: [],
types: ['Chile', 'Mint'], // hardcoded for now
- dirts: ['Vegetable Soil', 'Potting Soil'], // hardcoded for now
- updateId: -1,
- btnName: 'submit'
}
}
- componentDidMount(){
- // fetch data from db here
-
+ // pass this function to the addplant comp as a prop
+ addPlant = (plant) => {
+ plant.id = this.state.plants.length + 1 // TODO rework
+
+ let plants = [...this.state.plants, plant]; // create a copy of the array and add the new plant to it
+
+ this.setState({
+ plants: plants
+ })
+ }
+
+ deletePlant = (id) => {
+ let plants = this.state.plants.filter(plant =>{ // callback function
+ return plant.id !== id // when it returns false (the id is the same), it filters this object out of the array
+ })
+ this.setState({
+ plants: plants
+ })
+ }
+
+ activatePlant = (plant) => {
+ console.log('The plant ' + plant.name + ' will be monitored')
+ // TODO head for activate logic
}
render(){
@@ -38,50 +55,10 @@ class Settings extends React.Component{
- {
- this.state.updateId >= 0 | this.state.plants.length === 0? // show the form only if we edit the plant or there is no plant set yet
-
- Name
- {this.nameInput=(input)}}
- placeholder="plant"
- onChange={(e)=>this.setState({name:e.target.value})} />
-
-
- Type
- this.setState({type:e.target.value})}
- >
-
- {this.state.types.map((type, index) => {
- return
- })}
-
-
-
- Dirt
- this.setState({dirt:e.target.value})}
- >
-
- {this.state.dirts.map((dirt, index) => {
- return
- })}
-
-
-
-
- :null
- }
+
@@ -90,34 +67,16 @@ class Settings extends React.Component{
- {
- this.state.plants.length !== 0?
-
-
-
- | Plant name |
- Plant type |
- Dirt type |
- |
- |
-
-
-
- {
- this.state.plants.map((plant, index) => {
- return
- | {plant[0]} |
- {plant[1]} |
- {plant[2]} |
- |
- |
-
- })
- }
-
-
- : null
- }
+
+
+
+
@@ -125,57 +84,6 @@ class Settings extends React.Component{
);
}
- // search for arrow function for further syntax knowledge
- handleSubmit = (e) => {
- e.preventDefault();
- if (this.state.updateId >= 0) { // check if it is in edit mode
- this.state.plants[this.state.updateId][0] = this.state.name;
- this.state.plants[this.state.updateId][1] = this.state.type;
- this.state.plants[this.state.updateId][2] = this.state.dirt; // updates the name of the plant
- this.setState({
- updateId:-1, // Todo check docu
- name:'', // reset inputtext again
- btnName:'submit' // reset button to submit again
- })
- } else {
- let newDataElement = [
- this.state.name,
- this.state.type,
- this.state.dirt
- ]
- console.log("name " + newDataElement[0])
- console.log("type " + newDataElement[1])
- console.log("dirt " + newDataElement[2])
- this.setState(prevState =>({
- plants:[...prevState.plants, newDataElement], // adds a new plant array
- name:'' //to reset the inputfield
- }))
- return this.state.plants;
- }
-
- }
-
-
- removeItem = (value) => {
- this.setState({
- plants:this.state.plants.filter((plant) => { // filter function add docu
- return plant !== value;
- }),
- name:''
- })
- }
-
- editItem = (editedName, editedType, editedDirt, index) => {
- this.setState({
- name:editedName,
- type:editedType,
- dirt:editedDirt,
- btnName:'update',
- updateId:index // should be edited to a boolean
- })
- }
-
-
}
export default Settings;