Page size selector

This commit is contained in:
jendib 2015-03-02 00:07:42 +01:00
parent 6edae27d26
commit 5cf0532db7
4 changed files with 38 additions and 9 deletions

View File

@ -11,7 +11,7 @@ angular.module('docs').controller('Document', function($scope, $timeout, $state,
$scope.asc = false;
$scope.offset = 0;
$scope.currentPage = 1;
$scope.limit = 10;
$scope.limit = _.isUndefined(localStorage.documentsPageSize) ? 10 : localStorage.documentsPageSize;
$scope.search = '';
// A timeout promise is used to slow down search requests to the server
@ -59,7 +59,7 @@ angular.module('docs').controller('Document', function($scope, $timeout, $state,
/**
* Watch for search scope change.
*/
$scope.$watch('search', function(prev, next) {
$scope.$watch('search', function() {
if (timeoutPromise) {
// Cancel previous timeout
$timeout.cancel(timeoutPromise);
@ -84,6 +84,17 @@ angular.module('docs').controller('Document', function($scope, $timeout, $state,
$scope.loadDocuments();
};
/**
* Watch for page size change.
*/
$scope.$watch('limit', function(next, prev) {
localStorage.documentsPageSize = next;
if (next == prev) {
return;
}
$scope.loadDocuments();
});
/**
* Go to add document form.
*/

View File

@ -3,7 +3,7 @@
/**
* Document edition controller.
*/
angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $q, $http, $state, $stateParams, Restangular, Tag) {
angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $q, $http, $state, $stateParams, Restangular) {
// Alerts
$scope.alerts = [];
@ -156,7 +156,7 @@ angular.module('docs').controller('DocumentEdit', function($rootScope, $scope, $
var then = function() {
key++;
if ($scope.newFiles[key]) {
sendFile(key).then(then);
sendFile(key).then(then); // TODO Handle upload error
} else {
$scope.fileIsUploading = false;
$scope.fileProgress = 0;

View File

@ -47,8 +47,14 @@
</tbody>
</table>
<div class="text-center">
<div class="text-center pagination-box">
<pagination total-items="totalDocuments" max-size="5" page="currentPage"></pagination>
<label class="sr-only" for="pagesizeSelect">Page size</label>
<select ng-model="limit" id="pagesizeSelect" class="form-control">
<option value="10">10 per page</option>
<option value="20">20 per page</option>
<option value="30">30 per page</option>
</select>
</div>
<div class="text-right">

View File

@ -136,9 +136,21 @@ input[readonly].share-link {
}
// Pagination
.pagination {
ul > li {
cursor: pointer;
.pagination > .active > a {
cursor: pointer !important;
}
// Pagination box
.pagination-box {
pagination {
vertical-align: top;
}
select {
vertical-align: top;
width: auto;
display: inline-block;
margin: 20px 0;
}
}