diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 1dc96f3..f328beb 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -1,6 +1,7 @@ #= require jquery #= require jquery_ujs #= require jquery.autocomplete +#= require jquery.neighbour #= require bootstrap-dropdown #= require bootstrap-tooltip diff --git a/app/assets/javascripts/backbone/models/player.js.coffee b/app/assets/javascripts/backbone/models/player.js.coffee index 07ba2ac..5538ce4 100644 --- a/app/assets/javascripts/backbone/models/player.js.coffee +++ b/app/assets/javascripts/backbone/models/player.js.coffee @@ -47,18 +47,18 @@ class BeatHaven.Models.Player extends Backbone.Model if @playlist_on # not implemented else - nodes = @current_track.node().next() - return false unless nodes.length == 1 - @tracks.get(parseInt($(nodes[0]).data("id"), 10)).play() + node = $(".tracks li.now-playing").neighbour(".tracks li", 1) + return false unless node? + @tracks.get(parseInt($(node).data("id"), 10)).play() prev: -> return false unless @current_track? if @playlist_on # not implemented else - nodes = @current_track.node().prev() - return false unless nodes.length == 1 - @tracks.get(parseInt($(nodes[0]).data("id"), 10)).play() + node = $(".tracks li.now-playing").neighbour(".tracks li", -1) + return false unless node? + @tracks.get(parseInt($(node).data("id"), 10)).play() play_something: -> nodes = $(".artist-page .tracks li[data-id]") diff --git a/app/assets/javascripts/backbone/models/track.js.coffee b/app/assets/javascripts/backbone/models/track.js.coffee index 9fa24cc..fa0fb0d 100644 --- a/app/assets/javascripts/backbone/models/track.js.coffee +++ b/app/assets/javascripts/backbone/models/track.js.coffee @@ -28,6 +28,7 @@ class BeatHaven.Models.Track extends Backbone.Model self.start() add_to_library: (params) -> + self = this obj = soundManager.createSound id: @.get("id") url: @.get("url") @@ -39,8 +40,10 @@ class BeatHaven.Models.Track extends Backbone.Model BH.Player.update_progress_bar(this) onfinish: -> BH.Player.next() + self.node().removeClass("now-playing").removeClass("paused") ondataerror: -> BH.Player.next() + self.node().removeClass("now-playing").removeClass("paused") @.set("sm_obj", obj) node: -> diff --git a/app/assets/javascripts/backbone/templates/album/show.mustache b/app/assets/javascripts/backbone/templates/album/show.mustache index ce85d76..2494c21 100644 --- a/app/assets/javascripts/backbone/templates/album/show.mustache +++ b/app/assets/javascripts/backbone/templates/album/show.mustache @@ -1,7 +1,7 @@ -
+

{{album_title}} ({{album_year}})

-
-
+
+ - + {{track_length}} + + + + + {{/album_tracks}} + +
diff --git a/app/assets/javascripts/backbone/views/album/album_show.js.coffee b/app/assets/javascripts/backbone/views/album/album_show.js.coffee index ad9f4e0..7afbf3c 100644 --- a/app/assets/javascripts/backbone/views/album/album_show.js.coffee +++ b/app/assets/javascripts/backbone/views/album/album_show.js.coffee @@ -1,12 +1,17 @@ class BeatHaven.Views.AlbumShow extends Backbone.View - template: HoganTemplates["backbone/templates/album/show"] + template: HoganTemplates["album/show"] initialize: -> @model.on("change", @render, this) render: -> 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") + 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) BeatHaven.Player.tracks.push(track) $(@el).html(@template.render(@model.toJSON())) diff --git a/app/assets/stylesheets/album-track.css.scss b/app/assets/stylesheets/album-track.css.scss index fc840ad..e0a731f 100644 --- a/app/assets/stylesheets/album-track.css.scss +++ b/app/assets/stylesheets/album-track.css.scss @@ -162,3 +162,13 @@ } } } + +.artist-page.single-album { + .tracks > li { + width: 705px; + + .title { + max-width: 615px; + } + } + } diff --git a/app/models/album.rb b/app/models/album.rb index 21aeeda..babcbef 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -12,7 +12,7 @@ class Album < ActiveRecord::Base # .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" def pic_safe @@ -23,6 +23,10 @@ class Album < ActiveRecord::Base end end + def pic_thumb + pic_safe + end + def load_pic info = begin response = LastFM::Album.get_info(artist: (artist.nil? ? VA : artist.name), album: title) @@ -52,14 +56,14 @@ class Album < ActiveRecord::Base update_attributes( title: robbie_album.title, 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.update_attributes( disc_id: robbie_track.disc_id, position: robbie_track.position, title: robbie_track.title, 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.update_attributes( name: robbie_artist.name diff --git a/app/models/artist.rb b/app/models/artist.rb index c6fe0ed..87ab79b 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -2,9 +2,10 @@ class Artist < ActiveRecord::Base has_many :albums has_many :performers has_many :tracks, through: :performers + has_many :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 { includes(:albums).includes(:tracks) @@ -15,7 +16,7 @@ class Artist < ActiveRecord::Base end def url - "/artist/#{name.gsub(/\s/, "+")}" + "/artist/#{name.gsub(/\s/, "+")}" rescue "" end def import diff --git a/app/models/artist_genre.rb b/app/models/artist_genre.rb index e7a4271..6bcf489 100644 --- a/app/models/artist_genre.rb +++ b/app/models/artist_genre.rb @@ -1,3 +1,6 @@ class ArtistGenre < ActiveRecord::Base + belongs_to :artist + belongs_to :genre + attr_accessible :artist_id, :genre_id end diff --git a/app/models/track.rb b/app/models/track.rb index 855603f..996b19d 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -3,7 +3,7 @@ class Track < ActiveRecord::Base has_many :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{ includes(:artists) } diff --git a/app/views/api/albums/show.json.jbuilder b/app/views/api/albums/show.json.jbuilder index b416774..18c3fde 100644 --- a/app/views/api/albums/show.json.jbuilder +++ b/app/views/api/albums/show.json.jbuilder @@ -18,7 +18,7 @@ json.album_tracks @album.tracks.to_a do |json, track| json.duration track.duration json.length track.length json.artists track.artists.map(&:name) - json.album title - json.album_pic pic_safe + json.album @album.title + json.album_pic @album.pic_thumb end end diff --git a/config/routes.rb b/config/routes.rb index 4821e90..6e673f0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ BeatHaven::Application.routes.draw do namespace :api do 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 } end resources :search, only: [] do diff --git a/lib/assets/.gitkeep b/lib/assets/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/lib/assets/javascripts/jquery.neighbour.js.coffee b/lib/assets/javascripts/jquery.neighbour.js.coffee new file mode 100644 index 0000000..dfd7c56 --- /dev/null +++ b/lib/assets/javascripts/jquery.neighbour.js.coffee @@ -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