[ 
https://issues.apache.org/jira/browse/SCB-698?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16529805#comment-16529805
 ] 

ASF GitHub Bot commented on SCB-698:
------------------------------------

asifdxtreme closed pull request #382: SCB-698 Fix for services count in 
pagination during search
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/382
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/frontend/app/scripts/directives/tableDirective.js 
b/frontend/app/scripts/directives/tableDirective.js
index 4bb138c5..898933bd 100644
--- a/frontend/app/scripts/directives/tableDirective.js
+++ b/frontend/app/scripts/directives/tableDirective.js
@@ -29,8 +29,9 @@ angular.module('serviceCenter')
                 dialogClose: '=dialogClose',
                 buttons: '=buttons',
                 enableSearch: '=search',
-                appList:'=appList',
-                apiInfo:'=apiInfo'
+                appList: '=appList',
+                apiInfo: '=apiInfo',
+                searchFn: '=searchFn'
             },
             templateUrl: 'scripts/views/tableData.html',
             link: function(scope) {
@@ -64,6 +65,7 @@ angular.module('serviceCenter')
                 scope.searchClose = function() {
                     scope.showSearch = false;
                     scope.filter.search = "";
+                    scope.refresh();
                 };
 
                 scope.searchOpen = function() {
@@ -81,6 +83,10 @@ angular.module('serviceCenter')
                 scope.remove = function(serviceId, instances) {
                     scope.removes(serviceId, instances)
                 };
+
+                scope.fnSearch = function(searchData) {
+                    scope.searchFn(searchData);
+                }
             }
         };
     }]);
diff --git 
a/frontend/app/scripts/modules/serviceCenter/controllers/servicesListCtrl.js 
b/frontend/app/scripts/modules/serviceCenter/controllers/servicesListCtrl.js
index 5f2c432d..8d492dac 100644
--- a/frontend/app/scripts/modules/serviceCenter/controllers/servicesListCtrl.js
+++ b/frontend/app/scripts/modules/serviceCenter/controllers/servicesListCtrl.js
@@ -16,154 +16,150 @@
  */
 'use strict';
 angular.module('serviceCenter.sc', [])
-       .controller('servicesListController', ['$scope', 'httpService', 
'apiConstant', 'commonService', '$stateParams', '$mdDialog',
-               function($scope, httpService, apiConstant, commonService, 
$stateParams, $mdDialog){
+    .controller('servicesListController', ['$scope', 'httpService', 
'apiConstant', 'commonService', '$stateParams', '$mdDialog',
+        function($scope, httpService, apiConstant, commonService, 
$stateParams, $mdDialog) {
 
-                       $scope.appList = 'fetching';
-                       $scope.serviceList = 'serviceList';
-                       $scope.rowsPerPage = [5, 10];
-                       
-                       $scope.tableHeaders = [
-                               {
-                                       'key': 'name'
-                               },
-                               {
-                                       'key': 'status'
-                               },
-                               {
-                                       'key': 'appId'
-                               },
-                               {
-                                       'key': 'version'
-                               },
-                               {
-                                       'key': 'createdAt'
-                               },
-                               {
-                                       'key': 'instances'
-                               },
-                               {
-                                       'key': 'operation'
-                               }
-                       ];
+            $scope.appList = 'fetching';
+            $scope.serviceList = 'serviceList';
+            $scope.rowsPerPage = [5, 10];
 
-                       $scope.refreshAppList = function() {
-                               
angular.element(document.querySelector('.fa-refresh')).addClass('fa-spin');
-                               $scope.getAllServices();
-                       };
+            $scope.tableHeaders = [{
+                    'key': 'name'
+                },
+                {
+                    'key': 'status'
+                },
+                {
+                    'key': 'appId'
+                },
+                {
+                    'key': 'version'
+                },
+                {
+                    'key': 'createdAt'
+                },
+                {
+                    'key': 'instances'
+                },
+                {
+                    'key': 'operation'
+                }
+            ];
 
-            var deleteService = function(response){
-               if(response == "yes"){
-                       $(".loader").show();
-                               var url = apiConstant.api.deleteService.url;
-                               var api =  url.replace("{{serviceId}}", 
$scope.deleteServiceId);
-                                       var method = 
apiConstant.api.deleteService.method;
-                                       httpService.apiRequest(api, method, 
null, null, null).then(function(response){
-                                               if(response && response.status 
== 200){
-                                                       $(".loader").hide();
-                                                       $scope.refreshAppList();
-                                                       
commonService.oneBtnMsg("prompt", "serviceDeletedSuccessfully")
-                                               }else{
-                                                       $(".loader").hide();
-                                                       
commonService.oneBtnMsg("error","unableToDeleteService")
-                                               }
-                                       },function(error){
-                                                       $(".loader").hide();
-                                                       
commonService.oneBtnMsg("error","unableToDeleteService")
-                                       })
-               }
+            $scope.refreshAppList = function() {
+                
angular.element(document.querySelector('.fa-refresh')).addClass('fa-spin');
+                $scope.services = [];
+                $scope.getAllServices();
             };
 
-                       $scope.removeService = function(serviceId, instances) {
-                               $scope.deleteServiceId = serviceId;
-                               if(instances == 0){
-                                       commonService.twoBtnMsg("warning", 
"areYouSureToDelete", deleteService);
-                               }else {
-                                       commonService.oneBtnMsg("prompt", 
"cannotDeleteServiceWhenInstanceIsAvailable");
-                               }
+            $scope.searchFn = function(value) {
+                $scope.services = $scope.servicesCopy.filter((service) => {
+                    return 
service.serviceName.toLowerCase().indexOf(value.toLowerCase()) >= 0;
+                });
+                $scope.appList = $scope.services.length <= 0 ? 'empty' : '';
+            }
+
+            var deleteService = function(response) {
+                if (response == "yes") {
+                    $(".loader").show();
+                    var url = apiConstant.api.deleteService.url;
+                    var api = url.replace("{{serviceId}}", 
$scope.deleteServiceId);
+                    var method = apiConstant.api.deleteService.method;
+                    httpService.apiRequest(api, method, null, null, 
null).then(function(response) {
+                        if (response && response.status == 200) {
+                            $(".loader").hide();
+                            $scope.refreshAppList();
+                            commonService.oneBtnMsg("prompt", 
"serviceDeletedSuccessfully")
+                        } else {
+                            $(".loader").hide();
+                            commonService.oneBtnMsg("error", 
"unableToDeleteService")
+                        }
+                    }, function(error) {
+                        $(".loader").hide();
+                        commonService.oneBtnMsg("error", 
"unableToDeleteService")
+                    })
+                }
+            };
+
+            $scope.removeService = function(serviceId, instances) {
+                $scope.deleteServiceId = serviceId;
+                if (instances == 0) {
+                    commonService.twoBtnMsg("warning", "areYouSureToDelete", 
deleteService);
+                } else {
+                    commonService.oneBtnMsg("prompt", 
"cannotDeleteServiceWhenInstanceIsAvailable");
+                }
+            };
+
+            $scope.getAllServices = function() {
+                var filter = '';
+                if ($stateParams.status) {
+                    filter = $stateParams.status;
+                }
+                var url = apiConstant.api.microservice.url;
+                var method = apiConstant.api.microservice.method;
+
+                httpService.apiRequest(url, method).then(function(response) {
+                    if (response && response.data && response.data.services) {
+                        $scope.services = [];
+                        $scope.servicesCopy = [];
+                        response.data.services.forEach(function(service) {
+                            if (filter && service.status === filter) {
+                                processService(service);
+                            }
+                            if (!filter) {
+                                processService(service);
+                            }
+                        });
+
+                        if ($scope.services.length <= 0) {
+                            $scope.appList = 'empty';
+                        } else {
+                            $scope.appList = '';
+                        }
+                        
angular.element(document.querySelector('.fa-refresh')).removeClass('fa-spin');
+                    } else {
+                        $scope.appList = 'empty';
+                    }
+                }, function(error) {
+                    
angular.element(document.querySelector('.fa-refresh')).removeClass('fa-spin');
+                    $scope.appList = 'failed';
+                })
             };
+            $scope.getAllServices();
+
+            function processService(service) {
+                var instanceApi = apiConstant.api.instances.url;
+                var instanceUrl = instanceApi.replace("{{serviceId}}", 
service.serviceId);
+                var instanceMethod = apiConstant.api.instances.method;
+                var headers = {
+                    "X-ConsumerId": service.serviceId
+                };
 
-                       $scope.getAllServices = function() {
-                               var filter = '';
-                               if($stateParams.status) {
-                                       filter = $stateParams.status;
-                               }
-                               var url = apiConstant.api.microservice.url;
-                               var method = 
apiConstant.api.microservice.method;
+                var servicesList = {
+                    serviceName: service.serviceName,
+                    status: service.status,
+                    appId: service.appId,
+                    version: service.version,
+                    createdAt: commonService.timeFormat(service.timestamp),
+                    instances: 0,
+                    operation: '',
+                    serviceId: service.serviceId,
+                    disableBtn: false
+                };
 
-                               httpService.apiRequest(url, 
method).then(function(response){
-                                       if(response && response.data && 
response.data.services){
-                                               $scope.services = [];
-                                               
response.data.services.forEach(function(service){
-                                                       var instanceApi = 
apiConstant.api.instances.url;
-                                                       var instanceUrl = 
instanceApi.replace("{{serviceId}}", service.serviceId);
-                                                       var instanceMethod = 
apiConstant.api.instances.method;
-                                                       var headers = 
{"X-ConsumerId": service.serviceId};
-                                                       if(filter && 
service.status === filter) {
-                                                               var 
servicesList = {
-                                                                       
serviceName: service.serviceName,
-                                                                       status: 
service.status,
-                                                                       appId: 
service.appId,
-                                                                       
version: service.version,
-                                                                       
createdAt: commonService.timeFormat(service.timestamp),
-                                                                       
instances: 0,
-                                                                       
operation: '',
-                                                                       
serviceId: service.serviceId,
-                                                                       
disableBtn: false
-                                                               };
-                                                               
httpService.apiRequest(instanceUrl, instanceMethod, null, headers, 
null).then(function(resp){
-                                                                       if(resp 
&& resp.data && resp.data.instances){
-                                                                          
servicesList.instances = resp.data.instances.length;
-                                                                          
if(servicesList.instances > 0){
-                                                                               
        servicesList.disableBtn = true;
-                                                                          }
-                                                                       }
-                                                               });
-                                                       
-                                                               
$scope.services.push(servicesList);
-                                                       }
-                                                       if(!filter){
-                                                               var 
servicesList = {
-                                                                       
serviceName: service.serviceName,
-                                                                       status: 
service.status,
-                                                                       appId: 
service.appId,
-                                                                       
version: service.version,
-                                                                       
createdAt: commonService.timeFormat(service.timestamp),
-                                                                       
instances: 0,
-                                                                       
operation: '',
-                                                                       
serviceId: service.serviceId,
-                                                                       
disableBtn: false
-                                                               };
-                                                               
httpService.apiRequest(instanceUrl, instanceMethod, null, headers, 
null).then(function(resp){
-                                                                       if(resp 
&& resp.data && resp.data.instances){
-                                                                          
servicesList.instances = resp.data.instances.length;
-                                                                          
if(servicesList.instances > 0){
-                                                                               
        servicesList.disableBtn = true;
-                                                                          }
-                                                                       }
-                                                               });
-                                                       
-                                                               
$scope.services.push(servicesList);
-                                                       }
-                                               });
+                httpService.apiRequest(instanceUrl, instanceMethod, null, 
headers, null).then(function(resp) {
+                    if (resp && resp.data && resp.data.instances) {
+                        servicesList.instances = resp.data.instances.length;
+                        if (servicesList.instances > 0) {
+                            servicesList.disableBtn = true;
+                        }
+                    }
+                }, (error) => {
+                    servicesList.disableBtn = false;
+                });
+                $scope.services.push(servicesList);
+                $scope.servicesCopy.push(servicesList);
+            }
 
-                                               if($scope.services.length <= 0){
-                                                       $scope.appList = 
'empty';
-                                               }
-                                               else {
-                                                       $scope.appList = '';
-                                               }
-                                               
angular.element(document.querySelector('.fa-refresh')).removeClass('fa-spin');
-                                       }
-                                       else {
-                                               $scope.appList = 'empty';
-                                       }
-                               },function(error){
-                                       
angular.element(document.querySelector('.fa-refresh')).removeClass('fa-spin');
-                                       $scope.appList = 'failed';
-                               })
-                       };
-               
-                       $scope.getAllServices();
-               
-       }]);
+        }
+    ]);
\ No newline at end of file
diff --git a/frontend/app/scripts/modules/serviceCenter/views/servicesList.html 
b/frontend/app/scripts/modules/serviceCenter/views/servicesList.html
index 0022b300..7677229a 100644
--- a/frontend/app/scripts/modules/serviceCenter/views/servicesList.html
+++ b/frontend/app/scripts/modules/serviceCenter/views/servicesList.html
@@ -15,5 +15,4 @@
 limitations under the License.
 -->
 
-<table-data headers='tableHeaders' heading='serviceList' 
pagination='rowsPerPage' data='services' search='true' refresh='refreshAppList' 
-removes="removeService" app-list='appList'></table-data>
+<table-data headers='tableHeaders' heading='serviceList' 
pagination='rowsPerPage' data='services' search='true' refresh='refreshAppList' 
removes="removeService" app-list='appList' search-fn='searchFn'></table-data>
\ No newline at end of file
diff --git a/frontend/app/scripts/views/tableData.html 
b/frontend/app/scripts/views/tableData.html
index d93ad685..6de5c234 100644
--- a/frontend/app/scripts/views/tableData.html
+++ b/frontend/app/scripts/views/tableData.html
@@ -15,7 +15,7 @@
 limitations under the License.
 -->
 <md-content>
-       <md-card>
+    <md-card>
         <md-toolbar class="table-header">
             <div class="md-toolbar-tools">
                 {{heading | translate}}
@@ -29,57 +29,56 @@
             </div>
         </md-toolbar>
         <md-toolbar class="md-table-toolbar md-raised md-default" 
ng-if="showSearch">
-          <div class="md-toolbar-tools">
-            <form flex name="filter.form" class="no-padding" >
-              <input id="search" class="form-control" type="search" 
ng-model="filter.search" autofocus 
-              placeholder="{{ 'search' | translate }}" autocomplete="off">
-            </form>
-            <md-button class="md-icon-button"  aria-label="{{ 'close' | 
translate }}" title="{{ 'close' | translate }}">
-              <md-icon><i class="fa fa-close fa-lg" ng-click="searchClose()" 
></i></md-icon>
-            </md-button>
-          </div>
+            <div class="md-toolbar-tools">
+                <form flex name="filter.form" class="no-padding">
+                    <input id="search" class="form-control" type="search" 
ng-model="filter.search" ng-change="fnSearch(filter.search)" autofocus 
placeholder="{{ 'search' | translate }}" autocomplete="off">
+                </form>
+                <md-button class="md-icon-button" aria-label="{{ 'close' | 
translate }}" title="{{ 'close' | translate }}">
+                    <md-icon><i class="fa fa-close fa-lg" 
ng-click="searchClose()"></i></md-icon>
+                </md-button>
+            </div>
         </md-toolbar>
         <fetching-no-data data="appList" info="apiInfo"></fetching-no-data>
-        <md-table-container  ng-if="appList == ''" >
+        <md-table-container ng-if="appList == ''">
             <table data-md-table>
                 <thead md-head>
-                    <tr md-row>
-                        <th md-column ng-repeat="header in headers">
-                            {{ header.key | translate }}
-                        </th>
-                    </tr>
+                <tr md-row>
+                    <th md-column ng-repeat="header in headers">
+                        {{ header.key | translate }}
+                    </th>
+                </tr>
                 </thead>
                 <tbody>
-                    <tr md-row md-select="appData" id="target" 
data-ng-repeat="appData in data | filter: filter.search | orderBy: 
'serviceName' | limitTo: paginationQuery.limit : (paginationQuery.page - 1) * 
paginationQuery.limit">
-                        <td md-cell ng-repeat="(key, value) in appData">
+                <tr md-row md-select="appData" id="target" 
data-ng-repeat="appData in data | orderBy: 'serviceName' | limitTo: 
paginationQuery.limit : (paginationQuery.page - 1) * paginationQuery.limit">
+                    <td md-cell ng-repeat="(key, value) in appData">
                             <span ng-if="key == 'serviceName'">
                                 <a 
ui-sref="sc.info.instance({serviceId:'{{appData.serviceId}}'})">{{appData.serviceName}}</a>
                             </span>
-                            <span ng-if="key == 'status'">
+                        <span ng-if="key == 'status'">
                                 <div ng-if="value == 'UP'" 
class="serviceStatus up" ng-class="{'outofservice' : appData.instances == 
0}">{{value}}</div>
                                 <div ng-if="value == 'DOWN'" 
class="serviceStatus down">{{value}}</div>
                                 <div ng-if="value == 'STARTING'" 
class="serviceStatus starting">{{value}}</div>
                                 <div ng-if="value == 'OUTOFSERVICE'" 
class="serviceStatus outofservice">{{value}}</div>
                             </span>
-                            <span ng-if="key == 'operation'">
+                        <span ng-if="key == 'operation'">
                                 <md-button class="md-icon-button" 
ng-disabled="appData.instances != 0" ng-click="remove(appData.serviceId, 
appData.instances)" aria-label="{{ 'delete' | translate }}" title="{{ 'delete' 
| translate }}">
                                     <span class="glyphicon 
glyphicon-trash"></span>
-                                </md-button>
+                            </md-button>
                             </span>
-                            <span ng-if="key == 'address'">
+                        <span ng-if="key == 'address'">
                                 <span ng-repeat="endpoints in value track by 
$index">
                                     <li>{{endpoints}}</li>
                                 </span>
                             </span>
-                            <span ng-if="key != 'serviceId' && key != 
'serviceName' && key != 'disableBtn' && key != 'address' && key != 'operation' 
&& key !='status'">
+                        <span ng-if="key != 'serviceId' && key != 
'serviceName' && key != 'disableBtn' && key != 'address' && key != 'operation' 
&& key !='status'">
                                 {{value}}
                             </span>
-                        </td>
-                    </tr>
+                    </td>
+                </tr>
                 </tbody>
             </table>
         </md-table-container>
-         <md-table-pagination ng-if="(data && (data.length != 0))" 
class="pagination-class" md-limit="paginationQuery.limit" 
md-limit-options="pagination" md-page="paginationQuery.page" 
md-total="{{data.length}}" md-page-select="paginationOptions.pageSelect" 
md-boundary-links="paginationOptions.boundaryLinks" md-label="{page: 'Page:', 
rowsPerPage: 'Rows Per Page:', of: '&nbsp of &nbsp'}">
+        <md-table-pagination ng-if="(data && (data.length != 0))" 
class="pagination-class" md-limit="paginationQuery.limit" 
md-limit-options="pagination" md-page="paginationQuery.page" 
md-total="{{data.length}}" md-page-select="paginationOptions.pageSelect" 
md-boundary-links="paginationOptions.boundaryLinks" md-label="{page: 'Page:', 
rowsPerPage: 'Rows Per Page:', of: '&nbsp of &nbsp'}">
         </md-table-pagination>
-       </md-card>
+    </md-card>
 </md-content>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Pagination displays total count of data and not the filtered count
> ------------------------------------------------------------------
>
>                 Key: SCB-698
>                 URL: https://issues.apache.org/jira/browse/SCB-698
>             Project: Apache ServiceComb
>          Issue Type: Bug
>          Components: Service-Center
>    Affects Versions: service-center-1.0.0-m1
>            Reporter: Mohammad Asif Siddiqui
>            Assignee: Mohammad Asif Siddiqui
>            Priority: Major
>             Fix For: service-center-1.0.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to