Skip to content

Commit

Permalink
Extracting changeSorting into the Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
lexandro committed Jun 14, 2015
1 parent e7edf34 commit ae20355
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
23 changes: 2 additions & 21 deletions app/containers/containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ angular.module('containers', ['ngRoute'])
$scope.showAllContainersFlag = false;
$scope.showContainerSizeFlag = false;
$scope.selectAllFlag = false;
var sort = {};
//
var sort = {};
sort.column = 'Id'
sort.direction = 'ascending';
sort.desc = false;
$scope.sort = sort;
console.log(JSON.stringify(sort));
//
refreshContainers();
//
Expand Down Expand Up @@ -182,26 +181,8 @@ angular.module('containers', ['ngRoute'])
};

$scope.changeSorting = function (column) {
var sort = $scope.sort;
if (sort.column === column) {
if (sort.direction === 'ascending') {
sort.direction = 'descending';
sort.desc = true;
} else if (sort.direction === 'descending') {
sort.column = null;
sort.direction = null;
sort.desc = null;
}
} else {
sort.column = column;
sort.direction = 'ascending';
sort.desc = false;

}
$scope.sort = sort;
console.log(JSON.stringify(sort));
$scope.sort = Helpers.changeSorting($scope.sort, column);
};

}

function getContainerData(containerDataList, containerId) {
Expand Down
14 changes: 11 additions & 3 deletions app/images/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ angular.module('images', ['ngRoute'])
$location.path('/hosts');
} else {
//

$scope.showAllImagesFlag = false;
$scope.showUntaggedImagesFlag = false;
$scope.selectAllImagesFlag = false;
//
var sort = {};
sort.column = 'Id'
sort.direction = 'ascending';
sort.desc = false;
$scope.sort = sort;
//
refreshImages();


//
$scope.switchShowAllFlag = function () {
$scope.showAllImagesFlag = !$scope.showAllImagesFlag;
refreshImages();
Expand All @@ -39,6 +44,9 @@ angular.module('images', ['ngRoute'])
};
}

$scope.changeSorting = function (column) {
$scope.sort = Helpers.changeSorting($scope.sort, column);
};

$scope.removeSelectedImages = function () {
$scope.images.forEach(function (image) {
Expand Down
17 changes: 17 additions & 0 deletions app/shared/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ angular.module('services', [])
var rx = new RegExp('^\/?[a-zA-Z0-9][a-zA-Z0-9_.-]+$');

return rx.test(containerName);
},
changeSorting: function (sort, column) {
if (sort.column === column) {
if (sort.direction === 'ascending') {
sort.direction = 'descending';
sort.desc = true;
} else if (sort.direction === 'descending') {
sort.column = null;
sort.direction = null;
sort.desc = null;
}
} else {
sort.column = column;
sort.direction = 'ascending';
sort.desc = false;
}
return sort;
}
}
})
Expand Down

0 comments on commit ae20355

Please sign in to comment.