diff --git a/src/assets/css/app.css b/src/assets/css/app.css index db3b5e8..289d9bb 100644 --- a/src/assets/css/app.css +++ b/src/assets/css/app.css @@ -276,6 +276,10 @@ nav .active a { font-size: 70%; } +.items p a { + color: #aaa; +} + /* item */ .item { diff --git a/src/assets/img/refresh.gif b/src/assets/img/refresh.gif new file mode 100644 index 0000000..1b3280e Binary files /dev/null and b/src/assets/img/refresh.gif differ diff --git a/src/assets/js/app.js b/src/assets/js/app.js new file mode 100644 index 0000000..89ef531 --- /dev/null +++ b/src/assets/js/app.js @@ -0,0 +1,141 @@ +(function() { + + var feeds = []; + var queue = []; + var queue_length = 5; + + + function show_refresh_icon(feed_id) + { + var container = document.getElementById("loading-feed-" + feed_id); + + if (container) { + + var img = document.createElement("img"); + img.src = "./assets/img/refresh.gif"; + + container.appendChild(img); + } + } + + + function hide_refresh_icon(feed_id) + { + var container = document.getElementById("loading-feed-" + feed_id); + + if (container) { + + container.innerHTML = ""; + } + } + + + function refresh_feed(feed_id, callback) + { + if (! feed_id) { + + return false; + } + + show_refresh_icon(feed_id); + + var request = new XMLHttpRequest(); + + request.onload = function() { + + hide_refresh_icon(feed_id); + + try { + + var response = JSON.parse(this.responseText); + + if (callback) { + + callback(response); + } + + if (! response.result) { + + window.alert('Unable to refresh this feed: ' + feed_id); + } + } + catch (e) {} + }; + + request.open("GET", "?action=ajax-refresh-feed&feed_id=" + feed_id, true); + request.send(); + + return true; + } + + + function get_feeds() + { + var links = document.getElementsByTagName("a"); + + for (var i = 0, ilen = links.length; i < ilen; i++) { + + var feed_id = links[i].getAttribute('data-feed-id'); + + if (feed_id) { + + feeds.push(parseInt(feed_id)); + } + } + } + + + function refresh_all() + { + get_feeds(); + + var interval = setInterval(function() { + + while (feeds.length > 0 && queue.length < queue_length) { + + var feed_id = feeds.shift(); + + queue.push(feed_id); + + refresh_feed(feed_id, function(response) { + + var index = queue.indexOf(response.feed_id); + + if (index >= 0) { + + queue.splice(index, 1); + } + + if (feeds.length == 0 && queue.length == 0) { + + clearInterval(interval); + window.location.href = "?action=unread"; + } + }); + } + + }, 100); + } + + + document.onclick = function(e) { + + var action = e.target.getAttribute("data-action"); + + if (action) { + + e.preventDefault(); + + switch (action) { + case 'refresh-all': + refresh_all(); + break; + case 'refresh-feed': + var feed_id = e.target.getAttribute("data-feed-id"); + refresh_feed(feed_id); + break; + } + } + }; + +})(); \ No newline at end of file diff --git a/src/index.php b/src/index.php index a8183d4..30375ed 100644 --- a/src/index.php +++ b/src/index.php @@ -108,7 +108,7 @@ Router\get_action('remove', function() { }); -Router\get_action('refresh', function() { +Router\get_action('refresh-feed', function() { $id = Request\int_param('feed_id'); @@ -121,6 +121,19 @@ Router\get_action('refresh', function() { }); +Router\get_action('ajax-refresh-feed', function() { + + $id = Request\int_param('feed_id'); + + if ($id) { + + Response\json(array('feed_id' => $id, 'result' => Model\update_feed($id))); + } + + Response\json(array('feed_id' => 0, 'result' => false)); +}); + + Router\get_action('flush-unread', function() { Model\flush_unread(); diff --git a/src/model.php b/src/model.php index 2fd8fcd..d22f9b1 100644 --- a/src/model.php +++ b/src/model.php @@ -129,7 +129,7 @@ function get_unread_items() { return \PicoTools\singleton('db') ->table('items') - ->columns('items.id', 'items.title', 'items.updated', 'feeds.site_url') + ->columns('items.id', 'items.title', 'items.updated', 'items.url', 'feeds.site_url') ->join('feeds', 'id', 'feed_id') ->eq('status', 'unread') ->desc('updated') @@ -141,7 +141,7 @@ function get_read_items() { return \PicoTools\singleton('db') ->table('items') - ->columns('items.id', 'items.title', 'items.updated', 'feeds.site_url') + ->columns('items.id', 'items.title', 'items.updated', 'items.url', 'feeds.site_url') ->join('feeds', 'id', 'feed_id') ->eq('status', 'read') ->desc('updated') @@ -197,6 +197,11 @@ function update_feeds() update_items($feed['id'], $parser->execute()->items); } + else { + + print_r($feed); + die; + } } } @@ -212,7 +217,10 @@ function update_feed($feed_id) if ($parser !== false) { update_items($feed['id'], $parser->execute()->items); + return true; } + + return false; } diff --git a/src/templates/add.php b/src/templates/add.php index e3193e1..4ed5724 100644 --- a/src/templates/add.php +++ b/src/templates/add.php @@ -1,6 +1,10 @@
diff --git a/src/templates/app_header.php b/src/templates/app_header.php index c3e88a0..fcd81d2 100644 --- a/src/templates/app_header.php +++ b/src/templates/app_header.php @@ -5,6 +5,7 @@ miniflux +
diff --git a/src/templates/feed_menu.php b/src/templates/feed_menu.php deleted file mode 100644 index b6ba014..0000000 --- a/src/templates/feed_menu.php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/src/templates/feeds.php b/src/templates/feeds.php index 6a4319d..ac89f31 100644 --- a/src/templates/feeds.php +++ b/src/templates/feeds.php @@ -1,22 +1,30 @@ -

No subscriptions.

+

No subscription.

diff --git a/src/templates/import.php b/src/templates/import.php index 9972621..a81baf3 100644 --- a/src/templates/import.php +++ b/src/templates/import.php @@ -1,6 +1,10 @@ diff --git a/src/templates/read_item.php b/src/templates/read_item.php index 9afe580..170d2ee 100644 --- a/src/templates/read_item.php +++ b/src/templates/read_item.php @@ -6,12 +6,12 @@

- +

- | - + | +

diff --git a/src/templates/read_items.php b/src/templates/read_items.php index b99631d..12accb3 100644 --- a/src/templates/read_items.php +++ b/src/templates/read_items.php @@ -16,8 +16,9 @@ diff --git a/src/templates/unread_items.php b/src/templates/unread_items.php index 6b803bf..4c0f8a3 100644 --- a/src/templates/unread_items.php +++ b/src/templates/unread_items.php @@ -16,7 +16,8 @@