File tree 10 files changed +278
-0
lines changed
10 files changed +278
-0
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "presets" : [" react" ]
3
+ }
Original file line number Diff line number Diff line change
1
+ {"directory": "dashboard/static"}
Original file line number Diff line number Diff line change
1
+ build :
2
+ npm install
3
+ bower install
4
+ node_modules/.bin/babel dashboard/static/* .jsx > dashboard/static/dashboard.js
5
+
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " dashboard" ,
3
+ "authors" : [
4
+
5
+ ],
6
+ "description" : " A ReactJS based Dashboard for Runnerly" ,
7
+ "main" : " " ,
8
+ "license" : " MIT" ,
9
+ "homepage" : " " ,
10
+ "ignore" : [
11
+ " **/.*" ,
12
+ " node_modules" ,
13
+ " bower_components" ,
14
+ " test" ,
15
+ " tests"
16
+ ],
17
+ "dependencies" : {
18
+ "jquery" : " ^3.2.1" ,
19
+ "react" : " ^15.4.2"
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ from flask import Flask , render_template , jsonify
2
+
3
+ app = Flask (__name__ )
4
+
5
+
6
+ @app .route ('/api/runs.json' )
7
+ @app .route ('/api/training.json' )
8
+ @app .route ('/api/races.json' )
9
+ def _runs ():
10
+ run1 = {'title' : 'Endurance' , 'type' : 'training' }
11
+ run2 = {'title' : '10K de chalon' , 'type' : 'race' }
12
+ _data = [run1 , run2 ]
13
+ return jsonify (_data )
14
+
15
+
16
+ @app .route ('/' )
17
+ def index ():
18
+ return render_template ('index.html' )
19
+
20
+
21
+ if __name__ == '__main__' :
22
+ app .run ()
Original file line number Diff line number Diff line change
1
+ var RacesBox = React . createClass ( {
2
+ loadRacesFromServer : function ( ) {
3
+ var xhr = new XMLHttpRequest ( ) ;
4
+ xhr . open ( 'get' , this . props . url , true ) ;
5
+ xhr . onload = function ( ) {
6
+ var data = JSON . parse ( xhr . responseText ) ;
7
+ this . setState ( { data : data } ) ;
8
+ } . bind ( this ) ;
9
+ xhr . send ( ) ;
10
+ } ,
11
+
12
+ getInitialState : function ( ) {
13
+ return { data : [ ] } ;
14
+ } ,
15
+
16
+ componentDidMount : function ( ) {
17
+ this . loadRacesFromServer ( ) ;
18
+ } ,
19
+
20
+ render : function ( ) {
21
+ return (
22
+ < div >
23
+ < h2 > Races</ h2 >
24
+ < Races data = { this . state . data } />
25
+ </ div >
26
+ ) ;
27
+ }
28
+ } ) ;
29
+
30
+ var Races = React . createClass ( {
31
+ render : function ( ) {
32
+ var runNodes = this . props . data . map ( function ( run ) {
33
+ return (
34
+ < Race
35
+ title = { run . title }
36
+ type = { run . type }
37
+ />
38
+ ) ;
39
+ } ) ;
40
+
41
+ return (
42
+ < div >
43
+ { runNodes }
44
+ </ div >
45
+ ) ;
46
+ }
47
+ } ) ;
48
+
49
+
50
+ // Here we decide what goes in a Thing node, which we defined above.
51
+ var Race = React . createClass ( {
52
+ render : function ( ) {
53
+ return (
54
+ < div > { this . props . title } ({ this . props . type } )</ div >
55
+ ) ;
56
+ }
57
+ } ) ;
58
+
Original file line number Diff line number Diff line change
1
+ var RunsBox = React . createClass ( {
2
+ loadRunsFromServer : function ( ) {
3
+ var xhr = new XMLHttpRequest ( ) ;
4
+ xhr . open ( 'get' , this . props . url , true ) ;
5
+ xhr . onload = function ( ) {
6
+ var data = JSON . parse ( xhr . responseText ) ;
7
+ this . setState ( { data : data } ) ;
8
+ } . bind ( this ) ;
9
+ xhr . send ( ) ;
10
+ } ,
11
+
12
+ getInitialState : function ( ) {
13
+ return { data : [ ] } ;
14
+ } ,
15
+
16
+ componentDidMount : function ( ) {
17
+ this . loadRunsFromServer ( ) ;
18
+ } ,
19
+
20
+ render : function ( ) {
21
+ return (
22
+ < div >
23
+ < h2 > Runs</ h2 >
24
+ < Runs data = { this . state . data } />
25
+ </ div >
26
+ ) ;
27
+ }
28
+ } ) ;
29
+
30
+ var Runs = React . createClass ( {
31
+ render : function ( ) {
32
+ var runNodes = this . props . data . map ( function ( run ) {
33
+ return (
34
+ < Run
35
+ title = { run . title }
36
+ type = { run . type }
37
+ />
38
+ ) ;
39
+ } ) ;
40
+
41
+ return (
42
+ < div >
43
+ { runNodes }
44
+ </ div >
45
+ ) ;
46
+ }
47
+ } ) ;
48
+
49
+
50
+ var Run = React . createClass ( {
51
+ render : function ( ) {
52
+ return (
53
+ < div > { this . props . title } ({ this . props . type } )</ div >
54
+ ) ;
55
+ }
56
+ } ) ;
57
+
58
+
59
+ window . RunsBox = RunsBox ;
Original file line number Diff line number Diff line change
1
+ var TrainingRunsBox = React . createClass ( {
2
+ loadTrainingRunsFromServer : function ( ) {
3
+ var xhr = new XMLHttpRequest ( ) ;
4
+ xhr . open ( 'get' , this . props . url , true ) ;
5
+ xhr . onload = function ( ) {
6
+ var data = JSON . parse ( xhr . responseText ) ;
7
+ this . setState ( { data : data } ) ;
8
+ } . bind ( this ) ;
9
+ xhr . send ( ) ;
10
+ } ,
11
+
12
+ getInitialState : function ( ) {
13
+ return { data : [ ] } ;
14
+ } ,
15
+
16
+ componentDidMount : function ( ) {
17
+ this . loadTrainingRunsFromServer ( ) ;
18
+ } ,
19
+
20
+ render : function ( ) {
21
+ return (
22
+ < div >
23
+ < h2 > TrainingRuns</ h2 >
24
+ < TrainingRuns data = { this . state . data } />
25
+ </ div >
26
+ ) ;
27
+ }
28
+ } ) ;
29
+
30
+ var TrainingRuns = React . createClass ( {
31
+ render : function ( ) {
32
+ var runNodes = this . props . data . map ( function ( run ) {
33
+ return (
34
+ < TrainingRun
35
+ title = { run . title }
36
+ type = { run . type }
37
+ />
38
+ ) ;
39
+ } ) ;
40
+
41
+ return (
42
+ < div >
43
+ { runNodes }
44
+ </ div >
45
+ ) ;
46
+ }
47
+ } ) ;
48
+
49
+
50
+ // Here we decide what goes in a Thing node, which we defined above.
51
+ var TrainingRun = React . createClass ( {
52
+ render : function ( ) {
53
+ return (
54
+ < div > { this . props . title } ({ this . props . type } )</ div >
55
+ ) ;
56
+ }
57
+ } ) ;
58
+
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head lang ="en ">
4
+ < meta charset ="UTF-8 ">
5
+ < title > Runnerly Dashboard</ title >
6
+ </ head >
7
+ < body >
8
+ < div class ="container ">
9
+ < h1 > Runnerly Dashboard</ h1 >
10
+ < br >
11
+ < div id ="runs "> </ div >
12
+ < div id ="races "> </ div >
13
+ < div id ="training "> </ div >
14
+ </ div >
15
+
16
+ < script src ="/static/react/react.js "> </ script >
17
+ < script src ="/static/react/react-dom.js "> </ script >
18
+ < script src ="/static/babel/browser.js "> </ script >
19
+ < script src ="/static/dashboard.js "> </ script >
20
+
21
+ < script type ="text/babel ">
22
+ ReactDOM . render (
23
+ < RunsBox url = "/api/runs.json" /> ,
24
+ document . getElementById ( 'runs' )
25
+ ) ;
26
+ ReactDOM . render (
27
+ < RacesBox url = "/api/races.json" /> ,
28
+ document . getElementById ( 'races' )
29
+ ) ;
30
+ ReactDOM . render (
31
+ < TrainingRunsBox url = "/api/training.json" /> ,
32
+ document . getElementById ( 'training' )
33
+ ) ;
34
+ </ script >
35
+ </ body >
36
+ </ html >
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " dashboard" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " " ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1"
8
+ },
9
+ "author" : " " ,
10
+ "license" : " ISC" ,
11
+ "devDependencies" : {
12
+ "babel-cli" : " ^6.24.0" ,
13
+ "bower" : " ^1.8.0"
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments