Browse Source

Added real-time search to Ladder page.

master
Brandon Cornejo 11 years ago
parent
commit
8c2a32d346
  1. 14
      lib/currency.js
  2. 15
      lib/web.js
  3. 3
      web/public/css/app.css
  4. 0
      web/templates/index.jade
  5. 36
      web/templates/ladder.jade

14
lib/currency.js

@ -264,7 +264,8 @@ Currency.prototype.commands = function (data) {
break; break;
} }
} }
/*
// add currency // add currency
if (data[4] === 'add') { if (data[4] === 'add') {
if(parseInt(data[5], 10) > 0 && data[6]) { if(parseInt(data[5], 10) > 0 && data[6]) {
@ -285,6 +286,7 @@ Currency.prototype.commands = function (data) {
__self.adjust_currency('push', data[5], data[6]); __self.adjust_currency('push', data[5], data[6]);
} }
} }
*/
} }
// moderator commands // moderator commands
@ -594,9 +596,6 @@ Currency.prototype.query_rank = function(data, callback) {
callback(ranks, total); callback(ranks, total);
}); });
var file = require('fs');
file.appendFile('./../logs/error-log.txt', sql+'\n', function(d){});
}; };
Currency.prototype.query_top = function (data, callback) { Currency.prototype.query_top = function (data, callback) {
@ -738,6 +737,7 @@ Currency.prototype.handout_coins = function () {
// trigger coin handout // trigger coin handout
function insert_coins() { function insert_coins() {
__self.give_coins = __self.streaming; __self.give_coins = __self.streaming;
console.log('DATA - Inserting coins');
if (__self.give_coins) { if (__self.give_coins) {
var time = utils.make_interval(__self.give_coins_timer); var time = utils.make_interval(__self.give_coins_timer);
if (time === 0) { if (time === 0) {
@ -762,7 +762,7 @@ Currency.prototype.handout_coins = function () {
} }
// execute query // execute query
__self.db.execute(sql, function () {});
__self.db.execute(sql, function () { console.log('DATA - Completed adding coins to ' + __self.viewer_list.length + ' viewers'); });
setTimeout(insert_coins, 1000); setTimeout(insert_coins, 1000);
} else { } else {
setTimeout(insert_coins, time); setTimeout(insert_coins, time);
@ -781,6 +781,7 @@ Currency.prototype.handout_coins = function () {
if(name.charAt(0) === ':') name = name.slice(1); if(name.charAt(0) === ':') name = name.slice(1);
if (__self.viewer_list.indexOf(name) < 0 && __self.config.ignorelist.indexOf(name) < 0) { if (__self.viewer_list.indexOf(name) < 0 && __self.config.ignorelist.indexOf(name) < 0) {
__self.viewer_list.push(name); __self.viewer_list.push(name);
console.log("[*ADD NAME*] "+name+" from /names");
} }
}); });
} }
@ -794,6 +795,7 @@ Currency.prototype.handout_coins = function () {
} }
if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) { if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) {
__self.viewer_list.push(viewer); __self.viewer_list.push(viewer);
console.log("[*ADD NAME*] "+viewer+" from JOIN");
} }
} }
@ -807,6 +809,7 @@ Currency.prototype.handout_coins = function () {
var viewer_idx = __self.viewer_list.indexOf(viewer); var viewer_idx = __self.viewer_list.indexOf(viewer);
if (viewer_idx >= 0) { if (viewer_idx >= 0) {
__self.viewer_list.splice(viewer_idx); __self.viewer_list.splice(viewer_idx);
console.log("[*DEL NAME*] "+viewer+" from PART");
} }
} }
@ -819,6 +822,7 @@ Currency.prototype.handout_coins = function () {
} }
if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) { if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) {
__self.viewer_list.push(viewer); __self.viewer_list.push(viewer);
console.log("[*ADD NAME*] "+viewer+" from CHAT");
} }
if (__self.active_list.indexOf(viewer) < 0) { if (__self.active_list.indexOf(viewer) < 0) {
__self.active_list.push(viewer); __self.active_list.push(viewer);

15
lib/web.js

@ -46,8 +46,21 @@ WEB.prototype.start = function () {
slogan: __self.slogan, slogan: __self.slogan,
logo: __self.logo, logo: __self.logo,
twitter: __self.twitter, twitter: __self.twitter,
rows: rows
rows: rows,
});
});
});
__self.srv.get('/api/test', function(req, res) {
res.send("Hey, its Potatr. This data was pulled from the web.");
});
__self.srv.all('/api/data', function(req, res) {
sql = 'SELECT * FROM viewers ORDER BY points DESC;';
__self.db.execute(sql, function(rows) {
ladder_data = new Object();
rows.forEach(function(element, index, array){
ladder_data[element.user] = element.points;
}); });
res.send(ladder_data);
}); });
}); });

3
web/public/css/app.css

@ -12,3 +12,6 @@
filter: FlipH; filter: FlipH;
-ms-filter: "FlipH"; -ms-filter: "FlipH";
} }
.uk-search-field, .uk-search-field::-moz-placeholder {
color: #FFFFFF;
}

0
web/templates/index.jade

36
web/templates/ladder.jade

@ -32,6 +32,10 @@ html(lang="en")
br br
div.uk-width-1-1 div.uk-width-1-1
div.uk-panel.uk-panel-box div.uk-panel.uk-panel-box
div.uk-badge.uk-float-right
form.uk-search
input(class='uk-search-field', type='search', placeholder='Search...')
button(class='uk-close', type='reset')
table.uk-table.uk-table-hover.uk-table-striped table.uk-table.uk-table-hover.uk-table-striped
caption Potato Farmer Ladder Rankings caption Potato Farmer Ladder Rankings
thead thead
@ -47,6 +51,24 @@ html(lang="en")
data = !{JSON.stringify(rows)}; data = !{JSON.stringify(rows)};
$(document).ready(function(){ $(document).ready(function(){
// Live search of the ladder listings
$('.uk-search-field').keyup(function() {
var query = $(this).val();
if(query.length > 2) {
var temp = $('.uk-active').attr('page');
$('.uk-active').removeClass('uk-active').empty().append('<a>'+temp+'</a>');
$('table > tbody').empty();
data.forEach(function(element, index, array) {
if(element.user.search(new RegExp(query, 'i')) != -1) {
$('table > tbody').append($('<tr></tr>').append('<td>'+index+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
}
});
}
});
// Create pagination buttons // Create pagination buttons
for(var i = 1; i <= Math.ceil(data.length/perPage); i++) { for(var i = 1; i <= Math.ceil(data.length/perPage); i++) {
var button = $('<li page='+i+'></li>').append('<a>'+i+'</a>'); var button = $('<li page='+i+'></li>').append('<a>'+i+'</a>');
@ -63,8 +85,7 @@ html(lang="en")
// slice(a, b): a = (n*(x-1))+1, b = n*x where n = perPage and x=curerntPage (skip +1 at end of a for splice) // slice(a, b): a = (n*(x-1))+1, b = n*x where n = perPage and x=curerntPage (skip +1 at end of a for splice)
var a = (perPage*(z-1)), var a = (perPage*(z-1)),
b = perPage*z,
pstart = z-1;
b = perPage*z;
data.slice(a, b).forEach(function(element, index, array){ data.slice(a, b).forEach(function(element, index, array){
$('table > tbody').append($('<tr></tr>').append('<td>'+(a+index+1)+'</td><td>'+element.user+'</td><td>'+element.points+'</td>')); $('table > tbody').append($('<tr></tr>').append('<td>'+(a+index+1)+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
@ -74,10 +95,11 @@ html(lang="en")
$('.uk-pagination').append(button); $('.uk-pagination').append(button);
} }
// When search input is cleared, go back to first page
$('.uk-close').on('click', function(){
$('ul.uk-pagination > li').first().click();
});
// Show the first page when we load up
$('ul.uk-pagination > li').first().click(); $('ul.uk-pagination > li').first().click();
}); });
function createPaginationButton(button) {
}
Loading…
Cancel
Save