From 3e8ba74459b7183e3ccd2f73726a4941bb21765a Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 24 Aug 2013 17:53:16 +0000 Subject: [PATCH] view notifies by user [#568] --- modules/report/pages.js | 65 ++++++++++++++++++++++++-------------- public/script.js | 3 +- views/report/channels.jade | 8 ++++- views/report/notifies.jade | 2 +- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/modules/report/pages.js b/modules/report/pages.js index e766643..29efd84 100644 --- a/modules/report/pages.js +++ b/modules/report/pages.js @@ -62,36 +62,55 @@ var pages = function(dbot) { } }, - '/notify/:server/:channel': function(req, res) { + '/notify/:server/:item': function(req, res) { var server = req.params.server, - channel = req.params.channel, notifies = []; - this.db.search('notifies', { - 'server': server, - 'channel': channel - }, function(notify) { - notifies.push(notify); - }, function(err) { - var pNickCache = {}; - async.eachSeries(notifies, function(notify, next) { - if(!_.has(pNickCache, notify.user)) { - dbot.api.users.getUser(notify.user, function(user) { - pNickCache[notify.user] = user.primaryNick; - notify.user = user.primaryNick; + if(req.params.item.charAt(0) == '#') { + var channel = req.params.item; + + this.db.search('notifies', { + 'server': server, + 'channel': channel + }, function(notify) { + notifies.push(notify); + }, function(err) { + var pNickCache = {}; + async.eachSeries(notifies, function(notify, next) { + if(!_.has(pNickCache, notify.user)) { + dbot.api.users.getUser(notify.user, function(user) { + pNickCache[notify.user] = user.primaryNick; + notify.user = user.primaryNick; + next(); + }); + } else { + notify.user = pNickCache[notify.user]; next(); + } + }, function() { + res.render('notifies', { + 'server': server, + 'notifies': _.sortBy(notifies, 'time') }); - } else { - notify.user = pNickCache[notify.user]; - next(); - } - }, function() { - res.render('notifies', { - 'server': server, - 'notifies': _.sortBy(notifies, 'time') }); }); - }); + } else { + var username = req.params.item; + + dbot.api.users.resolveUser(server, username, function(user) { + this.db.search('notifies', { + 'user': user.id + }, function(notify) { + notify.user = user.primaryNick; + notifies.push(notify); + }, function() { + res.render('notifies', { + 'server': server, + 'notifies': _.sortBy(notifies, 'time') + }); + }); + }.bind(this)); + } } }; diff --git a/public/script.js b/public/script.js index d6155a2..6e4475d 100644 --- a/public/script.js +++ b/public/script.js @@ -12,7 +12,8 @@ function searchNotifies(q) { var notifies = document.getElementById('notifies'); for (var i=1, row; row=notifies.rows[i]; i++) { if(row.cells[3].innerHTML.indexOf(q) == -1 && - row.cells[2].innerHTML.indexOf(q) == -1) { + row.cells[2].innerHTML.indexOf(q) == -1 && + row.cells[1].innerHTML.indexOf(q) == -1) { row.style.display = 'none'; } else { row.style.display = ''; diff --git a/views/report/channels.jade b/views/report/channels.jade index d2bc86e..9849e3f 100644 --- a/views/report/channels.jade +++ b/views/report/channels.jade @@ -1,10 +1,16 @@ extends ../layout block content - h3 Channels on #{server} + h3 Browse by Channel on #{server} div#backlink a(href='/notify') « Server List ul#quotelist -each channel in channels a(href='/notify/'+server+'/'+encodeURIComponent(channel)) li.quotes #{channel} + + h3 Browse by User on #{server} + ul#quotelist + -each nUser in users + a(href='/notify/'+server+'/'+encodeURIComponent(nUser.name)) + li.quotes #{nUser.name} (#{nUser.count}) diff --git a/views/report/notifies.jade b/views/report/notifies.jade index 71d2763..648dac1 100644 --- a/views/report/notifies.jade +++ b/views/report/notifies.jade @@ -2,7 +2,7 @@ extends ../layout block content div#backlink - a(href='/notify/'+server) « Server Channels + a(href='/notify/'+server) « Server p div#controls input(type="text", name="search", id="search-text", oninput="searchNotifies(this.value)")