From 667f3f077356d3e463b856cbba7d5affaa6877d1 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Fri, 5 Jul 2013 22:37:19 -0400 Subject: [PATCH] Add items paging --- assets/css/app.css | 6 ++++++ assets/js/app.js | 20 ++++++++++++++++++++ common.php | 11 ++++++----- index.php | 27 ++++++++++++++++++++------- locales/de_DE/translations.php | 4 +++- locales/fr_FR/translations.php | 4 +++- model.php | 30 +++++++++++++++++++++++++++--- templates/app_header.php | 2 +- templates/bookmarks.php | 13 ++++++++++++- templates/config.php | 2 ++ templates/history.php | 16 +++++++++++++--- templates/unread_items.php | 11 +++++++++++ vendor/PicoDb/Table.php | 20 ++++++++++++++++---- 13 files changed, 140 insertions(+), 26 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index 20460c1..29ca956 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -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; diff --git a/assets/js/app.js b/assets/js/app.js index 96ac8d0..8679fe9 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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; } }; diff --git a/common.php b/common.php index d4ffa70..1d0a00b 100644 --- a/common.php +++ b/common.php @@ -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() diff --git a/index.php b/index.php index a54c993..d2a8285 100644 --- a/index.php +++ b/index.php @@ -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' ))); diff --git a/locales/de_DE/translations.php b/locales/de_DE/translations.php index 10539c4..784d43e 100644 --- a/locales/de_DE/translations.php +++ b/locales/de_DE/translations.php @@ -1,6 +1,8 @@ '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', diff --git a/locales/fr_FR/translations.php b/locales/fr_FR/translations.php index 0c462ee..94dd944 100644 --- a/locales/fr_FR/translations.php +++ b/locales/fr_FR/translations.php @@ -1,6 +1,8 @@ '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', diff --git a/model.php b/model.php index 85cbc80..5d216a2 100644 --- a/model.php +++ b/model.php @@ -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(); } diff --git a/templates/app_header.php b/templates/app_header.php index d8e8632..0419eab 100644 --- a/templates/app_header.php +++ b/templates/app_header.php @@ -19,7 +19,7 @@
diff --git a/templates/history.php b/templates/history.php index b9a8099..640aa95 100644 --- a/templates/history.php +++ b/templates/history.php @@ -1,12 +1,11 @@

- @@ -45,6 +44,17 @@

+ + + diff --git a/templates/unread_items.php b/templates/unread_items.php index 91a9d5a..4486a7f 100644 --- a/templates/unread_items.php +++ b/templates/unread_items.php @@ -51,6 +51,17 @@

+ + + diff --git a/vendor/PicoDb/Table.php b/vendor/PicoDb/Table.php index fc498bf..06f3484 100644 --- a/vendor/PicoDb/Table.php +++ b/vendor/PicoDb/Table.php @@ -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; }