Commit dba39c16 authored by yPhil's avatar yPhil
Browse files

Unread count!!

parent f2584cd8
......@@ -1374,3 +1374,22 @@ a:visited.ui-button {
button.ui-state-success {
background: var(--color-ui-success) !important;
}
.newItemsBadge {
display: inline-block;
flex-basis: content;
flex-grow: 1;
flex-shrink: 1;
font-size: 0.7em;
background: var(--color-ui-success);
color: #000;
width: 18px;
max-width: 18px;
min-width: 18px;
height: 16px;
margin: 4px 3px 0 0;
text-align: center;
/* line-height: 18px; */
border-radius: 3px;
/* box-shadow: 0 0 1px #333; */
}
......@@ -4,8 +4,6 @@ PTL.feed = {
add:function($column, url, name, type, limit, status, iconhash, nbitems, lastitem, clickNew, isQueryString, progress) {
// console.log('ADD: url:[%s], name:[%s], type:[%s], limit:[%s], status:[%s], iconhash:[%s], nbitems:[%s], lastitem:[%s], clickNew:[%s], isQueryString:[%s], progress:[%s]', url, name, type, limit, status, iconhash, nbitems, lastitem, clickNew, isQueryString, progress);
const feedIndex = $('#tabs').find('.feed').length;
const $feed = $('<li>')
......@@ -23,6 +21,9 @@ PTL.feed = {
$(this).attr('src', '/static/images/rss.gif');
});
const $newItemsBadge = $('<div>')
.attr('class', 'newItemsBadge');
const $feedIcon = $('<i>')
.attr('class', 'feed-control feedIcon translate')
.data('title', 'Fold / unfold this feed (%1)', url)
......@@ -180,6 +181,7 @@ PTL.feed = {
$feedHeader.append($feedToggle,
$feedHandle,
$titleDiv.append($titleLink),
$newItemsBadge,
$feedControls.append($prefsDiv, $reloadDiv));
$feed.append($feedHeader, $feedBody);
......@@ -198,6 +200,7 @@ PTL.feed = {
const $feedBody = $dataStore.parent().next('div.feedBody'),
$feedBodyUl = $('<ul>').attr('class', 'feedBody'),
feedUrl = $dataStore.data('url'),
nbItems = $dataStore.data('nbitems'),
feedType = $dataStore.data('type');
const l = PTL.util.getLocation(feedUrl),
......@@ -210,7 +213,7 @@ PTL.feed = {
newItems = index;
if (index == 30) return false;
if (index == nbItems) return false;
const $description = $.parseHTML(item.description),
imgTypes = ['image',
......@@ -454,13 +457,14 @@ PTL.feed = {
return $feedBodyUl;
},
getit:function(feedUrl, lastItem) {
getit:function(feedUrl, lastItem, nbItems) {
return new Promise((resolve, reject) => {
$.get("/feed", {
url: feedUrl,
dataType: 'json',
lastItem: lastItem
lastItem: lastItem,
nbItems: nbItems
}).done(function(data, textStatus, jqXHR) {
resolve(data);
}).fail(function(jqXHR, textStatus, errorThrown) {
......@@ -474,6 +478,7 @@ PTL.feed = {
const $dataStore = $button.parent().parent(),
$refreshButton = $dataStore.find('i.feedRefresh'),
$feedHeader = $dataStore.parent(),
$badge = $feedHeader.find('.newItemsBadge'),
$panel = $dataStore.parent().parent().parent(),
$feed = $dataStore.parent().parent(),
$feedTitle = $feed.children().children('.feedTitle'),
......@@ -551,7 +556,7 @@ PTL.feed = {
$feedBody.append(saved);
}
PTL.feed.getit(feedUrl, feedLastItem)
PTL.feed.getit(feedUrl, feedLastItem, feedNbItems)
.then(function(data) {
if (data.lastItem) {
......@@ -566,6 +571,8 @@ PTL.feed = {
const $html = $feedBody.html();
localStorage.setItem(feedUrl, $html);
$badge.text($feedBodyUl[1]);
$refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp) + ' (' + $feedBodyUl[1] + ' new items)' )
.removeClass('spin');
......@@ -583,7 +590,7 @@ PTL.feed = {
} else {
PTL.feed.getit(feedUrl, feedLastItem)
PTL.feed.getit(feedUrl, feedLastItem, feedNbItems)
.then(function(data) {
// console.log('YAAA: %s (%s)', JSON.stringify(data));
......@@ -610,11 +617,12 @@ PTL.feed = {
if (!$feedBody.is(':empty')) {
const $html = $feedBody.html();
console.log('Saving this: %s (%s)', $html, feedUrl);
localStorage.setItem(feedUrl, $html);
}
$badge.text($feedBodyUl[1]);
$refreshButton
.prop('title', PTL.tr('Refresh this feed (%1 - %2)', feedName || feedUrl, timeStamp) + ' (' + $feedBodyUl[1] + ' new items)' )
.removeClass('spin');
......
......@@ -34,7 +34,7 @@ function getParams(str) {
return params;
}
function getFeed (feedUrl, lastItem, callback) {
function getFeed (feedUrl, lastItem, nbItems, callback) {
// Get a response stream
fetch(feedUrl, {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
......@@ -66,8 +66,6 @@ function getFeed (feedUrl, lastItem, callback) {
try {
var item = this.read();
// console.error('ITEM: %s (%s)', JSON.stringify(item));
if (item !== null){
i++;
......@@ -75,7 +73,7 @@ function getFeed (feedUrl, lastItem, callback) {
newLastItem = item.link;
}
if (item.link !== lastItem) {
if (item.link !== lastItem && i < nbItems) {
console.error('### PUSHING [%s] lastItem:[%s]', item.link, newLastItem);
feedItems.push(item);
} else {
......
......@@ -70,7 +70,7 @@ router.use(morgan('combined'));
router.get('/feed', function(req, res) {
feeder.getFeed(req.query.url, req.query.lastItem, function (error, feedItems, feedTitle, feedLink, lastItem) {
feeder.getFeed(req.query.url, req.query.lastItem, req.query.nbItems, function (error, feedItems, feedTitle, feedLink, lastItem) {
if (feedItems && !res.headersSent) {
res.send({
......
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