Plugin admin fixes

This commit is contained in:
Egil Moeller 2012-04-17 22:18:43 +02:00
parent 6f774bc6a5
commit 7ab7ee9f5e
3 changed files with 64 additions and 34 deletions

View File

@ -9,8 +9,10 @@ $(document).ready(function () {
}); });
$("#do-search").unbind('click').click(function () { $("#do-search").unbind('click').click(function () {
if ($("#search-query")[0].value != "") socket.emit("search", {
socket.emit("search", $("#search-query")[0].value); pattern: $("#search-query")[0].value,
offset: $('#search-results').data('offset') || 0,
limit: 4});
}); });
$(".do-install").unbind('click').click(function (e) { $(".do-install").unbind('click').click(function (e) {
@ -29,8 +31,13 @@ $(document).ready(function () {
updateHandlers(); updateHandlers();
socket.on('progress', function (data) { socket.on('progress', function (data) {
if ($('#progress.dialog').data('progress') > data.progress) return;
$("#progress.dialog .close").hide(); $("#progress.dialog .close").hide();
$("#progress.dialog").show(); $("#progress.dialog").show();
$('#progress.dialog').data('progress', data.progress);
var message = "Unknown status"; var message = "Unknown status";
if (data.message) { if (data.message) {
message = "<span class='status'>" + data.message.toString() + "</span>"; message = "<span class='status'>" + data.message.toString() + "</span>";
@ -55,16 +62,26 @@ $(document).ready(function () {
}); });
socket.on('search-result', function (data) { socket.on('search-result', function (data) {
$("#search-results *").remove(); var widget=$(".search-results");
widget.data('query', data.query);
widget.data('total', data.total);
widget.find('.offset').html(data.qyery.offset);
widget.find('.limit').html(data.qyery.offset + data.qyery.offset.limit);
widget.find('.total').html(data.total);
widget.find(".results *").remove();
for (plugin_name in data.results) { for (plugin_name in data.results) {
var plugin = data.results[plugin_name]; var plugin = data.results[plugin_name];
var row = $("#search-result-template").clone(); var row = widget.find(".template tr").clone();
for (attr in plugin) { for (attr in plugin) {
row.find("." + attr).html(plugin[attr]); row.find("." + attr).html(plugin[attr]);
} }
$("#search-results").append(row); widget.find(".results").append(row);
} }
updateHandlers(); updateHandlers();
}); });

View File

@ -55,7 +55,7 @@ exports.install = function(plugin_name, cb) {
); );
}; };
exports.search = function(pattern, cb) { exports.search = function(query, cb) {
withNpm( withNpm(
function (cb) { function (cb) {
registry.get( registry.get(
@ -63,11 +63,18 @@ exports.search = function(pattern, cb) {
function (er, data) { function (er, data) {
if (er) return cb(er); if (er) return cb(er);
var res = {}; var res = {};
var i = 0;
for (key in data) { for (key in data) {
if (key.indexOf(plugins.prefix) == 0 && key.indexOf(pattern) != -1) if (/* && key.indexOf(plugins.prefix) == 0 */
res[key] = data[key]; key.indexOf(query.pattern) != -1) {
i++;
if (i > query.offset
&& i <= query.offset + query.limit) {
res[key] = data[key];
}
}
} }
cb(null, {results:res}); cb(null, {results:res, query: query, total:i});
} }
); );
}, },

View File

@ -40,31 +40,37 @@
</tbody> </tbody>
</table> </table>
<h1>Search for plugins to install</h1> <div class="paged listing search-results">
<form> <h1>Search for plugins to install</h1>
<input type="text" name="search" value="" id="search-query"> <form>
<input type="button" value="Search" id="do-search"> <input type="text" name="search" value="" id="search-query">
</form> <input type="button" value="Search" id="do-search">
<table> </form>
<thead> <table>
<tr> <thead>
<th>Name</th> <tr>
<th>Description</th> <th>Name</th>
<td></td> <th>Description</th>
</tr> <td></td>
</thead> </tr>
<tbody class="template"> </thead>
<tr id="search-result-template"> <tbody class="template">
<td class="name"></td> <tr>
<td class="description"></td> <td class="name"></td>
<td class="actions"> <td class="description"></td>
<input type="button" value="Install" class="do-install"> <td class="actions">
</td> <input type="button" value="Install" class="do-install">
</tr> </td>
</tbody> </tr>
<tbody id="search-results"> </tbody>
</tbody> <tbody class="results">
</table> </tbody>
</table>
<input type="button" value="<<" class="do-prev-page">
<span class="offset"></span>..<span class="limit"></span> of <span class="total"></span>.
<input type="button" value=">>" class="do-next-page">
</div>
<div id="progress" class="dialog"> <div id="progress" class="dialog">
<h1 class="title"> <h1 class="title">