@@ -19,90 +19,103 @@ import './App.css';
1919class 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 >
0 commit comments