Add items paging

This commit is contained in:
Frederic Guillot 2013-07-05 22:37:19 -04:00
parent e4c6f27767
commit 667f3f0773
13 changed files with 140 additions and 26 deletions

View File

@ -505,6 +505,12 @@ nav .active a {
opacity: 0.4;
}
#items-paging {
margin-top: 50px;
font-size: 75%;
text-align: center;
}
/* other pages */
section li {
margin-left: 15px;

View File

@ -176,6 +176,20 @@
}
function open_next_page()
{
var link = document.getElementById("next-page");
if (link) link.click();
}
function open_previous_page()
{
var link = document.getElementById("previous-page");
if (link) link.click();
}
function remove_item(item_id)
{
var item = document.getElementById("item-" + item_id);
@ -396,6 +410,12 @@
case 102: // f
bookmark_item();
break;
case 104: // h
open_previous_page();
break
case 108: // l
open_next_page();
break;
}
};

View File

@ -10,11 +10,12 @@ require 'schema.php';
require 'model.php';
const DB_VERSION = 8;
const APP_VERSION = 'master';
const APP_USERAGENT = 'Miniflux - http://miniflux.net';
const HTTP_TIMEOUT = 10;
const LIMIT_ALL = -1;
const DB_VERSION = 8;
const APP_VERSION = 'master';
const APP_USERAGENT = 'Miniflux - http://miniflux.net';
const HTTP_TIMEOUT = 10;
const LIMIT_ALL = -1;
const ITEMS_PER_PAGE = 80;
function get_db_filename()

View File

@ -203,20 +203,30 @@ Router\post_action('change-item-status', function() {
Router\get_action('history', function() {
$offset = Request\int_param('offset', 0);
$nb_items = Model\count_items('read');
Response\html(Template\layout('history', array(
'items' => Model\get_read_items(),
'items' => Model\get_read_items($offset, ITEMS_PER_PAGE),
'nb_items' => $nb_items,
'offset' => $offset,
'menu' => 'history',
'title' => t('History')
'title' => t('History').' ('.$nb_items.')'
)));
});
Router\get_action('bookmarks', function() {
$offset = Request\int_param('offset', 0);
$nb_items = Model\count_bookmarks();
Response\html(Template\layout('bookmarks', array(
'items' => Model\get_bookmarks(),
'items' => Model\get_bookmarks($offset, ITEMS_PER_PAGE),
'nb_items' => $nb_items,
'offset' => $offset,
'menu' => 'bookmarks',
'title' => t('Bookmarks')
'title' => t('Bookmarks').' ('.$nb_items.')'
)));
});
@ -411,7 +421,7 @@ Router\get_action('config', function() {
Router\post_action('config', function() {
$values = Request\values();
$values = Request\values() + array('nocontent' => 0);
list($valid, $errors) = Model\validate_config_update($values);
if ($valid) {
@ -444,8 +454,9 @@ Router\notfound(function() {
Model\autoflush();
$items = Model\get_unread_items();
$nb_items = count($items);
$offset = Request\int_param('offset', 0);
$items = Model\get_unread_items($offset, ITEMS_PER_PAGE);
$nb_items = Model\count_items('unread');;
if ($nb_items === 0) {
@ -455,6 +466,8 @@ Router\notfound(function() {
Response\html(Template\layout('unread_items', array(
'items' => $items,
'nb_items' => $nb_items,
'nb_unread_items' => $nb_items,
'offset' => $offset,
'title' => 'miniflux ('.$nb_items.')',
'menu' => 'unread'
)));

View File

@ -1,6 +1,8 @@
<?php
return array(
'Previous page' => 'Vorheriger Seite',
'Next page' => 'Nächster Seite',
'Do not fetch the content of articles' => 'Lade die Inhalte der Feeds nicht',
'Remove automatically read items' => 'Lösche gelesene Artikel automatisch',
'Never' => 'Nie',
@ -51,7 +53,7 @@ return array(
'No history' => 'Kein Verlauf',
'mark as unread' => 'als ungelesen markieren',
'History' => 'Verlauf',
'flush these items' => 'diese Einträge löschen',
'flush all items' => 'diese Einträge löschen',
'Item not found' => 'Eintrag nicht gefunden',
'Unread items' => 'Ungelesene Einträge',
'Next' => 'Weiter',

View File

@ -1,6 +1,8 @@
<?php
return array(
'Previous page' => 'Page précédente',
'Next page' => 'Page suivante',
'Do not fetch the content of articles' => 'Ne pas récupérer le contenu des articles',
'Remove automatically read items' => 'Supprimer automatiquement les éléments lus',
'Never' => 'Jamais',
@ -51,7 +53,7 @@ return array(
'No history' => 'Aucun historique',
'mark as unread' => 'marquer comme non lu',
'History' => 'Historique',
'flush these items' => 'supprimer ces éléments',
'flush all items' => 'supprimer tous les éléments',
'Item not found' => 'Élément introuvable',
'Unread items' => 'Éléments non lus',
'Next' => 'Suivant',

View File

@ -249,7 +249,7 @@ function remove_feed($feed_id)
}
function get_unread_items()
function get_unread_items($offset = null, $limit = null)
{
return \PicoTools\singleton('db')
->table('items')
@ -257,11 +257,22 @@ function get_unread_items()
->join('feeds', 'id', 'feed_id')
->eq('status', 'unread')
->desc('updated')
->offset($offset)
->limit($limit)
->findAll();
}
function get_read_items()
function count_items($status)
{
return \PicoTools\singleton('db')
->table('items')
->eq('status', $status)
->count();
}
function get_read_items($offset = null, $limit = null)
{
return \PicoTools\singleton('db')
->table('items')
@ -269,11 +280,22 @@ function get_read_items()
->join('feeds', 'id', 'feed_id')
->eq('status', 'read')
->desc('updated')
->offset($offset)
->limit($limit)
->findAll();
}
function get_bookmarks()
function count_bookmarks()
{
return \PicoTools\singleton('db')
->table('items')
->eq('bookmark', 1)
->count();
}
function get_bookmarks($offset = null, $limit = null)
{
return \PicoTools\singleton('db')
->table('items')
@ -282,6 +304,8 @@ function get_bookmarks()
->in('status', array('read', 'unread'))
->eq('bookmark', 1)
->desc('updated')
->offset($offset)
->limit($limit)
->findAll();
}

View File

@ -19,7 +19,7 @@
<a class="logo" href="?">mini<span>flux</span></a>
<ul>
<li <?= isset($menu) && $menu === 'unread' ? 'class="active"' : '' ?>>
<a href="?action=default"><?= t('unread') ?> <span id="nav-counter"><?= isset($nb_items) ? '('.$nb_items.')' : '' ?></span></a>
<a href="?action=default"><?= t('unread') ?> <span id="nav-counter"><?= isset($nb_unread_items) ? '('.$nb_unread_items.')' : '' ?></span></a>
</li>
<li <?= isset($menu) && $menu === 'bookmarks' ? 'class="active"' : '' ?>>
<a href="?action=bookmarks"><?= t('bookmarks') ?></a>

View File

@ -5,7 +5,7 @@
<?php else: ?>
<div class="page-header">
<h2><?= t('Bookmarks') ?></h2>
<h2><?= t('Bookmarks') ?> (<?= $nb_items ?>)</h2>
</div>
<section class="items">
@ -36,6 +36,17 @@
</p>
</article>
<?php endforeach ?>
<nav id="items-paging">
<?php if ($offset > 0): ?>
<a id="previous-page" href="?action=bookmarks&amp;offset=<?= ($offset - ITEMS_PER_PAGE) ?>"> <?= t('Previous page') ?></a>
<?php endif ?>
&nbsp;
<?php if (($nb_items - $offset) > ITEMS_PER_PAGE): ?>
<a id="next-page" href="?action=bookmarks&amp;offset=<?= ($offset + ITEMS_PER_PAGE) ?>"><?= t('Next page') ?> ⇾</a>
<?php endif ?>
</nav>
</section>
<?php endif ?>

View File

@ -48,6 +48,8 @@
<li><?= t('Open original link') ?> = <strong>v</strong></li>
<li><?= t('Open item') ?> = <strong>o</strong></li>
<li><?= t('Bookmark item') ?> = <strong>f</strong></li>
<li><?= t('Previous page') ?> = <strong>h</strong></li>
<li><?= t('Next page') ?> = <strong>l</strong></li>
</ul>
</div>
<div class="alert alert-normal">

View File

@ -1,12 +1,11 @@
<?php if (empty($items)): ?>
<p class="alert alert-info"><?= t('No history') ?></p>
<?php else: ?>
<div class="page-header">
<h2><?= t('History') ?></h2>
<h2><?= t('History') ?> (<?= $nb_items ?>)</h2>
<ul>
<li><a href="?action=confirm-flush-history"><?= t('flush these items') ?></a></li>
<li><a href="?action=confirm-flush-history"><?= t('flush all items') ?></a></li>
</ul>
</div>
@ -45,6 +44,17 @@
</p>
</article>
<?php endforeach ?>
<nav id="items-paging">
<?php if ($offset > 0): ?>
<a id="previous-page" href="?action=history&amp;offset=<?= ($offset - ITEMS_PER_PAGE) ?>"> <?= t('Previous page') ?></a>
<?php endif ?>
&nbsp;
<?php if (($nb_items - $offset) > ITEMS_PER_PAGE): ?>
<a id="next-page" href="?action=history&amp;offset=<?= ($offset + ITEMS_PER_PAGE) ?>"><?= t('Next page') ?> ⇾</a>
<?php endif ?>
</nav>
</section>
<?php endif ?>

View File

@ -51,6 +51,17 @@
</p>
</article>
<?php endforeach ?>
<nav id="items-paging">
<?php if ($offset > 0): ?>
<a id="previous-page" href="?action=unread&amp;offset=<?= ($offset - ITEMS_PER_PAGE) ?>"> <?= t('Previous page') ?></a>
<?php endif ?>
&nbsp;
<?php if (($nb_items - $offset) > ITEMS_PER_PAGE): ?>
<a id="next-page" href="?action=unread&amp;offset=<?= ($offset + ITEMS_PER_PAGE) ?>"><?= t('Next page') ?> ⇾</a>
<?php endif ?>
</nav>
</section>
<?php endif ?>

View File

@ -248,28 +248,40 @@ class Table
public function asc($column)
{
$this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' ASC';
if ($this->sql_order === '') {
$this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' ASC';
}
else {
$this->sql_order .= ', '.$this->db->escapeIdentifier($column).' ASC';
}
return $this;
}
public function desc($column)
{
$this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' DESC';
if ($this->sql_order === '') {
$this->sql_order = ' ORDER BY '.$this->db->escapeIdentifier($column).' DESC';
}
else {
$this->sql_order .= ', '.$this->db->escapeIdentifier($column).' DESC';
}
return $this;
}
public function limit($value)
{
$this->sql_limit = ' LIMIT '.(int) $value;
if (! is_null($value)) $this->sql_limit = ' LIMIT '.(int) $value;
return $this;
}
public function offset($value)
{
$this->sql_offset = ' OFFSET '.(int) $value;
if (! is_null($value)) $this->sql_offset = ' OFFSET '.(int) $value;
return $this;
}