1
1
import React , { Component } from 'react' ;
2
- import { Tabs , Tab , Container , Paper } from "@material-ui/core" ;
2
+ import { Tabs , Tab , Paper } from "@material-ui/core" ;
3
3
import TabPanel from '../components/TabPanel' ;
4
4
import Grid from '@material-ui/core/Grid' ;
5
+ import Table from '@material-ui/core/Table' ;
6
+ import TableBody from '@material-ui/core/TableBody' ;
7
+ import TableCell from '@material-ui/core/TableCell' ;
8
+ import TableContainer from '@material-ui/core/TableContainer' ;
9
+ import TableHead from '@material-ui/core/TableHead' ;
10
+ import TableRow from '@material-ui/core/TableRow' ;
5
11
import { withStyles } from '@material-ui/core/styles' ;
6
- import Divider from '@material-ui/core/Divider' ;
7
12
import LinearProgress from '@material-ui/core/LinearProgress' ;
8
13
import CircularProgress from '@material-ui/core/CircularProgress' ;
9
14
import { UploadForm , DownloadForm , ExecuteForm } from '../components/Forms' ;
@@ -27,19 +32,27 @@ class Admin extends Component {
27
32
activeIndex : 0 ,
28
33
loading : false ,
29
34
loadingCurrentFiles : false ,
30
- fileList : undefined ,
35
+ loadingStatistics : false ,
36
+ statistics : [ ] ,
31
37
filesInput : undefined ,
32
- fileListHtml : undefined
38
+ fileListHtml : undefined ,
39
+ lastExecution : undefined
33
40
}
34
41
35
42
this . handleIndexChange = this . handleIndexChange . bind ( this ) ;
36
43
this . handleUpload = this . handleUpload . bind ( this ) ;
37
44
this . handleExecute = this . handleExecute . bind ( this ) ;
38
45
this . handleGetFileList = this . handleGetFileList . bind ( this ) ;
46
+ this . handleGetStatistics = this . handleGetStatistics . bind ( this ) ;
39
47
}
40
48
41
- componentDidMount ( ) {
49
+ refreshPage ( ) {
42
50
this . handleGetFileList ( ) ;
51
+ this . handleGetStatistics ( ) ;
52
+ }
53
+
54
+ componentDidMount ( ) {
55
+ this . refreshPage ( ) ;
43
56
}
44
57
45
58
handleIndexChange ( event , newIndex ) {
@@ -67,32 +80,63 @@ class Admin extends Component {
67
80
68
81
async handleExecute ( event ) {
69
82
event . preventDefault ( ) ;
83
+ // TODO: it looks like it handles it, but may want to tie events into stats too (like set loadingStatistics: true)
70
84
this . setState ( { loading : true } ) ;
71
85
72
86
const response = await fetch ( '/api/execute' ) ;
73
87
const result = await response . json ( ) ;
74
88
75
89
this . setState ( { loading : false } ) ;
76
90
91
+ this . refreshPage ( ) ;
92
+
77
93
return result
78
94
}
79
95
96
+ async handleGetStatistics ( ) {
97
+ this . setState ( { loadingStatistics : true } )
98
+
99
+ try {
100
+ const statsData = await fetch ( "/api/statistics" ) ;
101
+ const statsResponse = await statsData . json ( ) ;
102
+
103
+ this . setState ( {
104
+ statistics : _ . toPairsIn ( statsResponse . stats ) ,
105
+ lastExecution : statsResponse . executionTime
106
+ } ) ;
107
+
108
+ console . log ( "statisticsListHtml" , this . state . statistics ) ;
109
+ // this.setState({statisticsListHtml: stats});
110
+ this . setState ( { loadingStatistics : false } )
111
+ }
112
+ finally {
113
+ this . setState ( { loadingStatistics : false } )
114
+ }
115
+
116
+ }
117
+
80
118
async handleGetFileList ( ) {
81
119
this . setState ( { loadingCurrentFiles : true } )
82
120
83
- const filesData = await fetch ( "/api/listCurrentFiles" ) ;
84
- const filesResponse = await filesData . json ( ) ;
121
+ try {
122
+ const filesData = await fetch ( "/api/listCurrentFiles" ) ;
123
+ const filesResponse = await filesData . json ( ) ;
85
124
86
- this . setState ( { fileList : filesResponse } ) ;
125
+ // this.setState({fileList: filesResponse});
87
126
88
- this . setState ( { fileListHtml : _ . map ( filesResponse , ( fileName ) => {
89
- return < li key = { fileName } > { fileName } </ li >
90
- } ) } ) ;
127
+ this . setState ( { fileListHtml : _ . map ( filesResponse , ( fileName ) => {
128
+ return ( < li key = { fileName } > { fileName } </ li > )
129
+ } ) } ) ;
130
+
131
+ console . log ( "fileListHtml" , this . state . fileListHtml ) ;
132
+ //just a UX indication that a new list has been loaded
133
+ //await new Promise(resolve => setTimeout(resolve, 1000));
134
+ }
91
135
92
- //just a UX indication that a new list has been loaded
93
- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
136
+ finally {
137
+ this . setState ( { loadingCurrentFiles : false } )
138
+ }
94
139
95
- this . setState ( { loadingCurrentFiles : false } )
96
140
}
97
141
98
142
render ( ) {
@@ -120,29 +164,65 @@ class Admin extends Component {
120
164
< CircularProgress />
121
165
</ div >
122
166
:
123
- < ul > { this . state . fileListHtml } </ ul >
167
+ < Paper style = { { padding : 5 } } >
168
+ < ul > { this . state . fileListHtml } </ ul >
169
+ </ Paper >
170
+
171
+ let currentStatistics = this . state . loadingStatistics === true ?
172
+ < div className = { classes . spinner } >
173
+ < CircularProgress />
174
+ </ div >
175
+ : _ . isEmpty ( this . state . statistics ) !== true &&
176
+ < TableContainer component = { Paper } className = "statisticsData" >
177
+ < Table aria-label = "simple table" className = { classes . table } >
178
+ < TableHead >
179
+ < TableRow >
180
+ < TableCell > Sources Matched</ TableCell >
181
+ < TableCell align = "left" > Number of Matches</ TableCell >
182
+ </ TableRow >
183
+ </ TableHead >
184
+ < TableBody >
185
+ { this . state . statistics . map ( ( row ) => (
186
+ < TableRow key = { row [ 0 ] } >
187
+ < TableCell align = "left" component = "th" scope = "row" >
188
+ { row [ 0 ] }
189
+ </ TableCell >
190
+ < TableCell align = "left" > { row [ 1 ] } </ TableCell >
191
+ </ TableRow >
192
+ ) ) }
193
+ </ TableBody >
194
+ </ Table >
195
+ </ TableContainer >
124
196
125
197
return (
126
- < Container >
127
- < h2 > Admin Options</ h2 >
128
- < Paper elevation = { 2 } style = { { "marginTop" :"1em" , "padding" :"2em" } } >
129
- < Grid container spacing = { 5 } >
130
- < Grid item >
131
- < Tabs value = { this . state . activeIndex } onChange = { this . handleIndexChange } >
132
- < Tab label = "Upload" />
133
- < Tab label = "Download" />
134
- < Tab label = "Execute" />
135
- </ Tabs >
136
- { currentTabWithState }
137
- < Divider orientation = "vertical" flexItem />
198
+ < div >
199
+ < h2 > Admin Portal</ h2 >
200
+ < Grid container spacing = { 3 } direction = "column" style = { { padding :30 } } >
201
+ < Grid container spacing = { 3 } direction = "row" >
202
+ < Grid item sm = { 5 } >
203
+ < h3 > Options</ h3 >
204
+ < Paper style = { { padding : 5 } } >
205
+ < Tabs value = { this . state . activeIndex } onChange = { this . handleIndexChange } >
206
+ < Tab label = "Upload" />
207
+ < Tab label = "Download" />
208
+ < Tab label = "Execute" />
209
+ </ Tabs >
210
+ { currentTabWithState }
211
+ </ Paper >
212
+ </ Grid >
213
+ < Grid item sm = { 4 } >
214
+ < h3 > Current Files</ h3 >
215
+ { currentListWithState }
216
+ </ Grid >
138
217
</ Grid >
139
- < Grid item >
140
- < h3 > Current Files</ h3 >
141
- { currentListWithState }
218
+ < Grid container spacing = { 3 } direction = "row" >
219
+ < Grid item sm = { 4 } >
220
+ < h3 > Matching Stats from last Execution: { this . state . lastExecution } </ h3 >
221
+ { currentStatistics }
222
+ </ Grid >
142
223
</ Grid >
143
224
</ Grid >
144
- </ Paper >
145
- </ Container >
225
+ </ div >
146
226
) ;
147
227
}
148
228
}
0 commit comments