From b82ade229dd8d2ba7bcffded331b150d957af19b Mon Sep 17 00:00:00 2001 From: magnolia-fan Date: Thu, 24 Nov 2011 03:37:41 +0400 Subject: [PATCH] Track availability, fixes --- app/assets/javascripts/player.coffee | 30 ++++++++++++++++++---------- app/assets/javascripts/search.coffee | 3 ++- app/assets/stylesheets/albums.scss | 3 +++ app/assets/stylesheets/player.scss | 3 +++ app/controllers/track_controller.rb | 2 +- app/views/artist/_page.html.haml | 2 +- config/routes.rb | 1 + 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/player.coffee b/app/assets/javascripts/player.coffee index c2965e5..b3046fe 100644 --- a/app/assets/javascripts/player.coffee +++ b/app/assets/javascripts/player.coffee @@ -57,8 +57,9 @@ class window.Player m = Math.floor(len / 60) s = len - Math.floor(len / 60) * 60 duration = m + ':' + (if s < 10 then '0' else '') + s + item_class = (if item.available == false then 'unavailable' else '') $('.playlist').append ' -
  • +
  • ' +duration+ '
    remove
    ' +item.artist+ '
    @@ -85,10 +86,13 @@ class window.Player $('.player .now-playing').html query $('.playlist li').removeClass 'now' $obj.addClass 'now' - _vk_music.search track.artist, track.name, track.duration, (audio) -> + _vk_music.search track.artist, track.name, track.length, (audio) -> if audio is null - console.log audio - _player.setTrack _player.nextTrack(true) + _session.query '/track/report', { id: track.id }, (r) -> + if r.status is 'success' + $('.playlist li[data-id="'+track.id+'"]').addClass("unavailable") + $($('.album div[data-id="'+track.id+'"]').siblings()[0]).addClass("unavailable") + _player.setTrack _player.nextTrack() else _player.playSource audio.url if track.length == 0 @@ -97,7 +101,7 @@ class window.Player s = len - Math.floor(len / 60) * 60 duration = m + ':' + (if s < 10 then '0' else '') + s _session.query '/track/update_length', { track_id: track.id, length: len }, (r) -> - if r.result is 'success' + if r.status is 'success' $('.playlist li[data-id="'+track.id+'"] .song-duration').text(duration) $($('.album div[data-id="'+track.id+'"]').siblings()[0]).text(duration) _player.updateNowListening track @@ -110,6 +114,12 @@ class window.Player return track false + getAlbumInfo: (id) -> + for album in _player.albums + if parseInt(album.id, 10) == parseInt(id, 10) + return album + false + hasTrack: -> if $('#jplayer audio').length > 0 return $('#jplayer audio').attr('src')? and $('#jplayer audio').attr('src') != '' @@ -240,21 +250,19 @@ $('.playlist li').live 'click', -> # Adding To Playlist actions $('.add-album').live 'click', -> - artist = $('.artist-info h2').text() - album = _player.albums[$(this).attr('data-album-id')] + album = _player.getAlbumInfo($(this).attr('data-album-id')) for item in album.tracks - item['artist'] = artist + item['artist'] = album.artist item['album'] = album.name _player.addTracks album.tracks false $('.s-add').live 'click', -> - artist = $('.artist-info h2').text() - album = _player.albums[$(this).attr('data-album-id')] + album = _player.getAlbumInfo($(this).attr('data-album-id')) item = album.tracks[$(this).attr('data-id')] for item in album.tracks if item.id == parseInt($(this).attr('data-id'), 10) - item['artist'] = artist + item['artist'] = album.artist item['album'] = album.name _player.addTracks [item] return false diff --git a/app/assets/javascripts/search.coffee b/app/assets/javascripts/search.coffee index 1420def..a982a9a 100644 --- a/app/assets/javascripts/search.coffee +++ b/app/assets/javascripts/search.coffee @@ -21,7 +21,8 @@ class window.Search if _session.getUser().id if data.artist.albums? for album in data.artist.albums - _player.albums[album.id] = album + album['artist'] = data.artist.name + _player.albums.push(album) $('.button-container').show() _search.hideSpinner() if data.status is 'loading' diff --git a/app/assets/stylesheets/albums.scss b/app/assets/stylesheets/albums.scss index 1096d26..6ed7816 100644 --- a/app/assets/stylesheets/albums.scss +++ b/app/assets/stylesheets/albums.scss @@ -34,6 +34,9 @@ & > h3 { margin: -5px 0 5px 0; } + tr.unavailable > td { + background-color: #FFF0F0; + } td.song-duration { text-align: right; .s-duration { diff --git a/app/assets/stylesheets/player.scss b/app/assets/stylesheets/player.scss index c8403ac..ee14c6c 100644 --- a/app/assets/stylesheets/player.scss +++ b/app/assets/stylesheets/player.scss @@ -109,6 +109,9 @@ margin: 16px 5px 0 0; cursor: pointer; } + &.unavailable { + background-color: #FFF0F0; + } &.now { background-color: #EAF5FF; } diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index 9467963..4647c0e 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -18,7 +18,7 @@ class TrackController < ApplicationController def report_unavailable track = Track.find(params[:id]) unless track.nil? or track.available - track.available = true + track.available = false track.save return render :json => { :status => :success } end diff --git a/app/views/artist/_page.html.haml b/app/views/artist/_page.html.haml index 4fdb96d..64e12a4 100644 --- a/app/views/artist/_page.html.haml +++ b/app/views/artist/_page.html.haml @@ -29,7 +29,7 @@ %small= " ("+album.year.to_s+")" %table.zebra-striped.tracklist - album.tracks.each do |track| - %tr + %tr{ class: (track.available == false ? "unavailable" : nil) } %td.song-title= track.name %td.song-duration .s-duration= (track.duration != '0:00' ? track.duration : ' '.html_safe) diff --git a/config/routes.rb b/config/routes.rb index ba08c7a..6823092 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,7 @@ Beathaven::Application.routes.draw do match 'lastfm/scrobble' => 'last_fm#scrobble' match 'track/update_length' => 'track#update_length' + match 'track/report' => 'track#report_unavailable' match 'settings' => 'user#settings'