ADDED: Home site with Top Artists/Tracks; CHANGED: Search Bar

This commit is contained in:
Tobias Klika
2011-05-08 16:59:06 +02:00
parent 01ebd2ee00
commit a889bf28e4
15 changed files with 180 additions and 245 deletions
+7
View File
@@ -0,0 +1,7 @@
class HomeController < ApplicationController
def index
@tracks = LastFM::Chart.getTopTracks 25
@artists = LastFM::Chart.getTopArtists 10
end
end
+2
View File
@@ -0,0 +1,2 @@
module HomeHelper
end
+47
View File
@@ -0,0 +1,47 @@
#home
= image_tag "cnt/9minutes-is-a-mashup-of-lastfm-and-youtube.png", :class=>"right"
= link_to image_tag("cnt/sign-up.png", :class=>"left"), '#'
%br.clean
%br
%br
.right
%h2.headline.small
%span.left Top Tracks
.navigate
%a.left
%a.right
%ul.songs.short{:count=>"5"}
- @tracks.track.each_with_index do |track, i|
%li
= image_tag "ico/play.png", :class=>"play"
= image_tag "ico/add.png", :class=>"add"
%span
%span= (i+1).to_s+"."
= track.name
=raw "&nbsp;by "
= link_to trimString(track.artist.name, 50), :controller=>"artists",:action=>"show",:id=>CGI.escape(track.artist.name)
.left
%h2.headline.small
%span.left Top Artists
.navigate
%a.left
%a.right
%ul.artists.big{:count=>"2"}
- @artists.artist.each do |artist|
%li
= link_to :controller=>:artists,:action=>:show,:id=>CGI.escape(artist.name) do
= image_tag validate_img_url(artist.image, "artist", :extralarge)
%p
= trimString(artist.name, 30)
%br><
=raw "<span>#{artist.listeners} Listeners, #{artist.playcount} Plays</span>"
%br.clean
.bottom
%hr
%p.left
=raw "&copy;2011 by 9minutes"
= link_to "Home", "#"
= link_to "Terms of Service", "#"
= link_to "Contact", "#"
= link_to "About", "#"
+1
View File
@@ -2,5 +2,6 @@ require 'LastFM/LastFMRequest'
require 'LastFM/Artist'
require 'LastFM/Album'
require 'LastFM/Track'
require 'LastFM/Chart'
LastFM::LastFMRequest::api_key = '4c32e360f68553ec8fdca3711456b4f9'
+3 -1
View File
@@ -1,6 +1,8 @@
Nineminutes::Application.routes.draw do
resources :artists, :constraints => { :id => /.*/ }
resources :search
resources :home
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -50,7 +52,7 @@ Nineminutes::Application.routes.draw do
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"
root :to => "home#index"
# See how all your routes lay out with "rake routes"
+12
View File
@@ -0,0 +1,12 @@
module LastFM
class Chart < LastFMRequest
def self.getTopArtists limit = nil, page = nil
chart_request "getTopArtists", "artists", limit, page
end
def self.getTopTracks limit = nil, page = nil
chart_request "getTopTracks", "tracks", limit, page
end
end
end
+4
View File
@@ -45,6 +45,10 @@ module LastFM
def self.track_request method, node, q, artist = nil, limit = nil, page = nil
prepare_result method, node, get('/', :query => { :method => "track.#{method.to_s}", :track => q, :artist => artist, :limit => limit, :page => page })
end
def self.chart_request method, node, limit = nil, page = nil
prepare_result method, node, get('/', :query => { :method => "chart.#{method.to_s}", :limit => limit, :page => page })
end
private
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

-239
View File
@@ -1,239 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails: Welcome aboard</title>
<style type="text/css" media="screen">
body {
margin: 0;
margin-bottom: 25px;
padding: 0;
background-color: #f0f0f0;
font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
font-size: 13px;
color: #333;
}
h1 {
font-size: 28px;
color: #000;
}
a {color: #03c}
a:hover {
background-color: #03c;
color: white;
text-decoration: none;
}
#page {
background-color: #f0f0f0;
width: 750px;
margin: 0;
margin-left: auto;
margin-right: auto;
}
#content {
float: left;
background-color: white;
border: 3px solid #aaa;
border-top: none;
padding: 25px;
width: 500px;
}
#sidebar {
float: right;
width: 175px;
}
#footer {
clear: both;
}
#header, #about, #getting-started {
padding-left: 75px;
padding-right: 30px;
}
#header {
background-image: url("images/rails.png");
background-repeat: no-repeat;
background-position: top left;
height: 64px;
}
#header h1, #header h2 {margin: 0}
#header h2 {
color: #888;
font-weight: normal;
font-size: 16px;
}
#about h3 {
margin: 0;
margin-bottom: 10px;
font-size: 14px;
}
#about-content {
background-color: #ffd;
border: 1px solid #fc0;
margin-left: -55px;
margin-right: -10px;
}
#about-content table {
margin-top: 10px;
margin-bottom: 10px;
font-size: 11px;
border-collapse: collapse;
}
#about-content td {
padding: 10px;
padding-top: 3px;
padding-bottom: 3px;
}
#about-content td.name {color: #555}
#about-content td.value {color: #000}
#about-content ul {
padding: 0;
list-style-type: none;
}
#about-content.failure {
background-color: #fcc;
border: 1px solid #f00;
}
#about-content.failure p {
margin: 0;
padding: 10px;
}
#getting-started {
border-top: 1px solid #ccc;
margin-top: 25px;
padding-top: 15px;
}
#getting-started h1 {
margin: 0;
font-size: 20px;
}
#getting-started h2 {
margin: 0;
font-size: 14px;
font-weight: normal;
color: #333;
margin-bottom: 25px;
}
#getting-started ol {
margin-left: 0;
padding-left: 0;
}
#getting-started li {
font-size: 18px;
color: #888;
margin-bottom: 25px;
}
#getting-started li h2 {
margin: 0;
font-weight: normal;
font-size: 18px;
color: #333;
}
#getting-started li p {
color: #555;
font-size: 13px;
}
#sidebar ul {
margin-left: 0;
padding-left: 0;
}
#sidebar ul h3 {
margin-top: 25px;
font-size: 16px;
padding-bottom: 10px;
border-bottom: 1px solid #ccc;
}
#sidebar li {
list-style-type: none;
}
#sidebar ul.links li {
margin-bottom: 5px;
}
</style>
<script type="text/javascript">
function about() {
info = document.getElementById('about-content');
if (window.XMLHttpRequest)
{ xhr = new XMLHttpRequest(); }
else
{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
xhr.open("GET","rails/info/properties",false);
xhr.send("");
info.innerHTML = xhr.responseText;
info.style.display = 'block'
}
</script>
</head>
<body>
<div id="page">
<div id="sidebar">
<ul id="sidebar-items">
<li>
<h3>Browse the documentation</h3>
<ul class="links">
<li><a href="http://api.rubyonrails.org/">Rails API</a></li>
<li><a href="http://stdlib.rubyonrails.org/">Ruby standard library</a></li>
<li><a href="http://corelib.rubyonrails.org/">Ruby core</a></li>
<li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
</ul>
</li>
</ul>
</div>
<div id="content">
<div id="header">
<h1>Welcome aboard</h1>
<h2>You&rsquo;re riding Ruby on Rails!</h2>
</div>
<div id="about">
<h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
<div id="about-content" style="display: none"></div>
</div>
<div id="getting-started">
<h1>Getting started</h1>
<h2>Here&rsquo;s how to get rolling:</h2>
<ol>
<li>
<h2>Use <code>rails generate</code> to create your models and controllers</h2>
<p>To see all available options, run it without parameters.</p>
</li>
<li>
<h2>Set up a default route and remove or rename this file</h2>
<p>Routes are set up in config/routes.rb.</p>
</li>
<li>
<h2>Create your database</h2>
<p>Run <code>rake db:migrate</code> to create your database. If you're not using SQLite (the default), edit <code>config/database.yml</code> with your username and password.</p>
</li>
</ol>
</div>
</div>
<div id="footer">&nbsp;</div>
</div>
</body>
</html>
+35
View File
@@ -10,6 +10,9 @@ $(document).ready(function(){
initPictureOverlay();
initArtistDescription();
initTopMusic();
navigateTopMusic();
});
$(window).load(function() {
@@ -48,6 +51,38 @@ function initPictureOverlay(){
}
function initTopMusic(){
$('#home .songs li').each(function(){
if($(this).parent().children().index(this)>=5) $(this).hide();
});
$('#home .artists li').each(function(){
if($(this).parent().children().index(this)>=2) $(this).hide();
});
}
function navigateTopMusic(){
$('#home .navigate a').live('click', function(){
$selector = $(this).closest("h2").next("ul");
$id = $selector.children("li:visible").first();
$start = $id.parent().children().index($id);
$count = parseInt($selector.attr("count"));
$size = $selector.children().size();
if($(this).hasClass("left")) {
$start -= $count;
if($start < 0) return;
}
else {
$start += $count;
if($start >= $size) return;
}
$selector.children().hide();
for($i=$start;$i<$start+$count;$i++)
$selector.children("li:eq("+$i+")").show();
});
}
function ajj(){
/*
$('#myajax').load('/artists', function() {
+56 -5
View File
@@ -66,13 +66,13 @@ a { text-decoration: none; color: #7d8791; }
margin: 0 auto;
}
#head { height: 140px; }
#head h1 { padding-top: 60px; float: left; }
#head h1 { padding-top: 55px; float: left; }
#search_form { position: relative; }
#search_form .wrap
{
width: 400px; /* 300 + 28*/
height: 38px;
margin-top: 60px;
margin-top: 50px;
border: 1px solid #dfe4e8;
border-radius: 7px;
-moz-border-radius: 7px;
@@ -108,7 +108,7 @@ a { text-decoration: none; color: #7d8791; }
#search_form .selection
{
position: absolute;
right: 50px; top: 65px;
right: 50px; top: 55px;
font-family: AauxNextBold, "Segoe UI", Arial, sans-serif;
font-size: 14px;
color: #868f98;
@@ -119,6 +119,7 @@ a { text-decoration: none; color: #7d8791; }
width: 65px;
height: 29px; line-height: 29px;
display: block;
opacity: 0.85;
}
#search_form .selection > span { text-transform: uppercase;}
#search_form .box
@@ -182,8 +183,10 @@ a { text-decoration: none; color: #7d8791; }
.headline
{
color: #7d8791;
color: #363d3f;
font-size: 32px;
overflow: hidden;
vertical-align: middle;
}
.headline, .headline span
{
@@ -539,4 +542,52 @@ div[wheel] > div { display: none; opacity: 0.0; position: relative; }
}
.overlay.album .mid li span { color: White; font-family: AauxNextMedium, "Segoe UI", Arial, sans-serif;}
.overlay.album .mid li:first-child { border-top: 0; }
.overlay.album .mid li:last-child { border-bottom: 0; }
.overlay.album .mid li:last-child { border-bottom: 0; }
.navigate
{
width: 44px;
height: 20px;
float: left;
margin-top: 5px;
padding-left: 10px;
}
.navigate .left, .navigate .right
{
width: 20px;
height: 20px;
background: url('../images/ico/navigate.png') 0 0;
cursor: pointer;
}
.navigate .right { background-position: -24px 0;}
.blocked
{
opacity: 0.5;
cursor: default!important;
}
#home .bottom hr
{
margin-top: 40px;
background: White;
height: 1px;
border: 0;
}
#home .bottom { font-size: 12px; }
#home .bottom a
{
margin-left: 10px;
color: #cbd3d9;
}
#home .bottom a:first-child { margin-left: 20px;}
#home .bottom a:hover
{
color: #40474c;
}
+9
View File
@@ -0,0 +1,9 @@
require 'test_helper'
class HomeControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end
end
+4
View File
@@ -0,0 +1,4 @@
require 'test_helper'
class HomeHelperTest < ActionView::TestCase
end