Moves the subsonic controller into its own module.

Removes many injected params that weren't used at all in it.
Removes the old commented getStarred function from the subsonic service.
This commit is contained in:
Hyzual 2014-11-06 22:59:00 +01:00
parent 1a830d6cef
commit b190d2f99f
5 changed files with 27 additions and 81 deletions

View file

@ -2,7 +2,7 @@
/* Declare app level module */ /* Declare app level module */
var jamstash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize', var jamstash = angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize',
'jamstash.subsonicService']); 'jamstash.subsonic.ctrl']);
jamstash.config(function ($routeProvider) { jamstash.config(function ($routeProvider) {
$routeProvider $routeProvider

View file

@ -1,9 +1,13 @@
'use strict'; /**
* jamstash.subsonic Module
*
* Access the Subsonic server through the dedicated service
*/
angular.module('jamstash.subsonic.ctrl', ['jamstash.subsonic.service'])
var jamstash = angular.module('JamStash'); .controller('SubsonicCtrl',
function SubsonicCtrl($scope, $rootScope, $routeParams, utils, globals, map, subsonic, notifications) {
jamstash.controller('SubsonicCtrl', 'use strict';
function SubsonicCtrl($scope, $rootScope, $location, $window, $routeParams, $http, utils, globals, model, map, subsonic, notifications) {
$scope.settings = globals.settings; $scope.settings = globals.settings;
$scope.itemType = 'ss'; $scope.itemType = 'ss';

View file

@ -4,7 +4,7 @@
* Provides access through $http to the Subsonic server's API. * Provides access through $http to the Subsonic server's API.
* Also offers more fine-grained functionality that is not part of Subsonic's API. * Also offers more fine-grained functionality that is not part of Subsonic's API.
*/ */
angular.module('jamstash.subsonicService', ['jamstash.globals', 'jamstash.utils', 'jamstash.model', angular.module('jamstash.subsonic.service', ['jamstash.globals', 'jamstash.utils', 'jamstash.model',
'jamstash.notifications', 'angular-underscore/utils']) 'jamstash.notifications', 'angular-underscore/utils'])
.factory('subsonic', function ($rootScope, $http, $q, globals, utils, map, notifications) { .factory('subsonic', function ($rootScope, $http, $q, globals, utils, map, notifications) {
@ -618,79 +618,6 @@ angular.module('jamstash.subsonicService', ['jamstash.globals', 'jamstash.utils'
return deferred.promise; return deferred.promise;
}, },
/*
getStarred: function (action, type) {
var deferred = $q.defer();
var size = globals.settings.AutoPlaylistSize;
content.selectedPlaylist = null;
content.selectedAutoPlaylist = 'starred';
$.ajax({
url: globals.BaseURL() + '/getStarred.view?' + globals.BaseParams() + '&size=' + size,
method: 'GET',
dataType: globals.settings.Protocol,
timeout: globals.settings.Timeout,
success: function (data) {
if (typeof data["subsonic-response"].starred !== 'undefined') {
var items = [];
switch (type) {
case 'artist':
if (typeof data["subsonic-response"].starred.artist !== 'undefined') {
if (data["subsonic-response"].starred.artist.length > 0) {
items = data["subsonic-response"].starred.artist;
} else {
items[0] = data["subsonic-response"].starred.artist;
}
}
break;
case 'album':
if (typeof data["subsonic-response"].starred.album !== 'undefined') {
if (data["subsonic-response"].starred.album.length > 0) {
items = data["subsonic-response"].starred.album;
} else {
items[0] = data["subsonic-response"].starred.album;
}
}
break;
case 'song':
if (typeof data["subsonic-response"].starred.song !== 'undefined') {
if (data["subsonic-response"].starred.song.length > 0) {
items = data["subsonic-response"].starred.song;
} else {
items[0] = data["subsonic-response"].starred.song;
}
if (action == 'add') {
angular.forEach(items, function (item, key) {
$rootScope.queue.push(map.mapSong(item));
});
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else if (action == 'play') {
$rootScope.queue = [];
angular.forEach(items, function (item, key) {
$rootScope.queue.push(map.mapSong(item));
});
var next = $rootScope.queue[0];
$rootScope.playSong(false, next);
notifications.updateMessage(items.length + ' Song(s) Added to Queue', true);
} else {
content.album = [];
content.song = [];
angular.forEach(items, function (item, key) {
content.song.push(map.mapSong(item));
});
}
}
break;
default:
break;
}
}
console.log("getStarred: ", content);
deferred.resolve(content);
}
});
return deferred.promise;
},
*/
newPlaylist: function (data, event) { newPlaylist: function (data, event) {
var deferred = $q.defer(); var deferred = $q.defer();
var reply = prompt("Choose a name for your new playlist.", ""); var reply = prompt("Choose a name for your new playlist.", "");

View file

@ -1,4 +1,19 @@
describe("Subsonic controller", function() { describe("Subsonic controller", function() {
'use strict'; 'use strict';
var $scope, subsonicCtrl;
/*
beforeEach(function() {
module('jamstash.subsonic.ctrl');
inject(function ($controller, $rootScope, $routeParams, utils, globals, map, subsonic, notifications) {
$scope = $rootScope.$new();
subsonicCtrl = $controller($scope, $rootScope, $routeParams, utils, globals, map, subsonic, notifications);
});
});
it("should behave...", function() {
});
*/
}); });

View file

@ -24,7 +24,7 @@ describe("Subsonic service -", function() {
} }
}; };
module('jamstash.subsonicService', function ($provide) { module('jamstash.subsonic.service', function ($provide) {
$provide.value('globals', mockGlobals); $provide.value('globals', mockGlobals);
}); });