diff --git a/app/app.js b/app/app.js index b3df69c..c15390a 100755 --- a/app/app.js +++ b/app/app.js @@ -1,7 +1,7 @@ /* Declare app level module */ angular.module('JamStash', ['ngCookies', 'ngRoute', 'ngSanitize', - 'jamstash.subsonic.ctrl', 'jamstash.archive.ctrl', 'jamstash.player.ctrl']) + 'jamstash.subsonic.ctrl', 'jamstash.archive.ctrl', 'jamstash.player.ctrl', 'jamstash.queue.ctrl']) .config(['$routeProvider',function($routeProvider) { 'use strict'; diff --git a/app/archive/archive-service.js b/app/archive/archive-service.js index 141359d..3447bc9 100644 --- a/app/archive/archive-service.js +++ b/app/archive/archive-service.js @@ -3,10 +3,11 @@ * * Access Archive.org */ -angular.module('jamstash.archive.service', ['jamstash.settings', 'jamstash.model', 'jamstash.notifications']) +angular.module('jamstash.archive.service', ['jamstash.settings', 'jamstash.model', 'jamstash.notifications', + 'jamstash.player.service']) -.factory('archive', ['$rootScope', '$http', '$q', '$sce', 'globals', 'model', 'utils', 'map', 'notifications', - function($rootScope, $http, $q, $sce, globals, model, utils, map, notifications) { +.factory('archive', ['$rootScope', '$http', '$q', '$sce', 'globals', 'model', 'utils', 'map', 'notifications', 'player', + function($rootScope, $http, $q, $sce, globals, model, utils, map, notifications, player) { 'use strict'; var index = { shortcuts: [], artists: [] }; @@ -192,7 +193,7 @@ angular.module('jamstash.archive.service', ['jamstash.settings', 'jamstash.model } }); var next = $rootScope.queue[0]; - $rootScope.playSong(false, next); + player.playSong(false, next); notifications.updateMessage(Object.keys(items).length + ' Song(s) Added to Queue', true); } else { content.album = []; @@ -213,4 +214,4 @@ angular.module('jamstash.archive.service', ['jamstash.settings', 'jamstash.model return deferred.promise; } }; -}]); \ No newline at end of file +}]); diff --git a/app/common/main-controller.js b/app/common/main-controller.js index 377db03..bf0f52d 100644 --- a/app/common/main-controller.js +++ b/app/common/main-controller.js @@ -10,7 +10,7 @@ $rootScope.MusicFolders = []; $rootScope.Genres = []; $rootScope.Messages = []; - + $rootScope.SelectedMusicFolder = ""; $rootScope.unity = null; $rootScope.loggedIn = function () { @@ -27,13 +27,6 @@ $rootScope.go = function (path) { $location.path(path); }; - /* - $scope.playSong = function (loadonly, data) { - $scope.$apply(function () { - $rootScope.playSong(loadonly, data); - }); - } - */ // Reads cookies and sets globals.settings values $scope.loadSettings = function () { @@ -226,9 +219,9 @@ $('#left-component').stop().scrollTo(el, 400); } } else if (unicode == 39 || unicode == 176) { // right arrow - $rootScope.nextTrack(); + player.nextTrack(); } else if (unicode == 37 || unicode == 177) { // back arrow - $rootScope.previousTrack(); + player.previousTrack(); } else if (unicode == 32 || unicode == 179 || unicode.toString() == '0179') { // spacebar player.playPauseSong(); return false; @@ -286,7 +279,7 @@ $rootScope.selectAll(songs); $rootScope.addSongsToQueue(); var next = $rootScope.queue[0]; - $rootScope.playSong(false, next); + player.playSong(false, next); }; $rootScope.playFrom = function (index, songs) { var from = songs.slice(index,songs.length); @@ -299,7 +292,7 @@ $rootScope.queue = []; $rootScope.addSongsToQueue(); var next = $rootScope.queue[0]; - $rootScope.playSong(false, next); + player.playSong(false, next); } }; $rootScope.addSongsToQueue = function () { @@ -417,6 +410,12 @@ } }); }; + // Hyz: I don't know yet how to remove the circular dependency between player-service + // and notification-service... So I'll keep this one there until I know. + $rootScope.nextTrack = function (loadonly, song) { + player.nextTrack(loadonly, song); + }; + $scope.updateFavorite = function (item) { var id = item.id; var starred = item.starred; @@ -441,7 +440,27 @@ $scope.toTrusted = function (html) { return $sce.trustAsHtml(html); }; - + + function loadTrackPosition() { + if (utils.browserStorageCheck()) { + // Load Saved Song + var song = angular.fromJson(localStorage.getItem('CurrentSong')); + if (song) { + player.playSong(true, song); + // Load Saved Queue + var items = angular.fromJson(localStorage.getItem('CurrentQueue')); + if (items) { + $rootScope.queue = items; + if ($rootScope.queue.length > 0) { + notifications.updateMessage($rootScope.queue.length + ' Saved Song(s)', true); + } + if (globals.settings.Debug) { console.log('Play Queue Loaded From localStorage: ' + $rootScope.queue.length + ' song(s)'); } + } + } + } else { + if (globals.settings.Debug) { console.log('HTML5::loadStorage not supported on your browser'); } + } + } /* Launch on Startup */ $scope.loadSettings(); @@ -454,7 +473,7 @@ if ($scope.loggedIn()) { //$scope.ping(); if (globals.settings.SaveTrackPosition) { - player.loadTrackPosition(); + loadTrackPosition(); player.startSaveTrackPosition(); } } diff --git a/app/common/main-controller_test.js b/app/common/main-controller_test.js new file mode 100644 index 0000000..045974b --- /dev/null +++ b/app/common/main-controller_test.js @@ -0,0 +1,30 @@ +describe("Main controller", function() { + 'use strict'; + + describe("updateFavorite -", function() { + + it("when starring a song, it notifies the user that the star was saved", function() { + + }); + + it("when starring an album, it notifies the user that the star was saved", function() { + + }); + + it("when starring an artist, it notifies the user that the star was saved", function() { + + }); + + it("given that the Subsonic server returns an error, when starring something, it notifies the user with the error message", function() { + //TODO: move to higher level + }); + + it("given that the Subsonic server is unreachable, when starring something, it notifies the user with the HTTP error code", function() { + //TODO: move to higher level + }); + }); + + describe("toggleSetting -", function() { + + }); +}); diff --git a/app/common/notification-service.js b/app/common/notification-service.js index 45a53fe..5716892 100644 --- a/app/common/notification-service.js +++ b/app/common/notification-service.js @@ -64,4 +64,4 @@ angular.module('jamstash.notifications', []) notifications[notification].close(); } }; -}]); \ No newline at end of file +}]); diff --git a/app/index.html b/app/index.html index 5d0d233..5877093 100755 --- a/app/index.html +++ b/app/index.html @@ -49,7 +49,7 @@
-