Add items sorting by date
This commit is contained in:
parent
240a12631a
commit
c2ce24a427
@ -88,7 +88,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set all items of the current page to the status read and redirect to the main page
|
// Set all items of the current page to the status read and redirect to the main page
|
||||||
function mark_items_as_read()
|
function mark_items_as_read(redirect)
|
||||||
{
|
{
|
||||||
var articles = document.getElementsByTagName("article");
|
var articles = document.getElementsByTagName("article");
|
||||||
var idlist = [];
|
var idlist = [];
|
||||||
@ -100,7 +100,7 @@
|
|||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
|
|
||||||
request.onload = function() {
|
request.onload = function() {
|
||||||
window.location.href = "?action=unread";
|
window.location.href = redirect;
|
||||||
};
|
};
|
||||||
|
|
||||||
request.open("POST", "?action=mark-items-as-read", true);
|
request.open("POST", "?action=mark-items-as-read", true);
|
||||||
@ -499,7 +499,11 @@
|
|||||||
break;
|
break;
|
||||||
case 'mark-all-read':
|
case 'mark-all-read':
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
mark_items_as_read();
|
mark_items_as_read("?action=unread");
|
||||||
|
break;
|
||||||
|
case 'mark-feed-read':
|
||||||
|
e.preventDefault();
|
||||||
|
mark_items_as_read("?action=feed-items&feed_id=" + e.target.getAttribute("data-feed-id"));
|
||||||
break;
|
break;
|
||||||
case 'original-link':
|
case 'original-link':
|
||||||
var item_id = e.target.getAttribute("data-item-id");
|
var item_id = e.target.getAttribute("data-item-id");
|
||||||
|
24
index.php
24
index.php
@ -259,14 +259,19 @@ Router\get_action('feed-items', function() {
|
|||||||
$offset = Request\int_param('offset', 0);
|
$offset = Request\int_param('offset', 0);
|
||||||
$nb_items = Model\count_feed_items($feed_id);
|
$nb_items = Model\count_feed_items($feed_id);
|
||||||
$feed = Model\get_feed($feed_id);
|
$feed = Model\get_feed($feed_id);
|
||||||
|
$order = Request\param('order', 'updated');
|
||||||
|
$direction = Request\param('direction', 'desc');
|
||||||
|
$items = Model\get_feed_items($feed_id, $offset, Model\get_config_value('items_per_page'), $order, $direction);
|
||||||
|
|
||||||
Response\html(Template\layout('feed_items', array(
|
Response\html(Template\layout('feed_items', array(
|
||||||
|
'order' => $order,
|
||||||
|
'direction' => $direction,
|
||||||
'feed' => $feed,
|
'feed' => $feed,
|
||||||
'items' => Model\get_feed_items($feed_id, $offset, Model\get_config_value('items_per_page')),
|
'items' => $items,
|
||||||
'nb_items' => $nb_items,
|
'nb_items' => $nb_items,
|
||||||
'offset' => $offset,
|
'offset' => $offset,
|
||||||
'items_per_page' => Model\get_config_value('items_per_page'),
|
'items_per_page' => Model\get_config_value('items_per_page'),
|
||||||
'menu' => 'feeds',
|
'menu' => 'feed-items',
|
||||||
'title' => '('.$nb_items.') '.$feed['title']
|
'title' => '('.$nb_items.') '.$feed['title']
|
||||||
)));
|
)));
|
||||||
});
|
});
|
||||||
@ -297,6 +302,15 @@ Router\get_action('mark-as-read', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Mark all unread items as read for a specific feed
|
||||||
|
Router\get_action('mark-feed-as-read', function() {
|
||||||
|
|
||||||
|
$feed_id = Request\int_param('feed_id');
|
||||||
|
Model\mark_feed_as_read($feed_id);
|
||||||
|
Response\redirect('?action=unread');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Mark sent items id as read (Ajax request)
|
// Mark sent items id as read (Ajax request)
|
||||||
Router\post_action('mark-items-as-read', function(){
|
Router\post_action('mark-items-as-read', function(){
|
||||||
|
|
||||||
@ -782,13 +796,17 @@ Router\notfound(function() {
|
|||||||
|
|
||||||
Model\autoflush();
|
Model\autoflush();
|
||||||
|
|
||||||
|
$order = Request\param('order', 'updated');
|
||||||
|
$direction = Request\param('direction', 'desc');
|
||||||
$offset = Request\int_param('offset', 0);
|
$offset = Request\int_param('offset', 0);
|
||||||
$items = Model\get_items('unread', $offset, Model\get_config_value('items_per_page'));
|
$items = Model\get_items('unread', $offset, Model\get_config_value('items_per_page'), $order, $direction);
|
||||||
$nb_items = Model\count_items('unread');
|
$nb_items = Model\count_items('unread');
|
||||||
|
|
||||||
if ($nb_items === 0) Response\redirect('?action=feeds¬hing_to_read=1');
|
if ($nb_items === 0) Response\redirect('?action=feeds¬hing_to_read=1');
|
||||||
|
|
||||||
Response\html(Template\layout('unread_items', array(
|
Response\html(Template\layout('unread_items', array(
|
||||||
|
'order' => $order,
|
||||||
|
'direction' => $direction,
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
'nb_items' => $nb_items,
|
'nb_items' => $nb_items,
|
||||||
'nb_unread_items' => $nb_items,
|
'nb_unread_items' => $nb_items,
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
'This subscription is empty, <a href="?action=unread">go back to unread items</a>' => 'Cet abonnement est vide, <a href="?action=unread">retourner à la liste des éléments non lus</a>',
|
||||||
|
'sort by date (%s)' => 'trier par date (%s)',
|
||||||
|
'most recent' => 'plus récents',
|
||||||
|
'older' => 'anciens d\'abord',
|
||||||
|
'Show only this subscription' => 'Montrer seulement cet abonnement',
|
||||||
'Go to unread' => 'Voir les éléments non lus',
|
'Go to unread' => 'Voir les éléments non lus',
|
||||||
'Go to bookmarks' => 'Voir les favoris',
|
'Go to bookmarks' => 'Voir les favoris',
|
||||||
'Go to history' => 'Voir l\'historique',
|
'Go to history' => 'Voir l\'historique',
|
||||||
|
32
model.php
32
model.php
@ -509,7 +509,7 @@ function disable_grabber_feed($feed_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_items($status, $offset = null, $limit = null)
|
function get_items($status, $offset = null, $limit = null, $order_column = 'updated', $order_direction = 'desc')
|
||||||
{
|
{
|
||||||
return \PicoTools\singleton('db')
|
return \PicoTools\singleton('db')
|
||||||
->table('items')
|
->table('items')
|
||||||
@ -527,7 +527,7 @@ function get_items($status, $offset = null, $limit = null)
|
|||||||
)
|
)
|
||||||
->join('feeds', 'id', 'feed_id')
|
->join('feeds', 'id', 'feed_id')
|
||||||
->eq('status', $status)
|
->eq('status', $status)
|
||||||
->desc('updated')
|
->orderBy($order_column, $order_direction)
|
||||||
->offset($offset)
|
->offset($offset)
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->findAll();
|
->findAll();
|
||||||
@ -583,12 +583,12 @@ function count_feed_items($feed_id)
|
|||||||
return \PicoTools\singleton('db')
|
return \PicoTools\singleton('db')
|
||||||
->table('items')
|
->table('items')
|
||||||
->eq('feed_id', $feed_id)
|
->eq('feed_id', $feed_id)
|
||||||
->in('status', array('read', 'unread'))
|
->eq('status', 'unread')
|
||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_feed_items($feed_id, $offset = null, $limit = null)
|
function get_feed_items($feed_id, $offset = null, $limit = null, $order_column = 'updated', $order_direction = 'desc')
|
||||||
{
|
{
|
||||||
return \PicoTools\singleton('db')
|
return \PicoTools\singleton('db')
|
||||||
->table('items')
|
->table('items')
|
||||||
@ -604,9 +604,9 @@ function get_feed_items($feed_id, $offset = null, $limit = null)
|
|||||||
'feeds.site_url'
|
'feeds.site_url'
|
||||||
)
|
)
|
||||||
->join('feeds', 'id', 'feed_id')
|
->join('feeds', 'id', 'feed_id')
|
||||||
->in('status', array('read', 'unread'))
|
->eq('status', 'unread')
|
||||||
->eq('feed_id', $feed_id)
|
->eq('feed_id', $feed_id)
|
||||||
->desc('updated')
|
->orderBy($order_column, $order_direction)
|
||||||
->offset($offset)
|
->offset($offset)
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->findAll();
|
->findAll();
|
||||||
@ -783,6 +783,26 @@ function mark_items_as_read(array $items_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Mark all items of a feed as read
|
||||||
|
function mark_feed_as_read($feed_id)
|
||||||
|
{
|
||||||
|
\PicoTools\singleton('db')->startTransaction();
|
||||||
|
|
||||||
|
$items_id = \PicoTools\singleton('db')
|
||||||
|
->table('items')
|
||||||
|
->columns('items.id')
|
||||||
|
->eq('status', 'unread')
|
||||||
|
->eq('feed_id', $feed_id)
|
||||||
|
->listing('id', 'id');
|
||||||
|
|
||||||
|
foreach ($items_id as $id) {
|
||||||
|
set_item_read($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
\PicoTools\singleton('db')->closeTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function mark_as_removed()
|
function mark_as_removed()
|
||||||
{
|
{
|
||||||
return \PicoTools\singleton('db')
|
return \PicoTools\singleton('db')
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
<?= Helper\escape(Helper\summary(strip_tags($item['content']), 50, 300)) ?>
|
<?= Helper\escape(Helper\summary(strip_tags($item['content']), 50, 300)) ?>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a href="?action=feed-items&feed_id=<?= $item['feed_id'] ?>"><?= Helper\escape($item['feed_title']) ?></a> |
|
<a href="?action=feed-items&feed_id=<?= $item['feed_id'] ?>" title="<?= t('Show only this subscription') ?>"><?= Helper\escape($item['feed_title']) ?></a> |
|
||||||
<?= dt('%e %B %Y %k:%M', $item['updated']) ?> |
|
<?= dt('%e %B %Y %k:%M', $item['updated']) ?> |
|
||||||
|
|
||||||
<span class="hide-mobile">
|
<span class="hide-mobile">
|
||||||
|
@ -1,16 +1,26 @@
|
|||||||
<?php if (empty($items)): ?>
|
<?php if (empty($items)): ?>
|
||||||
|
|
||||||
<p class="alert alert-info"><?= t('No item') ?></p>
|
<p class="alert">
|
||||||
|
<?= t('This subscription is empty, <a href="?action=unread">go back to unread items</a>') ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
|
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h2><?= Helper\escape($feed['title']) ?> (<?= $nb_items ?>)</h2>
|
<h2><?= Helper\escape($feed['title']) ?> (<?= $nb_items ?>)</h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="?action=feed-items&feed_id=<?= $feed['id'] ?>&order=updated&direction=<?= $direction == 'asc' ? 'desc' : 'asc' ?>"><?= t('sort by date (%s)', $direction == 'desc' ? t('older') : t('most recent')) ?></a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="?action=mark-feed-as-read&feed_id=<?= $feed['id'] ?>" data-action="mark-feed-read" data-feed-id="<?= $feed['id'] ?>"><?= t('mark all as read') ?></a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section class="items" id="listing">
|
<section class="items" id="listing">
|
||||||
<?php foreach ($items as $item): ?>
|
<?php foreach ($items as $item): ?>
|
||||||
<article id="item-<?= $item['id'] ?>" data-item-id="<?= $item['id'] ?>">
|
<article id="item-<?= $item['id'] ?>" data-item-id="<?= $item['id'] ?>" data-item-page="<?= $menu ?>" data-hide="true">
|
||||||
<h2>
|
<h2>
|
||||||
<?= $item['bookmark'] ? '★ ' : '' ?>
|
<?= $item['bookmark'] ? '★ ' : '' ?>
|
||||||
<a
|
<a
|
||||||
@ -43,11 +53,11 @@
|
|||||||
|
|
||||||
<nav id="items-paging">
|
<nav id="items-paging">
|
||||||
<?php if ($offset > 0): ?>
|
<?php if ($offset > 0): ?>
|
||||||
<a id="previous-page" href="?action=feed-items&feed_id=<?= $feed['id'] ?>&offset=<?= ($offset - $items_per_page) ?>">⇽ <?= t('Previous page') ?></a>
|
<a id="previous-page" href="?action=feed-items&feed_id=<?= $feed['id'] ?>&offset=<?= ($offset - $items_per_page) ?>&order=<?= $order ?>&direction=<?= $direction ?>">⇽ <?= t('Previous page') ?></a>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<?php if (($nb_items - $offset) > $items_per_page): ?>
|
<?php if (($nb_items - $offset) > $items_per_page): ?>
|
||||||
<a id="next-page" href="?action=feed-items&feed_id=<?= $feed['id'] ?>&offset=<?= ($offset + $items_per_page) ?>"><?= t('Next page') ?> ⇾</a>
|
<a id="next-page" href="?action=feed-items&feed_id=<?= $feed['id'] ?>&offset=<?= ($offset + $items_per_page) ?>&order=<?= $order ?>&direction=<?= $direction ?>"><?= t('Next page') ?> ⇾</a>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<span id="loading-feed-<?= $feed['id'] ?>"></span>
|
<span id="loading-feed-<?= $feed['id'] ?>"></span>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<a href="?action=feed-items&feed_id=<?= $feed['id'] ?>"><?= Helper\escape($feed['title']) ?></a>
|
<a href="?action=feed-items&feed_id=<?= $feed['id'] ?>" title="<?= t('Show only this subscription') ?>"><?= Helper\escape($feed['title']) ?></a>
|
||||||
|
|
||||||
<?php if ($feed['enabled']): ?>
|
<?php if ($feed['enabled']): ?>
|
||||||
<?php if ($feed['last_checked']): ?>
|
<?php if ($feed['last_checked']): ?>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<?= Helper\escape(Helper\summary(strip_tags($item['content']), 50, 300)) ?>
|
<?= Helper\escape(Helper\summary(strip_tags($item['content']), 50, 300)) ?>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a href="?action=feed-items&feed_id=<?= $item['feed_id'] ?>"><?= Helper\escape($item['feed_title']) ?></a> |
|
<a href="?action=feed-items&feed_id=<?= $item['feed_id'] ?>" title="<?= t('Show only this subscription') ?>"><?= Helper\escape($item['feed_title']) ?></a> |
|
||||||
|
|
||||||
<span class="hide-mobile"><?= dt('%e %B %Y %k:%M', $item['updated']) ?> |</span>
|
<span class="hide-mobile"><?= dt('%e %B %Y %k:%M', $item['updated']) ?> |</span>
|
||||||
|
|
||||||
|
@ -8,9 +8,10 @@
|
|||||||
<h2><?= t('<span id="page-counter">%s</span>unread items', isset($nb_items) ? $nb_items.' ' : '') ?></h2>
|
<h2><?= t('<span id="page-counter">%s</span>unread items', isset($nb_items) ? $nb_items.' ' : '') ?></h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<a href="?action=mark-as-read" data-action="mark-all-read">
|
<a href="?action=unread&order=updated&direction=<?= $direction == 'asc' ? 'desc' : 'asc' ?>"><?= t('sort by date (%s)', $direction == 'desc' ? t('older') : t('most recent')) ?></a>
|
||||||
<?= t('mark all as read') ?>
|
</li>
|
||||||
</a>
|
<li>
|
||||||
|
<a href="?action=mark-as-read" data-action="mark-all-read"><?= t('mark all as read') ?></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -32,7 +33,7 @@
|
|||||||
<?= Helper\escape(Helper\summary(strip_tags($item['content']), 50, 300)) ?>
|
<?= Helper\escape(Helper\summary(strip_tags($item['content']), 50, 300)) ?>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a href="?action=feed-items&feed_id=<?= $item['feed_id'] ?>"><?= Helper\escape($item['feed_title']) ?></a> |
|
<a href="?action=feed-items&feed_id=<?= $item['feed_id'] ?>" title="<?= t('Show only this subscription') ?>"><?= Helper\escape($item['feed_title']) ?></a> |
|
||||||
<span class="hide-mobile"><?= dt('%e %B %Y %k:%M', $item['updated']) ?> |</span>
|
<span class="hide-mobile"><?= dt('%e %B %Y %k:%M', $item['updated']) ?> |</span>
|
||||||
|
|
||||||
<span class="hide-mobile">
|
<span class="hide-mobile">
|
||||||
@ -67,11 +68,11 @@
|
|||||||
|
|
||||||
<nav id="items-paging">
|
<nav id="items-paging">
|
||||||
<?php if ($offset > 0): ?>
|
<?php if ($offset > 0): ?>
|
||||||
<a id="previous-page" href="?action=unread&offset=<?= ($offset - $items_per_page) ?>">⇽ <?= t('Previous page') ?></a>
|
<a id="previous-page" href="?action=unread&offset=<?= ($offset - $items_per_page) ?>&order=<?= $order ?>&direction=<?= $direction ?>">⇽ <?= t('Previous page') ?></a>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<?php if (($nb_items - $offset) > $items_per_page): ?>
|
<?php if (($nb_items - $offset) > $items_per_page): ?>
|
||||||
<a id="next-page" href="?action=unread&offset=<?= ($offset + $items_per_page) ?>"><?= t('Next page') ?> ⇾</a>
|
<a id="next-page" href="?action=unread&offset=<?= ($offset + $items_per_page) ?>&order=<?= $order ?>&direction=<?= $direction ?>"><?= t('Next page') ?> ⇾</a>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
9
vendor/PicoDb/Table.php
vendored
9
vendor/PicoDb/Table.php
vendored
@ -260,13 +260,10 @@ class Table
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function orderBy($column)
|
public function orderBy($column, $order = 'ASC')
|
||||||
{
|
{
|
||||||
if ($column[0] == '-') {
|
$order = strtoupper($order);
|
||||||
$order = 'DESC';
|
$order = $order === 'ASC' || $order === 'DESC' ? $order : 'ASC';
|
||||||
} else {
|
|
||||||
$order = 'ASC';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->sql_order === '') {
|
if ($this->sql_order === '') {
|
||||||
$this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' '.$order;
|
$this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' '.$order;
|
||||||
|
Loading…
Reference in New Issue
Block a user