Add sorting options in the articles list

pull/1/head
Grégory Oestreicher 2017-02-27 16:37:42 +01:00
parent 779639baf1
commit 64eddbadc6
8 changed files with 252 additions and 38 deletions

View File

@ -54,4 +54,6 @@ DISTFILES += \
qml/types/ServerSettings.qml \
rpm/harbour-wallaread.changes \
qml/pages/ServerPageShowDialog.qml \
qml/types/ServerPageShowPreferences.qml
qml/types/ServerPageShowPreferences.qml \
qml/types/ServerPageSortPreferences.qml \
qml/pages/ServerPageSortDialog.qml

View File

@ -23,7 +23,7 @@
.import QtQuick.LocalStorage 2.0 as Storage
/*
Exposed variable
Exposed variables
*/
var ArticlesFilter = {
@ -32,6 +32,12 @@ var ArticlesFilter = {
Starred: 4
}
var ArticlesSort = {
Created: 1,
Updated: 2,
Domain: 3
}
/*
Timer management, used for the various setTimeout() calls
*/
@ -380,7 +386,7 @@ function syncDeletedArticles( props, cb )
);
}
function getArticles( serverId, cb, filter )
function getArticles( serverId, cb, filter, sortOrder, sortAsc )
{
var db = getDatabase();
@ -389,6 +395,7 @@ function getArticles( serverId, cb, filter )
var articles = new Array
var err = null;
var where = "";
var order = "";
if ( filter & ArticlesFilter.Read )
where += " AND archived=1";
@ -398,8 +405,22 @@ function getArticles( serverId, cb, filter )
if ( filter & ArticlesFilter.Starred )
where += " AND starred=1";
if ( sortOrder === ArticlesSort.Created )
order = " ORDER BY created";
else if ( sortOrder === ArticlesSort.Updated )
order = " ORDER BY updated"
else if ( sortOrder === ArticlesSort.Domain )
order = " ORDER BY domain"
if ( order.length > 0 ) {
if ( sortAsc )
order += " ASC"
else
order += " DESC"
}
try {
var res = tx.executeSql( "SELECT * FROM articles WHERE server=?" + where, [ serverId ] );
var res = tx.executeSql( "SELECT * FROM articles WHERE server=?" + where + order, [ serverId ] );
for ( var i = 0; i < res.rows.length; ++i ) {
articles.push( res.rows[i] );
}

View File

@ -30,6 +30,8 @@ ListModel {
property bool showAll: false
property bool showRead: false
property bool showStarred: false
property int sortOrder: WallaBase.ArticlesSort.Created
property bool sortAsc: true
signal error( string message )
@ -48,7 +50,7 @@ ListModel {
filter |= WallaBase.ArticlesFilter.Starred
}
WallaBase.getArticles( serverId, onArticlesLoaded, filter )
WallaBase.getArticles( serverId, onArticlesLoaded, filter, sortOrder, sortAsc )
}
function onArticlesLoaded( articles, err ) {

View File

@ -32,7 +32,6 @@ Page {
property int serverId
property alias server: server
property alias showPreferences: showPreferences
Server {
id: server
@ -51,6 +50,10 @@ Page {
id: showPreferences
}
ServerPageSortPreferences {
id: sortPreferences
}
ArticlesModel {
id: articlesModel
@ -273,6 +276,18 @@ Page {
model: articlesModel
PullDownMenu {
MenuItem {
text: qsTr( "Sort: " ) + sortPreferences.getVisibleDescription()
onClicked: {
var dlg = pageStack.push( Qt.resolvedUrl( "ServerPageSortDialog.qml" ), { preferences: sortPreferences } )
dlg.accepted.connect ( function() {
articlesModel.sortOrder = sortPreferences.sortOrder
articlesModel.sortAsc = sortPreferences.sortAsc
serverPage.updateArticlesList()
} )
}
}
MenuItem {
text: qsTr( "Show: " ) + showPreferences.getVisibleDescription()
onClicked: {

View File

@ -0,0 +1,89 @@
/*
* WallaRead - A Wallabag 2+ client for SailfishOS
* © 2017 Grégory Oestreicher <greg@kamago.net>
*
* This file is part of WallaRead.
*
* WallaRead is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WallaRead is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WallaRead. If not, see <http://www.gnu.org/licenses/>.
*
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
import "../js/WallaBase.js" as WallaBase
Dialog {
id: serverSortDialog
allowedOrientations: Orientation.All
canAccept: true
property variant preferences
Component.onCompleted: {
if ( preferences.sortOrder === WallaBase.ArticlesSort.Created )
sortComboBox.currentIndex = 0
else if ( preferences.sortOrder === WallaBase.ArticlesSort.Updated )
sortComboBox.currentIndex = 1
else if ( preferences.sortOrder === WallaBase.ArticlesSort.Domain )
sortComboBox.currentIndex = 2
}
onDone: {
if ( result === DialogResult.Accepted ) {
if ( sortComboBox.currentItem.text === "Created" )
preferences.sortOrder = WallaBase.ArticlesSort.Created
else if ( sortComboBox.currentItem.text === "Updated" )
preferences.sortOrder = WallaBase.ArticlesSort.Updated
else if ( sortComboBox.currentItem.text === "Domain" )
preferences.sortOrder = WallaBase.ArticlesSort.Domain
preferences.sortAsc = sortAscSwitch.checked
}
}
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
width: parent.width
Column {
id: column
width: parent.width
DialogHeader {
acceptText: qsTr( "Sort view" )
}
ComboBox {
id: sortComboBox
width: parent.width
label: qsTr( "Sort order" )
menu: ContextMenu {
MenuItem { text: "Created" }
MenuItem { text: "Updated" }
MenuItem { text: "Domain" }
}
}
TextSwitch {
id: sortAscSwitch
width: parent.width
checked: preferences.sortAsc
text: qsTr( "Sort Ascending" )
}
}
}
}

View File

@ -0,0 +1,49 @@
/*
* WallaRead - A Wallabag 2+ client for SailfishOS
* © 2017 Grégory Oestreicher <greg@kamago.net>
*
* This file is part of WallaRead.
*
* WallaRead is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* WallaRead is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WallaRead. If not, see <http://www.gnu.org/licenses/>.
*
*/
import QtQuick 2.0
import "../js/WallaBase.js" as WallaBase
QtObject {
property int sortOrder: WallaBase.ArticlesSort.Created
property bool sortAsc: true
function getVisibleDescription() {
var ret = ""
if ( sortOrder === WallaBase.ArticlesSort.Created )
ret = qsTr( "Created" )
else if ( sortOrder === WallaBase.ArticlesSort.Updated )
ret = qsTr( "Updated" )
else if ( sortOrder === WallaBase.ArticlesSort.Domain )
ret = qsTr( "Domain" )
ret += " "
if ( sortAsc )
ret += "asc."
else
ret += "desc."
return ret
}
}

View File

@ -60,22 +60,6 @@
<source>Deleting</source>
<translation>Suppression</translation>
</message>
<message>
<source>Show unstarred articles</source>
<translation>Afficher les articles hors favoris</translation>
</message>
<message>
<source>Show only starred articles</source>
<translation>Seulement afficher les articles en favoris</translation>
</message>
<message>
<source>Show unread articles</source>
<translation>Afficher les articles non lus</translation>
</message>
<message>
<source>Show read articles</source>
<translation>Afficher les articles lus</translation>
</message>
<message>
<source>Article URL</source>
<translation>URL de l&apos;article</translation>
@ -88,6 +72,10 @@
<source>Show: </source>
<translation>Afficher : </translation>
</message>
<message>
<source>Sort: </source>
<translation>Tri : </translation>
</message>
</context>
<context>
<name>ServerPageShowDialog</name>
@ -123,6 +111,36 @@
<translation>tous</translation>
</message>
</context>
<context>
<name>ServerPageSortDialog</name>
<message>
<source>Sort view</source>
<translation>Trier la liste</translation>
</message>
<message>
<source>Sort order</source>
<translation>Ordre de tri</translation>
</message>
<message>
<source>Sort Ascending</source>
<translation>Trier par ordre croissant</translation>
</message>
</context>
<context>
<name>ServerPageSortPreferences</name>
<message>
<source>Created</source>
<translation>Création</translation>
</message>
<message>
<source>Updated</source>
<translation>Modification</translation>
</message>
<message>
<source>Domain</source>
<translation>Domaine</translation>
</message>
</context>
<context>
<name>ServerSettings</name>
<message>

View File

@ -52,22 +52,6 @@
<source>Article URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show unstarred articles</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show only starred articles</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show unread articles</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show read articles</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Refresh</source>
<translation type="unfinished"></translation>
@ -88,6 +72,10 @@
<source>Show: </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sort: </source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ServerPageShowDialog</name>
@ -123,6 +111,36 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ServerPageSortDialog</name>
<message>
<source>Sort view</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sort order</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sort Ascending</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ServerPageSortPreferences</name>
<message>
<source>Created</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Updated</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Domain</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ServerSettings</name>
<message>