[Groonga-commit] groonga/groonga-admin at 8cbef76 [master] Use incremental search for pagination

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Dec 16 21:21:28 JST 2014


Kouhei Sutou	2014-12-16 21:21:28 +0900 (Tue, 16 Dec 2014)

  New Revision: 8cbef76d933b44b76c862527686b1c069db0e840
  https://github.com/groonga/groonga-admin/commit/8cbef76d933b44b76c862527686b1c069db0e840

  Message:
    Use incremental search for pagination

  Modified files:
    app/scripts/controllers/table-search-controller.js
    app/views/tables/search.html

  Modified: app/scripts/controllers/table-search-controller.js (+16 -7)
===================================================================
--- app/scripts/controllers/table-search-controller.js    2014-12-16 21:02:54 +0900 (30ed47c)
+++ app/scripts/controllers/table-search-controller.js    2014-12-16 21:21:28 +0900 (d4c740e)
@@ -34,10 +34,16 @@ angular.module('groongaAdminApp')
         $scope.indexedColumns = [];
         $scope.commandLine = '';
         $scope.message = '';
-        $scope.currentPage = 1;
-        $scope.nRecordsInPage = 10;
-        $scope.maxNPages = 10;
         $scope.parameters = angular.copy($location.search());
+        if ($scope.parameters.limit && $scope.parameters.limit > 0) {
+          $scope.nRecordsInPage = $scope.parameters.limit;
+        } else {
+          $scope.nRecordsInPage = 10;
+        }
+        if ($scope.parameters.offset && $scope.nRecordsInPage > 0) {
+          $scope.currentPage = $scope.parameters.offset / $scope.nRecordsInPage;
+        }
+        $scope.maxNPages = 10;
 
         $scope.search = search;
         $scope.incrementalSearch = incrementalSearch;
@@ -135,6 +141,7 @@ angular.module('groongaAdminApp')
         });
         parameters.output_columns = packColumns(outputColumns);
 
+        parameters.offset = ($scope.currentPage - 1) * $scope.nRecordsInPage;
         parameters.limit = $scope.nRecordsInPage;
 
         var sortColumns = $scope.allColumns.filter(function(column) {
@@ -155,9 +162,7 @@ angular.module('groongaAdminApp')
       }
 
       function search() {
-        var parameters = buildParameters();
-        parameters.offset = ($scope.currentPage - 1) * $scope.nRecordsInPage;
-        $location.search(parameters);
+        $location.search(buildParameters());
       }
 
       function incrementalSearch() {
@@ -475,7 +480,11 @@ angular.module('groongaAdminApp')
                 });
                 $q.all(tasks)
                   .then(function() {
-                    select(buildParameters());
+                    var parameters = buildParameters();
+                    if ($scope.parameters.offset) {
+                      parameters.offset = $scope.parameters.offset;
+                    }
+                    select(parameters);
                   });
               });
           });

  Modified: app/views/tables/search.html (+2 -2)
===================================================================
--- app/views/tables/search.html    2014-12-16 21:02:54 +0900 (3771c2b)
+++ app/views/tables/search.html    2014-12-16 21:21:28 +0900 (4eab32d)
@@ -158,7 +158,7 @@
                 max-size="maxNPages"
                 rotate="false"
                 ng-model="currentPage"
-                ng-change="search()">
+                ng-change="incrementalSearch()">
     </pagination>
 
     <ul class="nav nav-tabs" role="tablist">
@@ -226,7 +226,7 @@
                 max-size="maxNPages"
                 rotate="false"
                 ng-model="currentPage"
-                ng-change="search()">
+                ng-change="incrementalSearch()">
     </pagination>
   </div>
 </div>
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index