diff --git a/assets/css/transport.css.sass b/assets/css/transport.css.sass
index e287dc8..78bb7bb 100644
--- a/assets/css/transport.css.sass
+++ b/assets/css/transport.css.sass
@@ -1,4 +1,4 @@
-#transport
+mpd-transport
position: fixed
bottom: 0
width: 20em
diff --git a/assets/js/components/app.js b/assets/js/components/app.js
index 8c3e340..e16befd 100644
--- a/assets/js/components/app.js
+++ b/assets/js/components/app.js
@@ -5,13 +5,14 @@ can.Component.extend({
template: can.view('views/app.mustache'),
scope: {
- queueSongs: new can.List(),
- status: new can.Map()
+ queueSongs: new QueueSong.List(),
+ status: new Status
},
events: {
init: function(element, options) {
- this.scope.attr('events', new Events(this.scope.queueSongs, this.scope.status));
+ Status.findOne({}, this.updateStatus.bind(this));
+ this.scope.attr('events', new Events(this.scope));
this.fetch();
},
@@ -22,8 +23,16 @@ can.Component.extend({
});
},
+ updateStatus: function(result) {
+ this.scope.attr('status', result);
+ },
+
update: function(songs) {
this.scope.attr('queueSongs', songs);
+ },
+
+ '{scope.status} change': function() {
+ this.scope.attr('queueSongs').updatePlaying(this.scope.status.song);
}
}
diff --git a/assets/js/components/transport.js b/assets/js/components/transport.js
new file mode 100644
index 0000000..ced3354
--- /dev/null
+++ b/assets/js/components/transport.js
@@ -0,0 +1,22 @@
+can.Component.extend({
+
+ tag: 'mpd-transport',
+
+ template: can.view('views/transport.mustache'),
+
+ events: {
+ sendCommand: function(command) {
+ can.ajax({
+ url: '/api/control/' + command,
+ type: 'PUT'
+ });
+ },
+
+ 'button click': function(element, event) {
+ var command = $(element).data('command');
+ this.sendCommand(command);
+ $(element).blur();
+ }
+ }
+
+});
diff --git a/assets/js/constructs/events.js b/assets/js/constructs/events.js
index 8834cbf..d52ee0a 100644
--- a/assets/js/constructs/events.js
+++ b/assets/js/constructs/events.js
@@ -1,6 +1,6 @@
var Events = can.Construct.extend({
- init: function(queue, status) {
+ init: function(scope) {
this.events = new EventSource('/api/stream')
self = this
@@ -9,24 +9,16 @@ var Events = can.Construct.extend({
response = JSON.parse(e.data);
switch (response.type) {
case 'status':
- status.attr(response.data, true);
+ scope.attr('status').attr(response.data);
break;
case 'queue':
- queue.replace(response.data);
- debugger;
+ scope.attr('queueSongs', response.data);
break;
case 'time':
- status.attr('time', response.data);
+ scope.attr('status.time', response.data);
break;
}
}
-
- status.bind('change', function(event, attr, how, newVal, oldVal) {
- if (attr == 'song') {
- debugger;
- queue.updatePlaying(how, newVal, oldVal);
- }
- });
},
});
diff --git a/assets/js/helpers/time.js b/assets/js/helpers/time.js
index 0c60b5b..1875f4c 100644
--- a/assets/js/helpers/time.js
+++ b/assets/js/helpers/time.js
@@ -7,4 +7,4 @@ window.timeHelpers = {
}
return minutes + ':' + seconds;
}
-}
+};
diff --git a/assets/js/models/queueSong.js b/assets/js/models/queueSong.js
index cdd8021..e3bf2f5 100644
--- a/assets/js/models/queueSong.js
+++ b/assets/js/models/queueSong.js
@@ -2,17 +2,21 @@ var QueueSong = can.Model.extend({
findAll: 'GET /api/queue'
-}, {});
+}, {
-QueueSong.List = can.List.extend({
-
- updatePlaying: function(how, newVal, oldVal) {
- if ((how == 'remove' || how == 'set') && this.attr(oldVal) != undefined) {
- this.attr(oldVal).attr('playing', false);
- }
- if (how == 'add' || how == 'set') {
- this.attr(newVal).attr('playing', true);
- }
+ formattedLength: function() {
+ return timeHelpers.formatLength(this.length)
+ }
+
+});
+
+QueueSong.List = can.List.extend({
+
+ updatePlaying: function(newSong) {
+ this.each(function(item) {
+ item.attr('playing', false);
+ });
+ this.attr(newSong).attr('playing', true);
}
});
diff --git a/assets/js/models/status.js b/assets/js/models/status.js
index 7aa5504..0791990 100644
--- a/assets/js/models/status.js
+++ b/assets/js/models/status.js
@@ -2,4 +2,34 @@ var Status = can.Model.extend({
findOne: 'GET /api/status'
-}, {});
+}, {
+
+ playing: function() {
+ return this.attr('state') === 'play'
+ },
+
+ playingOrPaused: function() {
+ return (this.attr('state') === 'play' || this.attr('state') === 'pause');
+ },
+
+ showTrackProgress: can.compute(function() {
+ return (this.playingOrPaused() && this.attr('time') != undefined);
+ }),
+
+ formattedElapsedTime: function() {
+ if (this.attr('time') != undefined) {
+ return timeHelpers.formatLength(this.attr('time')[0])
+ }
+ },
+
+ formattedTotalTime: function() {
+ if (this.attr('time') != undefined) {
+ return timeHelpers.formatLength(this.attr('time')[1])
+ }
+ },
+
+ markerPosition: function() {
+ return (this.attr('time')[0] / this.attr('time')[1]) * 100
+ }
+
+});
diff --git a/public/views/library.ejs b/public/views/library.ejs
deleted file mode 100644
index eead0f2..0000000
--- a/public/views/library.ejs
+++ /dev/null
@@ -1,15 +0,0 @@
-<%= browser.attr('title') %>
-
<%= song.attr('title') %>
-<%= song.attr('artist') %>
-<%= formatLength(song.attr('length')) %>
-