Refactor song selection across the app
- Added a new SelectedSongs service. Its purpose is to store an array of selected songs and all behaviour associated with it : adding songs to it, removing them, toggling a song, etc. It also changes each song's selected property. - Removed selectAll, selectNone, playAll, playFrom, addSongsToQueue and selectSong from main-controller.js. Those are now defined either in queue.js, subsonic.js or archive.js, depending on where they are used. I know it does add some duplication between archive.js and subsonic.js, but this will be addressed in a later commit (maybe by creating a shared service). - Refactored subsonic-service.js' addToPlaylist() and split it between subsonic-service.js and subsonic.js (like all the other playlist-related functions). - Moved subsonic-service.js' songsRemoveSelected() to subsonic.js since it only removes songs from the scope. - Removed $rootScope and utils (unused dependencies) from subsonic-service.js
This commit is contained in:
parent
7e0c5a176a
commit
5d385149f3
16 changed files with 658 additions and 276 deletions
|
@ -214,52 +214,7 @@ angular.module('JamStash')
|
|||
$scope.scrollToTop = function () {
|
||||
$('#left-component').stop().scrollTo('#MusicFolders', 400);
|
||||
};
|
||||
$rootScope.selectAll = function (songs) {
|
||||
angular.forEach(songs, function (item, key) {
|
||||
$scope.selectedSongs.push(item);
|
||||
item.selected = true;
|
||||
});
|
||||
};
|
||||
$rootScope.selectNone = function (songs) {
|
||||
angular.forEach(songs, function (item, key) {
|
||||
$scope.selectedSongs = [];
|
||||
item.selected = false;
|
||||
});
|
||||
};
|
||||
$rootScope.playAll = function (songs) {
|
||||
// TODO: Hyz: Replace
|
||||
player.queue = [];
|
||||
$rootScope.selectAll(songs);
|
||||
$rootScope.addSongsToQueue();
|
||||
var next = player.queue[0];
|
||||
player.play(next);
|
||||
};
|
||||
$rootScope.playFrom = function (index, songs) {
|
||||
// TODO: Hyz: Replace
|
||||
var from = songs.slice(index,songs.length);
|
||||
$scope.selectedSongs = [];
|
||||
angular.forEach(from, function (item, key) {
|
||||
$scope.selectedSongs.push(item);
|
||||
item.selected = true;
|
||||
});
|
||||
if ($scope.selectedSongs.length > 0) {
|
||||
player.queue = [];
|
||||
$rootScope.addSongsToQueue();
|
||||
var next = player.queue[0];
|
||||
player.play(next);
|
||||
}
|
||||
};
|
||||
$rootScope.addSongsToQueue = function () {
|
||||
// TODO: Hyz: Replace
|
||||
if ($scope.selectedSongs.length !== 0) {
|
||||
angular.forEach($scope.selectedSongs, function (item, key) {
|
||||
player.queue.push(item);
|
||||
item.selected = false;
|
||||
});
|
||||
notifications.updateMessage($scope.selectedSongs.length + ' Song(s) Added to Queue', true);
|
||||
$scope.selectedSongs.length = 0;
|
||||
}
|
||||
};
|
||||
|
||||
$rootScope.removeSong = function (item, songs) {
|
||||
// TODO: Hyz: Replace
|
||||
var index = songs.indexOf(item);
|
||||
|
@ -290,17 +245,6 @@ angular.module('JamStash')
|
|||
}
|
||||
});
|
||||
};
|
||||
$scope.selectedSongs = [];
|
||||
$scope.selectSong = function (data) {
|
||||
var i = $scope.selectedSongs.indexOf(data);
|
||||
if (i >= 0) {
|
||||
$scope.selectedSongs.splice(i, 1);
|
||||
data.selected = false;
|
||||
} else {
|
||||
$scope.selectedSongs.push(data);
|
||||
data.selected = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the target of this event is an input
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue