mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Start server from web ui
This commit is contained in:
parent
8ed68c0a4d
commit
b620ac5d55
9
main.js
9
main.js
@ -11,15 +11,14 @@ app.use(express.bodyParser());
|
||||
app.use(express.methodOverride());
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
|
||||
var servers = require('./routes/servers');
|
||||
|
||||
app.resource('api/missions', require('./routes/missions'));
|
||||
app.resource('api/mods', require('./routes/mods'));
|
||||
app.resource('api/servers', require('./routes/servers'));
|
||||
app.resource('api/servers', servers);
|
||||
app.resource('api/settings', require('./routes/settings'));
|
||||
|
||||
app.get('/api/servers/:id/start', function (req, res){
|
||||
manager.runServer();
|
||||
res.send({status:"ok"});
|
||||
});
|
||||
app.get('/api/servers/:server/start', servers.start);
|
||||
|
||||
app.get('/', function (req, res){
|
||||
res.sendfile(__dirname + '/public/index.html');
|
||||
|
16
manager.js
16
manager.js
@ -41,15 +41,25 @@ Server.prototype.start = function() {
|
||||
}
|
||||
|
||||
function Manager() {
|
||||
this.servers = [];
|
||||
this.serversArr = [];
|
||||
this.serversHash = {}
|
||||
};
|
||||
|
||||
Manager.prototype.addServer = (function (id, title) {
|
||||
mods = [];
|
||||
port = 2302;
|
||||
var server = new Server(id, title, port, mods)
|
||||
this.servers.push(server);
|
||||
this.serversArr.push(server);
|
||||
this.serversHash[id] = server;
|
||||
return server;
|
||||
});
|
||||
|
||||
module.exports = Manager;
|
||||
Manager.prototype.getServer = (function (id) {
|
||||
return this.serversHash[id];
|
||||
});
|
||||
|
||||
Manager.prototype.getServers = (function () {
|
||||
return this.serversArr;
|
||||
});
|
||||
|
||||
module.exports = Manager;
|
||||
|
@ -1,7 +1,7 @@
|
||||
define(function (require) {
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var $ = require('jquery'),
|
||||
Backbone = require('backbone'),
|
||||
LayoutView = require('app/views/layout'),
|
||||
@ -13,7 +13,7 @@ define(function (require) {
|
||||
Missions = require('app/collections/missions'),
|
||||
Mods = require('app/collections/mods'),
|
||||
Servers = require('app/collections/servers'),
|
||||
|
||||
|
||||
$body = $('body'),
|
||||
missions = new Missions(),
|
||||
mods = new Mods(),
|
||||
@ -23,28 +23,28 @@ define(function (require) {
|
||||
homeView = new HomeView({servers: servers}),
|
||||
missionsListView = new MissionsListView({collection: missions}),
|
||||
modsListView = new ModsListView({collection: mods});
|
||||
|
||||
|
||||
return Backbone.Router.extend({
|
||||
|
||||
|
||||
routes: {
|
||||
"missions": "missions",
|
||||
"mods": "mods",
|
||||
"servers/:id": "server",
|
||||
"": "home",
|
||||
},
|
||||
|
||||
|
||||
initialize: function () {
|
||||
layoutView.navigation.show(navigationView);
|
||||
missions.fetch();
|
||||
mods.fetch();
|
||||
servers.fetch();
|
||||
},
|
||||
|
||||
|
||||
home: function () {
|
||||
layoutView.content.show(homeView);
|
||||
homeView.delegateEvents();
|
||||
},
|
||||
|
||||
|
||||
missions: function () {
|
||||
layoutView.content.show(missionsListView);
|
||||
missionsListView.delegateEvents();
|
||||
@ -54,11 +54,11 @@ define(function (require) {
|
||||
layoutView.content.show(modsListView);
|
||||
modsListView.delegateEvents();
|
||||
},
|
||||
|
||||
server: function () {
|
||||
layoutView.content.show(new ServerView({model: servers.first()}));
|
||||
|
||||
server: function (id) {
|
||||
layoutView.content.show(new ServerView({model: servers.get(id)}));
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,15 +1,32 @@
|
||||
define(function (require) {
|
||||
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
tpl = require('text!tpl/servers/info.html');
|
||||
|
||||
tpl = require('text!tpl/servers/info.html');
|
||||
|
||||
return Marionette.ItemView.extend({
|
||||
template: _.template(tpl),
|
||||
|
||||
events: {
|
||||
"click #start": "start"
|
||||
},
|
||||
|
||||
start: function (event) {
|
||||
var self = this;
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
url: "/api/servers/" + this.model.get('id') + "/start",
|
||||
type: 'GET',
|
||||
success: function (resp) {
|
||||
console.log(resp);
|
||||
},
|
||||
error: $.noop
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1 +1,3 @@
|
||||
<h2><%-title%></h2>
|
||||
<h2><%-title%></h2>
|
||||
|
||||
<a class="btn btn-primary" href="#" id="start">Start</a>
|
||||
|
@ -10,4 +10,4 @@
|
||||
<div class="tab-pane active" id="info"></div>
|
||||
<div class="tab-pane" id="mods"></div>
|
||||
<div class="tab-pane" id="settings"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -5,7 +5,7 @@ var Manager = require('./../manager');
|
||||
var manager = new Manager();
|
||||
|
||||
exports.index = function (req, res){
|
||||
res.send(manager.servers);
|
||||
res.send(manager.getServers());
|
||||
};
|
||||
|
||||
exports.create = function (req, res){
|
||||
@ -14,6 +14,10 @@ exports.create = function (req, res){
|
||||
res.send(manager.addServer(id, title));
|
||||
};
|
||||
|
||||
exports.show = function (req, res){
|
||||
res.send(manager.getServer(req.params.server));
|
||||
};
|
||||
|
||||
exports.update = function(req, res){
|
||||
res.send('update server ' + req.params.server);
|
||||
};
|
||||
@ -21,3 +25,9 @@ exports.update = function(req, res){
|
||||
exports.destroy = function(req, res){
|
||||
res.send('destroy server ' + req.params.server);
|
||||
};
|
||||
|
||||
exports.start = function (req, res){
|
||||
var server = manager.getServer(req.params.server);
|
||||
server.start();
|
||||
res.send({status:"ok"});
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user