Track availability, fixes
This commit is contained in:
parent
d4203d26fd
commit
b82ade229d
|
@ -57,8 +57,9 @@ class window.Player
|
||||||
m = Math.floor(len / 60)
|
m = Math.floor(len / 60)
|
||||||
s = len - Math.floor(len / 60) * 60
|
s = len - Math.floor(len / 60) * 60
|
||||||
duration = m + ':' + (if s < 10 then '0' else '') + s
|
duration = m + ':' + (if s < 10 then '0' else '') + s
|
||||||
|
item_class = (if item.available == false then 'unavailable' else '')
|
||||||
$('.playlist').append '
|
$('.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="song-duration">' +duration+ '</div>
|
||||||
<div class="remove">remove</div>
|
<div class="remove">remove</div>
|
||||||
<div class="artist-name">' +item.artist+ '</div>
|
<div class="artist-name">' +item.artist+ '</div>
|
||||||
|
@ -85,10 +86,13 @@ class window.Player
|
||||||
$('.player .now-playing').html query
|
$('.player .now-playing').html query
|
||||||
$('.playlist li').removeClass 'now'
|
$('.playlist li').removeClass 'now'
|
||||||
$obj.addClass '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
|
if audio is null
|
||||||
console.log audio
|
_session.query '/track/report', { id: track.id }, (r) ->
|
||||||
_player.setTrack _player.nextTrack(true)
|
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
|
else
|
||||||
_player.playSource audio.url
|
_player.playSource audio.url
|
||||||
if track.length == 0
|
if track.length == 0
|
||||||
|
@ -97,7 +101,7 @@ class window.Player
|
||||||
s = len - Math.floor(len / 60) * 60
|
s = len - Math.floor(len / 60) * 60
|
||||||
duration = m + ':' + (if s < 10 then '0' else '') + s
|
duration = m + ':' + (if s < 10 then '0' else '') + s
|
||||||
_session.query '/track/update_length', { track_id: track.id, length: len }, (r) ->
|
_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)
|
$('.playlist li[data-id="'+track.id+'"] .song-duration').text(duration)
|
||||||
$($('.album div[data-id="'+track.id+'"]').siblings()[0]).text(duration)
|
$($('.album div[data-id="'+track.id+'"]').siblings()[0]).text(duration)
|
||||||
_player.updateNowListening track
|
_player.updateNowListening track
|
||||||
|
@ -110,6 +114,12 @@ class window.Player
|
||||||
return track
|
return track
|
||||||
false
|
false
|
||||||
|
|
||||||
|
getAlbumInfo: (id) ->
|
||||||
|
for album in _player.albums
|
||||||
|
if parseInt(album.id, 10) == parseInt(id, 10)
|
||||||
|
return album
|
||||||
|
false
|
||||||
|
|
||||||
hasTrack: ->
|
hasTrack: ->
|
||||||
if $('#jplayer audio').length > 0
|
if $('#jplayer audio').length > 0
|
||||||
return $('#jplayer audio').attr('src')? and $('#jplayer audio').attr('src') != ''
|
return $('#jplayer audio').attr('src')? and $('#jplayer audio').attr('src') != ''
|
||||||
|
@ -240,21 +250,19 @@ $('.playlist li').live 'click', ->
|
||||||
# Adding To Playlist actions
|
# Adding To Playlist actions
|
||||||
|
|
||||||
$('.add-album').live 'click', ->
|
$('.add-album').live 'click', ->
|
||||||
artist = $('.artist-info h2').text()
|
album = _player.getAlbumInfo($(this).attr('data-album-id'))
|
||||||
album = _player.albums[$(this).attr('data-album-id')]
|
|
||||||
for item in album.tracks
|
for item in album.tracks
|
||||||
item['artist'] = artist
|
item['artist'] = album.artist
|
||||||
item['album'] = album.name
|
item['album'] = album.name
|
||||||
_player.addTracks album.tracks
|
_player.addTracks album.tracks
|
||||||
false
|
false
|
||||||
|
|
||||||
$('.s-add').live 'click', ->
|
$('.s-add').live 'click', ->
|
||||||
artist = $('.artist-info h2').text()
|
album = _player.getAlbumInfo($(this).attr('data-album-id'))
|
||||||
album = _player.albums[$(this).attr('data-album-id')]
|
|
||||||
item = album.tracks[$(this).attr('data-id')]
|
item = album.tracks[$(this).attr('data-id')]
|
||||||
for item in album.tracks
|
for item in album.tracks
|
||||||
if item.id == parseInt($(this).attr('data-id'), 10)
|
if item.id == parseInt($(this).attr('data-id'), 10)
|
||||||
item['artist'] = artist
|
item['artist'] = album.artist
|
||||||
item['album'] = album.name
|
item['album'] = album.name
|
||||||
_player.addTracks [item]
|
_player.addTracks [item]
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -21,7 +21,8 @@ class window.Search
|
||||||
if _session.getUser().id
|
if _session.getUser().id
|
||||||
if data.artist.albums?
|
if data.artist.albums?
|
||||||
for album in 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()
|
$('.button-container').show()
|
||||||
_search.hideSpinner()
|
_search.hideSpinner()
|
||||||
if data.status is 'loading'
|
if data.status is 'loading'
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
& > h3 {
|
& > h3 {
|
||||||
margin: -5px 0 5px 0;
|
margin: -5px 0 5px 0;
|
||||||
}
|
}
|
||||||
|
tr.unavailable > td {
|
||||||
|
background-color: #FFF0F0;
|
||||||
|
}
|
||||||
td.song-duration {
|
td.song-duration {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
.s-duration {
|
.s-duration {
|
||||||
|
|
|
@ -109,6 +109,9 @@
|
||||||
margin: 16px 5px 0 0;
|
margin: 16px 5px 0 0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
&.unavailable {
|
||||||
|
background-color: #FFF0F0;
|
||||||
|
}
|
||||||
&.now {
|
&.now {
|
||||||
background-color: #EAF5FF;
|
background-color: #EAF5FF;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class TrackController < ApplicationController
|
||||||
def report_unavailable
|
def report_unavailable
|
||||||
track = Track.find(params[:id])
|
track = Track.find(params[:id])
|
||||||
unless track.nil? or track.available
|
unless track.nil? or track.available
|
||||||
track.available = true
|
track.available = false
|
||||||
track.save
|
track.save
|
||||||
return render :json => { :status => :success }
|
return render :json => { :status => :success }
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
%small= " ("+album.year.to_s+")"
|
%small= " ("+album.year.to_s+")"
|
||||||
%table.zebra-striped.tracklist
|
%table.zebra-striped.tracklist
|
||||||
- album.tracks.each do |track|
|
- album.tracks.each do |track|
|
||||||
%tr
|
%tr{ class: (track.available == false ? "unavailable" : nil) }
|
||||||
%td.song-title= track.name
|
%td.song-title= track.name
|
||||||
%td.song-duration
|
%td.song-duration
|
||||||
.s-duration= (track.duration != '0:00' ? track.duration : ' '.html_safe)
|
.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 'lastfm/scrobble' => 'last_fm#scrobble'
|
||||||
|
|
||||||
match 'track/update_length' => 'track#update_length'
|
match 'track/update_length' => 'track#update_length'
|
||||||
|
match 'track/report' => 'track#report_unavailable'
|
||||||
|
|
||||||
match 'settings' => 'user#settings'
|
match 'settings' => 'user#settings'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue