1
0
Fork 0

Playback, import fixes

This commit is contained in:
Gregory Eremin 2012-09-17 12:25:38 +04:00
parent a29f4433ca
commit e8fa9e4cda
14 changed files with 80 additions and 43 deletions

View File

@ -1,6 +1,7 @@
#= require jquery #= require jquery
#= require jquery_ujs #= require jquery_ujs
#= require jquery.autocomplete #= require jquery.autocomplete
#= require jquery.neighbour
#= require bootstrap-dropdown #= require bootstrap-dropdown
#= require bootstrap-tooltip #= require bootstrap-tooltip

View File

@ -47,18 +47,18 @@ class BeatHaven.Models.Player extends Backbone.Model
if @playlist_on if @playlist_on
# not implemented # not implemented
else else
nodes = @current_track.node().next() node = $(".tracks li.now-playing").neighbour(".tracks li", 1)
return false unless nodes.length == 1 return false unless node?
@tracks.get(parseInt($(nodes[0]).data("id"), 10)).play() @tracks.get(parseInt($(node).data("id"), 10)).play()
prev: -> prev: ->
return false unless @current_track? return false unless @current_track?
if @playlist_on if @playlist_on
# not implemented # not implemented
else else
nodes = @current_track.node().prev() node = $(".tracks li.now-playing").neighbour(".tracks li", -1)
return false unless nodes.length == 1 return false unless node?
@tracks.get(parseInt($(nodes[0]).data("id"), 10)).play() @tracks.get(parseInt($(node).data("id"), 10)).play()
play_something: -> play_something: ->
nodes = $(".artist-page .tracks li[data-id]") nodes = $(".artist-page .tracks li[data-id]")

View File

@ -28,6 +28,7 @@ class BeatHaven.Models.Track extends Backbone.Model
self.start() self.start()
add_to_library: (params) -> add_to_library: (params) ->
self = this
obj = soundManager.createSound obj = soundManager.createSound
id: @.get("id") id: @.get("id")
url: @.get("url") url: @.get("url")
@ -39,8 +40,10 @@ class BeatHaven.Models.Track extends Backbone.Model
BH.Player.update_progress_bar(this) BH.Player.update_progress_bar(this)
onfinish: -> onfinish: ->
BH.Player.next() BH.Player.next()
self.node().removeClass("now-playing").removeClass("paused")
ondataerror: -> ondataerror: ->
BH.Player.next() BH.Player.next()
self.node().removeClass("now-playing").removeClass("paused")
@.set("sm_obj", obj) @.set("sm_obj", obj)
node: -> node: ->

View File

@ -1,7 +1,7 @@
<div class="artist-page"> <div class="artist-page single-album">
<h1 class="title">{{album_title}} ({{album_year}})</h1> <h1 class="title">{{album_title}} ({{album_year}})</h1>
<div class="album"> <div class="album row">
<div class="pic"> <div class="pic span3">
<img src="{{album_pic}}" alt="{{album_title}}"><br> <img src="{{album_pic}}" alt="{{album_title}}"><br>
<div class="bh-underlay-blue"> <div class="bh-underlay-blue">
<a href="" class="btn btn-bh-dark album-add"> <a href="" class="btn btn-bh-dark album-add">
@ -16,30 +16,32 @@
</a> </a>
</div> --> </div> -->
</div> </div>
<ul class="tracks"> <div class="span9">
{{#album_tracks}} <ul class="tracks">
<li data-id="{{track_id}}"> {{#album_tracks}}
<a href="" class="btn btn-round track-play" data-translate-title="artist.album.track.play" title="{{i18n_play}}"> <li data-id="{{track_id}}">
<i class="icon-play"></i> <a href="" class="btn btn-round track-play" data-translate-title="artist.album.track.play" title="{{i18n_play}}">
</a> <i class="icon-play"></i>
<a href="" class="btn btn-round track-pause" data-translate-title="artist.album.track.pause" title="{{i18n_pause}}"> </a>
<i class="icon-pause"></i> <a href="" class="btn btn-round track-pause" data-translate-title="artist.album.track.pause" title="{{i18n_pause}}">
</a> <i class="icon-pause"></i>
<div class="title"> </a>
<div class="inner"> <div class="title">
<a href="{{track_url}}" class="track-link">{{track_title}}</a> <div class="inner">
<span class="delimiter">&mdash;</span> <a href="{{track_url}}" class="track-link">{{track_title}}</a>
<ul class="artists"> <span class="delimiter">&mdash;</span>
{{#track_artists}}<li><a href="{{artist_url}}" class="artist-page">{{artist_title}}</a></li>{{/track_artists}} <ul class="artists">
</ul> {{#track_artists}}<li><a href="{{artist_url}}" class="artist-page">{{artist_title}}</a></li>{{/track_artists}}
</ul>
</div>
</div> </div>
</div> <span class="length">{{track_length}}</span>
<span class="length">{{track_length}}</span> <a href="" class="btn btn-round track-add" data-translate-title="artist.album.track.add" title="{{i18n_add}}">
<a href="" class="btn btn-round track-add" data-translate-title="artist.album.track.add" title="{{i18n_add}}"> <i class="icon-plus"></i>
<i class="icon-plus"></i> </a>
</a> </li>
</li> {{/album_tracks}}
{{/album_tracks}} </ul>
</ul> </div>
</div> </div>
</div> </div>

View File

@ -1,12 +1,17 @@
class BeatHaven.Views.AlbumShow extends Backbone.View class BeatHaven.Views.AlbumShow extends Backbone.View
template: HoganTemplates["backbone/templates/album/show"] template: HoganTemplates["album/show"]
initialize: -> initialize: ->
@model.on("change", @render, this) @model.on("change", @render, this)
render: -> render: ->
if typeof @model.get("album_tracks") != "undefined" if typeof @model.get("album_tracks") != "undefined"
@model.set "i18n_add", BH.I18n.t("artist.album.add")
@model.set "i18n_play", BH.I18n.t("artist.album.play")
for track_info in @model.get("album_tracks") for track_info in @model.get("album_tracks")
track_info["i18n_add"] = BH.I18n.t("artist.album.track.add")
track_info["i18n_play"] = BH.I18n.t("artist.album.track.play")
track_info["i18n_pause"] = BH.I18n.t("artist.album.track.pause")
track = new BeatHaven.Models.Track(track_info.meta) track = new BeatHaven.Models.Track(track_info.meta)
BeatHaven.Player.tracks.push(track) BeatHaven.Player.tracks.push(track)
$(@el).html(@template.render(@model.toJSON())) $(@el).html(@template.render(@model.toJSON()))

View File

@ -162,3 +162,13 @@
} }
} }
} }
.artist-page.single-album {
.tracks > li {
width: 705px;
.title {
max-width: 615px;
}
}
}

View File

@ -12,7 +12,7 @@ class Album < ActiveRecord::Base
# .order('"albums"."year" ASC') # .order('"albums"."year" ASC')
} }
attr_accessible :artist_id, :pic, :rovi_id, :title, :year, :is_hidden attr_accessible :artist_id, :pic, :rovi_id, :title, :year, :is_hidden, :tracks
VA = "Various Artists" VA = "Various Artists"
def pic_safe def pic_safe
@ -23,6 +23,10 @@ class Album < ActiveRecord::Base
end end
end end
def pic_thumb
pic_safe
end
def load_pic def load_pic
info = begin info = begin
response = LastFM::Album.get_info(artist: (artist.nil? ? VA : artist.name), album: title) response = LastFM::Album.get_info(artist: (artist.nil? ? VA : artist.name), album: title)
@ -52,14 +56,14 @@ class Album < ActiveRecord::Base
update_attributes( update_attributes(
title: robbie_album.title, title: robbie_album.title,
year: robbie_album.year, year: robbie_album.year,
tracks: robbie_album.tracks.each { |robbie_track| tracks: robbie_album.tracks.map{ |robbie_track|
track = Track.find_or_create_by_rovi_id(robbie_track.id) track = Track.find_or_create_by_rovi_id(robbie_track.id)
track.update_attributes( track.update_attributes(
disc_id: robbie_track.disc_id, disc_id: robbie_track.disc_id,
position: robbie_track.position, position: robbie_track.position,
title: robbie_track.title, title: robbie_track.title,
duration: robbie_track.duration, duration: robbie_track.duration,
artists: robbie_track.artists.map { |robbie_artist| artists: robbie_track.artists.map{ |robbie_artist|
track_artist = Artist.find_or_create_by_rovi_id(robbie_artist.id) track_artist = Artist.find_or_create_by_rovi_id(robbie_artist.id)
track_artist.update_attributes( track_artist.update_attributes(
name: robbie_artist.name name: robbie_artist.name

View File

@ -2,9 +2,10 @@ class Artist < ActiveRecord::Base
has_many :albums has_many :albums
has_many :performers has_many :performers
has_many :tracks, through: :performers has_many :tracks, through: :performers
has_many :artist_genres
has_many :genres, through: :artist_genres has_many :genres, through: :artist_genres
attr_accessible :bio, :is_group, :name, :pic, :rovi_id attr_accessible :bio, :is_group, :name, :pic, :rovi_id, :albums, :genres
scope :discography, lambda { scope :discography, lambda {
includes(:albums).includes(:tracks) includes(:albums).includes(:tracks)
@ -15,7 +16,7 @@ class Artist < ActiveRecord::Base
end end
def url def url
"/artist/#{name.gsub(/\s/, "+")}" "/artist/#{name.gsub(/\s/, "+")}" rescue ""
end end
def import def import

View File

@ -1,3 +1,6 @@
class ArtistGenre < ActiveRecord::Base class ArtistGenre < ActiveRecord::Base
belongs_to :artist
belongs_to :genre
attr_accessible :artist_id, :genre_id attr_accessible :artist_id, :genre_id
end end

View File

@ -3,7 +3,7 @@ class Track < ActiveRecord::Base
has_many :performers has_many :performers
has_many :artists, through: :performers has_many :artists, through: :performers
attr_accessible :album_id, :disc_id, :duration, :position, :rovi_id, :title attr_accessible :album_id, :disc_id, :duration, :position, :rovi_id, :title, :artists
scope :with_artists, lambda{ scope :with_artists, lambda{
includes(:artists) includes(:artists)
} }

View File

@ -18,7 +18,7 @@ json.album_tracks @album.tracks.to_a do |json, track|
json.duration track.duration json.duration track.duration
json.length track.length json.length track.length
json.artists track.artists.map(&:name) json.artists track.artists.map(&:name)
json.album title json.album @album.title
json.album_pic pic_safe json.album_pic @album.pic_thumb
end end
end end

View File

@ -1,7 +1,7 @@
BeatHaven::Application.routes.draw do BeatHaven::Application.routes.draw do
namespace :api do namespace :api do
resources :artists, only: [:show], constraints: { id: /.+/ }, format: :json resources :artists, only: [:show], constraints: { id: /.+/ }, format: :json
resources :albums, only: [:show, :picture] do resources :albums, only: [:show, :picture], format: :json do
member { get :picture } member { get :picture }
end end
resources :search, only: [] do resources :search, only: [] do

View File

View File

@ -0,0 +1,8 @@
$.fn.neighbour = (context, offset) ->
self = this[0]
result = null
nodes = $(context)
nodes.each (i, node) ->
result = nodes[i+offset] if node is self
result = null if typeof result is "undefined"
result