Skip to content

Commit

Permalink
add tests for lorenzofox3#276
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzofox3 committed Jan 14, 2015
1 parent bf0f0f5 commit 7e70bc8
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 357 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smart-table",
"version": "1.4.6",
"version": "1.4.7",
"homepage": "https://github.com/lorenzofox3/Smart-Table",
"authors": [
"lorenzofox3 <[email protected]>"
Expand Down
6 changes: 5 additions & 1 deletion changeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ function(tableState, tableController){
## version 1.4.6

* evaluate sort predicate as late as possible
* fix #262
* fix #262

## version 1.4.7

* fix #276
118 changes: 59 additions & 59 deletions dist/smart-table.debug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @version 1.4.5
* @version 1.4.7
* @license MIT
*/
(function (ng, undefined){
Expand Down Expand Up @@ -106,7 +106,7 @@ ng.module('smart-table')
if (pagination.number !== undefined) {
pagination.numberOfPages = filtered.length > 0 ? Math.ceil(filtered.length / pagination.number) : 1;
pagination.start = pagination.start >= filtered.length ? (pagination.numberOfPages - 1) * pagination.number : pagination.start;
filtered = filtered.slice(pagination.start, pagination.start + pagination.number);
filtered = filtered.slice(pagination.start, pagination.start + parseInt(pagination.number));
}
displaySetter($scope, filtered);
};
Expand Down Expand Up @@ -330,75 +330,75 @@ ng.module('smart-table')
}]);

ng.module('smart-table')
.directive('stPagination', function () {
return {
restrict: 'EA',
require: '^stTable',
scope: {
stItemsByPage: '=?',
stDisplayedPages: '=?'
},
templateUrl: function(element, attrs) {
if (attrs.stTemplate) {
return attrs.stTemplate;
}
return 'template/smart-table/pagination.html';
},
link: function (scope, element, attrs, ctrl) {

scope.stItemsByPage = scope.stItemsByPage ? +(scope.stItemsByPage) : 10;
scope.stDisplayedPages = scope.stDisplayedPages ? +(scope.stDisplayedPages) : 5;
.directive('stPagination', function () {
return {
restrict: 'EA',
require: '^stTable',
scope: {
stItemsByPage: '=?',
stDisplayedPages: '=?'
},
templateUrl: function (element, attrs) {
if (attrs.stTemplate) {
return attrs.stTemplate;
}
return 'template/smart-table/pagination.html';
},
link: function (scope, element, attrs, ctrl) {

scope.currentPage = 1;
scope.pages = [];
scope.stItemsByPage = scope.stItemsByPage ? +(scope.stItemsByPage) : 10;
scope.stDisplayedPages = scope.stDisplayedPages ? +(scope.stDisplayedPages) : 5;

function redraw() {
var paginationState = ctrl.tableState().pagination;
var start = 1;
var end;
var i;
scope.currentPage = Math.floor(paginationState.start / paginationState.number) + 1;
scope.currentPage = 1;
scope.pages = [];

start = Math.max(start, scope.currentPage - Math.abs(Math.floor(scope.stDisplayedPages / 2)));
end = start + scope.stDisplayedPages;
function redraw() {
var paginationState = ctrl.tableState().pagination;
var start = 1;
var end;
var i;
scope.currentPage = Math.floor(paginationState.start / paginationState.number) + 1;

if (end > paginationState.numberOfPages) {
end = paginationState.numberOfPages + 1;
start = Math.max(1, end - scope.stDisplayedPages);
}
start = Math.max(start, scope.currentPage - Math.abs(Math.floor(scope.stDisplayedPages / 2)));
end = start + scope.stDisplayedPages;

scope.pages = [];
scope.numPages = paginationState.numberOfPages;
if (end > paginationState.numberOfPages) {
end = paginationState.numberOfPages + 1;
start = Math.max(1, end - scope.stDisplayedPages);
}

for (i = start; i < end; i++) {
scope.pages.push(i);
}
}
scope.pages = [];
scope.numPages = paginationState.numberOfPages;

//table state --> view
scope.$watch(function () {
return ctrl.tableState().pagination;
}, redraw, true);
for (i = start; i < end; i++) {
scope.pages.push(i);
}
}

//scope --> table state (--> view)
scope.$watch('stItemsByPage', function () {
scope.selectPage(1);
});
//table state --> view
scope.$watch(function () {
return ctrl.tableState().pagination;
}, redraw, true);

scope.$watch('stDisplayedPages', redraw);
//scope --> table state (--> view)
scope.$watch('stItemsByPage', function () {
scope.selectPage(1);
});

//view -> table state
scope.selectPage = function (page) {
if (page > 0 && page <= scope.numPages) {
ctrl.slice((page - 1) * scope.stItemsByPage, scope.stItemsByPage);
}
};
scope.$watch('stDisplayedPages', redraw);

//select the first page
ctrl.slice(0, scope.stItemsByPage);
}
//view -> table state
scope.selectPage = function (page) {
if (page > 0 && page <= scope.numPages) {
ctrl.slice((page - 1) * scope.stItemsByPage, scope.stItemsByPage);
}
};
});

//select the first page
ctrl.slice(0, scope.stItemsByPage);
}
};
});

ng.module('smart-table')
.directive('stPipe', function () {
Expand Down
4 changes: 2 additions & 2 deletions dist/smart-table.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smart-table",
"version": "1.4.6",
"version": "1.4.7",
"description": "",
"main": "dist/smart-table.debug.js",
"scripts": {
Expand Down
Loading

0 comments on commit 7e70bc8

Please sign in to comment.