Skip to content

Commit

Permalink
new logged
Browse files Browse the repository at this point in the history
  • Loading branch information
bentglasstube committed Jun 17, 2011
1 parent 6125fc1 commit e013ef8
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 38 deletions.
4 changes: 3 additions & 1 deletion environments/development.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
logger: console
logger: store
logger_format: '<li class="%L">[%t] %m at %f:%l</li>'
log: debug
session: simple
show_errors: 1
warnings: 0


4 changes: 2 additions & 2 deletions environments/production.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
logger: file
logger: store
logger_format: '<li class="%L">[%t] %m at %f:%l</li>'
log: warning
session: simple
show_errors: 0
warnings: 1

23 changes: 23 additions & 0 deletions lib/Dancer/Logger/Store.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Dancer::Logger::Store;

use strict;
use warnings;

use base 'Dancer::Logger::Abstract';
our $sink = [];

sub _log {
my ($self, $level, $message) = @_;
push @{$sink}, $self->format_message($level => $message);
}

sub fetch {
return $sink;
}

sub clear {
$sink = [];
}

1;

29 changes: 29 additions & 0 deletions lib/Radio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,35 @@ ajax '/current' => sub {
}
};

get '/log' => sub {
require_login or return;

template 'log', { log => Dancer::Logger::Store->fetch };
};

post '/log' => sub {
require_login or return;

if (params->{clear}) {
Dancer::Logger::Store->clear;
flash 'Log cleared';
}

redirect '/log';
};

get '/config' => sub {
require_login or return;

template 'config';
};

get '/upload' => sub {
require_login or return;

template 'upload';
};

# default route (404)
any qr{.*} => sub {
status 'not_found';
Expand Down
24 changes: 16 additions & 8 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ form dd {
padding: 0 0.5em;
}

li.error {
color: #933;
}

.album {
float: left;
margin: 0 0.5em 0.5em;
Expand Down Expand Up @@ -326,10 +322,6 @@ li.error {
font-weight: bold;
}

.error {
text-align: center;
}

.ui-sortable li {
cursor: move;
}
Expand All @@ -338,3 +330,19 @@ li.error {
display: none;
}

#log li {
list-style: none;
}

#log .debug {
color: #448;
}

#log .warning {
color: #884;
}

#log .error {
color: #844;
}

1 change: 1 addition & 0 deletions views/config.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>This feature is not yet available.</p>
15 changes: 15 additions & 0 deletions views/log.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<form method="post" action="/log">
<fieldset>
<input type="submit" name="clear" value="Clear Log" />
</fieldset>
</form>

<% if log.size > 0 %>
<ul id="log">
<% for message in log %>
<% message %>
<% end %>
</ul>
<% else %>
<p class="empty">Nothing new in the logs</p>
<% end %>
4 changes: 2 additions & 2 deletions views/login.tt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<fieldset>
<dl>
<dt><label for="name">Name:</label></dt>
<dd><input name="name" id="name" value="<% params.name %>" /></dd>
<dd><input name="name" id="name" value="<% params.name %>" tabindex="1" /></dd>
<dt><label for="pass">Password:</label></dt>
<dd><input type="password" name="pass" id="pass" /></dd>
<dd><input type="password" name="pass" id="pass" tabindex="2" /></dd>
</dl>
<input type="submit" value="Log In" />
</fieldset>
Expand Down
4 changes: 3 additions & 1 deletion views/nav.tt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<% link('/songs', 'Songs') %>
<% link('/queue', 'Queue') %>
<% if session.user %>
<%# link('/upload', 'Upload') %>
<% link('/upload', 'Upload') %>
<% link('/config', 'Config') %>
<% link('/log', 'Logs') %>
<% link('/logout', 'Log out') %>
<% else %>
<% link('/login', 'Log In') %>
Expand Down
25 changes: 1 addition & 24 deletions views/upload.tt
Original file line number Diff line number Diff line change
@@ -1,25 +1,2 @@
<% if results and results.size > 0 %>
<h2>Upload Results</h2>
<ul>
<% foreach entry in results %>
<% if entry.error %>
<li class="error"><% entry.filename %> - <% entry.error %></li>
<% else %>
<li>Added <a href="/songs/<% entry.song.id %>"><% entry.song.artist %> - <% entry.song.title %></a></li>
<% end %>
<% end %>
</ul>
<% end %>
<p>This feature is not yet available.</p>

<h2>Upload</h2>
<p>
Uploaded songs will be converted automatically the correct format. You may
also upload an archive full of songs and all of them will be processed and
added to the station.
</p>
<form method="post" action="/upload" enctype="multipart/form-data">
<fieldset>
<p><input type="file" name="upload" id="upload" /></p>
<input type="submit" value="Upload" />
</fieldset>
</form>

0 comments on commit e013ef8

Please sign in to comment.