Check for outdated mods from PlayWithSix and button in listview to update

This commit is contained in:
Björn Dahlgren 2014-04-21 15:24:47 +02:00
parent 77026aa4bc
commit 6efdf0d34a
5 changed files with 55 additions and 5 deletions

View File

@ -9,6 +9,7 @@
"express-resource": "~1.0.0",
"when": "~3.1.0",
"gamedig": "^0.2.4",
"ip": "^0.3.0"
"ip": "^0.3.0",
"playwithsix": "0.0.1"
}
}

View File

@ -15,5 +15,13 @@ define(function (require) {
itemView: ListItemView,
itemViewContainer: "tbody",
template: template,
initialize: function (options) {
this.on("itemview:mods:update", this.update, this);
},
update: function() {
this.collection.fetch();
},
});
});

View File

@ -12,6 +12,23 @@ define(function (require) {
return Marionette.ItemView.extend({
tagName: "tr",
template: template
template: template,
events: {
"click .update": "update"
},
update: function (event) {
var self = this;
event.preventDefault();
$.ajax({
url: "/api/mods/" + this.model.get('name'),
type: 'PUT',
success: function (resp) {
self.trigger("mods:update", mods);
},
error: $.noop
});
},
});
});

View File

@ -1,3 +1,9 @@
<td>
<a href='#mods/<%-name%>'><%-name%></a>
<% if (outdated) { %>
<a class="btn btn-primary btn-xs update pull-right">
<span class="glyphicon glyphicon-save"></span>
Update
</a>
<% } %>
</td>

View File

@ -1,10 +1,15 @@
var fs = require('fs')
, path = require('path')
, playwithsix = require('playwithsix')
, when = require('when')
, nodefn = require('when/node/function');
var config = require('./../config');
function downloadMod(mod, cb) {
playwithsix.downloadMod(config.path, mod, cb);
}
function walk (directory) {
createFile = function (file, stat) {
return {
@ -49,10 +54,13 @@ exports.index = function(req, res){
} else {
var mods = files.filter(function (file) {
return file.charAt(0) == "@";
}).map(function (mod) {
return { name: mod }
});
res.send(mods);
playwithsix.checkOutdated(config.path, function (outdatedMods, err) {
res.send(mods.map(function (mod) {
return { name: mod, outdated: outdatedMods.indexOf(mod) >= 0 };
}));
});
}
});
};
@ -70,6 +78,16 @@ exports.show = function(req, res){
});
};
exports.update = function(req, res){
downloadMod(req.params.mod, function (mods, err) {
if (mods && !err) {
res.send(mods);
} else {
res.send(500, err);
}
});
};
exports.destroy = function(req, res){
res.send('destroy mod ' + req.params.mod);
};