From 4acf17f63698323f2f68e1dd116ccd3eaa9ab7da Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 25 May 2014 17:54:46 +0000 Subject: [PATCH] tags --- modules/report/pages.js | 30 ++++++++++++++++++++++-------- views/layout.jade | 2 +- views/report/channels.jade | 6 ++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/modules/report/pages.js b/modules/report/pages.js index 1397df7..3c17030 100644 --- a/modules/report/pages.js +++ b/modules/report/pages.js @@ -8,7 +8,8 @@ var pages = function(dbot) { var server = req.user.server, userCount = {}, users = [], - channelCount = {}; + channelCount = {}, + tags = {}; this.db.scan('notifies', function(notify) { if(!_.has(userCount, notify.user)) { @@ -19,6 +20,10 @@ var pages = function(dbot) { } userCount[notify.user]++; channelCount[notify.channel]++; + _.each(notify.tags, function(tag) { + if(!_.has(tags, tag)) tags[tag] = 0; + tags[tag]++; + }); }, function() { userCount = _.map(userCount, function(value, key) { return { @@ -39,7 +44,8 @@ var pages = function(dbot) { res.render('channels', { 'server': server, 'users': users, - 'channels': channelCount + 'channels': channelCount, + 'tags': tags }); }); }); @@ -110,16 +116,24 @@ var pages = function(dbot) { '/notify/:item': function(req, res) { var server = req.user.server, + type = req.query.t, notifies = []; - if(req.params.item.charAt(0) == '#') { - var channel = req.params.item; + console.log(type); - this.db.search('notifies', { + if(req.params.item.charAt(0) == '#') { + var item = req.params.item, + search = { 'server': server, - 'channel': channel - }, function(notify) { - notifies.push(notify); + }; + if(type != 'tag') search.channel = item; + + this.db.search('notifies', search, function(notify) { + if(type == 'tag') { + if(_.include(notify.tags, item)) notifies.push(notify); + } else { + notifies.push(notify); + } }, function(err) { var pNickCache = {}; async.eachSeries(notifies, function(notify, next) { diff --git a/views/layout.jade b/views/layout.jade index c78c770..dfb3649 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -1,4 +1,4 @@ -!!! 5 +doctype html html(lang='en') head meta(charset='utf-8') diff --git a/views/report/channels.jade b/views/report/channels.jade index 3edc3bd..a96c412 100644 --- a/views/report/channels.jade +++ b/views/report/channels.jade @@ -18,3 +18,9 @@ block content -each nUser in users a(href='/notify/'+encodeURIComponent(nUser.name)) li.quotes #{nUser.name} (#{nUser.count}) + + h3 Browse by Tag on #{server} + ul#quotelist + -each count, tag in tags + a(href='/notify/'+encodeURIComponent(tag)+'?t=tag') + li.quotes #{tag} (#{count})