Adds back displaying the currently playing song as such in the queue

We no longer alter the song, the queue gets this from the player.
That way we can't have two songs marked as 'playing' at the same time.
This commit is contained in:
Hyzual 2015-01-03 14:54:09 +01:00
parent c787c468b9
commit 3c809d1903
7 changed files with 31 additions and 47 deletions

View file

@ -103,6 +103,7 @@ angular.module('JamStash')
}; };
$scope.$watchCollection('queue', function(newItem, oldItem) { $scope.$watchCollection('queue', function(newItem, oldItem) {
// TODO: Hyz: Replace
if (oldItem.length != newItem.length if (oldItem.length != newItem.length
&& globals.settings.ShowQueue) { && globals.settings.ShowQueue) {
$rootScope.showQueue(); $rootScope.showQueue();
@ -123,14 +124,7 @@ angular.module('JamStash')
$('#right-component').addClass('lgcolumn_expanded'); $('#right-component').addClass('lgcolumn_expanded');
}; };
$scope.toggleQueue = function () { $scope.toggleQueue = function () {
if ($('#SideBar').css('display') == 'none') { if ($('#SideBar').css('display') === 'none') {
$rootScope.showQueue();
} else {
$rootScope.hideQueue();
}
};
$scope.toggleQueue = function () {
if ($('#SideBar').css('display') == 'none') {
$rootScope.showQueue(); $rootScope.showQueue();
} else { } else {
$rootScope.hideQueue(); $rootScope.hideQueue();
@ -275,6 +269,7 @@ angular.module('JamStash')
}); });
}; };
$rootScope.playAll = function (songs) { $rootScope.playAll = function (songs) {
// TODO: Hyz: Replace
$rootScope.queue = []; $rootScope.queue = [];
$rootScope.selectAll(songs); $rootScope.selectAll(songs);
$rootScope.addSongsToQueue(); $rootScope.addSongsToQueue();
@ -282,6 +277,7 @@ angular.module('JamStash')
player.play(next); player.play(next);
}; };
$rootScope.playFrom = function (index, songs) { $rootScope.playFrom = function (index, songs) {
// TODO: Hyz: Replace
var from = songs.slice(index,songs.length); var from = songs.slice(index,songs.length);
$scope.selectedSongs = []; $scope.selectedSongs = [];
angular.forEach(from, function (item, key) { angular.forEach(from, function (item, key) {
@ -296,6 +292,7 @@ angular.module('JamStash')
} }
}; };
$rootScope.addSongsToQueue = function () { $rootScope.addSongsToQueue = function () {
// TODO: Hyz: Replace
if ($scope.selectedSongs.length !== 0) { if ($scope.selectedSongs.length !== 0) {
angular.forEach($scope.selectedSongs, function (item, key) { angular.forEach($scope.selectedSongs, function (item, key) {
$rootScope.queue.push(item); $rootScope.queue.push(item);
@ -306,6 +303,7 @@ angular.module('JamStash')
} }
}; };
$rootScope.removeSong = function (item, songs) { $rootScope.removeSong = function (item, songs) {
// TODO: Hyz: Replace
var index = songs.indexOf(item); var index = songs.indexOf(item);
songs.splice(index, 1); songs.splice(index, 1);
}; };
@ -337,17 +335,6 @@ angular.module('JamStash')
} }
}); });
}; };
$scope.queueTotal = function () {
var total = 0;
utils.arrayForEach(self.queue(), function (item) {
total += parseInt(item.duration());
});
if (self.queue().length > 0) {
return self.queue().length + ' song(s), ' + utils.secondsToTime(total) + ' total time';
} else {
return '0 song(s), 00:00:00 total time';
}
};
$scope.selectedSongs = []; $scope.selectedSongs = [];
$scope.selectSong = function (data) { $scope.selectSong = function (data) {
var i = $scope.selectedSongs.indexOf(data); var i = $scope.selectedSongs.indexOf(data);
@ -419,6 +406,7 @@ angular.module('JamStash')
if (song) { if (song) {
player.load(song); player.load(song);
} }
if (globals.settings.Debug) { console.log('Current Position Loaded from localStorage: ', song); }
}; };
$scope.loadQueue = function () { $scope.loadQueue = function () {

View file

@ -221,23 +221,6 @@ describe("Player service -", function() {
}; };
}); });
xit("when I play it, the song is marked as playing", function() {
player.play(song);
expect(player.getPlayingSong()).toBe(song);
expect(song.playing).toBeTruthy();
});
xit("when I restart the current song, the song is still marked as playing", function() {
song.playing = true;
//player.getPlayingSong() = song;
player.restart();
expect(player.getPlayingSong()).toBe(song);
expect(song.playing).toBeTruthy();
});
it("when the song was playing and I play it again, it restarts the current song", function() { it("when the song was playing and I play it again, it restarts the current song", function() {
spyOn(player, "restart"); spyOn(player, "restart");

View file

@ -17,19 +17,19 @@
</div> </div>
<div id="songdetails"> <div id="songdetails">
<div id="coverart"> <div id="coverart">
<a ng-click="fancyboxOpenImage(playingSong.coverartfull)"> <a ng-click="fancyboxOpenImage(getPlayingSong().coverartfull)">
<img ng-src="{{player.playingSong.coverartthumb}}" src="images/albumdefault_60.jpg" height="30" width="30" /> <img ng-src="{{getPlayingSong().coverartthumb}}" src="images/albumdefault_60.jpg" height="30" width="30" />
</a> </a>
</div> </div>
<ul> <ul>
<li class="song" id="{{player.playingSong.id}}" ng-bind-html="player.playingSong.name" title="{{player.playingSong.specs}}"></li> <li class="song" id="{{getPlayingSong().id}}" ng-bind-html="getPlayingSong().name" title="{{getPlayingSong().specs}}"></li>
<li class="album" ng-bind-html="player.playingSong.album"></li> <li class="album" ng-bind-html="getPlayingSong().album"></li>
</ul> </ul>
<div id="songdetails_controls"> <div id="songdetails_controls">
<a href="" class="jukebox" title="Jukebox Mode [Beta]" ng-click="toggleSetting('Jukebox')" ng-class="{'hoverSelected': !settings.Jukebox }"></a> <a href="" class="jukebox" title="Jukebox Mode [Beta]" ng-click="toggleSetting('Jukebox')" ng-class="{'hoverSelected': !settings.Jukebox }"></a>
<a href="" class="loop" title="Repeat" ng-click="toggleSetting('Repeat')" ng-class="{'hoverSelected': !settings.Repeat }"></a> <a href="" class="loop" title="Repeat" ng-click="toggleSetting('Repeat')" ng-class="{'hoverSelected': !settings.Repeat }"></a>
<a href="" id="action_SaveProgress" class="lock" title="Save Track Position: On" ng-show="settings.SaveTrackPosition"></a> <a href="" id="action_SaveProgress" class="lock" title="Save Track Position: On" ng-show="settings.SaveTrackPosition"></a>
<a title="Favorite" href="" ng-class="{'favorite': player.playingSong.starred, 'rate': !player.playingSong.starred}" ng-click="updateFavorite(player.playingSong)" stop-event="click"></a> <a title="Favorite" href="" ng-class="{'favorite': getPlayingSong().starred, 'rate': !getPlayingSong().starred}" ng-click="updateFavorite(getPlayingSong())" stop-event="click"></a>
<a href="" id="action_Mute" class="mute" title="Mute"></a> <a href="" id="action_Mute" class="mute" title="Mute"></a>
<a href="" id="action_UnMute" class="unmute" title="Unmute" style="display: none;"></a> <a href="" id="action_UnMute" class="unmute" title="Unmute" style="display: none;"></a>
<!--<div class="jp-volume-bar"><div class="jp-volume-bar-value"></div></div><a href="" id="action_VolumeMax" class="volume" title="Max Volume"></a>--> <!--<div class="jp-volume-bar"><div class="jp-volume-bar-value"></div></div><a href="" id="action_VolumeMax" class="volume" title="Max Volume"></a>-->

View file

@ -10,7 +10,9 @@ angular.module('jamstash.player.controller', ['jamstash.player.service', 'jamsta
$scope.player = player; $scope.player = player;
$scope.updateFavorite = function (song) { $scope.getPlayingSong = function () {
// TODO return player.getPlayingSong();
}; };
//TODO: Hyz: updateFavorite - leave in rootScope ?
}]); }]);

View file

@ -7,7 +7,7 @@
<div id="SideQueue"> <div id="SideQueue">
<ul class="simplelist songlist noselect"> <ul class="simplelist songlist noselect">
<div ng-repeat="song in [player.queue] track by $index" class="songs" sortable> <div ng-repeat="song in [player.queue] track by $index" class="songs" sortable>
<li class="row song" ng-repeat="o in song" ng-click="selectSong(o)" ng-dblclick="playSong(o)" ng-class="{'selected': o.selected, 'playing': o.playing}"> <li class="row song" ng-repeat="o in song" ng-click="selectSong(o)" ng-dblclick="playSong(o)" ng-class="{'selected': o.selected, 'playing': isPlayingSong(o)}">
<div class="itemactions"> <div class="itemactions">
<a class="remove" href="" title="Remove Song" ng-click="removeSongFromQueue(o)" stop-event="click"></a> <a class="remove" href="" title="Remove Song" ng-click="removeSongFromQueue(o)" stop-event="click"></a>
<a href="" title="Favorite" ng-class="{'favorite': o.starred, 'rate': !o.starred}" ng-click="updateFavorite(o)" stop-event="click"></a> <a href="" title="Favorite" ng-class="{'favorite': o.starred, 'rate': !o.starred}" ng-click="updateFavorite(o)" stop-event="click"></a>

View file

@ -32,4 +32,10 @@ angular.module('jamstash.queue.controller', ['jamstash.player.service'])
$scope.removeSelectedSongsFromQueue = function () { $scope.removeSelectedSongsFromQueue = function () {
player.removeSongs($scope.selectedSongs); player.removeSongs($scope.selectedSongs);
}; };
$scope.isPlayingSong = function (song) {
return angular.equals(song, player.getPlayingSong());
};
//TODO: Hyz: updateFavorite - leave in rootScope ?
}]); }]);

View file

@ -2,9 +2,7 @@ describe("Queue controller", function() {
'use strict'; 'use strict';
var player, scope, globals; var player, scope, globals;
var song = { var song;
id: 7310
};
beforeEach(function() { beforeEach(function() {
module('jamstash.queue.controller'); module('jamstash.queue.controller');
@ -20,6 +18,7 @@ describe("Queue controller", function() {
player: player player: player
}); });
}); });
song = { id: 7310 };
}); });
it("When I play a song, it calls play in the player service", function() { it("When I play a song, it calls play in the player service", function() {
@ -59,4 +58,10 @@ describe("Queue controller", function() {
scope.removeSelectedSongsFromQueue(); scope.removeSelectedSongsFromQueue();
expect(player.removeSongs).toHaveBeenCalledWith([song, secondSong]); expect(player.removeSongs).toHaveBeenCalledWith([song, secondSong]);
}); });
it("asks the player service if a given song is the currently playing song", function() {
spyOn(player, "getPlayingSong").and.returnValue(song);
expect(scope.isPlayingSong(song)).toBeTruthy();
expect(player.getPlayingSong).toHaveBeenCalled();
});
}); });