@@ -21,18 +21,26 @@ class ConfigContent extends React.Component {
2121 this . getConfig ( ) ;
2222 this . getServerSettings ( ) ;
2323 }
24-
24+
2525 capitalizeFirstLetter ( string ) {
2626 return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
2727 }
2828
2929 handleServerSettingsChange ( name , e ) {
30+ let fieldValue
3031 var change = this . state . serverSettings ;
31- change [ name ] = e . target . value ;
32+
33+ if ( e . target . value === "true" || e . target . value === "false" ) {
34+ fieldValue = Boolean ( e . target . value )
35+ } else {
36+ fieldValue = e . target . value
37+ }
38+ console . log ( name , fieldValue )
39+ change [ name ] = fieldValue ;
40+
3241 this . setState ( { serverSettings : change } ) ;
33- console . log ( this . state ) ;
3442 }
35-
43+
3644 getConfig ( ) {
3745 $ . ajax ( {
3846 url : "/api/config" ,
@@ -63,7 +71,7 @@ class ConfigContent extends React.Component {
6371 }
6472 } ) ;
6573 }
66-
74+
6775 updateServerSettings ( e ) {
6876 e . preventDefault ( ) ;
6977 var serverSettingsJSON = JSON . stringify ( this . state . serverSettings )
@@ -75,7 +83,7 @@ class ConfigContent extends React.Component {
7583 success : ( data ) => {
7684 console . log ( data ) ;
7785 if ( data . success === true ) {
78- console . log ( "settings updated" )
86+ console . log ( "settings updated" )
7987 }
8088 }
8189 } )
@@ -84,7 +92,7 @@ class ConfigContent extends React.Component {
8492 formTypeField ( key , setting ) {
8593 if ( key . startsWith ( "_comment_" ) ) {
8694 return (
87- < input
95+ < input
8896 key = { key }
8997 ref = { key }
9098 id = { key }
@@ -93,58 +101,81 @@ class ConfigContent extends React.Component {
93101 />
94102 )
95103 }
96- if ( typeof setting === "number" ) {
104+
105+ switch ( typeof setting ) {
106+ case "number" :
97107 return (
98108 < input
99109 key = { key }
100- ref = { key }
101- id = { key }
102- className = "form-control"
103- defaultValue = { setting }
104- type = "number"
105- onChange = { this . handleServerSettingsChange . bind ( this , key ) }
106- />
107- )
108- } else if ( typeof setting === "string" ) {
109- return (
110- < input
111- key = { key }
112- ref = { key }
113- id = { key }
114- className = "form-control"
115- defaultValue = { setting }
116- type = "text"
110+ ref = { key }
111+ id = { key }
112+ className = "form-control"
113+ defaultValue = { setting }
114+ type = "number"
117115 onChange = { this . handleServerSettingsChange . bind ( this , key ) }
118116 />
119117 )
120- } else if ( typeof setting === "boolean" ) {
118+ case "string" :
119+ if ( key . includes ( "password" ) ) {
120+ return (
121+ < input
122+ key = { key }
123+ ref = { key }
124+ id = { key }
125+ className = "form-control"
126+ defaultValue = { setting }
127+ type = "password"
128+ onChange = { this . handleServerSettingsChange . bind ( this , key ) }
129+ />
130+ )
131+ } else {
132+ return (
133+ < input
134+ key = { key }
135+ ref = { key }
136+ id = { key }
137+ className = "form-control"
138+ defaultValue = { setting }
139+ type = "text"
140+ onChange = { this . handleServerSettingsChange . bind ( this , key ) }
141+ />
142+ )
143+ }
144+ case "boolean" :
145+ console . log ( key )
121146 return (
122147 < select key = { key } ref = { key } id = { key } className = "form-control" onChange = { this . handleServerSettingsChange . bind ( this , key ) } >
123148 < option value = { true } > True</ option >
124149 < option value = { false } > False</ option >
125150 </ select >
126151 )
127- } else if ( Array . isArray ( setting ) ) {
128- return (
129- < input
130- key = { key }
131- ref = { key }
132- id = { key }
133- className = "form-control"
134- defaultValue = { setting }
135- type = "password"
136- onChange = { this . handleServerSettingsChange . bind ( this , key ) }
137- />
138- )
139- } else {
152+ case "object" :
153+ if ( Array . isArray ( setting ) ) {
154+ return (
155+ < input
156+ key = { key }
157+ ref = { key }
158+ id = { key }
159+ className = "form-control"
160+ defaultValue = { setting }
161+ type = "text"
162+ onChange = { this . handleServerSettingsChange . bind ( this , key ) }
163+ />
164+ )
165+ } else {
166+ if ( Object . keys ( setting ) . length > 0 ) {
167+ //this.formTypeField(key, setting);
168+ }
169+ }
170+ default :
140171 return (
141- < input
172+ < input
142173 key = { key }
143- ref = { key }
144- id = { key }
145- className = "form-control"
146- defaultValue = { setting }
147- type = "text"
174+ ref = { key }
175+ id = { key }
176+ className = "form-control"
177+ defaultValue = { setting }
178+ type = "text"
148179 onChange = { this . handleServerSettingsChange . bind ( this , key ) }
149180 />
150181 )
@@ -157,15 +188,15 @@ class ConfigContent extends React.Component {
157188 < div className = "content-wrapper" >
158189 < section className = "content-header" >
159190 < h1 >
160- Config
191+ Config
161192 < small > Manage game configuration</ small >
162193 </ h1 >
163194 < ol className = "breadcrumb" >
164195 < li > < IndexLink to = "/" > < i className = "fa fa-dashboard" > </ i > Server Control</ IndexLink > </ li >
165196 < li className = "active" > Here</ li >
166197 </ ol >
167198 </ section >
168-
199+
169200 < section className = "content" >
170201 < div className = "box" >
171202 < div className = "box-header" >
@@ -185,13 +216,13 @@ class ConfigContent extends React.Component {
185216 var setting_key = this . capitalizeFirstLetter ( key . replace ( / _ / g, " " ) )
186217 var comment = this . state . serverSettings [ "_comment_" + key ]
187218 return (
188- < div className = "form-group" >
189- < label htmlFor = { key } className = "control-label col-md-3" > { setting_key } </ label >
190- < div className = "col-md-6" >
191- { this . formTypeField ( key , setting ) }
192- < p className = "help-block" > { comment } </ p >
193- </ div >
194- </ div >
219+ < div className = "form-group" >
220+ < label htmlFor = { key } className = "control-label col-md-3" > { setting_key } </ label >
221+ < div className = "col-md-6" >
222+ { this . formTypeField ( key , setting ) }
223+ < p className = "help-block" > { comment } </ p >
224+ </ div >
225+ </ div >
195226 )
196227 } , this ) }
197228 < div className = "col-xs-6" >
@@ -213,7 +244,7 @@ class ConfigContent extends React.Component {
213244 < div className = "box-header" >
214245 < h3 className = "box-title" > Game Configuration</ h3 >
215246 </ div >
216-
247+
217248 < div className = "box-body" >
218249 < div className = "row" >
219250 < div className = "col-md-10" >
@@ -232,7 +263,7 @@ class ConfigContent extends React.Component {
232263 </ thead >
233264 < Settings
234265 section = { key }
235- config = { conf }
266+ config = { conf }
236267 />
237268 </ table >
238269 </ div >
0 commit comments