mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Add status and refactor JS.
This commit is contained in:
parent
3bb9103dbe
commit
3c7601d681
@ -2,13 +2,30 @@ var QueueSong = can.Model({
|
|||||||
findAll: 'GET /api/queue'
|
findAll: 'GET /api/queue'
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
QueueSong.findAll({}, function(songs) {
|
var queueSongs = new can.List();
|
||||||
$('#queue').html(can.view('queueTemplate',
|
|
||||||
{ songs: songs }));
|
|
||||||
}, function(xhr) {
|
|
||||||
|
|
||||||
|
// Update the queue display when the queueSongs list changes
|
||||||
|
queueSongs.bind('change', function(event) {
|
||||||
|
$('#queue').html(can.view('queueTemplate',
|
||||||
|
{ songs: this }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Get the songs currently in the queue
|
||||||
|
QueueSong.findAll({}, function(songs) {
|
||||||
|
queueSongs.replace(songs);
|
||||||
|
}, function(xhr) {
|
||||||
|
console.log("An error occured with the request.");
|
||||||
|
});
|
||||||
|
|
||||||
|
var updatePlaying = function(queue, index) {
|
||||||
|
queue.forEach(function(element) {
|
||||||
|
element.attr('playing', false);
|
||||||
|
});
|
||||||
|
item = queue.attr(index);
|
||||||
|
item.attr('playing', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up necessary events and startup stuff
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Bind transport click events.
|
// Bind transport click events.
|
||||||
$('#transport').on('click', '#controls button', function(e) {
|
$('#transport').on('click', '#controls button', function(e) {
|
||||||
|
|||||||
@ -4,4 +4,8 @@ class MPDConnection
|
|||||||
@@mpd.connect unless @@mpd.connected?
|
@@mpd.connect unless @@mpd.connected?
|
||||||
@@mpd
|
@@mpd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.status
|
||||||
|
self.mpd.status
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -7,6 +7,7 @@ require 'sinatra/asset_pipeline'
|
|||||||
require 'json'
|
require 'json'
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
|
|
||||||
|
require './models/mpd_connection'
|
||||||
require './models/control'
|
require './models/control'
|
||||||
require './models/album'
|
require './models/album'
|
||||||
require './models/artist'
|
require './models/artist'
|
||||||
@ -26,6 +27,10 @@ class MPDClient < Sinatra::Base
|
|||||||
|
|
||||||
namespace '/api' do
|
namespace '/api' do
|
||||||
|
|
||||||
|
get '/status' do
|
||||||
|
JSON MPDConnection.status
|
||||||
|
end
|
||||||
|
|
||||||
get '/albums' do
|
get '/albums' do
|
||||||
JSON Album.all.map(&:to_h)
|
JSON Album.all.map(&:to_h)
|
||||||
end
|
end
|
||||||
@ -53,6 +58,7 @@ class MPDClient < Sinatra::Base
|
|||||||
put '/control/:action' do
|
put '/control/:action' do
|
||||||
if Control.controls.include?(params[:action].to_sym)
|
if Control.controls.include?(params[:action].to_sym)
|
||||||
Control.send(params[:action])
|
Control.send(params[:action])
|
||||||
|
JSON MPDConnection.status
|
||||||
else
|
else
|
||||||
not_found
|
not_found
|
||||||
end
|
end
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
<h2>Queue</h2>
|
<h2>Queue</h2>
|
||||||
<ul id="queue">
|
<ul id="queue">
|
||||||
{{#songs}}
|
{{#songs}}
|
||||||
<li{{#playing}} class="playing"{{/playing}}>{{ artist }} - {{ title }}</li>
|
<li id="{{ id }}"{{#playing}} class="playing"{{/playing}}>{{ artist }} - {{ title }}</li>
|
||||||
{{/songs}} {{^songs}}
|
{{/songs}} {{^songs}}
|
||||||
<li>Play queue empty</li>
|
<li>Play queue empty</li>
|
||||||
{{/songs}}
|
{{/songs}}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user