ui improvements, renamed http status handler

This commit is contained in:
majormjr 2016-04-27 20:12:00 -04:00
parent 0fc88191f4
commit f643a07135
12 changed files with 109 additions and 28435 deletions

File diff suppressed because it is too large Load Diff

View File

@ -478,9 +478,9 @@ func StartServer(w http.ResponseWriter, r *http.Request) {
log.Printf("Factorio server started on port: %d", FactorioServ.Port)
}
resp.Data = fmt.Sprintf("Factorio server started on port: %s", FactorioServ.Port)
resp.Data = fmt.Sprintf("Factorio server with save: %s started on port: %d", FactorioServ.Savefile, FactorioServ.Port)
resp.Success = true
log.Printf("Factorio server started on port: %s", FactorioServ.Port)
if err := json.NewEncoder(w).Encode(resp); err != nil {
log.Printf("Error encoding config file JSON reponse: ", err)
}
@ -520,7 +520,7 @@ func StopServer(w http.ResponseWriter, r *http.Request) {
}
}
func RunningServer(w http.ResponseWriter, r *http.Request) {
func CheckServer(w http.ResponseWriter, r *http.Request) {
resp := JSONResponse{
Success: false,
}
@ -540,11 +540,11 @@ func RunningServer(w http.ResponseWriter, r *http.Request) {
}
log.Printf("Server status sent with data: %+v", resp.Data)
} else {
log.Printf("Server not running, creating status response")
resp.Success = true
status := map[string]string{}
status["status"] = "stopped"
resp.Data = status
log.Printf("Server not running, creating status response: %v", status)
if err := json.NewEncoder(w).Encode(resp); err != nil {
log.Printf("Error encoding config file JSON reponse: ", err)
}

View File

@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"log"
"net/http"
)
@ -48,10 +49,9 @@ func main() {
loadFlags()
FactorioServ = initFactorio()
FactorioServ.Port = 12345
FactorioServ.Savefile = "testingsaves"
router := NewRouter()
fmt.Printf("Starting server on: %s:%s", config.ServerIP, config.ServerPort)
log.Fatal(http.ListenAndServe(config.ServerIP+":"+config.ServerPort, router))
}

View File

@ -142,6 +142,6 @@ var apiRoutes = Routes{
"RunningServer",
"GET",
"/server/status",
RunningServer,
CheckServer,
},
}

View File

@ -17,7 +17,7 @@ type FactorioServer struct {
AutosaveSlots int `json:"autosave_slots"`
Port int `json:"port"`
DisallowCmd bool `json:"disallow_cmd"`
Running bool
Running bool `json:"bool"`
PeerToPeer bool `json:"peer2peer"`
AutoPause bool `json:"auto_pause"`
StdOut io.ReadCloser
@ -119,7 +119,7 @@ func (f *FactorioServer) Stop() error {
f.Running = false
log.Printf("Sent SIGINT to Factorio process")
log.Printf("Sent SIGINT to Factorio process, Factorio server shutting down...")
return nil
}

View File

@ -1,4 +1,5 @@
import React from 'react';
import {IndexLink} from 'react-router';
import Settings from './Config/Settings.jsx';
class ConfigContent extends React.Component {
@ -37,7 +38,7 @@ class ConfigContent extends React.Component {
<small>Manage server configuration</small>
</h1>
<ol className="breadcrumb">
<li><a href="#"><i className="fa fa-dashboard"></i> Level</a></li>
<li><IndexLink to="/"><i className="fa fa-dashboard"></i>Server Control</IndexLink></li>
<li className="active">Here</li>
</ol>
</section>

View File

@ -29,8 +29,7 @@ class Index extends React.Component {
<small>Control your Factorio server</small>
</h1>
<ol className="breadcrumb">
<li><IndexLink to="/"><i className="fa fa-dashboard"></i> Level</IndexLink></li>
<li className="active">Here</li>
<li><IndexLink to="/"><i className="fa fa-dashboard"></i>Server Control</IndexLink></li>
</ol>
</section>

View File

@ -1,4 +1,5 @@
import React from 'react';
import {IndexLink} from 'react-router';
import LogLines from './Logs/LogLines.jsx';
class LogsContent extends React.Component {
@ -37,7 +38,7 @@ class LogsContent extends React.Component {
<small>Analyze Factorio Logs</small>
</h1>
<ol className="breadcrumb">
<li><a href="#"><i className="fa fa-dashboard"></i> Level</a></li>
<li><IndexLink to="/"><i className="fa fa-dashboard"></i>Server Control</IndexLink></li>
<li className="active">Here</li>
</ol>
</section>

View File

@ -68,7 +68,7 @@ class ModsContent extends React.Component {
<small>Manage your mods</small>
</h1>
<ol className="breadcrumb">
<li><IndexLink to="/"><i className="fa fa-dashboard"></i> Level</IndexLink></li>
<li><IndexLink to="/"><i className="fa fa-dashboard fa-fw"></i>Server Control</IndexLink></li>
<li className="active">Here</li>
</ol>
</section>

View File

@ -1,4 +1,5 @@
import React from 'react';
import {IndexLink} from 'react-router';
import SavesList from './Saves/SavesList.jsx';
import CreateSave from './Saves/CreateSave.jsx';
import UploadSave from './Saves/UploadSave.jsx';
@ -36,7 +37,7 @@ class SavesContent extends React.Component {
<small>Factorio Save Files</small>
</h1>
<ol className="breadcrumb">
<li><a href="#"><i className="fa fa-dashboard"></i> Level</a></li>
<li><IndexLink to="/"><i className="fa fa-dashboard fa-fw"></i>Server Control</IndexLink></li>
<li className="active">Here</li>
</ol>
</section>

View File

@ -138,88 +138,94 @@ class ServerCtl extends React.Component {
<div className="box-body">
<form action="" onSubmit={this.startServer}>
<div className="form-group">
<select ref="savefile" class="form-control">
{this.props.saves.map( (save, i) => {
return(
<option key={save.name} value={save.name}>{save.name}</option>
)
})}
</select>
<label>Select Save File</label>
</div>
<form action="" onSubmit={this.startServer}>
<div className="form-group">
<div className="row">
<div className="col-md-4">
<button className="btn btn-block btn-success" type="submit"><i className="fa fa-play fa-fw"></i>Start Factorio Server</button>
</div>
<div className="col-md-4">
<button className="btn btn-block btn-danger" type="button" onClick={this.stopServer}><i className="fa fa-stop fa-fw"></i>Stop Factorio Server</button>
</div>
</div>
<div className="box box-success">
<hr />
<select ref="savefile" className="form-control">
{this.props.saves.map( (save, i) => {
return(
<option key={save.name} value={save.name}>{save.name}</option>
)
})}
</select>
<label>Select Save File</label>
</div>
<div className="box box-success">
<button type="button" className="btn btn-box-tool" data-widget="collapse">
<div className="box-header with-border">
<i className="fa fa-plus"></i><h4 className="box-title">Advanced</h4>
</div>
<div className="box-header with-border">
<i className="fa fa-plus fa-fw"></i><h4 className="box-title">Advanced</h4>
</div>
</button>
<div className="box-body" style={{display: "none"}}>
<label for="latency">Server latency setting (ms)</label>
<div id="latency" className="input-group">
<input ref="latency" name="latency" id="latency" type="text" className="form-control" onchange={this.state.latency} value={this.state.latency} placeholder={this.state.latency} />
<div className="input-group-btn">
<button type="button" className="btn btn-primary" onClick={this.incrementLatency}><i className="fa fa-arrow-up"></i></button>
<button type="button" className="btn btn-primary" onClick={this.decrementLatency}><i className="fa fa-arrow-down"></i></button>
<div className="box-body" style={{display: "none"}}>
<label for="latency">Server latency setting (ms)</label>
<div id="latency" className="input-group">
<input ref="latency" name="latency" id="latency" type="text" className="form-control" onchange={this.state.latency} value={this.state.latency} placeholder={this.state.latency} />
<div className="input-group-btn">
<button type="button" className="btn btn-primary" onClick={this.incrementLatency}><i className="fa fa-arrow-up"></i></button>
<button type="button" className="btn btn-primary" onClick={this.decrementLatency}><i className="fa fa-arrow-down"></i></button>
</div>
</div>
</div>
<label for="autosaveInterval">Autosave Interval (mins)</label>
<div id="autosaveInterval" className="input-group">
<input ref="autosaveInterval" name="autosaveInterval" id="autosaveInterval" type="text" className="form-control" onchange={this.state.autosaveInterval} value={this.state.autosaveInterval} placeholder={this.state.autosaveInterval} />
<div className="input-group-btn">
<button type="button" className="btn btn-primary" onClick={this.incrementAutosave}><i className="fa fa-arrow-up"></i></button>
<button type="button" className="btn btn-primary" onClick={this.decrementAutosave}><i className="fa fa-arrow-down"></i></button>
<label for="autosaveInterval">Autosave Interval (mins)</label>
<div id="autosaveInterval" className="input-group">
<input ref="autosaveInterval" name="autosaveInterval" id="autosaveInterval" type="text" className="form-control" onchange={this.state.autosaveInterval} value={this.state.autosaveInterval} placeholder={this.state.autosaveInterval} />
<div className="input-group-btn">
<button type="button" className="btn btn-primary" onClick={this.incrementAutosave}><i className="fa fa-arrow-up"></i></button>
<button type="button" className="btn btn-primary" onClick={this.decrementAutosave}><i className="fa fa-arrow-down"></i></button>
</div>
</div>
</div>
<label for="autosaveSlots">Autosave Slots</label>
<div id="autosaveSlots" className="input-group">
<input ref="autosaveSlots" name="autosaveSlots" id="autosaveSlots" type="text" className="form-control" onChange={this.state.autosaveSlots} value={this.state.autosaveSlots} placeholder={this.state.autosaveSlots} />
<div className="input-group-btn">
<button type="button" className="btn btn-primary" onClick={this.incrementAutosaveSlots}><i className="fa fa-arrow-up"></i></button>
<button type="button" className="btn btn-primary" onClick={this.decrementAutosaveSlots}><i className="fa fa-arrow-down"></i></button>
<label for="autosaveSlots">Autosave Slots</label>
<div id="autosaveSlots" className="input-group">
<input ref="autosaveSlots" name="autosaveSlots" id="autosaveSlots" type="text" className="form-control" onChange={this.state.autosaveSlots} value={this.state.autosaveSlots} placeholder={this.state.autosaveSlots} />
<div className="input-group-btn">
<button type="button" className="btn btn-primary" onClick={this.incrementAutosaveSlots}><i className="fa fa-arrow-up"></i></button>
<button type="button" className="btn btn-primary" onClick={this.decrementAutosaveSlots}><i className="fa fa-arrow-down"></i></button>
</div>
</div>
</div>
<label for="port">Factorio Server Port</label>
<div id="port" className="input-group">
<input ref="port" name="port" id="port" type="text" className="form-control" onChange={this.state.port} value={this.state.port} placeholder={this.state.port} />
<div className="input-group-btn">
<button type="button" className="btn btn-primary" onClick={this.incrementPort}><i className="fa fa-arrow-up"></i></button>
<button type="button" className="btn btn-primary" onClick={this.decrementPort}><i className="fa fa-arrow-down"></i></button>
</div>
</div>
<div className="input-group">
<div className="checkbox">
<label for="autoPause">
Auto Pause when no players connected
</label>
<input id="autoPause" ref="autoPause" type="checkbox" onClick={this.toggleAutoPause} />
<label for="port">Factorio Server Port</label>
<div id="port" className="input-group">
<input ref="port" name="port" id="port" type="text" className="form-control" onChange={this.state.port} value={this.state.port} placeholder={this.state.port} />
<div className="input-group-btn">
<button type="button" className="btn btn-primary" onClick={this.incrementPort}><i className="fa fa-arrow-up"></i></button>
<button type="button" className="btn btn-primary" onClick={this.decrementPort}><i className="fa fa-arrow-down"></i></button>
</div>
</div>
<div className="input-group">
<div className="checkbox">
<label for="autoPause">
Auto Pause when no players connected
</label>
<input id="autoPause" ref="autoPause" type="checkbox" onClick={this.toggleAutoPause} />
</div>
<div className="checkbox">
<label for="p2p">
Peer to peer connection method
</label>
<input id="p2p" ref="p2p" type="checkbox" onClick={this.toggleP2P} />
</div>
<div className="checkbox">
<label for="p2p">
Peer to peer connection method
</label>
<input id="p2p" ref="p2p" type="checkbox" onClick={this.toggleP2P} />
</div>
<div className="checkbox">
<label for="allowCmd">
Allow commands on the server
</label>
<input id="allowCmd" ref="allowCmd" type="checkbox" onClick={this.toggleAllowCmd} />
<div className="checkbox">
<label for="allowCmd">
Allow commands on the server
</label>
<input id="allowCmd" ref="allowCmd" type="checkbox" onClick={this.toggleAllowCmd} />
</div>
</div>
</div>
</div>
</div>
<button className="btn btn-block btn-success" type="submit">Start Factorio Server</button>
</form>
<button className="btn btn-block btn-danger" type="button" onClick={this.stopServer}>Stop Factorio Server</button>
</form>
</div>
</div>

View File

@ -3,12 +3,27 @@ import React from 'react';
class ServerStatus extends React.Component {
constructor(props) {
super(props);
this.formatServerStatus = this.formatServerStatus.bind(this)
}
capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
formatServerStatus(serverStatus) {
var result = {}
if (serverStatus === "running") {
result = <span className="label label-success">Running</span>
return result
} else if (serverStatus == "stopped") {
result = <span className="label label-danger">Not Running</span>
return result
}
return serverStatus
}
render() {
return(
<div className="box">
@ -30,7 +45,7 @@ class ServerStatus extends React.Component {
return(
<tr key={key}>
<td>{this.capitalizeFirstLetter(key)}</td>
<td>{this.props.serverStatus[key]}</td>
<td>{this.formatServerStatus(this.props.serverStatus[key])}</td>
</tr>
)
}, this)}