Skip to content

Commit

Permalink
working dashboard funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Jun 21, 2019
1 parent 44cf877 commit b2c333e
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -96,7 +96,7 @@ If you have any problems with the `package-lock.json`, just delete it and try ag
- [x] Re-add login name to all logging functions
- [x] Clean webUtils
- [x] Adapt getStatus endpoint and integrate
- [ ] Make dashboard functionalities work
- [x] Make dashboard functionalities work
- [ ] Player modal endpoints
- [ ] Execute cmd buffer modal
- [ ] Code fxserver beta resource
Expand Down
25 changes: 19 additions & 6 deletions src/webroutes/fxCommands.js
Expand Up @@ -26,30 +26,43 @@ module.exports = async function action(res, req) {
if(action == 'admin_say'){
webUtils.appendLog(req, `say ${parameter}`, context);
globals.fxRunner.srvCmd('say ' + parameter);
return webUtils.sendOutput(res, 'Okay');
return sendOutput(res, 'Okay');

}else if(action == 'restart_res'){
webUtils.appendLog(req, `restart ${parameter}`, context);
let toResp = await globals.fxRunner.srvCmdBuffer('restart ' + parameter);
return webUtils.sendOutput(res, toResp);
return sendOutput(res, toResp);

}else if(action == 'start_res'){
webUtils.appendLog(req, `start ${parameter}`, context);
let toResp = await globals.fxRunner.srvCmdBuffer('start ' + parameter);
return webUtils.sendOutput(res, toResp);
return sendOutput(res, toResp);

}else if(action == 'stop_res'){
webUtils.appendLog(req, `stop ${parameter}`, context);
let toResp = await globals.fxRunner.srvCmdBuffer('stop ' + parameter);
return webUtils.sendOutput(res, toResp);
return sendOutput(res, toResp);

}else if(action == 'refresh_res'){
webUtils.appendLog(req, `refresh`, context);
let toResp = await globals.fxRunner.srvCmdBuffer('refresh');
return webUtils.sendOutput(res, toResp);
return sendOutput(res, toResp);

}else{
webUtils.appendLog(req, `unknown action`, context);
return webUtils.sendOutput(res, 'Unknown action!');
return sendOutput(res, 'Unknown action!');
}
};



//================================================================
/**
* Wrapper function to render the generic view and send the output
* @param {object} res
* @param {string} msg
*/
async function sendOutput(res, msg){
let out = await webUtils.renderMasterView('generic', {headerTitle: 'Output', message: msg});
return res.send(out);
}
58 changes: 52 additions & 6 deletions web/dashboard.html
Expand Up @@ -12,12 +12,12 @@ <h2>Server Dashboard</h2>
<div class="card card-accent-danger" style="min-height: 160px;">
<div class="card-header font-weight-bold">FXServer Control:</div>
<div class="card-body text-center align-middle">
<button onclick="controlAction('start')" class="btn btn-outline-danger btn-lg mx-auto m-2"
type="button" id="ctrl-start">START</button> &nbsp;
<button onclick="controlAction('restart')" class="btn btn-outline-danger btn-lg mx-auto m-2"
<button onclick="controlAction('start')" class="btn btn-outline-danger btn-lg mx-auto m-2" type="button"
id="ctrl-start">START</button> &nbsp;
<button onclick="controlAction('restart')" class="btn btn-outline-danger btn-lg mx-auto m-2"
type="button" id="ctrl-restart">RESTART</button> &nbsp;
<button onclick="controlAction('stop')" class="btn btn-outline-danger btn-lg mx-auto m-2"
type="button" id="ctrl-stop">STOP</button>
<button onclick="controlAction('stop')" class="btn btn-outline-danger btn-lg mx-auto m-2" type="button"
id="ctrl-stop">STOP</button>
</div>
</div>

Expand Down Expand Up @@ -108,6 +108,52 @@ <h2>Server Dashboard</h2>
{{include("footer")/}}



<script>
// Control actions (start/restart/stop)
function controlAction(action) {
if (action !== 'start' && !window.confirm('Are you sure you want to ' + action + ' the server?')) {
return;
}

$.ajax({
url: actionURL = '/fxControls/' + action,
type: "GET",
dataType: "json",
timeout: 2000,
success: function (data) {
if (data.logout) {
window.location = '/auth?logout';
return;
}
console.log(data);
},
error: function (xmlhttprequest, textstatus, message) {
alert('Error executing control action.');
}
});
}

//Commands
let paramRequiredCommands = [
'admin_say',
'restart_res',
'start_res',
'stop_res'
];
$('#frm_action').change(function () {
var action = $("#frm_action").val();
if (paramRequiredCommands.indexOf(action) != -1) {
$("#frm_parameter").prop('readonly', false);
} else {
$("#frm_parameter").prop('readonly', true);
}
});
</script>




<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.bundle.min.js"></script>
<script src="js/custom-tooltips.min.js"></script>
<script>
Expand Down Expand Up @@ -169,4 +215,4 @@ <h2>Server Dashboard</h2>
}
}
});
</script>
</script>
2 changes: 1 addition & 1 deletion web/fullReport.html
@@ -1,10 +1,10 @@
{{include("header")/}}


<div class="text-center mb-4">
<h2>Full Status Report</h2>
</div>


<div class="row justify-content-md-center">
<div class="col-md-4 ">
<div class="alert alert-secondary text-center" role="alert">
Expand Down
17 changes: 17 additions & 0 deletions web/generic.html
@@ -0,0 +1,17 @@
{{include("header")/}}


<div class="text-center mb-4">
<h2>Output</h2>
</div>

<div class="row justify-content-md-center">
<div class="col-md-4 ">
<div class="alert alert-secondary text-center" role="alert">
{{message}}
</div>
</div>
</div>


{{include("footer")/}}

0 comments on commit b2c333e

Please sign in to comment.