Skip to content

Commit

Permalink
Fixed issue #186
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia committed Dec 25, 2015
1 parent a856b15 commit c76f11e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
39 changes: 26 additions & 13 deletions src/component/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ angular.module('ngTasty.component.table', [
.controller('TableController', function($scope, $attrs, $filter, tableConfig, tastyUtil) {
var listScopeToWatch, initTable, newScopeName, initStatus,
updateClientSideResource, updateServerSideResource, setDirectivesValues,
buildClientResource, buildUrl, paramsInitialCycle, initNow, loadOnInit;
buildClientResource, buildUrl, paramsInitialCycle, initNow, loadOnInit,
filterChangedPage;
var vm = this;
vm.$scope = $scope;
initStatus = {};
Expand Down Expand Up @@ -375,23 +376,20 @@ angular.module('ngTasty.component.table', [
updateServerSideResource = function (updateFrom) {
if (updateFrom === 'filters') {
if (Number.isInteger($scope.init.filterBase)) {
if ($scope.params.page !== $scope.init.filterBase) {
filterChangedPage = true;
}
$scope.params.page = $scope.init.filterBase;
}
}

// after filter
// change the page

$scope.url = buildUrl($scope.params, $scope.filters);
console.log('url : ' + updateFrom, $scope.url, $scope.params);


if ($scope.reload) {
$scope.reload = function () {
$scope.resourceCallback($scope.url, angular.copy($scope.params))
.then(function (resource) {
setDirectivesValues(resource);
});
};
}
if ((initNow || updateFrom === 'params') &&
!$scope.logs.updateServerSideResourceRunning) {
function updateServerSideResource () {
$scope.logs.updateServerSideResourceRunning = true;
var paramsObj = angular.copy($scope.params);
paramsObj.filters = $scope.filters;
Expand All @@ -401,6 +399,22 @@ angular.module('ngTasty.component.table', [
$scope.logs.updateServerSideResourceRunning = false;
});
}

if ($scope.reload) {
$scope.reload = updateServerSideResource;
}
if ((initNow || updateFrom === 'params') &&
!$scope.logs.updateServerSideResourceRunning) {

if ($scope.reload) {
if (!filterChangedPage) {
updateServerSideResource();
}
} else {
updateServerSideResource();
filterChangedPage = false;
}
}
};

// AngularJs $watch callbacks
Expand All @@ -417,7 +431,6 @@ angular.module('ngTasty.component.table', [
}
$scope.$watchCollection('params', function watchParams (newValue, oldValue){
if (newValue !== oldValue) {
console.log('params', newValue, oldValue)
// Run update resuorce only if we are on
// the second cycle or more of `params`
if (paramsInitialCycle === false) {
Expand Down
4 changes: 2 additions & 2 deletions src/component/test/table-server-side.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ describe('Component: table server side', function () {
$scope.$digest();
});

it('should return paramsObj with filter value', function () {
it('should return paramsObj with filter value ', function () {
$scope.filterBy = {
'name': 'mill',
'sf-location': ''
Expand All @@ -939,7 +939,7 @@ describe('Component: table server side', function () {
expect($scope.paramsUrl).toEqual('sort-by=name&sort-order=dsc&page=1&count=20&name=mill');
expect($scope.paramsObj.sortBy).toEqual('name');
expect($scope.paramsObj.sortOrder).toEqual('dsc');
expect($scope.paramsObj.page).toEqual(4);
expect($scope.paramsObj.page).toEqual(1);
expect($scope.paramsObj.count).toEqual(20);
expect($scope.paramsObj.thead).toEqual(true);
expect($scope.paramsObj.pagination).toEqual(true);
Expand Down

0 comments on commit c76f11e

Please sign in to comment.