Skip to content

Commit

Permalink
Add "most-often played songs" feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
bigpresh committed Jul 7, 2012
1 parent 711179d commit 35940d0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/DancerJukebox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ get '/' => sub {
# See what's currently queued:
my $queued_songs = _get_queued_songs();
debug_dump("queued songs" => $queued_songs);

template 'index' => {
current => $current_song,
playlist_snippet => \@songs_around_current,
Expand All @@ -61,6 +62,20 @@ get '/search' => sub {
template 'search' => { results => \@results };
};

# Listing most-played songs
get '/popular' => sub {
# TODO: configurable number of most-played songs
# TODO: fetch title for each song (or store titles when queuing)
my $sth = database->prepare(<<QUERY);
select path, count(*) as times_queued from queue
group by path order by times_queued desc limit 40
QUERY
$sth->execute;
my $popular = $sth->fetchall_arrayref({});
debug "Popular songs: ", $popular;
template 'popular' => { popular => $popular };
};

# Adding songs to the queue:
post '/enqueue' => sub {
my @songs_to_queue;
Expand Down
1 change: 1 addition & 0 deletions views/layouts/main.tt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ $(document).ready(function(){
<ul id="nav">
<li><a href="/">Home</a></li>
<li><a href="/search">Search</a></li>
<li><a href="/popular">Popular songs</a></li>
</ul>
<br clear="both" />

Expand Down
44 changes: 44 additions & 0 deletions views/popular.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

<h1>Most popular songs</h1>

<p>
The following are the most commonly played songs on this DancerJukebox install.
</p>

<p>
Tick the songs you want to queue, then hit the bloody great big queue button.
</p>

<form method="post" action="/enqueue">

<div style="float:right;margin-right: 80px;">
<input type="submit" value="Queue selected"
style="width: 150px; height: 125px;">
</div>


<ul>
[% FOREACH song IN popular %]
<li><label>
<input type="checkbox" name="song" value="[% song.path %]" />
[% IF song.title %]
[% song.title %]
[% ELSE %]
[% song.path %]
[% END %]
</label></li>
[% END %]
</ul>



</form>


<script>
$(document).ready(function() {
// focus on the first text input field in the first field on the page
$("input[type='text']:first", document.forms[0]).focus();
});
</script>

0 comments on commit 35940d0

Please sign in to comment.