@@ -15,7 +15,8 @@ angular.module('topcoderX')
15
15
totalPages : 1 ,
16
16
initialized : false ,
17
17
query : '' ,
18
- lastKey : [ ]
18
+ lastKey : [ ] ,
19
+ pages : 1
19
20
} ;
20
21
21
22
$scope . addUserMapping = function ( ) {
@@ -40,7 +41,14 @@ angular.module('topcoderX')
40
41
config . isLoading = true ;
41
42
UserMappingsService . search ( config . query , config . sortBy , config . sortDir , config . pageNumber , config . pageSize , config . lastKey [ config . pageNumber ] ) // eslint-disable-line max-len
42
43
. 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
+ }
44
52
if ( res . data . lastKey && ( res . data . lastKey . githubLastKey || res . data . lastKey . gitlabLastKey ) ) {
45
53
config . lastKey [ config . pageNumber + 1 ] = res . data . lastKey ;
46
54
if ( ! config . pages || config . pages <= config . pageNumber ) {
@@ -122,21 +130,37 @@ angular.module('topcoderX')
122
130
if ( pageNumber === 0 || pageNumber > $scope . tableConfig . pages ||
123
131
( pageNumber === $scope . tableConfig . pages &&
124
132
$scope . tableConfig . pageNumber === pageNumber ) ) {
125
- return false ;
133
+ return false ;
126
134
}
127
135
$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
+ }
129
149
} ;
130
150
131
151
$scope . onSearchIconClicked = function ( ) {
132
152
$scope . tableConfig . pageNumber = 1 ;
153
+ $scope . tableConfig . pages = 1 ;
154
+ $scope . tableConfig . allItems = [ ] ;
133
155
$scope . getUserMappings ( ) ;
134
156
} ;
135
157
136
158
$scope . onSearchReset = function ( ) {
137
159
var config = $scope . tableConfig ;
138
160
config . query = '' ;
139
161
$scope . tableConfig . pageNumber = 1 ;
162
+ $scope . tableConfig . pages = 1 ;
163
+ $scope . tableConfig . allItems = [ ] ;
140
164
$scope . getUserMappings ( ) ;
141
165
} ;
142
166
0 commit comments