[gnome-documents/wip/split-view: 7/12] search: Split OffsetController so that each view can have its own



commit b195bf89b0fee3db7f7172f73492ac258ffb5cbc
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Oct 16 13:33:30 2014 +0200

    search: Split OffsetController so that each view can have its own
    
    When we have separate views for documents, collections and search, each
    of them would require separate queries to count the number of items
    they have, and the offset can be different in each case. So, we need to
    allow each view to have its own OffsetController implementation.
    
    Currently the only implementation is OffsetOverviewController, which is
    the same as the unified OffsetController that we had.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686461

 src/search.js |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/src/search.js b/src/search.js
index ffa18a4..6ce5066 100644
--- a/src/search.js
+++ b/src/search.js
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012 Red Hat, Inc.
+ * Copyright (c) 2011, 2012, 2014 Red Hat, Inc.
  *
  * Gnome Documents is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by the
@@ -40,7 +40,7 @@ function initSearch(context) {
     context.searchMatchManager = new SearchMatchManager(context);
     context.searchTypeManager = new SearchTypeManager(context);
     context.searchController = new SearchController(context);
-    context.offsetController = new OffsetController(context);
+    context.offsetController = new OffsetOverviewController(context);
     context.queryBuilder = new Query.QueryBuilder(context);
 };
 
@@ -509,10 +509,9 @@ const _OFFSET_STEP = 50;
 const OffsetController = new Lang.Class({
     Name: 'OffsetController',
 
-    _init: function(context) {
+    _init: function() {
         this._offset = 0;
         this._itemCount = 0;
-        this._context = context;
     },
 
     // to be called by the view
@@ -523,7 +522,7 @@ const OffsetController = new Lang.Class({
 
     // to be called by the model
     resetItemCount: function() {
-        let query = this._context.queryBuilder.buildCountQuery();
+        let query = this.getQuery();
 
         Application.connectionQueue.add
             (query.sparql, null, Lang.bind(this,
@@ -550,6 +549,10 @@ const OffsetController = new Lang.Class({
                 }));
     },
 
+    getQuery: function() {
+        log('Error: OffsetController implementations must override getQuery');
+    },
+
     // to be called by the model
     resetOffset: function() {
         this._offset = 0;
@@ -572,3 +575,17 @@ const OffsetController = new Lang.Class({
     }
 });
 Signals.addSignalMethods(OffsetController.prototype);
+
+const OffsetOverviewController = new Lang.Class({
+    Name: 'OffsetOverviewController',
+    Extends: OffsetController,
+
+    _init: function(context) {
+        this.parent();
+        this._context = context;
+    },
+
+    getQuery: function() {
+        return this._context.queryBuilder.buildCountQuery();
+    }
+});


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]