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



commit f398f06786a01b6116c6bcac0063f3c857e97e67
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 256d061..03c96d7 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
@@ -41,7 +41,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);
 };
 
@@ -549,10 +549,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
@@ -563,7 +562,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,
@@ -590,6 +589,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;
@@ -612,3 +615,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]