mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Remove Play withSIX
This commit is contained in:
parent
4154cd697f
commit
a39e6f17e0
97
lib/mods.js
97
lib/mods.js
@ -1,14 +1,9 @@
|
||||
var async = require('async')
|
||||
var events = require('events')
|
||||
var filesize = require('filesize')
|
||||
var fs = require('fs.extra')
|
||||
var _ = require('lodash')
|
||||
var path = require('path')
|
||||
var playwithsix = require('playwithsix')
|
||||
|
||||
var Mods = function (config) {
|
||||
this.config = config
|
||||
this.liteMods = true
|
||||
this.mods = []
|
||||
}
|
||||
|
||||
@ -25,52 +20,6 @@ Mods.prototype.delete = function (mod, cb) {
|
||||
})
|
||||
}
|
||||
|
||||
Mods.prototype.download = function (mod, cb) {
|
||||
var self = this
|
||||
var currentDownloadMod = null
|
||||
|
||||
playwithsix.downloadMod(this.config.path, mod, {lite: this.liteMods}, function (err, mods) {
|
||||
if (currentDownloadMod) {
|
||||
currentDownloadMod.progress = null
|
||||
self.emit('mods', self.mods)
|
||||
}
|
||||
self.updateMods()
|
||||
|
||||
if (cb) {
|
||||
cb(err, mods)
|
||||
}
|
||||
}).on('progress', function (progress) {
|
||||
var modName = progress.mod
|
||||
|
||||
if (!currentDownloadMod || currentDownloadMod.name !== modName) {
|
||||
if (currentDownloadMod) {
|
||||
currentDownloadMod.progress = null
|
||||
}
|
||||
|
||||
var mod = _.find(self.mods, {name: modName})
|
||||
|
||||
if (mod) {
|
||||
currentDownloadMod = mod
|
||||
} else {
|
||||
currentDownloadMod = {
|
||||
name: modName,
|
||||
outdated: false,
|
||||
playWithSix: true
|
||||
}
|
||||
self.mods.push(currentDownloadMod)
|
||||
}
|
||||
}
|
||||
|
||||
// Progress in whole percent
|
||||
var newProgress = parseInt(progress.completed / progress.size * 100, 10)
|
||||
|
||||
if (newProgress !== currentDownloadMod.progress) {
|
||||
currentDownloadMod.progress = newProgress
|
||||
self.emit('mods', self.mods)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Mods.prototype.updateMods = function () {
|
||||
var self = this
|
||||
fs.readdir(self.config.path, function (err, files) {
|
||||
@ -79,54 +28,16 @@ Mods.prototype.updateMods = function () {
|
||||
} else {
|
||||
var mods = files.filter(function (file) {
|
||||
return file.charAt(0) === '@'
|
||||
})
|
||||
|
||||
playwithsix.checkOutdated(self.config.path, function (err, outdatedMods) {
|
||||
if (err) {
|
||||
console.log('Error checking for outdated mods: ' + err)
|
||||
}).map(function (name) {
|
||||
return {
|
||||
name: name
|
||||
}
|
||||
})
|
||||
|
||||
async.map(mods, function (mod, cb) {
|
||||
var modPath = path.join(self.config.path, mod)
|
||||
self.isPlayWithSixMod(modPath, function (isPlayWithSixMod) {
|
||||
cb(null, {
|
||||
name: mod,
|
||||
outdated: outdatedMods && outdatedMods.indexOf(mod) >= 0,
|
||||
progress: null,
|
||||
playWithSix: isPlayWithSixMod
|
||||
})
|
||||
})
|
||||
}, function (err, mods) {
|
||||
if (!err) {
|
||||
self.mods = mods
|
||||
self.emit('mods', mods)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Mods.prototype.isPlayWithSixMod = function (modPath, cb) {
|
||||
var pwsFile = path.join(modPath, '.synq.json')
|
||||
fs.exists(pwsFile, function (exists) {
|
||||
if (cb) {
|
||||
cb(exists)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Mods.prototype.search = function (query, cb) {
|
||||
playwithsix.search(query, function (err, mods) {
|
||||
if (err) {
|
||||
cb(err)
|
||||
} else {
|
||||
mods.map(function (mod) {
|
||||
mod.formattedSize = filesize(mod.size)
|
||||
})
|
||||
cb(null, mods)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = Mods
|
||||
|
@ -27,7 +27,6 @@
|
||||
"lodash": "^3.6.0",
|
||||
"morgan": "^1.8.1",
|
||||
"multer": "^1.3.0",
|
||||
"playwithsix": "0.0.13",
|
||||
"serve-static": "^1.12.1",
|
||||
"slugify": "^1.1.0",
|
||||
"socket.io": "^1.0.4",
|
||||
|
@ -1,89 +0,0 @@
|
||||
define(function (require) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
ListItemView = require('app/views/mods/search/list_item'),
|
||||
Ladda = require('ladda'),
|
||||
Mods = require('app/collections/mods'),
|
||||
tpl = require('text!tpl/mods/form.html');
|
||||
|
||||
return Marionette.CompositeView.extend({
|
||||
|
||||
events: {
|
||||
'submit': 'beforeSubmit',
|
||||
},
|
||||
|
||||
itemView: ListItemView,
|
||||
itemViewContainer: "tbody",
|
||||
template: _.template(tpl),
|
||||
|
||||
initialize: function (options) {
|
||||
this.mods = options.mods;
|
||||
this.collection = new Mods();
|
||||
this.bind('ok', this.submit);
|
||||
this.bind('shown', this.shown);
|
||||
|
||||
var self = this;
|
||||
this.listenTo(this.mods, "change reset add remove", function () {
|
||||
self.collection.trigger('reset');
|
||||
});
|
||||
},
|
||||
|
||||
itemViewOptions: function(options) {
|
||||
options.set('mods', this.mods);
|
||||
},
|
||||
|
||||
beforeSubmit: function(e) {
|
||||
e.preventDefault();
|
||||
this.submit();
|
||||
},
|
||||
|
||||
shown: function (modal) {
|
||||
var $okBtn = modal.$el.find('.btn.ok');
|
||||
$okBtn.addClass('ladda-button').attr('data-style', 'expand-left');
|
||||
|
||||
this.laddaBtn = Ladda.create($okBtn.get(0));
|
||||
|
||||
this.$el.find('form .mod').focus();
|
||||
},
|
||||
|
||||
submit: function (modal) {
|
||||
var self = this;
|
||||
var $form = this.$el.find('form');
|
||||
|
||||
if (modal) {
|
||||
self.modal.preventClose();
|
||||
}
|
||||
|
||||
$form.find('.form-group').removeClass('has-error');
|
||||
$form.find('.help-block').text('');
|
||||
|
||||
this.laddaBtn.start();
|
||||
self.modal.$el.find('.btn.cancel').addClass('disabled');
|
||||
|
||||
$.ajax({
|
||||
url: '/api/mods/search',
|
||||
type: 'POST',
|
||||
data: {
|
||||
query: $form.find('.query').val()
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
self.laddaBtn.stop();
|
||||
self.modal.$el.find('.btn.cancel').removeClass('disabled');
|
||||
self.collection.set(data);
|
||||
},
|
||||
error: function () {
|
||||
self.laddaBtn.stop();
|
||||
$form.find('.form-group').addClass('has-error');
|
||||
$form.find('.help-block').text('Problem searching, try again');
|
||||
self.modal.$el.find('.btn.cancel').removeClass('disabled');
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
@ -7,7 +7,6 @@ define(function (require) {
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
ListItemView = require('app/views/mods/list_item'),
|
||||
FormView = require('app/views/mods/form'),
|
||||
tpl = require('text!tpl/mods/list.html'),
|
||||
|
||||
template = _.template(tpl);
|
||||
@ -18,7 +17,6 @@ define(function (require) {
|
||||
template: template,
|
||||
|
||||
events: {
|
||||
"click #download": "download",
|
||||
"click #refresh": "refresh",
|
||||
},
|
||||
|
||||
@ -26,19 +24,6 @@ define(function (require) {
|
||||
this.listenTo(this.collection, "change reset", this.render);
|
||||
},
|
||||
|
||||
download: function (event) {
|
||||
event.preventDefault();
|
||||
var view = new FormView({mods: this.collection});
|
||||
var modal = new Backbone.BootstrapModal({
|
||||
content: view,
|
||||
animate: true,
|
||||
cancelText: 'Close',
|
||||
okText: 'Search',
|
||||
});
|
||||
view.modal = modal;
|
||||
modal.open();
|
||||
},
|
||||
|
||||
refresh: function (event) {
|
||||
event.preventDefault();
|
||||
$.ajax({
|
||||
|
@ -18,7 +18,6 @@ define(function (require) {
|
||||
|
||||
events: {
|
||||
"click .destroy": "destroy",
|
||||
"click .update": "update",
|
||||
},
|
||||
|
||||
destroy: function (event) {
|
||||
@ -35,25 +34,5 @@ define(function (require) {
|
||||
self.model.destroy();
|
||||
});
|
||||
},
|
||||
|
||||
update: function (event) {
|
||||
var self = this;
|
||||
event.preventDefault();
|
||||
|
||||
var $updateBtn = this.$el.find(".update");
|
||||
var laddaBtn = Ladda.create($updateBtn.get(0));
|
||||
laddaBtn.start();
|
||||
|
||||
$.ajax({
|
||||
url: "/api/mods/" + this.model.get('name'),
|
||||
type: 'PUT',
|
||||
success: function (resp) {
|
||||
laddaBtn.stop();
|
||||
},
|
||||
error: function (resp) {
|
||||
laddaBtn.stop();
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
|
@ -1,58 +0,0 @@
|
||||
define(function (require) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
Ladda = require('ladda'),
|
||||
tpl = require('text!tpl/mods/search/list_item.html'),
|
||||
|
||||
template = _.template(tpl);
|
||||
|
||||
return Marionette.ItemView.extend({
|
||||
tagName: "tr",
|
||||
template: template,
|
||||
|
||||
events: {
|
||||
"click .install": "install"
|
||||
},
|
||||
|
||||
templateHelpers: {
|
||||
progress: function() {
|
||||
if (this.mods.get(this.name)) {
|
||||
return this.mods.get(this.name).get('progress');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
install: function (event) {
|
||||
var self = this;
|
||||
event.preventDefault();
|
||||
|
||||
this.laddaBtn = Ladda.create(this.$el.find(".ladda-button").get(0));
|
||||
this.laddaBtn.start();
|
||||
this.$el.find('.ladda-button').addClass('disabled');
|
||||
|
||||
$.ajax({
|
||||
url: "/api/mods/",
|
||||
type: 'POST',
|
||||
data: {
|
||||
name: this.model.get('name'),
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function (resp) {
|
||||
self.laddaBtn.stop();
|
||||
self.$el.find('.ladda-button').removeClass('disabled');
|
||||
},
|
||||
error: function (resp) {
|
||||
self.laddaBtn.stop();
|
||||
self.$el.find('.ladda-button').removeClass('disabled');
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
@ -1,23 +0,0 @@
|
||||
<p>
|
||||
Install mods from <a href='http://play.withsix.com/' target=_blank>Play withSIX</a>
|
||||
</p>
|
||||
|
||||
<form class="form" role="form" action="/api/mods" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="query" class="control-label">Search</label>
|
||||
<input type="text" class="form-control query" name="query" id="query">
|
||||
<span class="help-block"></span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Mod</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<!-- want to insert collection items, here -->
|
||||
<tbody></tbody>
|
||||
</table>
|
@ -3,11 +3,6 @@
|
||||
Refresh
|
||||
</a>
|
||||
|
||||
<a class="btn btn-primary" id="download" href="#">
|
||||
<span class="glyphicon glyphicon-search"></span>
|
||||
Search & Download
|
||||
</a>
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -1,30 +1,11 @@
|
||||
<td>
|
||||
<a href='#mods/<%-name%>'><%-name%></a>
|
||||
|
||||
<% if (playWithSix) { %>
|
||||
<img src="/images/playwithsix.png" height="20px" width="20px" />
|
||||
<% } %>
|
||||
</td>
|
||||
<td>
|
||||
<% if (progress) { %>
|
||||
<div class="progress" style="margin-bottom: 0;">
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="<%-progress%>" aria-valuemin="0" aria-valuemax="100" style="width: <%-progress%>%; min-width: 2em;">
|
||||
<%-progress%>%
|
||||
</div>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<a class="btn btn-danger btn-xs destroy ladda-button pull-right" data-style="expand-left">
|
||||
<span class="glyphicon glyphicon-trash"></span>
|
||||
Delete
|
||||
</a>
|
||||
|
||||
<% if (outdated) { %>
|
||||
<a class="btn btn-primary btn-xs update ladda-button pull-right" data-style="expand-left" style="margin-right: 8px">
|
||||
<span class="glyphicon glyphicon-save"></span>
|
||||
Update
|
||||
</a>
|
||||
<% } %>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
<% } %>
|
||||
</td>
|
||||
|
@ -1,34 +0,0 @@
|
||||
<td style="width: 100%;">
|
||||
<p>
|
||||
<strong><%-name%></strong>
|
||||
<small>
|
||||
<% if (typeof(type) != "undefined" && type) { %>
|
||||
<%-type%>
|
||||
<% } else { %>
|
||||
Unknown
|
||||
<% } %>
|
||||
</small>
|
||||
</p>
|
||||
<p><%-title%></p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<% if (progress()) { %>
|
||||
<div class="progress" style="margin-bottom: 0;">
|
||||
<div class="progress-bar" role="progressbar" aria-valuenow="<%-progress()%>" aria-valuemin="0" aria-valuemax="100" style="width: <%-progress()%>%; min-width: 2em;">
|
||||
<%-progress()%>%
|
||||
</div>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<a class="btn btn-primary btn-xs install ladda-button pull-right" data-style="expand-left">
|
||||
<span class="glyphicon glyphicon-save"></span>
|
||||
Install
|
||||
</a>
|
||||
<% } %>
|
||||
<div class="clearfix"></div>
|
||||
</p>
|
||||
<p>
|
||||
<small class="pull-right"><%-formattedSize%></small>
|
||||
<div class="clearfix"></div>
|
||||
</p>
|
||||
</td>
|
@ -7,16 +7,6 @@ module.exports = function (modsManager) {
|
||||
res.send(modsManager.mods)
|
||||
})
|
||||
|
||||
router.post('/', function (req, res) {
|
||||
modsManager.download(req.body.name)
|
||||
res.status(204).send()
|
||||
})
|
||||
|
||||
router.put('/:mod', function (req, res) {
|
||||
modsManager.download(req.params.mod)
|
||||
res.status(204).send()
|
||||
})
|
||||
|
||||
router.delete('/:mod', function (req, res) {
|
||||
modsManager.delete(req.params.mod, function (err) {
|
||||
if (err) {
|
||||
@ -32,16 +22,5 @@ module.exports = function (modsManager) {
|
||||
res.status(204).send()
|
||||
})
|
||||
|
||||
router.post('/search', function (req, res) {
|
||||
var query = req.body.query || ''
|
||||
modsManager.search(query, function (err, mods) {
|
||||
if (err || !mods) {
|
||||
res.status(500).send(err)
|
||||
} else {
|
||||
res.send(mods)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return router
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
var should = require('should')
|
||||
|
||||
var Mods = require('../../lib/mods.js')
|
||||
|
||||
describe('Mods', function () {
|
||||
describe('search()', function () {
|
||||
it('should find mods', function (done) {
|
||||
var mods = new Mods()
|
||||
mods.search('', function (err, mods) {
|
||||
should(err).be.null()
|
||||
mods.should.not.be.empty()
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user