Commit 869cd643 authored by yPhil's avatar yPhil
Browse files

Awaiting

parent fbfcb287
......@@ -12,7 +12,7 @@ PTL.db = {
query.onsuccess = (event) => {
if (!event.target.result) {
console.log(`Feed ${url} not found`);
reject('No such feed');
resolve(null);
} else {
// console.table(event.target.result);
resolve(event.target.result);
......@@ -20,7 +20,8 @@ PTL.db = {
};
query.onerror = (event) => {
console.log(event.target.errorCode);
console.log('Catched in db.read: [%s]', event.target.errorCode);
reject(event.target.errorCode);
};
txn.oncomplete = function () {
......
......@@ -505,7 +505,7 @@ PTL.feed = {
return $feedBodyUl;
},
getIcon:function(feedHost) {
fetchIcon:function(feedHost) {
return new Promise((resolve, reject) => {
......@@ -524,10 +524,7 @@ PTL.feed = {
});
},
writeToDb:function(url, content) {
},
getFeed:function(feedUrl, lastItem, nbItems) {
fetchFeed:function(feedUrl, lastItem, nbItems) {
return new Promise((resolve, reject) => {
$.get("/feed", {
......@@ -543,259 +540,263 @@ PTL.feed = {
});
},
populate:function($button, progress, newLimit) {
const $dataStore = $button.parent().parent(),
$refreshButton = $dataStore.find('i.feedRefresh').addClass('spin'),
$feedHeader = $dataStore.parent(),
$badge = $feedHeader.children('.newItemsBadge'),
$feed = $dataStore.parent().parent(),
$feedTitle = $feedHeader.children('.feedTitle'),
$feedLink = $feedTitle.children('a'),
$feedBody = $dataStore.parent().next('div.feedBody'),
$feedBodyUl = $feedBody.find('ul.feedBody'),
feedUrl = $dataStore.data('url'),
feedName = $dataStore.data('name'),
feedType = $dataStore.data('type'),
feedLimit = newLimit || $dataStore.data('limit'),
feedStatus = $dataStore.data('status'),
feedIconHash = $dataStore.data('iconhash'),
feedNbItems = $dataStore.data('nbitems'),
feedLastItem = $dataStore.attr('data-lastitem') || '',
$feedToggle = $feedHeader.children('.feedToggle'),
$feedIcon = $feedToggle.children('.feedIcon').addClass('fold'),
$favIcon = $feedToggle.children('.favicon');
const l = PTL.util.getLocation(feedUrl),
feedProtocol = l.protocol ? l.protocol + '//' : '//',
feedHost = feedProtocol + l.hostname,
dateObj = new Date(),
timeStamp = dateObj.getUTCHours() + ":" + dateObj.getUTCMinutes() + ":" + dateObj.getUTCSeconds();
var feedTitle;
$feedBodyUl.css('border', '1px solid red');
if ($dataStore.data('status') == 'on') {
$feedIcon.removeClass('fold');
} else {
$dataStore
.parent()
.parent()
.children('div.feedBody')
.addClass('folded');
}
populate:function($button, progress, newLimit) {
const $dataStore = $button.parent().parent(),
$refreshButton = $dataStore.find('i.feedRefresh').addClass('spin'),
$feedHeader = $dataStore.parent(),
$badge = $feedHeader.children('.newItemsBadge'),
$feed = $dataStore.parent().parent(),
$feedTitle = $feedHeader.children('.feedTitle'),
$feedLink = $feedTitle.children('a'),
$feedBody = $dataStore.parent().next('div.feedBody'),
$feedBodyUl = $feedBody.find('ul.feedBody'),
feedUrl = $dataStore.data('url'),
feedName = $dataStore.data('name'),
feedType = $dataStore.data('type'),
feedLimit = newLimit || $dataStore.data('limit'),
feedStatus = $dataStore.data('status'),
feedIconHash = $dataStore.data('iconhash'),
feedNbItems = $dataStore.data('nbitems'),
feedLastItem = $dataStore.attr('data-lastitem') || '',
$feedToggle = $feedHeader.children('.feedToggle'),
$feedIcon = $feedToggle.children('.feedIcon').addClass('fold'),
$favIcon = $feedToggle.children('.favicon');
const l = PTL.util.getLocation(feedUrl),
feedProtocol = l.protocol ? l.protocol + '//' : '//',
feedHost = feedProtocol + l.hostname,
dateObj = new Date(),
timeStamp = dateObj.getUTCHours() + ":" + dateObj.getUTCMinutes() + ":" + dateObj.getUTCSeconds();
var feedTitle;
$feedBodyUl.css('border', '1px solid red');
if ($dataStore.data('status') == 'on') {
$feedIcon.removeClass('fold');
} else {
$dataStore
.parent()
.parent()
.children('div.feedBody')
.addClass('folded');
}
if (feedIconHash) {
$favIcon.attr('src', '/favicons/' + feedIconHash + '.favicon');
} else {
PTL.feed.getIcon(feedHost).then((iconhash) => {
if (iconhash) {
$favIcon.attr('src', '/favicons/' + iconhash + '.favicon');
$dataStore.data('iconhash', iconhash);
PTL.tab.saveTabs();
}
}).catch((error) => {
console.log('error: %s (%s)',error);
$favIcon.addClass('icon-rss');
});
if (feedIconHash) {
$favIcon.attr('src', '/favicons/' + feedIconHash + '.favicon');
} else {
PTL.feed.fetchIcon(feedHost).then((iconhash) => {
if (iconhash) {
$favIcon.attr('src', '/favicons/' + iconhash + '.favicon');
$dataStore.data('iconhash', iconhash);
PTL.tab.saveTabs();
}
}).catch((error) => {
console.log('error: %s (%s)',error);
$favIcon.addClass('icon-rss');
});
}
feedTitle = (feedName) ? feedName : feedUrl;
$feedLink.text(feedTitle)
.attr('href', feedUrl)
.attr('title', feedTitle + ' (' + feedUrl + ')')
.removeClass('danger');
feedTitle = (feedName) ? feedName : feedUrl;
$feedLink.text(feedTitle)
.attr('href', feedUrl)
.attr('title', feedTitle + ' (' + feedUrl + ')')
.removeClass('danger');
let request = indexedDB.open(PTL.DbName, PTL.DbVersion);
let request = indexedDB.open(PTL.DbName, PTL.DbVersion);
request.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
request.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
request.onsuccess = function(event) {
request.onsuccess = async function(event) {
const getFeed = PTL.db.getFeed(event.target.result, feedUrl)
.then((res) => {
let readFeed = await PTL.db.readFeed(url);
if (res) {
console.log('YAH!: %s (%s)', JSON.stringify(res));
}
if (readFeed) {
}).then((res) => {
let lastiItems = await PTL.feed.lastiItems(readFeed);
if (res) {
console.log('YAH!: %s (%s)', JSON.stringify(res));
}
let fetchFeed = await PTL.feed.fetchFeed(readFeed, lastItem);
}).catch((error) => {
console.log('SHIT!: %s (%s)', JSON.stringify(error));
});
if (fetchFeed) {
var db = event.target.result;
let ReadTransaction = db.transaction(PTL.DbStore, "readonly");
let objectStore = ReadTransaction.objectStore(PTL.DbStore);
let request = objectStore.get(feedUrl);
let lastItems = await PTL.feed.lastItems(fetchFeed[0]);
PTL.db.putFeed(lastItems);
request.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
}
request.onsuccess = function(event) {
} else {
let fetchFeed = await PTL.feed.fetchFeed(url, lastItem);
let lastItems = await PTL.feed.lastItems(fetchFeed);
PTL.db.putFeed(lastItems);
}
if (event.target.result) {
var db = event.target.result;
let ReadTransaction = db.transaction(PTL.DbStore, "readonly");
let objectStore = ReadTransaction.objectStore(PTL.DbStore);
let request = objectStore.get(feedUrl);
console.log('yeah!: %s (%s)');
request.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
$feedBody.html(event.target.result.content);
request.onsuccess = function(event) {
PTL.feed.getFeed(feedUrl, feedLastItem).then((data) => {
if (event.target.result) {
// console.log('Kayn: %s (%s)', JSON.stringify(data.thereArenewItems));
console.log('yeah!: %s (%s)');
if (data.lastItem) {
console.log('YEP: %s (%s)', data.lastItem);
$dataStore.attr('data-lastitem', data.lastItem);
}
$feedBody.html(event.target.result.content);
PTL.feed.lastItems(data, $dataStore).then((itemList) => {
PTL.feed.fetchFeed(feedUrl, feedLastItem).then((data) => {
console.log('itemList: %s (%s)', JSON.stringify(itemList));
// console.log('Kayn: %s (%s)', JSON.stringify(data.thereArenewItems));
var $newFeedBodyUl = $(itemList[0]);
if (data.lastItem) {
console.log('YEP: %s (%s)', data.lastItem);
$dataStore.attr('data-lastitem', data.lastItem);
}
if (data.lastItem) {
try {
$dataStore.data('lastitem', data.lastItem);
} catch(error) {
console.log('lastItems error: %s (%s)', error);
}
}
PTL.feed.lastItems(data, $dataStore).then((itemList) => {
console.log('Kayn, but thereArenewItems: (%s)', JSON.stringify(data.thereArenewItems));
console.log('itemList: %s (%s)', JSON.stringify(itemList));
if (data.thereArenewItems) {
var $newFeedBodyUl = $(itemList[0]);
$feedBody.prepend($newFeedBodyUl);
$badge.fadeIn('slow').text(itemList[1]);
if (data.lastItem) {
try {
$dataStore.data('lastitem', data.lastItem);
} catch(error) {
console.log('lastItems error: %s (%s)', error);
}
}
let ReadTransaction = db.transaction(PTL.DbStore, "readwrite"),
feeds = ReadTransaction.objectStore(PTL.DbStore),
feed = {url: feedUrl, content: $feedBody.html()},
WriteRequest = feeds.put(feed);
console.log('Kayn, but thereArenewItems: (%s)', JSON.stringify(data.thereArenewItems));
WriteRequest.onsuccess = function() {
console.log("Feed added to the store: (%s) (%s)", feedUrl, request.result);
PTL.tab.saveTabs();
};
if (data.thereArenewItems) {
WriteRequest.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
$feedBody.prepend($newFeedBodyUl);
$badge.fadeIn('slow').text(itemList[1]);
} else {
$badge.fadeOut('slow');
}
let ReadTransaction = db.transaction(PTL.DbStore, "readwrite"),
feeds = ReadTransaction.objectStore(PTL.DbStore),
feed = {url: feedUrl, content: $feedBody.html()},
WriteRequest = feeds.put(feed);
$refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp) + ' (' + $newFeedBodyUl[1] + ' new items)' )
.removeClass('spin');
WriteRequest.onsuccess = function() {
console.log("Feed added to the store: (%s) (%s)", feedUrl, request.result);
PTL.tab.saveTabs();
};
}).catch();
WriteRequest.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
}).catch(function(error) {
console.log('whoops: %s (%s)', JSON.stringify(error), feedUrl);
$feedBody.empty().append(PTL.feed.errorFeed(error, feedUrl));
$feedBody.css('height', '');
} else {
$badge.fadeOut('slow');
}
$refreshButton.removeClass('spin');
});
$refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp) + ' (' + $newFeedBodyUl[1] + ' new items)' )
.removeClass('spin');
} else {
}).catch();
// console.log('Makayn\'sh: [%s] (%s)', feedLastItem, feedUrl);
}).catch(function(error) {
console.log('whoops: %s (%s)', JSON.stringify(error), feedUrl);
$feedBody.empty().append(PTL.feed.errorFeed(error, feedUrl));
$feedBody.css('height', '');
$refreshButton.removeClass('spin');
});
PTL.feed.getFeed(feedUrl, 'noLastItem').then(function(data) {
} else {
console.log('MaKaynash, but thereArenewItems: (%s)', JSON.stringify(data.thereArenewItems));
// console.log('Makayn\'sh: [%s] (%s)', feedLastItem, feedUrl);
if (feedName) {
feedTitle = feedName;
} else if (data.feedTitle) {
feedTitle = data.feedTitle;
$dataStore.data('name', feedTitle);
}
PTL.feed.fetchFeed(feedUrl, 'noLastItem').then(function(data) {
$feedLink.text(feedTitle)
.attr('href', data.feedLink)
.attr('title', feedTitle + ' (' + feedUrl + ')');
console.log('MaKaynash, but thereArenewItems: (%s)', JSON.stringify(data.thereArenewItems));
if (data.lastItem) {
console.log('YEP: %s (%s)', data.lastItem);
$dataStore.attr('data-lastitem', data.lastItem);
}
if (feedName) {
feedTitle = feedName;
} else if (data.feedTitle) {
feedTitle = data.feedTitle;
$dataStore.data('name', feedTitle);
}
PTL.feed.lastItems(data, $dataStore).then((itemList) => {
$feedLink.text(feedTitle)
.attr('href', data.feedLink)
.attr('title', feedTitle + ' (' + feedUrl + ')');
$feedBody.html(itemList[0]);
if (data.lastItem) {
console.log('YEP: %s (%s)', data.lastItem);
$dataStore.attr('data-lastitem', data.lastItem);
}
PTL.feed.lastItems(data, $dataStore).then((itemList) => {
$badge.text(itemList[1]);
$feedBody.html(itemList[0]);
if (itemList[1] > 0) {
$badge.fadeIn('slow');
} else {
$badge.fadeOut('slow');
}
$badge.text(itemList[1]);
$refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp) + ' (' + itemList[1] + ' new items)' )
.removeClass('spin');
if (itemList[1] > 0) {
$badge.fadeIn('slow');
} else {
$badge.fadeOut('slow');
}
let request = indexedDB.open(PTL.DbName, PTL.DbVersion);
$refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp) + ' (' + itemList[1] + ' new items)' )
.removeClass('spin');
request.onsuccess = (event) => {
let request = indexedDB.open(PTL.DbName, PTL.DbVersion);
let db = event.target.result;
request.onsuccess = (event) => {
if (!db.objectStoreNames.contains(PTL.DbStore)) {
db.createObjectStore(PTL.DbStore, {keyPath: PTL.DbKey});
}
let db = event.target.result;
let transaction = db.transaction(PTL.DbStore, "readwrite"),
feeds = transaction.objectStore(PTL.DbStore),
feed = {url: feedUrl, content: itemList[0]},
request = feeds.put(feed);
if (!db.objectStoreNames.contains(PTL.DbStore)) {
db.createObjectStore(PTL.DbStore, {keyPath: PTL.DbKey});
}
request.onsuccess = function() {
console.log("Feed added to the store: ", request.result);
};
let transaction = db.transaction(PTL.DbStore, "readwrite"),
feeds = transaction.objectStore(PTL.DbStore),
feed = {url: feedUrl, content: itemList[0]},
request = feeds.put(feed);
request.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
request.onsuccess = function() {
console.log("Feed added to the store: ", request.result);
};
};
request.onerror = function(event) {
PTL.util.say(PTL.tr('DataBase error: %1', event.target.error), 'error');
};
});
};
})
.catch(function(error) {
console.log('whoops: %s (%s)', JSON.stringify(error));
$feedBody
.empty()
.append(PTL.feed.errorFeed(error, feedUrl))
.css('height', '');
$badge.fadeOut('fast');
$refreshButton.removeClass('spin');
});
});
}
};
})
.catch(function(error) {
console.log('whoops: %s (%s)', JSON.stringify(error));
$feedBody
.empty()
.append(PTL.feed.errorFeed(error, feedUrl))
.css('height', '');
$badge.fadeOut('fast');
$refreshButton.removeClass('spin');
});
}
};
};
};
if (progress) progress.increment();
if (progress) progress.increment();
}
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment