@@ -4,6 +4,14 @@ var __extends = (this && this.__extends) || function (d, b) {
44 function __ ( ) { this . constructor = d ; }
55 d . prototype = b === null ? Object . create ( b ) : ( __ . prototype = b . prototype , new __ ( ) ) ;
66} ;
7+ var __assign = ( this && this . __assign ) || Object . assign || function ( t ) {
8+ for ( var s , i = 1 , n = arguments . length ; i < n ; i ++ ) {
9+ s = arguments [ i ] ;
10+ for ( var p in s ) if ( Object . prototype . hasOwnProperty . call ( s , p ) )
11+ t [ p ] = s [ p ] ;
12+ }
13+ return t ;
14+ } ;
715var __decorate = ( this && this . __decorate ) || function ( decorators , target , key , desc ) {
816 var c = arguments . length , r = c < 3 ? target : desc === null ? desc = Object . getOwnPropertyDescriptor ( target , key ) : desc , d ;
917 if ( typeof Reflect === "object" && typeof Reflect . decorate === "function" ) r = Reflect . decorate ( decorators , target , key , desc ) ;
@@ -15,8 +23,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
1523} ;
1624var React = require ( 'react' ) ;
1725var react_redux_1 = require ( 'react-redux' ) ;
18- var path_1 = require ( 'path' ) ;
19- var TextField_1 = require ( 'material-ui/TextField' ) ;
2026var SelectField_1 = require ( 'material-ui/SelectField' ) ;
2127var Card_1 = require ( 'material-ui/Card' ) ;
2228var RaisedButton_1 = require ( 'material-ui/RaisedButton' ) ;
@@ -25,6 +31,7 @@ var languageItems_1 = require('./languageItems');
2531var runnerItems_1 = require ( './runnerItems' ) ;
2632var Top_1 = require ( '../TopPanel/Top' ) ;
2733var redux_form_1 = require ( 'redux-form' ) ;
34+ var coderoad_cli_1 = require ( 'coderoad-cli' ) ;
2835var styles = {
2936 card : {
3037 margin : '10px' ,
@@ -35,57 +42,55 @@ var styles = {
3542 margin : '30px 10px 20px 10px' ,
3643 } ,
3744} ;
45+ var fields = [ 'name' , 'language' , 'runner' ] ;
46+ var validate = function ( values ) {
47+ var errors = { } ;
48+ if ( ! name ) {
49+ errors . name = 'Required' ;
50+ }
51+ else if ( ! coderoad_cli_1 . validateName ( name ) ) {
52+ errors . name = 'Invalid "coderoad-*" name' ;
53+ }
54+ if ( ! values . language ) {
55+ errors . language = 'Required' ;
56+ }
57+ if ( ! values . runner ) {
58+ errors . runner = 'Required' ;
59+ }
60+ return errors ;
61+ } ;
3862var TutorialConfig = ( function ( _super ) {
3963 __extends ( TutorialConfig , _super ) ;
4064 function TutorialConfig ( props ) {
4165 _super . call ( this , props ) ;
66+ var _a = this . props . packageJson , name = _a . name , config = _a . config ;
4267 this . state = {
43- pj : this . props . packageJson
68+ name : name ,
69+ language : config . language ,
70+ runner : config . runner ,
4471 } ;
4572 }
4673 TutorialConfig . prototype . componentDidMount = function ( ) {
4774 Top_1 . default . toggle ( false ) ;
4875 } ;
49- TutorialConfig . prototype . handleText = function ( prop , event ) {
50- this . handleChange ( prop , event . target . value ) ;
51- } ;
52- TutorialConfig . prototype . handleSelect = function ( prop , event , index , value ) {
53- this . handleChange ( prop , value ) ;
54- } ;
55- TutorialConfig . prototype . handleChange = function ( prop , val ) {
56- var obj = { } ;
57- obj [ prop ] = val ;
58- var target = null ;
59- switch ( prop ) {
60- case 'name' :
61- this . setState ( { pj : Object . assign ( { } , this . state . pj , obj ) } ) ;
62- break ;
63- case 'language' :
64- case 'runner' :
65- var config = Object . assign ( { } , this . state . pj . config , obj ) ;
66- var pj = Object . assign ( { } , this . state . pj , { config : config } ) ;
67- this . setState ( { pj : pj } ) ;
68- return ;
69- case 'repo' :
70- var repo = {
71- repository : {
72- type : 'git' ,
73- url : prop
74- } ,
75- bugs : {
76- url : path_1 . resolve ( prop , 'issues' )
77- }
78- } ;
79- this . setState ( { pj : Object . assign ( { } , this . state . pj , repo ) } ) ;
80- return ;
81- }
76+ TutorialConfig . prototype . handleChange = function ( field , e ) {
77+ console . log ( e ) ;
78+ var nextState = { } ;
79+ nextState [ field ] = e . target . value ;
80+ this . setState ( Object . assign ( { } , this . state , nextState ) ) ;
8281 } ;
8382 TutorialConfig . prototype . save = function ( ) {
84- this . props . save ( this . state . pj ) ;
83+ console . log ( this . state ) ;
84+ } ;
85+ TutorialConfig . prototype . handleText = function ( prop , e , v ) {
86+ console . log ( e ) ;
87+ var next = { } ;
88+ next [ prop ] = v ;
89+ this . setState ( Object . assign ( { } , this . state , next ) ) ;
8590 } ;
8691 TutorialConfig . prototype . render = function ( ) {
87- var pj = this . state . pj ;
88- return ( React . createElement ( Card_1 . Card , { style : styles . card } , React . createElement ( Card_1 . CardHeader , { title : 'Tutorial Configuration' } ) , React . createElement ( TextField_1 . default , { floatingLabelText : 'Tutorial Package Name' , defaultValue : pj . name , onChange : this . handleText . bind ( this , 'name' ) } ) , React . createElement ( "br" , null ) , React . createElement ( SelectField_1 . default , { floatingLabelText : 'Language' , value : pj . config . language , onChange : this . handleSelect . bind ( this , 'language' ) } , languageItems_1 . default ( ) ) , React . createElement ( "br" , null ) , React . createElement ( SelectField_1 . default , { floatingLabelText : 'Test Runner' , value : pj . config . runner , onChange : this . handleSelect . bind ( this , 'runner' ) } , runnerItems_1 . default ( pj . config . language ) ) , React . createElement ( "br" , null ) , React . createElement ( RaisedButton_1 . default , { style : styles . button , label : 'Save' , primary : true , onTouchTap : this . save . bind ( this ) } ) , React . createElement ( RaisedButton_1 . default , { style : styles . button , label : 'Continue' , secondary : true , onTouchTap : this . props . routeToPage . bind ( this ) } ) ) ) ;
92+ var _a = this . state , name = _a . name , language = _a . language , runner = _a . runner ;
93+ return ( React . createElement ( Card_1 . Card , { style : styles . card } , React . createElement ( Card_1 . CardHeader , { title : 'Tutorial Configuration' } ) , React . createElement ( "input" , { type : 'text' , value : name , onChange : this . handleText . bind ( this , 'name' ) } ) , React . createElement ( "br" , null ) , React . createElement ( SelectField_1 . default , __assign ( { floatingLabelText : 'Language' , value : language } , language , { onChange : this . handleChange . bind ( this , 'language' ) } ) , languageItems_1 . default ( ) ) , React . createElement ( "br" , null ) , React . createElement ( SelectField_1 . default , __assign ( { floatingLabelText : 'Test Runner' , value : runner } , runner , { onChange : this . handleChange . bind ( this , 'runner' ) } ) , runnerItems_1 . default ( language ) ) , React . createElement ( "br" , null ) , React . createElement ( RaisedButton_1 . default , { style : styles . button , label : 'Save' , primary : true , onTouchTap : this . save . bind ( this ) } ) , React . createElement ( RaisedButton_1 . default , { style : styles . button , label : 'Continue' , secondary : true , onTouchTap : this . props . routeToPage . bind ( this ) } ) ) ) ;
8994 } ;
9095 TutorialConfig = __decorate ( [
9196 react_redux_1 . connect ( function ( state ) { return ( {
@@ -104,5 +109,5 @@ var TutorialConfig = (function (_super) {
104109Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
105110exports . default = redux_form_1 . reduxForm ( {
106111 form : 'config' ,
107- fields : [ 'name' , 'language' , 'runner' ] ,
112+ fields : fields ,
108113} ) ( TutorialConfig ) ;
0 commit comments