Skip to content

Commit 516a2e4

Browse files
authored
Merge pull request #16 from ucfcs/feature/dynamic-table
Feature/dynamic table
2 parents 78890ef + d0a2919 commit 516a2e4

4 files changed

Lines changed: 86 additions & 65 deletions

File tree

duct-drone-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"dependencies": {
3434
"body-parser": "^1.19.0",
35+
"cors": "^2.8.5",
3536
"express": "^4.16.4",
3637
"mongodb": "^3.2.2",
3738
"mongoose": "^5.4.22",

duct-drone-app/server/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const express = require('express');
22
const path = require('path');
33
const mongoose = require('mongoose');
44
const bodyParser = require('body-parser');
5+
const cors = require('cors');
56
const entryRoute = require('./routes/entry');
67
const mapRoute = require('./routes/map');
78

@@ -13,7 +14,8 @@ const port = process.env.PORT || 5000;
1314

1415
const bodyParserJSON = bodyParser.json();
1516
const bodyParserURLEncoded = bodyParser.urlencoded({ extended: true });
16-
// respond with "hello world" when a GET request is made to the homepage
17+
18+
app.use(cors());
1719
app.use(express.static(path.join(__dirname, '../build')));
1820

1921
// create a GET route

duct-drone-app/src/App.jsx

Lines changed: 79 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,90 +19,103 @@ import './App.css';
1919
class App extends Component {
2020
constructor(props){
2121
super(props);
22-
this.escFunction = this.escFunction.bind(this);
22+
this.state = {
23+
logData: [],
24+
};
25+
this.keyRecord = this.keyRecord.bind(this);
2326
}
24-
escFunction = (event) => {
25-
console.log(event.key);
27+
keyRecord = (event) => {
28+
// console.log(event.key);
2629
}
2730
componentDidMount(){
28-
document.addEventListener("keydown", this.escFunction, false);
31+
document.addEventListener("keydown", this.keyRecord, false);
32+
fetch('http://localhost:5000/api/get/maps',
33+
{
34+
method: 'GET',
35+
})
36+
.then(response => response.json())
37+
.then(data => {
38+
this.setState({logData: data});
39+
});
2940
}
3041
componentWillUnmount(){
31-
document.removeEventListener("keydown", this.escFunction, false);
42+
document.removeEventListener("keydown", this.keyRecord, false);
3243
}
3344
render() {
34-
const currentDataCols = [
35-
{
36-
Header: 'Temperature',
37-
accessor: 'currentTemp',
38-
},
39-
{
40-
Header: 'Air Velocity',
41-
accessor: 'currentAirVelocity',
42-
},
43-
];
44-
const currentData = [{
45-
id: 23,
46-
currentTemp: '90 F',
47-
currentAirVelocity: '30 m/s',
48-
}];
45+
Number.prototype.pad = function(size) {
46+
var s = String(this);
47+
while (s.length < (size || 2)) {s = "0" + s;}
48+
return s;
49+
}
50+
const { logData } = this.state;
4951
const logCols = [
50-
{
51-
Header: 'Date',
52-
accessor: 'date',
53-
},
5452
{
5553
Header: 'Time',
5654
accessor: 'time',
55+
Cell: row=> {
56+
const date = new Date(row.row.time);
57+
return(
58+
<div>
59+
<span>{date.getHours().pad(2)}:{date.getMinutes().pad(2)}</span>
60+
</div>
61+
);
62+
63+
}
5764
},
5865
{
5966
Header: 'Temperature',
60-
accessor: 'logTemp',
67+
accessor: 'temperature.$numberDecimal',
6168
},
6269
{
6370
Header: 'Air Velocity',
64-
accessor: 'airVelocity',
71+
accessor: 'air_velocity.$numberDecimal',
6572
},
6673
{
67-
Header: 'Location',
68-
accessor: 'location',
74+
Header: 'X',
75+
accessor: 'coordinateX',
76+
Cell: row => {
77+
return(
78+
<div>
79+
<span>{row.row._original.coordinates.x}</span>
80+
</div>
81+
);
82+
}
6983
},
70-
{
71-
Header: 'Battery',
72-
accessor: 'batteryLevel',
73-
},
74-
84+
{
85+
Header: 'Y',
86+
accessor: 'coordinateY',
87+
Cell: row => {
88+
return(
89+
<div>
90+
<span>{row.row._original.coordinates.y}</span>
91+
</div>
92+
);
93+
},
94+
},
95+
{
96+
Header: 'Z',
97+
accessor: 'coordinateZ',
98+
Cell: row => {
99+
return(
100+
<div>
101+
<span>{row.row._original.coordinates.z}</span>
102+
</div>
103+
);
104+
}
105+
}
75106
];
76-
const logData = [
77-
{
78-
id: 3535,
79-
date: '8/13/19',
80-
time: '3:00 PM',
81-
logTemp: '93 F',
82-
airVelocity: '30 m/s',
83-
location: '90 N 35 E',
84-
batteryLevel: '30%',
85-
},
107+
const currentCols = [
86108
{
87-
id: 3535,
88-
date: '8/13/19',
89-
time: '3:00 PM',
90-
logTemp: '93 F',
91-
airVelocity: '30 m/s',
92-
location: '90 N 35 E',
93-
batteryLevel: '30%',
109+
Header: 'Temperature',
110+
accessor: 'temperature',
94111
},
95112
{
96-
id: 3535,
97-
date: '8/13/19',
98-
time: '3:00 PM',
99-
logTemp: '93 F',
100-
airVelocity: '30 m/s',
101-
location: '90 N 35 E',
102-
batteryLevel: '30%',
103-
},
104-
];
113+
Header: 'Air Velocity',
114+
accessor: 'air_velocity',
115+
}
116+
]
105117
return (
118+
106119
<div onKeyPress={(e) => console.log(e.key)}>
107120
<Router>
108121
<Container>
@@ -112,9 +125,13 @@ class App extends Component {
112125
<div id="feed" />
113126
<div id="action-bar">
114127
<Switch>
115-
<Route path="/" exact component={Control} />
116-
<Route path="/data/" component={() => <DataTable columns={currentDataCols} data={currentData} />} />
117-
<Route path="/logs/" component={() => <DataTable columns={logCols} data={logData} />} />
128+
<Route path="/" exact component={Control} />
129+
<Route path="/logs/" render={() =>
130+
<DataTable columns={logCols} data={logData.length != 0 ? logData[0].sensorData : [] } pageSize={15} />
131+
} />
132+
<Route path="/data/" render={() =>
133+
<DataTable columns={logCols} data={[]}/>
134+
} />
118135
</Switch>
119136
<Navigation />
120137
</div>

duct-drone-app/src/DataTable.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import React, { Component } from 'react';
2+
import { Redirect } from 'react-router-dom';
23
import './DataTable.css';
34
import ReactTable from 'react-table';
45
import 'react-table/react-table.css';
56

67
/* eslint-disable react/prefer-stateless-function */
78
class DataTable extends Component {
89
render() {
9-
const { data, columns } = this.props;
10+
const { data, columns, pageSize } = this.props;
1011
return (
1112
<ReactTable
1213
className="-striped"
1314
data={data}
1415
columns={columns}
15-
defaultPageSize={15}
16+
defaultPageSize={pageSize}
1617
showPaginationBottom={false}
1718
showPageSizeOptions={false}
1819
style={{

0 commit comments

Comments
 (0)