From 735c6e1229e7636194fdad4439e2decde87a871b Mon Sep 17 00:00:00 2001 From: Colin Frei Date: Mon, 29 Jul 2013 17:36:14 +0200 Subject: [PATCH] move queuelist to it's own file --- js/controllers.js | 4 ++-- js/queueList.js | 42 ++++++++++++++++++++++++++++++++++++++++++ js/services.js | 38 -------------------------------------- 3 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 js/queueList.js diff --git a/js/controllers.js b/js/controllers.js index 55b484b..e8c8928 100644 --- a/js/controllers.js +++ b/js/controllers.js @@ -52,8 +52,8 @@ function FeedCtrl($scope, $routeParams, $location, feeds, pageSwitcher) { pageSwitcher.setBack('feeds'); } -function QueueListCtrl($scope, $rootScope, pageSwitcher, feedItems, feeds, downloader, newQueueList) { - $scope.queue = newQueueList.getQueueList(); +function QueueListCtrl($scope, $rootScope, pageSwitcher, feedItems, feeds, downloader, queueList, pageChanger) { + $scope.queue = queueList.getQueueList(); $scope.playItem = function(id) { feedItems.get(id, function(feedItem) { diff --git a/js/queueList.js b/js/queueList.js new file mode 100644 index 0000000..585bd82 --- /dev/null +++ b/js/queueList.js @@ -0,0 +1,42 @@ +angular.module('podcasts.queueList', ['podcasts.database']) + .run(['queueList', function(queueList) { + queueList.rebuildList(); + }]) + .service('queueList', ['db', '$rootScope', function(oldDb, $rootScope) { + var queueList = []; + + function getQueueList() { + return queueList; + } + + function rebuildList() { + queueList = []; + + oldDb.getCursor("feedItem", function(ixDbCursorReq) + { + if(typeof ixDbCursorReq !== "undefined") { + ixDbCursorReq.onsuccess = function (e) { + var cursor = ixDbCursorReq.result || e.result; + if (cursor) { + // This additional check is necessary, since the index doesn't seem to always catch correctly + if (cursor.value.queued) { + queueList.push(cursor.value); + } + + cursor.continue(); + } else { + $rootScope.$apply(); + } + } + } + }, undefined, IDBKeyRange.only(1), false, 'ixQueued'); + } + + return { + rebuildList: rebuildList, + getQueueList: function() { + return queueList; + } + }; + }]) +; diff --git a/js/services.js b/js/services.js index 76e4d09..58a9347 100644 --- a/js/services.js +++ b/js/services.js @@ -545,44 +545,6 @@ angular.module('podcasts.settings', ['podcasts.database']) }]) ; -angular.module('podcasts.queueList', ['podcasts.database']) - .run(['newQueueList', function(queueList) { - queueList.rebuildList(); - }]) - .service('newQueueList', ['db', '$rootScope', function(oldDb, $rootScope) { - var queueList = []; - - function getQueueList() { - return queueList; - } - - function rebuildList() { - oldDb.getCursor("feedItem", function(ixDbCursorReq) - { - if(typeof ixDbCursorReq !== "undefined") { - ixDbCursorReq.onsuccess = function (e) { - var cursor = ixDbCursorReq.result || e.result; - if (cursor) { - // This additional check is necessary, since the index doesn't seem to always catch correctly - if (cursor.value.queued) { - queueList.push(cursor.value); - } - - cursor.continue(); - } else { - $rootScope.$apply(); - } - } - } - }, undefined, IDBKeyRange.only(1), false, 'ixQueued'); - } - - return { - rebuildList: rebuildList, - getQueueList: getQueueList - }; - }]) -; angular.module('podcasts.importer', ['podcasts.utilities', 'podcasts.services'])