Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Fix information about showed entries below paginated table. Closes #R… #297

Merged
merged 1 commit into from
Jul 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _partials/developer-materials-results.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
option(value="25") 25
label.inline entries
br
p Showing {{paginate.currentPage}} to {{paginate.currentPage + pagination.size}} of {{data.materials.length}} entries
p Showing {{(paginate.currentPage * pagination.size - pagination.size + 1) | safeNumber}} to {{ Math.min(data.materials.length, paginate.currentPage * pagination.size) | safeNumber}} of {{data.materials.length | safeNumber}} entries
.large-17.small-24.columns
nav#paginator(ng-hide="pagination.viewall || !data.materials.length || data.loading")
ul.pagination
Expand Down
18 changes: 18 additions & 0 deletions javascripts/developer-materials.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ dcp.filter('formatName',function(){
}
});

/**
* safeNumber is an "ng filter" that accept string value
* and convert to number (using radix of 10). If parsing
* fails (NaN) then 0 is returned.
*/
dcp.filter('safeNumber', function() {
return function(input) {
var n = parseInt(input, 10);
return isNaN(n) ? 0 : n;
}
});

dcp.controller('developerMaterialsController', function($scope, materialService) {

window.scope = $scope;
Expand All @@ -243,6 +255,12 @@ dcp.controller('developerMaterialsController', function($scope, materialService)
size : 10
};

// Add Math object to $scope so we can use it directly in Angular expressions
// like: {{ Math.min(data.materials.length, paginate.currentPage * pagination.size) }}
// This might not be clean technique from Angular perspective (more clear would be
// to do all required calculations in controller and not the view)
$scope.Math = Math;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goign to fix this - Math should not be passed into the scope


/*
Handle Pagination
*/
Expand Down