Track availability, fixes
This commit is contained in:
parent
d4203d26fd
commit
b82ade229d
|
@ -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 '
|
||||
<li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'">
|
||||
<li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'" class="'+item_class+'">
|
||||
<div class="song-duration">' +duration+ '</div>
|
||||
<div class="remove">remove</div>
|
||||
<div class="artist-name">' +item.artist+ '</div>
|
||||
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
& > h3 {
|
||||
margin: -5px 0 5px 0;
|
||||
}
|
||||
tr.unavailable > td {
|
||||
background-color: #FFF0F0;
|
||||
}
|
||||
td.song-duration {
|
||||
text-align: right;
|
||||
.s-duration {
|
||||
|
|
|
@ -109,6 +109,9 @@
|
|||
margin: 16px 5px 0 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
&.unavailable {
|
||||
background-color: #FFF0F0;
|
||||
}
|
||||
&.now {
|
||||
background-color: #EAF5FF;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
Loading…
Reference in New Issue