diff --git a/package.json b/package.json index 23625ed..25bf52a 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/public/js/app/views/mods/list.js b/public/js/app/views/mods/list.js index e9f3821..d0fa8c1 100644 --- a/public/js/app/views/mods/list.js +++ b/public/js/app/views/mods/list.js @@ -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(); + }, }); }); diff --git a/public/js/app/views/mods/list_item.js b/public/js/app/views/mods/list_item.js index 9d55553..3498ce3 100644 --- a/public/js/app/views/mods/list_item.js +++ b/public/js/app/views/mods/list_item.js @@ -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 + }); + }, }); }); diff --git a/public/js/tpl/mods/list_item.html b/public/js/tpl/mods/list_item.html index 145a90c..318e2fd 100644 --- a/public/js/tpl/mods/list_item.html +++ b/public/js/tpl/mods/list_item.html @@ -1,3 +1,9 @@ <%-name%> + <% if (outdated) { %> + + + Update + + <% } %> diff --git a/routes/mods.js b/routes/mods.js index e8e9199..fc96620 100644 --- a/routes/mods.js +++ b/routes/mods.js @@ -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); };