2012-04-11 18:07:19 +02:00
|
|
|
$(document).ready(function () {
|
2012-04-29 19:54:38 +02:00
|
|
|
|
|
|
|
var socket,
|
|
|
|
loc = document.location,
|
|
|
|
port = loc.port == "" ? (loc.protocol == "https:" ? 443 : 80) : loc.port,
|
|
|
|
url = loc.protocol + "//" + loc.hostname + ":" + port + "/",
|
|
|
|
pathComponents = location.pathname.split('/'),
|
2012-04-29 20:12:15 +02:00
|
|
|
// Strip admin/plugins
|
|
|
|
baseURL = pathComponents.slice(0,pathComponents.length-2).join('/') + '/',
|
2012-04-29 19:54:38 +02:00
|
|
|
resource = baseURL.substring(1) + "socket.io";
|
|
|
|
|
|
|
|
//connect
|
|
|
|
socket = io.connect(url, {resource : resource}).of("/pluginfw/installer");
|
2012-04-11 18:07:19 +02:00
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
function search(searchTerm) {
|
|
|
|
if(search.searchTerm != searchTerm) {
|
|
|
|
search.offset = 0
|
|
|
|
search.results = []
|
|
|
|
search.end = false
|
|
|
|
}
|
|
|
|
search.searchTerm = searchTerm;
|
|
|
|
socket.emit("search", {searchTerm: searchTerm, offset:search.offset, length: search.limit});
|
|
|
|
search.offset += search.limit;
|
|
|
|
}
|
|
|
|
search.offset = 0
|
|
|
|
search.limit = 12
|
|
|
|
search.results = []
|
|
|
|
search.end = true// have we received all results already?
|
|
|
|
|
|
|
|
function displayPluginList(plugins, container, template) {
|
|
|
|
plugins.forEach(function(plugin) {
|
|
|
|
var row = template.clone();
|
|
|
|
|
|
|
|
for (attr in plugin) {
|
|
|
|
if(attr == "name"){ // Hack to rewrite URLS into name
|
|
|
|
row.find(".name").html("<a target='_blank' href='https://npmjs.org/package/"+plugin['name']+"'>"+plugin['name']+"</a>");
|
|
|
|
}else{
|
|
|
|
row.find("." + attr).html(plugin[attr]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
row.find(".version").html( plugin.version );
|
|
|
|
|
|
|
|
container.append(row);
|
|
|
|
})
|
|
|
|
updateHandlers();
|
2012-04-18 13:43:34 +02:00
|
|
|
}
|
|
|
|
|
2012-04-11 18:07:19 +02:00
|
|
|
function updateHandlers() {
|
2013-03-25 17:20:10 +01:00
|
|
|
// Search
|
2013-01-24 22:39:52 +01:00
|
|
|
$("#search-query").unbind('keyup').keyup(function () {
|
2013-03-25 17:20:10 +01:00
|
|
|
search($("#search-query").val());
|
2012-04-11 18:07:19 +02:00
|
|
|
});
|
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
// update & install
|
2013-01-26 22:15:19 +01:00
|
|
|
$(".do-install, .do-update").unbind('click').click(function (e) {
|
2012-04-11 18:07:19 +02:00
|
|
|
var row = $(e.target).closest("tr");
|
2013-01-22 19:28:38 +01:00
|
|
|
socket.emit("install", row.find(".name").text());
|
2012-04-11 18:07:19 +02:00
|
|
|
});
|
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
// uninstall
|
2012-04-11 18:07:19 +02:00
|
|
|
$(".do-uninstall").unbind('click').click(function (e) {
|
|
|
|
var row = $(e.target).closest("tr");
|
2013-01-22 19:28:38 +01:00
|
|
|
socket.emit("uninstall", row.find(".name").text());
|
2012-04-11 18:07:19 +02:00
|
|
|
});
|
2012-04-18 13:43:34 +02:00
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
// Infinite scroll
|
|
|
|
$(window).unbind('scroll').scroll(function() {
|
|
|
|
if(search.end) return;// don't keep requesting if there are no more results
|
|
|
|
var top = $('.search-results .results > tr').last().offset().top
|
|
|
|
if($(window).scrollTop()+$(window).height() > top) search(search.searchTerm)
|
|
|
|
})
|
2012-04-11 18:07:19 +02:00
|
|
|
}
|
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
socket.on('results:search', function (data) {
|
|
|
|
console.log('got search results', data)
|
|
|
|
search.results = search.results.concat(data.results);
|
|
|
|
if(!data.results.length) search.end = true;
|
2013-01-24 22:39:52 +01:00
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
var searchWidget = $(".search-results");
|
|
|
|
searchWidget.find(".results *").remove();
|
|
|
|
displayPluginList(search.results, searchWidget.find(".results"), searchWidget.find(".template tr"))
|
2012-04-11 18:07:19 +02:00
|
|
|
});
|
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
socket.on('results:installed', function (data) {
|
2012-04-11 18:07:19 +02:00
|
|
|
$("#installed-plugins *").remove();
|
2013-03-25 17:20:10 +01:00
|
|
|
displayPluginList(data.installed, $("#installed-plugins"), $("#installed-plugin-template"))
|
2013-01-26 22:15:19 +01:00
|
|
|
|
2013-03-25 12:45:23 +01:00
|
|
|
setTimeout(function() {
|
|
|
|
socket.emit('checkUpdates');
|
|
|
|
}, 5000)
|
2012-04-11 18:07:19 +02:00
|
|
|
});
|
2013-01-26 22:15:19 +01:00
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
socket.on('results:updatable', function(data) {
|
|
|
|
$('#installed-plugins > tr').each(function(i, tr) {
|
2013-01-26 22:15:19 +01:00
|
|
|
var pluginName = $(tr).find('.name').text()
|
|
|
|
|
|
|
|
if (data.updatable.indexOf(pluginName) >= 0) {
|
|
|
|
var actions = $(tr).find('.actions')
|
|
|
|
actions.append('<input class="do-update" type="button" value="Update" />')
|
|
|
|
actions.css('width', 200)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
updateHandlers();
|
|
|
|
})
|
2012-04-11 18:07:19 +02:00
|
|
|
|
2013-03-25 17:20:10 +01:00
|
|
|
// init
|
|
|
|
updateHandlers();
|
|
|
|
socket.emit("getInstalled");
|
|
|
|
search('');
|
2012-04-11 18:07:19 +02:00
|
|
|
});
|