Switch to using new db class
This commit is contained in:
parent
0215b5990d
commit
a658b40946
4 changed files with 206 additions and 217 deletions
104
js/database.js
Normal file
104
js/database.js
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
angular.module('podcasts.database', [])
|
||||||
|
.run(['dbBackend', function(dbBackend) {
|
||||||
|
var dbConfig = (function () {
|
||||||
|
//Create IndexedDB ObjectStore and Indexes via ixDbEz
|
||||||
|
dbBackend.createObjStore("feed", "id", true);
|
||||||
|
dbBackend.createIndex("feed", "ixUrl", "url", true);
|
||||||
|
dbBackend.createObjStore("feedItem", "id", true);
|
||||||
|
dbBackend.createIndex("feedItem", "ixGuid", "guid", true);
|
||||||
|
dbBackend.createIndex("feedItem", "ixFeedId", "feedId");
|
||||||
|
dbBackend.createIndex("feedItem", "ixQueued", "queued");
|
||||||
|
dbBackend.createObjStore("setting", "id", true);
|
||||||
|
dbBackend.createIndex("setting", "ixName", "name", true);
|
||||||
|
dbBackend.put("setting", {'name': "refreshInterval", 'value': 20000});
|
||||||
|
});
|
||||||
|
|
||||||
|
//Create or Open the local IndexedDB database via ixDbEz
|
||||||
|
dbBackend.startDB("podcastDb", 11, dbConfig, undefined, undefined, false);
|
||||||
|
}])
|
||||||
|
.value('dbBackend', ixDbEz)
|
||||||
|
.service('db', ['$q', '$rootScope', 'dbBackend', function($q, $rootScope, dbBackend) {
|
||||||
|
var _getOne = function(store, identifier) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
dbBackend.getCursor(store, function(ixDbCursorReq)
|
||||||
|
{
|
||||||
|
if(typeof ixDbCursorReq !== "undefined") {
|
||||||
|
ixDbCursorReq.onsuccess = function (e) {
|
||||||
|
var cursor = ixDbCursorReq.result || e.result;
|
||||||
|
if (cursor) {
|
||||||
|
$rootScope.$apply(deferred.resolve(cursor.value));
|
||||||
|
|
||||||
|
cursor.continue();
|
||||||
|
} else {
|
||||||
|
//TODO: not sure if this'll work, since it may both resolve and reject.
|
||||||
|
// May need to check if any were resolved or not first
|
||||||
|
|
||||||
|
// deferred.reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deferred.reject();
|
||||||
|
}
|
||||||
|
}, null, IDBKeyRange.only(identifier));
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
function _get(store, range, indexName) {
|
||||||
|
var deferred = $q.defer(),
|
||||||
|
results = [];
|
||||||
|
|
||||||
|
dbBackend.getCursor(
|
||||||
|
store,
|
||||||
|
function(ixDbCursorReq) {
|
||||||
|
if(typeof ixDbCursorReq !== "undefined") {
|
||||||
|
ixDbCursorReq.onsuccess = function (e) {
|
||||||
|
var cursor = ixDbCursorReq.result || e.result;
|
||||||
|
if (cursor) {
|
||||||
|
results.push(cursor.value);
|
||||||
|
|
||||||
|
cursor.continue();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$rootScope.$apply(deferred.resolve(results));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
deferred.reject();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
deferred.reject();
|
||||||
|
},
|
||||||
|
range,
|
||||||
|
false,
|
||||||
|
indexName
|
||||||
|
);
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _put(store, data, id) {
|
||||||
|
var deferred = $q.defer();
|
||||||
|
|
||||||
|
dbBackend.put(store, data, id, function(key) {
|
||||||
|
$rootScope.$apply(deferred.resolve(key));
|
||||||
|
}, function() {
|
||||||
|
deferred.reject();
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _delete(store, id) {
|
||||||
|
dbBackend.delete(store, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
getOne: _getOne,
|
||||||
|
get: _get,
|
||||||
|
put: _put,
|
||||||
|
delete: _delete
|
||||||
|
};
|
||||||
|
}]);
|
162
js/models.js
162
js/models.js
|
@ -1,18 +1,19 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
||||||
.service('feeds', ['$log', '$q', 'dbNew', 'db', 'downloaderBackend', 'xmlParser', 'feedItems', 'utilities', '$rootScope', function($log, $q, db, dbOld, downloaderBackend, xmlParser, feedItems, utilities, $rootScope) {
|
.service('feeds', ['$log', '$q', 'db', 'downloaderBackend', 'xmlParser', 'feedItems', 'utilities', '$rootScope', function($log, $q, db, downloaderBackend, xmlParser, feedItems, utilities, $rootScope) {
|
||||||
var feeds = [];
|
var feeds = [];
|
||||||
|
|
||||||
function _add(url) {
|
function _add(url) {
|
||||||
var feedService = this;
|
var feedService = this;
|
||||||
var finishSave = function(newFeed) {
|
var finishSave = function(newFeed) {
|
||||||
dbOld.put("feed", newFeed, undefined, function(key) {
|
var promise = db.put("feed", newFeed)
|
||||||
newFeed.id = key;
|
.then(function(key) {
|
||||||
|
newFeed.id = key;
|
||||||
|
|
||||||
feedService.feeds.push(newFeed);
|
feedService.feeds.push(newFeed);
|
||||||
feedService.downloadItems(newFeed);
|
feedService.downloadItems(newFeed);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var cleanedUrl = utilities.clean_url(url);
|
var cleanedUrl = utilities.clean_url(url);
|
||||||
|
@ -65,22 +66,15 @@ angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
||||||
feed.image = new Blob([feed.image]);
|
feed.image = new Blob([feed.image]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbOld.getCursor("feedItem", function(ixDbCursorReq)
|
feed.items = [];
|
||||||
{
|
db.get("feedItem", IDBKeyRange.only(feed.id), "ixFeedId")
|
||||||
feed.items = [];
|
.then(function(results) {
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
angular.forEach(results, function(item) {
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
feed.items.push(item);
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
});
|
||||||
if (cursor) {
|
|
||||||
feed.items.push(cursor.value);
|
|
||||||
|
|
||||||
cursor.continue();
|
$rootScope.$apply(deferred.resolve(feed));
|
||||||
} else {
|
});
|
||||||
$rootScope.$apply(deferred.resolve(feed));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, null, IDBKeyRange.only(feed.id), undefined, 'ixFeedId');
|
|
||||||
}, function(value) {
|
}, function(value) {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
});
|
});
|
||||||
|
@ -89,58 +83,46 @@ angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
||||||
}
|
}
|
||||||
|
|
||||||
function _list($scope) {
|
function _list($scope) {
|
||||||
var feeds = this.feeds;
|
var feeds = this.feeds,
|
||||||
dbOld.getCursor("feed", function(ixDbCursorReq)
|
promise = db.get("feed");
|
||||||
{
|
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
|
||||||
if (cursor) {
|
|
||||||
if (typeof cursor.value.image === 'string') {
|
|
||||||
cursor.value.image = new Blob(
|
|
||||||
[cursor.value.image],
|
|
||||||
{type: 'application/octet-stream'}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
feeds.push(cursor.value);
|
|
||||||
$scope.$apply();
|
|
||||||
|
|
||||||
cursor.continue();
|
promise.then(function(results) {
|
||||||
}
|
angular.forEach(results, function(item) {
|
||||||
|
if (typeof item.image === 'string') {
|
||||||
|
item.image = new Blob(
|
||||||
|
[item.image],
|
||||||
|
{type: 'application/octet-stream'}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
feeds.push(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _delete(id) {
|
function _delete(id) {
|
||||||
$log.info('Deleting feed with ID ' + id);
|
$log.info('Deleting feed with ID ' + id);
|
||||||
feedItems.deleteByFeedId(id);
|
feedItems.deleteByFeedId(id);
|
||||||
dbOld.delete("feed", id);
|
db.delete("feed", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param feedItems
|
|
||||||
* @param updateStatus function that gets called for each item it goes through
|
* @param updateStatus function that gets called for each item it goes through
|
||||||
* Takes the feedItem as the argument
|
* Takes the feedItem as the argument
|
||||||
*/
|
*/
|
||||||
function _downloadAllItems(feedItems, updateStatus) {
|
function _downloadAllItems(updateStatus) {
|
||||||
var feedService = this;
|
var feedService = this,
|
||||||
dbOld.getCursor("feed", function(ixDbCursorReq)
|
promise = db.get("feed");
|
||||||
{
|
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
|
||||||
|
|
||||||
if (cursor) {
|
promise.then(function(results) {
|
||||||
feedService.downloadItems(cursor.value, updateStatus);
|
angular.forEach(results, function(item) {
|
||||||
|
feedService.downloadItems(item, updateStatus);
|
||||||
|
});
|
||||||
|
|
||||||
cursor.continue();
|
updateStatus();
|
||||||
} else {
|
|
||||||
updateStatus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +167,7 @@ angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
||||||
downloadItems: _downloadItems
|
downloadItems: _downloadItems
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
.service('feedItems', ['dbNew', 'db', '$q', '$rootScope', function(db, oldDb, $q, $rootScope) {
|
.service('feedItems', ['db', '$q', '$rootScope', function(db, $q, $rootScope) {
|
||||||
function _get(id, onSuccess, onFailure) {
|
function _get(id, onSuccess, onFailure) {
|
||||||
db.getOne("feedItem", id)
|
db.getOne("feedItem", id)
|
||||||
.then(function(value) {
|
.then(function(value) {
|
||||||
|
@ -210,20 +192,16 @@ angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
||||||
}
|
}
|
||||||
|
|
||||||
function _delete(feedItemId) {
|
function _delete(feedItemId) {
|
||||||
oldDb.delete("feedItem", feedItemId);
|
db.delete("feedItem", feedItemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _deleteByFeedId(feedId) {
|
function _deleteByFeedId(feedId) {
|
||||||
oldDb.getCursor("feedItem", function(ixDbCursorReq) {
|
db.get("feedItem", IDBKeyRange.only(feedId), "ixFeedId")
|
||||||
if (typeof ixDbCursorReq !== "undefined") {
|
.then(function(results) {
|
||||||
ixDbCursorReq.onsuccess = function(e) {
|
angular.forEach(results, function(item) {
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
this._delete(item.id);
|
||||||
if (cursor) {
|
})
|
||||||
this.delete(cursor.value.id);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, null, IDBKeyRange.only(feedId), null, 'ixFeedId');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _add(object) {
|
function _add(object) {
|
||||||
|
@ -237,9 +215,10 @@ angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
||||||
description: object.description,
|
description: object.description,
|
||||||
audioUrl: object.audioUrl,
|
audioUrl: object.audioUrl,
|
||||||
queued: object.queued
|
queued: object.queued
|
||||||
};
|
},
|
||||||
|
promise = db.put("feedItem", newFeedItem);
|
||||||
|
|
||||||
oldDb.put("feedItem", newFeedItem, undefined, function() {
|
promise.then(function() {
|
||||||
deferred.resolve(newFeedItem);
|
deferred.resolve(newFeedItem);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -253,8 +232,6 @@ angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
||||||
this.listQueue(tempQueueList, function() {
|
this.listQueue(tempQueueList, function() {
|
||||||
var returnNextValue = false,
|
var returnNextValue = false,
|
||||||
didReturnValue = false;
|
didReturnValue = false;
|
||||||
console.log(feedItem.id);
|
|
||||||
console.log('and now values');
|
|
||||||
angular.forEach(tempQueueList.queue, function(value, key) {
|
angular.forEach(tempQueueList.queue, function(value, key) {
|
||||||
if (returnNextValue) {
|
if (returnNextValue) {
|
||||||
deferred.resolve(value);
|
deferred.resolve(value);
|
||||||
|
@ -281,41 +258,36 @@ angular.module('podcasts.models', ['podcasts.database', 'podcasts.utilities'])
|
||||||
* @param done
|
* @param done
|
||||||
*/
|
*/
|
||||||
function _listQueue(queueList, done) {
|
function _listQueue(queueList, done) {
|
||||||
oldDb.getCursor("feedItem", function(ixDbCursorReq)
|
db.get("feedItem", IDBKeyRange.only(1), "ixQueued")
|
||||||
{
|
.then(function(results) {
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
angular.forEach(results, function(item) {
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
// This additional check is necessary, since the index doesn't seem to always catch correctly
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
if (item.queued) {
|
||||||
if (cursor) {
|
queueList.addToQueue(item);
|
||||||
// This additional check is necessary, since the index doesn't seem to always catch correctly
|
|
||||||
if (cursor.value.queued) {
|
|
||||||
queueList.addToQueue(cursor.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.continue();
|
|
||||||
} else {
|
|
||||||
if (typeof done === 'function') {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}, undefined, IDBKeyRange.only(1), false, 'ixQueued');
|
done();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _unQueue(feedItemId) {
|
function _unQueue(feedItemId) {
|
||||||
var feedItem = _get(feedItemId, function(feedItem) {
|
var feedItem = _get(feedItemId, function(feedItem) {
|
||||||
feedItem.queued = 0;
|
feedItem.queued = 0;
|
||||||
oldDb.put("feedItem", feedItem, undefined, function() {
|
|
||||||
$rootScope.$broadcast('queueListRefresh');
|
var promise = db.put("feedItem", feedItem);
|
||||||
});
|
.then(function() {
|
||||||
|
$rootScope.$broadcast('queueListRefresh');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _addToQueue(feedItemId) {
|
function _addToQueue(feedItemId) {
|
||||||
var feedItem = _get(feedItemId, function(feedItem) {
|
var feedItem = _get(feedItemId, function(feedItem) {
|
||||||
feedItem.queued = 1;
|
feedItem.queued = 1;
|
||||||
oldDb.put("feedItem", feedItem, undefined, function() {
|
|
||||||
|
var promise = db.put("feedItem", feedItem);
|
||||||
|
promise.then(function() {
|
||||||
$rootScope.$broadcast('queueListRefresh');
|
$rootScope.$broadcast('queueListRefresh');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@ angular.module('podcasts.queueList', ['podcasts.database'])
|
||||||
.run(['queueList', function(queueList) {
|
.run(['queueList', function(queueList) {
|
||||||
queueList.rebuildList();
|
queueList.rebuildList();
|
||||||
}])
|
}])
|
||||||
.service('queueList', ['db', '$rootScope', function(oldDb, $rootScope) {
|
.service('queueList', ['db', '$rootScope', function(db, $rootScope) {
|
||||||
var queueList = [];
|
var queueList = [];
|
||||||
|
|
||||||
function getQueueList() {
|
function getQueueList() {
|
||||||
|
@ -12,24 +12,16 @@ angular.module('podcasts.queueList', ['podcasts.database'])
|
||||||
function rebuildList() {
|
function rebuildList() {
|
||||||
queueList = [];
|
queueList = [];
|
||||||
|
|
||||||
oldDb.getCursor("feedItem", function(ixDbCursorReq)
|
db.get("feedItem", IDBKeyRange.only(1), "ixQueued")
|
||||||
{
|
.then(function(results) {
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
angular.forEach(results, function(item) {
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
if (item.queued) {
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
queueList.push(item);
|
||||||
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');
|
$rootScope.$apply();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
129
js/services.js
129
js/services.js
|
@ -319,23 +319,16 @@ angular.module('podcasts.downloader', ['podcasts.settings', 'podcasts.database',
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var itemsToDownload = [];
|
var itemsToDownload = [];
|
||||||
db.getCursor("feedItem", function(ixDbCursorReq)
|
db.get("feedItem", IDBKeyRange.only(1), "ixQueueud")
|
||||||
{
|
.then(function(results) {
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
angular.forEach(results, function(item) {
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
if (!item.audio && item.audioUrl) {
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
itemsToDownload.push(item);
|
||||||
|
|
||||||
if (cursor) {
|
|
||||||
if (!cursor.value.audio && cursor.value.audioUrl) {
|
|
||||||
itemsToDownload.push(cursor.value);
|
|
||||||
}
|
|
||||||
cursor.continue();
|
|
||||||
} else {
|
|
||||||
downloader.downloadFiles(itemsToDownload);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}, undefined, IDBKeyRange.only(1), undefined, 'ixQueued');
|
downloader.downloadFiles(itemsToDownload);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -376,59 +369,6 @@ angular.module('podcasts.downloader', ['podcasts.settings', 'podcasts.database',
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
angular.module('podcasts.database', [])
|
|
||||||
.run(function() {
|
|
||||||
var dbConfig = (function () {
|
|
||||||
//Create IndexedDB ObjectStore and Indexes via ixDbEz
|
|
||||||
ixDbEz.createObjStore("feed", "id", true);
|
|
||||||
ixDbEz.createIndex("feed", "ixUrl", "url", true);
|
|
||||||
ixDbEz.createObjStore("feedItem", "id", true);
|
|
||||||
ixDbEz.createIndex("feedItem", "ixGuid", "guid", true);
|
|
||||||
ixDbEz.createIndex("feedItem", "ixFeedId", "feedId");
|
|
||||||
ixDbEz.createIndex("feedItem", "ixQueued", "queued");
|
|
||||||
ixDbEz.createObjStore("setting", "id", true);
|
|
||||||
ixDbEz.createIndex("setting", "ixName", "name", true);
|
|
||||||
ixDbEz.put("setting", {'name': "refreshInterval", 'value': 20000});
|
|
||||||
});
|
|
||||||
|
|
||||||
//Create or Open the local IndexedDB database via ixDbEz
|
|
||||||
ixDbEz.startDB("podcastDb", 10, dbConfig, undefined, undefined, false);
|
|
||||||
})
|
|
||||||
.value('db', ixDbEz)
|
|
||||||
.service('dbNew', ['$q', '$rootScope', 'db', function($q, $rootScope, _db) {
|
|
||||||
var _getOne = function(store, identifier) {
|
|
||||||
var deferred = $q.defer();
|
|
||||||
|
|
||||||
_db.getCursor(store, function(ixDbCursorReq)
|
|
||||||
{
|
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
|
||||||
if (cursor) {
|
|
||||||
$rootScope.$apply(deferred.resolve(cursor.value));
|
|
||||||
|
|
||||||
cursor.continue();
|
|
||||||
} else {
|
|
||||||
//TODO: not sure if this'll work, since it may both resolve and reject.
|
|
||||||
// May need to check if any were resolved or not first
|
|
||||||
|
|
||||||
// deferred.reject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
deferred.reject();
|
|
||||||
}
|
|
||||||
}, null, IDBKeyRange.only(identifier));
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
getOne: _getOne
|
|
||||||
};
|
|
||||||
}]);
|
|
||||||
|
|
||||||
|
|
||||||
angular.module('podcasts.updater', ['podcasts.settings', 'podcasts.alarmManager', 'podcasts.downloader'])
|
angular.module('podcasts.updater', ['podcasts.settings', 'podcasts.alarmManager', 'podcasts.downloader'])
|
||||||
.run(['update', function(update) {
|
.run(['update', function(update) {
|
||||||
//update.checkFeeds();
|
//update.checkFeeds();
|
||||||
|
@ -462,25 +402,18 @@ angular.module('podcasts.settings', ['podcasts.database'])
|
||||||
waiting = [];
|
waiting = [];
|
||||||
|
|
||||||
function _init() {
|
function _init() {
|
||||||
db.getCursor("setting", function(ixDbCursorReq)
|
db.get("setting")
|
||||||
{
|
.then(function(results) {
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
angular.forEach(results, function(item) {
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
settings[item.name] = item;
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
});
|
||||||
if (cursor) {
|
|
||||||
settings[cursor.value.name] = cursor.value;
|
|
||||||
|
|
||||||
cursor.continue();
|
initialized = true;
|
||||||
} else {
|
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
for (var i = 0, l = waiting.length; i < l; i++) {
|
for (var i = 0, l = waiting.length; i < l; i++) {
|
||||||
waiting[i]();
|
waiting[i]();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _set(name, value, key) {
|
function _set(name, value, key) {
|
||||||
|
@ -514,26 +447,14 @@ angular.module('podcasts.settings', ['podcasts.database'])
|
||||||
if (!angular.isUndefined(settings[name])) {
|
if (!angular.isUndefined(settings[name])) {
|
||||||
onSuccess(settings[name]);
|
onSuccess(settings[name]);
|
||||||
} else {
|
} else {
|
||||||
db.getCursor("setting", function(ixDbCursorReq)
|
db.get("setting", IDBKeyRange.only(name), "ixName")
|
||||||
{
|
.then(function(results) {
|
||||||
if(typeof ixDbCursorReq !== "undefined") {
|
onSuccess(results[0]);
|
||||||
ixDbCursorReq.onsuccess = function (e) {
|
}, function() {
|
||||||
var cursor = ixDbCursorReq.result || e.result;
|
if (typeof onFailure === 'function') {
|
||||||
if (cursor) {
|
|
||||||
onSuccess(cursor.value);
|
|
||||||
} else {
|
|
||||||
if (typeof onFailure === 'function') {
|
|
||||||
onFailure();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ixDbCursorReq.onerror = function (e) {
|
|
||||||
console.log('didnt get setting');
|
|
||||||
onFailure();
|
onFailure();
|
||||||
};
|
}
|
||||||
}
|
});
|
||||||
}, function() { onFailure(); }, IDBKeyRange.only(name), undefined, 'ixName');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue