Skip to content

Commit

Permalink
working search
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 28, 2011
1 parent 0efb444 commit e60e384
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ app.use(express.static(__dirname + '/public'));
// JSON api

app.get('/stats', provides('json'), json.stats);
app.get('/job/search', provides('json'), json.search);
app.get('/jobs/:from..:to/:order?', provides('json'), json.jobRange);
app.get('/jobs/:type/:status/:from..:to/:order?', provides('json'), json.jobTypeRange);
app.get('/jobs/:status/:from..:to/:order?', provides('json'), json.jobStatusRange);
Expand Down
18 changes: 17 additions & 1 deletion lib/http/public/javascripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
o(function(){
var search = o('#search');
search.keyup(function(){
var val = search.val();
var val = search.val().trim()
, jobs = o('#jobs .job');

// show all
if (val.length < 2) return jobs.show();

// query
o.get('/job/search?q=' + val, function(ids){
jobs.each(function(i, el){
var id = el.id.replace('job-', '');
if (~ids.indexOf(id)) {
o(el).show();
} else {
o(el).hide();
}
});
});
});
});
18 changes: 18 additions & 0 deletions lib/http/routes/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@

var Queue = require('../../kue')
, Job = require('../../queue/job')
, reds = require('reds')
, queue = new Queue;

/**
* Search instance.
*/

var search = reds.createSearch('q:search');

/**
* Get statistics including:
*
Expand Down Expand Up @@ -158,6 +165,17 @@ exports.updateState = function(req, res){
});
};

/**
* Search and respond with ids.
*/

exports.search = function(req, res){
search.query(req.query.q, function(err, ids){
if (err) return res.send({ error: err.message });
res.send(ids);
});
};

/**
* Get log for job :id.
*/
Expand Down

0 comments on commit e60e384

Please sign in to comment.