Functionality to remove server from manager

This commit is contained in:
Björn Dahlgren 2014-06-05 01:02:09 +02:00
parent 957e665ff2
commit fca9580bd8
4 changed files with 43 additions and 4 deletions

View File

@ -84,7 +84,10 @@ Server.prototype.stop = function(cb) {
if (!handled) {
handled = true;
self.emit('stopped');
cb();
if (cb) {
cb();
}
}
});
@ -94,7 +97,10 @@ Server.prototype.stop = function(cb) {
if (!handled) {
handled = true;
self.emit('stopped');
cb();
if (cb) {
cb();
}
}
}, 5000);
@ -126,6 +132,27 @@ Manager.prototype.addServer = (function (id, title) {
return server;
});
Manager.prototype.removeServer = (function (id) {
var server = this.serversHash[id];
if (!server) {
return {};
}
var index = this.serversArr.indexOf(server);
if (index > -1) {
this.serversArr.splice(index, 1);
}
delete this.serversHash[id];
this.save();
if (server.pid) {
server.stop();
}
return server;
});
Manager.prototype._addServer = (function (id, title, port, mods) {
var server = new Server(id, title, port, mods);
this.serversArr.push(server);

View File

@ -12,6 +12,14 @@ define(function (require) {
return Marionette.ItemView.extend({
tagName: "tr",
template: template
template: template,
events: {
"click .delete": "delete"
},
delete: function (event) {
this.model.destroy({wait: true});
},
});
});

View File

@ -1,3 +1,6 @@
<td>
<a href='#servers/<%-id%>'><%-title%></a>
<button type="button" class="btn btn-danger btn-xs delete pull-right">
<span class="glyphicon glyphicon-remove"></span> Delete
</button>
</td>

View File

@ -67,7 +67,8 @@ exports.update = function(req, res){
};
exports.destroy = function(req, res){
res.send('destroy server ' + req.params.server);
var server = manager.removeServer(req.params.server);
res.send(server);
};
exports.start = function (req, res){