1
0
Fork 0

Models refactoring, artist page draft

This commit is contained in:
magnolia-fan 2011-04-06 02:58:11 +04:00
parent d3d0f993c5
commit e14303c044
14 changed files with 18065 additions and 329 deletions

View File

@ -1,3 +1,5 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery protect_from_forgery
require 'pp'
#require 'cobravsmongoose'
end end

View File

@ -1,11 +1,7 @@
# encoding: utf-8
class ArtistController < ApplicationController class ArtistController < ApplicationController
require 'open-uri'
def view def view
@artist = Artist.getByName(params[:name]) @artist = Artist.getByName(params[:name].gsub('+', ' ').gsub('%20', ' '))
@albums = ReleaseGroup.getArtistAlbums(@artist.id)
rg_ids = []
@albums.each do |a|
rg_ids << a.id
end
@releases = Release.getReleases(rg_ids, true, true);
end end
end end

View File

@ -0,0 +1,5 @@
class Album < ActiveRecord::Base
set_table_name 'musicbrainz.bh_release_group'
belongs_to :artist
has_many :releases, :conditions => "release_type = 1", :order => 'date ASC, id ASC'
end

View File

@ -1,5 +1,7 @@
class Artist < ActiveRecord::Base class Artist < ActiveRecord::Base
set_table_name 'musicbrainz.bh_artist' set_table_name 'musicbrainz.bh_artist'
has_many :albums, :conditions => "release_type = 1", :order => 'year ASC, id ASC'
def self.getByName(name) def self.getByName(name)
Artist.first(:conditions => ['name = ? AND id=credit_id', name], :order => 'rating DESC') Artist.first(:conditions => ['name = ? AND id=credit_id', name], :order => 'rating DESC')
end end

View File

@ -1,23 +1,5 @@
class Release < ActiveRecord::Base class Release < ActiveRecord::Base
set_table_name 'musicbrainz.bh_release' set_table_name 'musicbrainz.bh_release'
def self.getReleases(release_groups, group_by_release = false, only_official = false) belongs_to :album
releases = Release.all( has_many :tracks, :order => 'position ASC'
:conditions => [
'release_group IN(?) AND '+
(only_official ? 'release_type=1' : 'release_type IS NOT NULL'), release_groups
],
:order => 'date ASC, id ASC'
)
if group_by_release
g_releases = {}
releases.each do |release|
if g_releases[release.release_group].nil?
g_releases[release.release_group] = {}
end
g_releases[release.release_group] << release
end
return g_releases
end
return releases
end
end end

View File

@ -1,6 +0,0 @@
class ReleaseGroup < ActiveRecord::Base
set_table_name 'musicbrainz.bh_release_group'
def self.getArtistAlbums(artist_id)
ReleaseGroup.all(:conditions => ['artist_id = ? AND release_type=1', artist_id], :order => 'year ASC, id ASC')
end
end

View File

@ -1,59 +1,12 @@
class Track < ActiveRecord::Base class Track < ActiveRecord::Base
set_table_name 'musicbrainz.bh_track' set_table_name 'musicbrainz.bh_track'
belongs_to :release
@@bad_names = [ def convertLength
'[silence]' (length /= 1000).round!
]
def self.getReleaseTracks(release_ids, group_by_release = false)
tracks = Track
.all(:conditions => ['release_id IN(?)', release_ids], :order => 'release_id ASC, position ASC')
.map{|track| track.length = (track.length /= 1000).round; track}
if group_by_release
g_tracks = {}
tracks.each do |track|
if g_tracks[track.release_id].nil?
g_tracks[track.release_id] = {}
end
g_tracks[track.release_id][track.id] = track
end
return g_tracks
end end
tracks def clearName
end
def self.getUniqueReleaseTracks(release_ids)
tracks = self.getReleaseTracks(release_ids, true)
unique_tracks = []
track_list = {
'album' => [],
'bonus' => []
}
tracks.shift[1].each do |track|
unless @@bad_names.include?(track[1].name)
track_list['album'] << track[1]
unique_tracks << self.clearName(track[1].name)
end
end
tracks.each do |group|
group.each do |track|
unless @@bad_names.include?(track[1].name) && unique_tracks.include?(self.clearName(track[1].name))
track_list['bonus'] << track[1]
unique_tracks << self.clearName(track[1].name)
end
end
end
track_list
end
def self.clearName(name)
name.gsub('&', 'and').gsub(/[^a-z0-9]/, '').downcase name.gsub('&', 'and').gsub(/[^a-z0-9]/, '').downcase
end end
end end

View File

@ -1 +1,22 @@
<h1><%= @artist.name %></h1> <h1 class="artist"><%= @artist.name %></h1>
<% @artist.albums.each do |album| %>
<% if album.releases.length > 0 %>
<div class="album">
<div class="pic"></div>
<h3 class="name"><%= album.name %> (<%= album.year %>)</h3>
<%
releases = album.releases
first_release = releases.first
%>
<ul class="tracks">
<% first_release.tracks.each do |track| %>
<li>
<span class="play"></span>
<span class="track-name"><%= track.name %></span>
<span class="duration"><%= track.length %></span>
</li>
<% end %>
</ul>
</div>
<% end %>
<% end %>

View File

@ -1,14 +1,16 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Beathaven</title> <title>BeatHaven</title>
<%= stylesheet_link_tag :all %> <%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %> <%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %> <%= csrf_meta_tag %>
</head> </head>
<body> <body>
<div id="contents">
<div class="inner-1">
<%= yield %> <%= yield %>
</div>
</div>
</body> </body>
</html> </html>

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@ -1,239 +1 @@
<!DOCTYPE html> Hello, World!
<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>

View File

@ -0,0 +1,77 @@
body, h1, h2, h3, h4, form, ul, li {
margin: 0;
padding: 0;
}
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#contents {
width: 1000px;
margin: 0 0 0 -500px;
left: 50%;
position: relative;
/* background-color: #EEE;*/
}
.inner-1 {
margin: 2em;
}
.artist {
display: block;
width: 100%;
text-align: center;
margin: 0 0 0.5em 0;
font-size: 3em;
}
.album {
width: 100%;
clear: both;
}
.album .pic {
width: 250px;
height: 250px;
background-color: #DDD;
float: left;
margin: 0 1em 1em 0;
}
.album .name {
display: block;
float: left;
width: 400px;
font-size: 1.5em;
margin: 0 0 0.5em 0;
/* background-color: yellowgreen;*/
}
.album .tracks {
display: block;
float: left;
width: 400px;
margin-bottom: 1em;
/* background-color: lightblue;*/
}
.album .tracks li {
display: block;
float: left;
width: 100%;
line-height: 30px;
}
.album .tracks li .duration {
font-size: 0.5em;
display: block;
float: right;
}
.album .tracks li .play {
display: block;
float: left;
background-image: url(/images/play.png);
width: 31px;
height: 30px;
margin: 0 0.3em 0 0;

View File

@ -1 +1 @@
28729 2408