Skip to content

Commit

Permalink
Merge pull request #1018 from hashmapinc/Tempus-971-Device-Pagination
Browse files Browse the repository at this point in the history
Tempus 971 device pagination
  • Loading branch information
shgupta22 committed Jan 16, 2019
2 parents 738f3db + b27f038 commit 492d3d9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
3 changes: 3 additions & 0 deletions ui/src/app/api/device.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function DeviceService($http, $q, $window, userService, attributeService, custom

function getTenantDevices(pageLink, applyCustomersInfo, config, type, pageNum) {
var deferred = $q.defer();
if(angular.isDefined(type) && type == 'Gateway') {
pageNum = 0;
}
var url = '/api/tenant/devices?limit=' + pageLink.limit + '&pageNum=' + pageNum;
if (angular.isDefined(pageLink.textSearch)) {
url += '&textSearch=' + pageLink.textSearch;
Expand Down
15 changes: 13 additions & 2 deletions ui/src/app/components/grid.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function GridController($scope, $rootScope, $state, $mdDialog, $document, $q, $m
}

var pageSize = 10 * columns;
var pageNumber = 1;

vm.columns = columns;

Expand Down Expand Up @@ -210,11 +211,18 @@ function GridController($scope, $rootScope, $state, $mdDialog, $document, $q, $m

fetchMoreItems_: function () {
if (vm.items.hasNext && !vm.items.pending) {
var promise = vm.fetchItemsFunc(vm.items.nextPageLink, $scope.searchConfig.searchEntitySubtype);
var promise;
//Pagination is implmented for device only
if(angular.isDefined(vm.config.entityType) && vm.config.entityType === 'device'){
promise = vm.fetchItemsFunc(vm.items.nextPageLink, $scope.searchConfig.searchEntitySubtype,pageNumber);
} else {
promise = vm.fetchItemsFunc(vm.items.nextPageLink, $scope.searchConfig.searchEntitySubtype);
}
if (promise) {
vm.items.pending = true;
promise.then(
function success(items) {
pageNumber = pageNumber + 1;
if (vm.items.reloadPending) {
vm.items.pending = false;
reload();
Expand Down Expand Up @@ -295,7 +303,9 @@ function GridController($scope, $rootScope, $state, $mdDialog, $document, $q, $m
}
itemRow.push(item);
}
vm.items.nextPageLink = items.nextPageLink;
if(items.nextPageLink) {
vm.items.nextPageLink = items.nextPageLink;
}
vm.items.hasNext = items.hasNext;
if (vm.items.hasNext) {
vm.items.nextPageLink.limit = pageSize;
Expand Down Expand Up @@ -557,6 +567,7 @@ function GridController($scope, $rootScope, $state, $mdDialog, $document, $q, $m
function refreshList() {
let preservedTopIndex = vm.topIndex;
vm.items.data.length = 0;
pageNumber = 1;
vm.items.rowData.length = 0;
vm.items.nextPageLink = {
limit: preservedTopIndex + pageSize,
Expand Down
36 changes: 16 additions & 20 deletions ui/src/app/device/device.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function DeviceController($rootScope,userService, deviceService, customer
search: null
};


var pageNumber = 1;
vm.deviceGridConfig = {
deleteItemTitleFunc: deleteDeviceTitle,
deleteItemContentFunc: deleteDeviceText,
Expand All @@ -90,6 +90,7 @@ export function DeviceController($rootScope,userService, deviceService, customer
deleteItemsContentFunc: deleteDevicesText,

saveItemFunc: saveDevice,
entityType: 'device',

getItemTitleFunc: getDeviceTitle,

Expand Down Expand Up @@ -154,13 +155,8 @@ export function DeviceController($rootScope,userService, deviceService, customer
}

if (vm.devicesScope === 'tenant') {
fetchDevicesFunction = function (pageLink, deviceType) {
if($scope.query.page == 1){
return deviceService.getTenantDevices(pageLink, true, null, deviceType,0);
}else {
return deviceService.getTenantDevices(pageLink, true, null, deviceType,$scope.query.page - 1);
}

fetchDevicesFunction = function (pageLink, deviceType,pageNumber) {
return deviceService.getTenantDevices(pageLink, true, null, deviceType,pageNumber - 1);
};
deleteDeviceFunction = function (deviceId) {
return deviceService.deleteDevice(deviceId);
Expand Down Expand Up @@ -247,13 +243,8 @@ export function DeviceController($rootScope,userService, deviceService, customer


} else if (vm.devicesScope === 'customer' || vm.devicesScope === 'customer_user') {
fetchDevicesFunction = function (pageLink, deviceType) {
if($scope.query.page == 1){
return deviceService.getCustomerDevices(customerId, pageLink, true, null, deviceType, 0);
}else{
return deviceService.getCustomerDevices(customerId, pageLink, true, null, deviceType, $scope.query.page - 1);
}

fetchDevicesFunction = function (pageLink, deviceType,pageNumber) {
return deviceService.getCustomerDevices(customerId, pageLink, true, null, deviceType, pageNumber - 1);
};
deleteDeviceFunction = function (deviceId) {
return deviceService.unassignDeviceFromCustomer(deviceId);
Expand Down Expand Up @@ -334,12 +325,16 @@ export function DeviceController($rootScope,userService, deviceService, customer

}

loadTableData();
if($scope.tableView){
loadTableData();
}


function loadTableData() {
var promise = vm.deviceGridConfig.fetchItemsFunc({limit: $scope.query.limit, textSearch: ''}, false);
var promise = vm.deviceGridConfig.fetchItemsFunc({limit: $scope.query.limit, textSearch: ''}, false, pageNumber);
if(promise) {
promise.then(function success(items) {
$scope.devices.data = [];
var deviceSortList = $filter('orderBy')(items.data, $scope.query.order);
if ($scope.query.search != null) {

Expand Down Expand Up @@ -378,15 +373,15 @@ export function DeviceController($rootScope,userService, deviceService, customer
}

$scope.resetFilter = function() {

$scope.query = {
order: 'name',
limit: $scope.query.limit,
page: 1,
search: null
};

loadTableData();
if($scope.tableView) {
loadTableData();
}
}

vm.loadTableData = loadTableData;
Expand All @@ -404,6 +399,7 @@ export function DeviceController($rootScope,userService, deviceService, customer

$scope.onPaginate = function(page) {
$scope.query.page = page;
pageNumber = page;
loadTableData();
}

Expand Down

0 comments on commit 492d3d9

Please sign in to comment.