Better plugin admin interface
parent
d6f476312d
commit
4c1d94343f
|
@ -27,7 +27,7 @@ exports.socketio = function (hook_name, args, cb) {
|
|||
|
||||
socket.on("search", function (query) {
|
||||
socket.emit("progress", {progress:0, message:'Fetching results...'});
|
||||
installer.search(query, function (progress) {
|
||||
installer.search(query, true, function (progress) {
|
||||
if (progress.results)
|
||||
socket.emit("search-result", progress);
|
||||
socket.emit("progress", progress);
|
||||
|
|
|
@ -1,18 +1,28 @@
|
|||
$(document).ready(function () {
|
||||
var socket = io.connect().of("/pluginfw/installer");
|
||||
|
||||
$('.search-results').data('query', {
|
||||
pattern: '',
|
||||
offset: 0,
|
||||
limit: 4,
|
||||
});
|
||||
|
||||
var doUpdate = false;
|
||||
|
||||
var search = function () {
|
||||
socket.emit("search", $('.search-results').data('query'));
|
||||
}
|
||||
|
||||
function updateHandlers() {
|
||||
$("#progress.dialog .close").unbind('click').click(function () {
|
||||
$("#progress.dialog").hide();
|
||||
});
|
||||
|
||||
$("#do-search").unbind('click').click(function () {
|
||||
socket.emit("search", {
|
||||
pattern: $("#search-query")[0].value,
|
||||
offset: $('#search-results').data('offset') || 0,
|
||||
limit: 4});
|
||||
var query = $('.search-results').data('query');
|
||||
query.pattern = $("#search-query")[0].value;
|
||||
query.offset = 0;
|
||||
search();
|
||||
});
|
||||
|
||||
$(".do-install").unbind('click').click(function (e) {
|
||||
|
@ -26,12 +36,29 @@ $(document).ready(function () {
|
|||
doUpdate = true;
|
||||
socket.emit("uninstall", row.find(".name").html());
|
||||
});
|
||||
|
||||
$(".do-prev-page").unbind('click').click(function (e) {
|
||||
var query = $('.search-results').data('query');
|
||||
query.offset -= query.limit;
|
||||
if (query.offset < 0) {
|
||||
query.offset = 0;
|
||||
}
|
||||
search();
|
||||
});
|
||||
$(".do-next-page").unbind('click').click(function (e) {
|
||||
var query = $('.search-results').data('query');
|
||||
var total = $('.search-results').data('total');
|
||||
if (query.offset + query.limit < total) {
|
||||
query.offset += query.limit;
|
||||
}
|
||||
search();
|
||||
});
|
||||
}
|
||||
|
||||
updateHandlers();
|
||||
|
||||
socket.on('progress', function (data) {
|
||||
if ($('#progress.dialog').data('progress') > data.progress) return;
|
||||
if (data.progress > 0 && $('#progress.dialog').data('progress') > data.progress) return;
|
||||
|
||||
$("#progress.dialog .close").hide();
|
||||
$("#progress.dialog").show();
|
||||
|
@ -100,5 +127,6 @@ $(document).ready(function () {
|
|||
});
|
||||
|
||||
socket.emit("load");
|
||||
search();
|
||||
|
||||
});
|
||||
|
|
|
@ -55,18 +55,33 @@ exports.install = function(plugin_name, cb) {
|
|||
);
|
||||
};
|
||||
|
||||
exports.search = function(query, cb) {
|
||||
exports.searchCache = null;
|
||||
|
||||
exports.search = function(query, cache, cb) {
|
||||
withNpm(
|
||||
function (cb) {
|
||||
registry.get(
|
||||
"/-/all", null, 600, false, true,
|
||||
var getData = function (cb) {
|
||||
if (cache && exports.searchCache) {
|
||||
cb(null, exports.searchCache);
|
||||
} else {
|
||||
registry.get(
|
||||
"/-/all", null, 600, false, true,
|
||||
function (er, data) {
|
||||
if (er) return cb(er);
|
||||
exports.searchCache = data;
|
||||
cb(er, data);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
getData(
|
||||
function (er, data) {
|
||||
if (er) return cb(er);
|
||||
var res = {};
|
||||
var i = 0;
|
||||
for (key in data) {
|
||||
if (/* && key.indexOf(plugins.prefix) == 0 */
|
||||
key.indexOf(query.pattern) != -1) {
|
||||
if ( key.indexOf(plugins.prefix) == 0
|
||||
&& key.indexOf(query.pattern) != -1) {
|
||||
i++;
|
||||
if (i > query.offset
|
||||
&& i <= query.offset + query.limit) {
|
||||
|
|
Loading…
Reference in New Issue