Basic setting playlist
This commit is contained in:
parent
4ade7fa77f
commit
9a79ae0527
|
@ -187,6 +187,25 @@ class window.Player
|
||||||
if _session.getUser().lastfm_username
|
if _session.getUser().lastfm_username
|
||||||
_session.query '/lastfm/scrobble?r=' +Math.random(), track
|
_session.query '/lastfm/scrobble?r=' +Math.random(), track
|
||||||
false
|
false
|
||||||
|
|
||||||
|
emptyPlaylist: ->
|
||||||
|
$('.playlist li').remove()
|
||||||
|
$('#jplayer').jPlayer 'clearMedia'
|
||||||
|
$('.player .now-playing').text 'Add some music to playlist'
|
||||||
|
$('.player .loaded, .player .played').width 0
|
||||||
|
false
|
||||||
|
|
||||||
|
setPlaylist: (data) ->
|
||||||
|
this.emptyPlaylist()
|
||||||
|
tracks = []
|
||||||
|
for item in data.playlist_items
|
||||||
|
tracks.push
|
||||||
|
id: item.track.id
|
||||||
|
name: item.track.name
|
||||||
|
artist: item.track.artists[0].name
|
||||||
|
length: item.track.length
|
||||||
|
this.addTracks tracks
|
||||||
|
false
|
||||||
|
|
||||||
|
|
||||||
# Player Controls
|
# Player Controls
|
||||||
|
@ -216,10 +235,7 @@ $('.repeat, .shuffle').live 'click', ->
|
||||||
|
|
||||||
$('.do_empty').live 'click', ->
|
$('.do_empty').live 'click', ->
|
||||||
if confirm('Are you sure?')
|
if confirm('Are you sure?')
|
||||||
$('.playlist li').remove()
|
_player.emptyPlaylist()
|
||||||
$('#jplayer').jPlayer 'clearMedia'
|
|
||||||
$('.player .now-playing').text 'Add some music to playlist'
|
|
||||||
$('.player .loaded, .player .played').width 0
|
|
||||||
false
|
false
|
||||||
|
|
||||||
# Playlist Actions
|
# Playlist Actions
|
||||||
|
@ -267,3 +283,11 @@ $('.s-add').live 'click', ->
|
||||||
_player.addTracks [item]
|
_player.addTracks [item]
|
||||||
return false
|
return false
|
||||||
false
|
false
|
||||||
|
|
||||||
|
$('.set-playlist').live 'click', ->
|
||||||
|
_search.showSpinner()
|
||||||
|
$.get "/playlist/#{$(this).data('playlist-id')}", (playlist) ->
|
||||||
|
_player.setPlaylist playlist
|
||||||
|
_search.hideSpinner()
|
||||||
|
false
|
||||||
|
false
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class PlaylistController < ApplicationController
|
||||||
|
def data
|
||||||
|
@playlist = Playlist.find_by_id(params[:id])
|
||||||
|
render json: @playlist, include: { playlist_items: { include: { track: { include: { artists: {} }}}}}
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,5 @@
|
||||||
class Playlist < ActiveRecord::Base
|
class Playlist < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :artist
|
||||||
has_many :playlist_items
|
has_many :playlist_items
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@ class Artist < ActiveRecord::Base
|
||||||
has_many :artist_links, :dependent => :destroy
|
has_many :artist_links, :dependent => :destroy
|
||||||
has_many :artist_aliases, :dependent => :destroy
|
has_many :artist_aliases, :dependent => :destroy
|
||||||
has_many :tracks, :through => :track_artists
|
has_many :tracks, :through => :track_artists
|
||||||
|
has_many :playlists
|
||||||
|
|
||||||
after_initialize :prepare_description
|
after_initialize :prepare_description
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ class Track < ActiveRecord::Base
|
||||||
belongs_to :album
|
belongs_to :album
|
||||||
has_many :track_artists
|
has_many :track_artists
|
||||||
has_many :artists, :through => :track_artists
|
has_many :artists, :through => :track_artists
|
||||||
@duration
|
has_many :playlist_items
|
||||||
|
|
||||||
def duration
|
def duration
|
||||||
if self.length
|
if self.length
|
||||||
|
|
|
@ -11,29 +11,31 @@
|
||||||
%p= @artist.desc.html_safe unless @artist.desc.nil?
|
%p= @artist.desc.html_safe unless @artist.desc.nil?
|
||||||
- unless @artist.artist_links.empty?
|
- unless @artist.artist_links.empty?
|
||||||
.service-icons
|
.service-icons
|
||||||
%a.foreign-link{ :href => "http://last.fm/artist/#{@artist.name.gsub(" ", "+")}", :target => '_blank' }
|
%a.foreign-link{ href: "http://last.fm/artist/#{@artist.name.gsub(" ", "+")}", target: '_blank' }
|
||||||
= image_tag 'services/lastfm.ico'
|
= image_tag 'services/lastfm.ico'
|
||||||
- @artist.artist_links.each do |service|
|
- @artist.artist_links.each do |service|
|
||||||
- if ['wikipedia', 'microblog', 'official_homepage', 'social_network', 'youtube'].include?(service.service)
|
- if ['wikipedia', 'microblog', 'official_homepage', 'social_network', 'youtube'].include?(service.service)
|
||||||
%a.foreign-link{ :href => service.url, :target => '_blank' }
|
%a.foreign-link{ href: service.url, target: '_blank' }
|
||||||
= image_tag 'services/'+service.service+(service.service == 'official_homepage' ? '.png' : '.ico')
|
= image_tag 'services/'+service.service+(service.service == 'official_homepage' ? '.png' : '.ico')
|
||||||
|
|
||||||
.row
|
- unless @artist.playlists.empty?
|
||||||
.span7.offset4
|
.row
|
||||||
%h3 Playlists
|
.span7.offset4
|
||||||
%table.zebra-striped
|
%h3 Playlists
|
||||||
%tr
|
%table.zebra-striped
|
||||||
%td
|
%tr
|
||||||
%a{ href: "" } Last.fm TOP
|
- @artist.playlists.each do |playlist|
|
||||||
|
%td
|
||||||
|
%a.set-playlist{ href: "", 'data-playlist-id' => playlist.id }= playlist.name
|
||||||
|
|
||||||
- @artist.albums.each do |album|
|
- @artist.albums.each do |album|
|
||||||
.row.album
|
.row.album
|
||||||
.span4.columns.art
|
.span4.columns.art
|
||||||
%img{ :src => album.pic_url }
|
%img{ src: album.pic_url }
|
||||||
.button-container
|
.button-container
|
||||||
%a.btn.add-album{ :'data-album-id' => album.id }= I18n.t 'player.add'
|
%a.btn.add-album{ 'data-album-id' => album.id }= I18n.t 'player.add'
|
||||||
.span7.columns.tracks
|
.span7.columns.tracks
|
||||||
%h3{ :'data-album-id' => album.id }
|
%h3{ 'data-album-id' => album.id }
|
||||||
= album.name
|
= album.name
|
||||||
%small= " ("+album.year.to_s+")"
|
%small= " ("+album.year.to_s+")"
|
||||||
%table.zebra-striped.tracklist
|
%table.zebra-striped.tracklist
|
||||||
|
@ -42,4 +44,4 @@
|
||||||
%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)
|
||||||
%span.label.success.s-add{ :'data-album-id' => album.id, :'data-id' => track.id }= I18n.t 'player.add_one'
|
%span.label.success.s-add{ 'data-album-id' => album.id, 'data-id' => track.id }= I18n.t 'player.add_one'
|
||||||
|
|
|
@ -15,6 +15,8 @@ Beathaven::Application.routes.draw do
|
||||||
match 'track/update_length' => 'track#update_length'
|
match 'track/update_length' => 'track#update_length'
|
||||||
match 'track/report' => 'track#report_unavailable'
|
match 'track/report' => 'track#report_unavailable'
|
||||||
|
|
||||||
|
match 'playlist/(:id)' => 'playlist#data'
|
||||||
|
|
||||||
match 'settings' => 'user#settings'
|
match 'settings' => 'user#settings'
|
||||||
|
|
||||||
match 'artist/autocomplete' => 'last_fm#autocomplete'
|
match 'artist/autocomplete' => 'last_fm#autocomplete'
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddArtistToPlaylists < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :playlists, :artist_id, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20111012064322) do
|
ActiveRecord::Schema.define(:version => 20111126142207) do
|
||||||
|
|
||||||
create_table "album_formats", :force => true do |t|
|
create_table "album_formats", :force => true do |t|
|
||||||
t.integer "album_id"
|
t.integer "album_id"
|
||||||
|
@ -155,6 +155,7 @@ ActiveRecord::Schema.define(:version => 20111012064322) do
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.integer "artist_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "release_formats", :force => true do |t|
|
create_table "release_formats", :force => true do |t|
|
||||||
|
|
Loading…
Reference in New Issue