@@ -15,7 +15,8 @@ angular.module('topcoderX')
1515 totalPages : 1 ,
1616 initialized : false ,
1717 query : '' ,
18- lastKey : [ ]
18+ lastKey : [ ] ,
19+ pages : 1
1920 } ;
2021
2122 $scope . addUserMapping = function ( ) {
@@ -40,7 +41,14 @@ angular.module('topcoderX')
4041 config . isLoading = true ;
4142 UserMappingsService . search ( config . query , config . sortBy , config . sortDir , config . pageNumber , config . pageSize , config . lastKey [ config . pageNumber ] ) // eslint-disable-line max-len
4243 . then ( function ( res ) {
43- config . items = res . data . docs ;
44+ if ( config . query ) {
45+ config . allItems = res . data . docs ;
46+ config . items = config . allItems . slice ( 0 , config . pageSize ) ;
47+ config . pages = Math . ceil ( config . allItems . length / config . pageSize ) ;
48+ }
49+ else {
50+ config . items = res . data . docs ;
51+ }
4452 if ( res . data . lastKey && ( res . data . lastKey . githubLastKey || res . data . lastKey . gitlabLastKey ) ) {
4553 config . lastKey [ config . pageNumber + 1 ] = res . data . lastKey ;
4654 if ( ! config . pages || config . pages <= config . pageNumber ) {
@@ -122,21 +130,37 @@ angular.module('topcoderX')
122130 if ( pageNumber === 0 || pageNumber > $scope . tableConfig . pages ||
123131 ( pageNumber === $scope . tableConfig . pages &&
124132 $scope . tableConfig . pageNumber === pageNumber ) ) {
125- return false ;
133+ return false ;
126134 }
127135 $scope . tableConfig . pageNumber = pageNumber ;
128- $scope . getUserMappings ( ) ;
136+ if ( $scope . tableConfig . query && $scope . tableConfig . allItems ) {
137+ var start = ( $scope . tableConfig . pageNumber - 1 ) * $scope . tableConfig . pageSize - 1 ;
138+ if ( pageNumber === 1 ) {
139+ start = 0 ;
140+ }
141+ $scope . tableConfig . items = $scope . tableConfig . allItems . slice (
142+ start , $scope . tableConfig . pageSize ) ;
143+ $scope . tableConfig . initialized = true ;
144+ $scope . tableConfig . isLoading = false ;
145+ }
146+ else {
147+ $scope . getUserMappings ( ) ;
148+ }
129149 } ;
130150
131151 $scope . onSearchIconClicked = function ( ) {
132152 $scope . tableConfig . pageNumber = 1 ;
153+ $scope . tableConfig . pages = 1 ;
154+ $scope . tableConfig . allItems = [ ] ;
133155 $scope . getUserMappings ( ) ;
134156 } ;
135157
136158 $scope . onSearchReset = function ( ) {
137159 var config = $scope . tableConfig ;
138160 config . query = '' ;
139161 $scope . tableConfig . pageNumber = 1 ;
162+ $scope . tableConfig . pages = 1 ;
163+ $scope . tableConfig . allItems = [ ] ;
140164 $scope . getUserMappings ( ) ;
141165 } ;
142166
0 commit comments