Skip to content

Commit

Permalink
Add top rooms to profiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
martindale committed Mar 16, 2015
1 parent c4d889e commit 6ebbec0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
28 changes: 27 additions & 1 deletion controllers/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
collectUserPlaylists,
collectUserPlays,
collectPlayStats,
collectArtistData
collectArtistData,
collectRooms
], function(err, results) {

var playlists = results[0];
Expand Down Expand Up @@ -40,6 +41,7 @@ module.exports = {
, artist: (results[3]) ? results[3].artist : null
, tracks: (results[3]) ? results[3].tracks : null
, trackCount: (results[3]) ? results[3].trackCount : null
, topRoomsByQueues: results[4]
});

if (req.app.config.jobs && req.app.config.jobs.enabled) {
Expand All @@ -52,6 +54,30 @@ module.exports = {
}

});

function collectRooms(done) {
Play.aggregate([
{ $match: {
_curator: person._id
} },
{ $group: { _id: '$_room', count: { $sum: 1 } } },
{ $sort: { 'count': -1 } },
{ $limit: LIMIT }
], function(err, collected) {
Room.populate( collected , {
path: '_id'
}, function(err, topRooms) {
topRooms = topRooms.map(function(x) {
return {
_room: x._id,
count: x.count
};
});

done( null , topRooms );
});
});
}

function collectUserPlays(done) {
Play.find({ _curator: person._id }).sort('-timestamp').limit(20).populate('_track _curator _room').exec(function(err, plays) {
Expand Down
12 changes: 11 additions & 1 deletion views/person.jade
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ block content
a(href="#sets", data-toggle="tab") Sets
if (artist)
| /Albums
li
a(href="#rooms", data-toggle="tab") Rooms
li
a(href="#plays", data-toggle="tab") Plays

Expand Down Expand Up @@ -162,7 +164,15 @@ block content
i.icon-remove
a.btn.btn-mini(href="#", data-action="queue-set", data-set-slug="#{playlist._creator.slug}/#{playlist.slug}") ♫ queue »


.tab-pane#rooms
h3 Rooms

.row-fluid
.span6
h4 Most Queues
each room in topRoomsByQueues
li queued <strong>#{room.count}</strong> tracks in
a(href="#{room._room.index}") #{room._room.name}

.tab-pane#plays
h3 Recent Plays (<a href="/#{person.slug}/plays">view all &raquo;</a>)
Expand Down

0 comments on commit 6ebbec0

Please sign in to comment.