[gnome-documents/origin/wip/abono/sort-by: 3/4] query, view: Change the ORDER BY clause
- From: Alessandro Bono <abono src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/origin/wip/abono/sort-by: 3/4] query, view: Change the ORDER BY clause
- Date: Wed, 4 Nov 2015 11:34:08 +0000 (UTC)
commit 3fcaa158436014701d052b2c63e0d11933b0d552
Author: Alessandro Bono <shadow openaliasbox org>
Date: Mon Oct 19 21:43:11 2015 +0200
query, view: Change the ORDER BY clause
src/query.js | 35 +++++++++++++++++++++++++++++------
src/trackerController.js | 13 ++++++++++---
src/view.js | 3 ++-
3 files changed, 41 insertions(+), 10 deletions(-)
---
diff --git a/src/query.js b/src/query.js
index f1dd34b..a1f09f6 100644
--- a/src/query.js
+++ b/src/query.js
@@ -19,6 +19,7 @@
*
*/
+const Gd = imports.gi.Gd;
const GdPrivate = imports.gi.GdPrivate;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
@@ -124,7 +125,7 @@ const QueryBuilder = new Lang.Class({
return whereSparql;
},
- _buildQueryInternal: function(global, flags, offsetController) {
+ _buildQueryInternal: function(global, flags, offsetController, sortFlag) {
let whereSparql = this._buildWhere(global, flags);
let tailSparql = '';
@@ -138,9 +139,31 @@ const QueryBuilder = new Lang.Class({
step = offsetController.getOffsetStep();
}
+ let sortType;
+ let sortBy;
+ switch (sortFlag) {
+ case Gd.MainColumns.PRIMARY_TEXT:
+ sortType = 'ASC';
+ sortBy = '?title';
+ break;
+ case Gd.MainColumns.SECONDARY_TEXT:
+ sortType = 'ASC';
+ sortBy = '?author';
+ break;
+ case Gd.MainColumns.MTIME:
+ sortType = 'DESC';
+ sortBy = '?mtime';
+ break;
+ default:
+ sortType = 'DESC';
+ sortBy = '?mtime';
+ break;
+ }
+
tailSparql +=
- 'ORDER BY DESC (?mtime)' +
+ 'ORDER BY ' + sortType + ' (' + sortBy + ')' +
('LIMIT %d OFFSET %d').format(step, offset);
+ log(tailSparql);
}
let sparql =
@@ -148,8 +171,8 @@ const QueryBuilder = new Lang.Class({
'nie:url(?urn) ' + // uri
'nfo:fileName(?urn)' + // filename
'nie:mimeType(?urn)' + // mimetype
- 'nie:title(?urn) ' + // title
- 'tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher), \'\') ' + // author
+ 'nie:title(?urn) AS ?title ' + // title
+ 'tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher), \'\') AS ?author ' + //
author
'tracker:coalesce(nfo:fileLastModified(?urn), nie:contentLastModified(?urn)) AS ?mtime ' + //
mtime
'nao:identifier(?urn) ' + // identifier
'rdf:type(?urn) ' + // type
@@ -168,8 +191,8 @@ const QueryBuilder = new Lang.Class({
return this._createQuery(sparql);
},
- buildGlobalQuery: function(flags, offsetController) {
- return this._createQuery(this._buildQueryInternal(true, flags, offsetController));
+ buildGlobalQuery: function(flags, offsetController, sortFlag) {
+ return this._createQuery(this._buildQueryInternal(true, flags, offsetController, sortFlag));
},
buildCountQuery: function(flags) {
diff --git a/src/trackerController.js b/src/trackerController.js
index 3a71a4c..53f34b9 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -272,6 +272,10 @@ const TrackerController = new Lang.Class({
this._refreshPending = true;
},
+ setSortBy: function(sortBy) {
+ this._sortBy = sortBy;
+ },
+
start: function() {
if (this._isStarted)
return;
@@ -310,7 +314,8 @@ const TrackerCollectionsController = new Lang.Class({
flags = Query.QueryFlags.COLLECTIONS;
return Application.queryBuilder.buildGlobalQuery(flags,
- Application.offsetCollectionsController);
+ Application.offsetCollectionsController,
+ this._sortBy);
},
});
@@ -328,7 +333,8 @@ const TrackerDocumentsController = new Lang.Class({
getQuery: function() {
return Application.queryBuilder.buildGlobalQuery(Query.QueryFlags.DOCUMENTS,
- Application.offsetDocumentsController);
+ Application.offsetDocumentsController,
+ this._sortBy);
},
});
@@ -367,6 +373,7 @@ const TrackerSearchController = new Lang.Class({
getQuery: function() {
return Application.queryBuilder.buildGlobalQuery(Query.QueryFlags.SEARCH,
- Application.offsetSearchController);
+ Application.offsetSearchController,
+ this._sortBy);
},
});
diff --git a/src/view.js b/src/view.js
index 969ee8e..d6ca17e 100644
--- a/src/view.js
+++ b/src/view.js
@@ -360,7 +360,6 @@ const ViewContainer = new Lang.Class({
this._sortSettingsId = Application.application.connect('action-state-changed::sort-by',
Lang.bind(this, this._updateSortForSettings));
- this._updateSortForSettings();
// setup selection controller => view
Application.selectionController.connect('selection-mode-changed',
@@ -385,6 +384,7 @@ const ViewContainer = new Lang.Class({
}));
[ this._offsetController, this._trackerController ] = getController(this._mode);
+ this._updateSortForSettings();
this._offsetController.connect('item-count-changed', Lang.bind(this,
function(controller, count) {
@@ -424,6 +424,7 @@ const ViewContainer = new Lang.Class({
let sortColumn = Application.settings.get_enum('sort-by');
let sortType = sortColumn != Gd.MainColumns.MTIME ?
Gtk.SortType.ASCENDING : Gtk.SortType.DESCENDING;
+ this._trackerController.setSortBy(sortColumn);
this._model.set_sort_column_id(sortColumn, sortType);
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]