← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15912: tracker capture - tei search server side paging

 

------------------------------------------------------------
revno: 15912
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Mon 2014-06-30 15:16:30 +0200
message:
  tracker capture - tei search server side paging
removed:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/pagination.html
added:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/serverside-pagination.html
modified:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/filters.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/tei.html


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-06-30 05:56:38 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/components/dashboard/dashboard-controller.js	2014-06-30 13:16:30 +0000
@@ -36,7 +36,7 @@
     $scope.selectedProgramId = null;
     
     $scope.selectedTeiId = ($location.search()).tei; 
-    $scope.selectedProgramId = ($location.search()).programId; 
+    $scope.selectedProgramId = ($location.search()).program; 
     $scope.selectedOrgUnit = storage.get('SELECTED_OU');
     $scope.selectedProgram;
     $scope.programs = []; 

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-06-30 05:56:38 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-06-30 13:16:30 +0000
@@ -29,8 +29,7 @@
     $scope.ouMode = $scope.ouModes[0];
     
     //Paging
-    $scope.rowsPerPage = 50;
-    $scope.currentPage = Paginator.getPage() + 1;   
+    $scope.pager = {pageSize: 50, page: 1, toolBarDisplay: 5};   
     
     //EntityList
     $scope.showTrackedEntityDiv = false;
@@ -74,7 +73,7 @@
                         $scope.attributes = atts;   
                         $scope.attributes = $scope.generateAttributeFilters($scope.attributes);
                         $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
-                        $scope.search($scope.searchMode.listAll);
+                        $scope.prepareForsearch($scope.searchMode.listAll);
                     });
                 }, 100);
             });           
@@ -146,56 +145,88 @@
         }       
     };
     
-    $scope.search = function(mode){ 
+    $scope.prepareForsearch = function(mode){ 
 
+        $scope.selectedSearchMode = mode;
         $scope.emptySearchText = false;
         $scope.emptySearchAttribute = false;
         $scope.showSearchDiv = false;
         $scope.showRegistrationDiv = false;                          
         $scope.trackedEntityList = null; 
         
-        var queryUrl = null, 
-            programUrl = null, 
-            attributeUrl = {url: null, hasValue: false};
+        $scope.queryUrl = null;
+        $scope.programUrl = null;
+        $scope.attributeUrl = {url: null, hasValue: false};
     
         if($scope.selectedProgram){
-            programUrl = 'program=' + $scope.selectedProgram.id;
+            $scope.programUrl = 'program=' + $scope.selectedProgram.id;
         }        
         
         //check search mode
-        if( mode === $scope.searchMode.freeText ){     
+        if( $scope.selectedSearchMode === $scope.searchMode.freeText ){     
             if(!$scope.searchText){                
                 $scope.emptySearchText = true;
                 return;
             }       
             
             $scope.showTrackedEntityDiv = true;      
-            queryUrl = 'query=' + $scope.searchText;                     
+            $scope.queryUrl = 'query=' + $scope.searchText;                     
         }
-        else if( mode === $scope.searchMode.attributeBased ){
+        else if( $scope.selectedSearchMode === $scope.searchMode.attributeBased ){
             $scope.showTrackedEntityDiv = true;                  
-            attributeUrl = EntityQueryFactory.getQueryForAttributes($scope.attributes, $scope.enrollment);
+            $scope.attributeUrl = EntityQueryFactory.getQueryForAttributes($scope.attributes, $scope.enrollment);
             
-            if(!attributeUrl.hasValue && !$scope.selectedProgram){
+            if(!$scope.attributeUrl.hasValue && !$scope.selectedProgram){
                 $scope.emptySearchAttribute = true;
                 $scope.showSearchDiv = true;
                 return;
             }
         }
-        else if( mode === $scope.searchMode.listAll ){   
+        else if( $scope.selectedSearchMode === $scope.searchMode.listAll ){   
             $scope.showTrackedEntityDiv = true;    
         } 
 
+        $scope.search();
+    };
+    
+    $scope.search = function(){
+        
         //get events for the specified parameters
         TEIService.search($scope.selectedOrgUnit.id, 
                                             $scope.ouMode.name,
-                                            queryUrl,
-                                            programUrl,
-                                            attributeUrl.url).then(function(data){
-            $scope.trackedEntityList = data;            
+                                            $scope.queryUrl,
+                                            $scope.programUrl,
+                                            $scope.attributeUrl.url,
+                                            $scope.pager).then(function(data){
+            $scope.trackedEntityList = data; 
+            
+            if( data.pager ){
+                $scope.pager = data.pager;
+                $scope.pager.toolBarDisplay = 5;
+
+                Paginator.setPage($scope.pager.page);
+                Paginator.setPageCount($scope.pager.pageCount);
+                Paginator.setPageSize($scope.pager.pageSize);
+                Paginator.setItemCount($scope.pager.total);                    
+            }
+            
         });
     };
     
+    $scope.jumpToPage = function(){
+        $scope.search();
+    };
+    
+    $scope.resetPageSize = function(){
+        $scope.pager.page = 1;        
+        $scope.search();
+    };
+    
+    $scope.getPage = function(page){    
+        $scope.pager.page = page;
+        $scope.search();
+    };
+    
     $scope.generateAttributeFilters = function(attributes){
 
         angular.forEach(attributes, function(attribute){

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js	2014-06-27 10:57:20 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/directives.js	2014-06-30 13:16:30 +0000
@@ -250,5 +250,25 @@
         element.draggable();
       }
     };  
+})
+
+.directive('serversidePaginator', function factory() {
+    return {
+        restrict: 'E',
+        controller: function ($scope, Paginator) {
+            $scope.paginator = Paginator;
+        },
+        templateUrl: 'views/serverside-pagination.html'
+    };
+})
+
+.directive('clientsidePaginator', function factory() {
+    return {
+        restrict: 'E',
+        controller: function ($scope, Paginator) {
+            $scope.paginator = Paginator;
+        },
+        templateUrl: 'views/clientside-pagination.html'
+    };
 });
 

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/filters.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/filters.js	2014-03-17 15:59:31 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/filters.js	2014-06-30 13:16:30 +0000
@@ -60,6 +60,7 @@
     };    
 })
 
+
 .filter('paginate', function(Paginator) {
     return function(input, rowsPerPage) {
         if (!input) {
@@ -68,7 +69,7 @@
 
         if (rowsPerPage) {
             Paginator.rowsPerPage = rowsPerPage;
-        }
+        }       
         
         Paginator.itemCount = input.length;
 

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-06-30 11:46:04 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-06-30 13:16:30 +0000
@@ -277,8 +277,11 @@
             });            
             return promise;
         },        
-        search: function(ouId, ouMode, queryUrl, programUrl, attributeUrl) {           
+        search: function(ouId, ouMode, queryUrl, programUrl, attributeUrl, pager) {           
             
+            var pgSize = pager ? pager.pageSize : 50;
+            var pg = pager ? pager.page : 1;
+                
             var url =  '../api/trackedEntityInstances.json?ou=' + ouId + '&ouMode='+ ouMode;
             
             if(queryUrl){
@@ -291,7 +294,7 @@
                 url = url + '&' + attributeUrl;
             }
             
-            promise = $http.get( url ).then(function(response){                                
+            promise = $http.get( url + '&pageSize=' + pgSize + '&page=' + pg ).then(function(response){                                
                 return EntityService.formatter(response.data);
             });            
             return promise;
@@ -694,14 +697,16 @@
 })
 
 /* Pagination service */
+/* Pagination service */
 .service('Paginator', function () {
-    this.page = 0;
-    this.rowsPerPage = 50;
+    this.page = 1;
+    this.pageSize = 50;
     this.itemCount = 0;
-    this.limitPerPage = 5;
+    this.pageCount = 0;
+    this.toolBarDisplay = 5;
 
     this.setPage = function (page) {
-        if (page > this.pageCount()) {
+        if (page > this.getPageCount()) {
             return;
         }
 
@@ -712,64 +717,48 @@
         return this.page;
     };
     
-    this.getRowsPerPage = function(){
-        return this.rowsPerPage;
-    };
-
-    this.nextPage = function () {
-        if (this.isLastPage()) {
-            return;
-        }
-
-        this.page++;
-    };
-
-    this.perviousPage = function () {
-        if (this.isFirstPage()) {
-            return;
-        }
-
-        this.page--;
-    };
-
-    this.firstPage = function () {
-        this.page = 0;
-    };
-
-    this.lastPage = function () {
-        this.page = this.pageCount() - 1;
-    };
-
-    this.isFirstPage = function () {
-        return this.page == 0;
-    };
-
-    this.isLastPage = function () {
-        return this.page == this.pageCount() - 1;
-    };
-
-    this.pageCount = function () {
-        var count = Math.ceil(parseInt(this.itemCount, 10) / parseInt(this.rowsPerPage, 10)); 
-        if (count === 1) { this.page = 0; } return count;
+    this.setPageSize = function(pageSize){
+      this.pageSize = pageSize;
+    };
+    
+    this.getPageSize = function(){
+        return this.pageSize;
+    };
+    
+    this.setItemCount = function(itemCount){
+      this.itemCount = itemCount;
+    };
+    
+    this.getItemCount = function(){
+        return this.itemCount;
+    };
+    
+    this.setPageCount = function(pageCount){
+        this.pageCount = pageCount;
+    };
+
+    this.getPageCount = function () {
+        return this.pageCount;
     };
 
     this.lowerLimit = function() { 
-        var pageCountLimitPerPageDiff = this.pageCount() - this.limitPerPage;
+        var pageCountLimitPerPageDiff = this.getPageCount() - this.toolBarDisplay;
 
         if (pageCountLimitPerPageDiff < 0) { 
             return 0; 
         }
 
-        if (this.page > pageCountLimitPerPageDiff + 1) { 
+        if (this.getPage() > pageCountLimitPerPageDiff + 1) { 
             return pageCountLimitPerPageDiff; 
         } 
 
-        var low = this.page - (Math.ceil(this.limitPerPage/2) - 1); 
+        var low = this.getPage() - (Math.ceil(this.toolBarDisplay/2) - 1); 
 
         return Math.max(low, 0);
     };
 })
 
+
 /*this is just a hack - there should be better way */
 .service('ValidDate', function(){    
     var dateValidation;    
@@ -832,7 +821,7 @@
                     }        
                 });                
             });
-            return {headers: attributes, rows: entityList};                                    
+            return {headers: attributes, rows: entityList, pager: grid.metaData.pager};                                    
         }        
     };
 })

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2014-06-30 05:56:38 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/tracker-capture.js	2014-06-30 13:16:30 +0000
@@ -134,7 +134,7 @@
 
     //drop down menu for program selection
     $("#selectDropDown").width($("#selectDropDownParent").width());
-    $("#selectDropDown").css('margin-right: -15x;');
+    $("#selectDropDown").css('margin-right: 15x;');
     $(".select-drop-down-button").on('click', function(e) {
         e.stopPropagation();
         $("#selectDropDown").dropdown('toggle');

=== removed file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/pagination.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/pagination.html	2014-05-26 08:08:05 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/pagination.html	1970-01-01 00:00:00 +0000
@@ -1,53 +0,0 @@
-<div class="paging-container">
-    <table style="background-color: #ebf0f6;" width='100%'>
-        <tr>
-            <td>
-                {{'total_number_of_pages'| translate}}: {{paginator.pageCount()}}
-            </td>
-            <td>
-                <span>{{'rows_per_page'| translate}}:</span> <input type="text" style="width:50px;" ng-model="rowsPerPage"> 
-            </td>
-            <td>
-                <span>{{'jump_to_page'| translate}}:</span> <input type="text" style="width:50px;" ng-model="currentPage" value="{{paginator.page + 1}}" ng-blur="jumpToPage(currentPage)"> 
-            </td>
-        </tr>
-        <tr>
-            <td colspan="3"><hr/></td>
-        </tr>
-        <tr>
-            <td colspan="3">
-                <div class="paging">
-                    <span ng-show="(paginator.getPage() + 1) > 1">
-                        <a href ng-click="paginator.firstPage()" title="{{'first'| translate}}"> 
-                            &laquo;&laquo;
-                        </a>
-                        <a href ng-click="paginator.perviousPage()" title="{{'previous'| translate}}"> 
-                            &laquo;
-                        </a>                    
-                    </span>
-                    <span ng-hide="(paginator.getPage() + 1) > 1">
-                        <span title="{{'first'| translate}}">&laquo;&laquo;</span>
-                        <span title="{{'previous'| translate}}">&laquo;</span>
-                    </span>
-                    <a href ng-click="paginator.setPage(i)" title="{{'page'| translate}} {{i + 1}}" ng-repeat="i in []| forLoop:paginator.lowerLimit():paginator.pageCount() | limitTo : paginator.limitPerPage" ng-class="paginator.getPage() == i && 'active'">
-                        {{i + 1}}
-                    </a>
-
-                    <span ng-show="(paginator.getPage() + 1) < paginator.pageCount()">
-                        <a href ng-click="paginator.nextPage()" title="{{'next'| translate}}" > 
-                            &raquo;
-                        </a>
-                        <a href ng-click="paginator.lastPage()" title="{{'last'| translate}}"> 
-                            &raquo;&raquo;
-                        </a>
-                    </span>
-                    <span ng-hide="(paginator.getPage() + 1) < paginator.pageCount()">
-                        <span class="next" title="{{'next'| translate}}">&raquo; </span>
-                        <span class="last" title="{{'last'| translate}}">&raquo;&raquo;</span>
-                    </span>
-
-                </div>
-            </td>
-        </tr>
-    </table>   
-</div>
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/serverside-pagination.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/serverside-pagination.html	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/serverside-pagination.html	2014-06-30 13:16:30 +0000
@@ -0,0 +1,52 @@
+<div class="paging-container">
+    <table style="background-color: #ebf0f6;" width='100%'>
+        <tr>
+            <td>
+                {{'total_number_of_pages'| translate}}: {{pager.pageCount}}
+            </td>
+            <td>
+                <span>{{'rows_per_page'| translate}}:</span> <input type="text" style="width:50px;" ng-model="pager.pageSize" ng-blur="resetPageSize()"> 
+            </td>
+            <td>
+                <span>{{'jump_to_page'| translate}}:</span> <input type="text" style="width:50px;" ng-model="pager.page" ng-blur="jumpToPage()"> 
+            </td>
+        </tr>
+        <tr>
+            <td colspan="3"><hr/></td>
+        </tr>
+        <tr>
+            <td colspan="3">
+                <div class="paging">
+                    <span ng-show="pager.page > 1">
+                        <a href ng-click="getPage(1)" title="{{'first'| translate}}"> 
+                            &laquo;&laquo;
+                        </a>
+                        <a href ng-click="getPage(pager.page - 1)" title="{{'previous'| translate}}"> 
+                            &laquo;
+                        </a>                    
+                    </span>
+                    <span ng-hide="pager.page > 1">
+                        <span title="{{'first'| translate}}">&laquo;&laquo;</span>
+                        <span title="{{'previous'| translate}}">&laquo;</span>
+                    </span>
+                    <a href ng-click="getPage(i+1)" title="{{'page'| translate}} {{i + 1}}" ng-repeat="i in []| forLoop:paginator.lowerLimit():pager.pageCount | limitTo : pager.toolBarDisplay" ng-class="pager.page == i + 1 && 'active'">
+                        {{i + 1}}
+                    </a>
+
+                    <span ng-show="pager.page < pager.pageCount">
+                        <a href ng-click="getpage(pager.page + 1)" title="{{'next'| translate}}" > 
+                            &raquo;
+                        </a>
+                        <a href ng-click="getPage(pager.pageCount)" title="{{'last'| translate}}"> 
+                            &raquo;&raquo;
+                        </a>
+                    </span>
+                    <span ng-hide="pager.page < pager.pageCount">
+                        <span class="next" title="{{'next'| translate}}">&raquo; </span>
+                        <span class="last" title="{{'last'| translate}}">&raquo;&raquo;</span>
+                    </span>
+                </div>
+            </td>
+        </tr>
+    </table>   
+</div>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/tei.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/tei.html	2014-06-19 09:37:45 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/tei.html	2014-06-30 13:16:30 +0000
@@ -24,7 +24,7 @@
                             </tr>                        
                         </thead>
                         <tbody id="list">
-                            <tr ng-repeat="trackedEntity in trackedEntityList.rows| paginate:rowsPerPage" 
+                            <tr ng-repeat="trackedEntity in trackedEntityList.rows" 
                                 ng-click="showDashboard(trackedEntity)">
                                 <td ng-show="gridColumn.show"                                            
                                     ng-repeat="gridColumn in gridColumns">                                                
@@ -35,7 +35,7 @@
                     </table>
                 </div>
                 <!-- entity ends -->  
-                <paginator></paginator>                      
+                <serverside-paginator></serverside-paginator>                    
             </div>
         </div>                        
     </div>