diff --git a/assets/js/application.js b/assets/js/application.js index d4bca60..7a070bd 100644 --- a/assets/js/application.js +++ b/assets/js/application.js @@ -5,3 +5,13 @@ App.QueueRoute = Ember.Route.extend({ return Ember.$.getJSON('/api/queue'); } }); + +App.ControlsController = Ember.Controller.extend({ + actions: { + previous: function() { return Ember.$.ajax('/api/control/previous', { type: 'PUT' }); }, + play: function() { return Ember.$.ajax('/api/control/play', { type: 'PUT' }); }, + pause: function() { return Ember.$.ajax('/api/control/pause', { type: 'PUT' }); }, + stop: function() { return Ember.$.ajax('/api/control/stop', { type: 'PUT' }); }, + next: function() { return Ember.$.ajax('/api/control/next', { type: 'PUT' }); } + } +}); diff --git a/models/song.rb b/models/song.rb index b1e1195..e6da89a 100644 --- a/models/song.rb +++ b/models/song.rb @@ -1,15 +1,17 @@ require './models/mpd_connection' -class Song < Struct.new(:artist, :album, :title) +class Song < Struct.new(:artist, :album, :title, :current) - def initialize(song) + def initialize(song, current: false) @song = song self.artist = song.artist self.album = song.album self.title = song.title + self.current = current end def self.queue - MPDConnection.mpd.queue.map { |song| self.new(song) } + current_song = MPDConnection.mpd.status[:songid] + MPDConnection.mpd.queue.map { |song| self.new(song, current: (song.id == current_song)) } end end diff --git a/views/index.erb b/views/index.erb index e85a8a7..623e18b 100644 --- a/views/index.erb +++ b/views/index.erb @@ -2,6 +2,11 @@