Use angular-ui pagination

This commit is contained in:
Nils Maier 2014-02-24 07:46:11 +01:00
parent a773d03dc4
commit 6027005616
3 changed files with 33 additions and 63 deletions

View File

@ -1,3 +1,7 @@
.pagination ul > li:not(.disabled) {
cursor: pointer;
}
.pagination ul > li.active > a { .pagination ul > li.active > a {
color: #fff; color: #fff;
background-color: #428bca; background-color: #428bca;

View File

@ -276,6 +276,22 @@
</fieldset> </fieldset>
</form> </form>
<span class="clearfix"></span>
<div class="pagination pagination-right" ng-show="totalDownloads > pageSize">
<pagination
total-items="totalDownloads"
items-per-page="pageSize"
max-size="6"
page="currentPage"
boundary-links="true"
previous-text="&lsaquo;"
next-text="&rsaquo;"
first-text="&laquo;"
last-text="&raquo;"
>
</pagination>
</div>
<table <table
ng-repeat="download in getDownloads()" ng-repeat="download in getDownloads()"
@ -531,34 +547,18 @@
<!-- {{{ download pagination --> <!-- {{{ download pagination -->
<div class="pagination pagination-right" ng-show="totalDownloads > pageSize"> <div class="pagination pagination-right" ng-show="totalDownloads > pageSize">
<ul> <pagination
<li total-items="totalDownloads"
ng-class="{disabled: currentPage == 1}" items-per-page="pageSize"
ng-click="setPage(1)"> max-size="6"
<a href="#">&laquo;</a> page="currentPage"
</li> boundary-links="true"
<li previous-text="&lsaquo;"
ng-class="{disabled: currentPage == 1}" next-text="&rsaquo;"
ng-click="advancePage(-1)"> first-text="&laquo;"
<a href="#"></a> last-text="&raquo;"
</li> >
<li </pagination>
ng-repeat="page in getPages()"
ng-class="{active: currentPage == page}"
ng-click="setPage(page)">
<a href="#">{{page}}</a>
</li>
<li
ng-class="{disabled: currentPage == totalPages}"
ng-click="advancePage(1)">
<a href="#"></a>
</li>
<li
ng-class="{disabled: currentPage == totalPages}"
ng-click="setPage(totalPages)">
<a href="#">&raquo;</a>
</li>
</ul>
</div> </div>
<!-- }}} --> <!-- }}} -->

View File

@ -1,5 +1,6 @@
angular angular
.module('webui.ctrls.download', [ .module('webui.ctrls.download', [
"ui.bootstrap",
'webui.services.utils', 'webui.services.rpc', 'webui.services.alerts', 'webui.services.utils', 'webui.services.rpc', 'webui.services.alerts',
'webui.services.settings', 'webui.services.modals' 'webui.services.settings', 'webui.services.modals'
]) ])
@ -171,11 +172,6 @@ function(
// current displayed page // current displayed page
scope.currentPage = 1; scope.currentPage = 1;
scope.pageControlRadius = 3;
// total maximum pages
scope.totalPages = 0;
// total amount of downloads returned by aria2 // total amount of downloads returned by aria2
scope.totalAria2Downloads = function() { scope.totalAria2Downloads = function() {
return scope.active.length return scope.active.length
@ -219,42 +215,12 @@ function(
scope.totalDownloads = downloads.length; scope.totalDownloads = downloads.length;
scope.totalPages = Math.ceil(scope.totalDownloads / scope.pageSize) || 1;
// fix the bug when downloads are deleted until no left on a specific page
if (scope.currentPage > scope.totalPages)
scope.currentPage = scope.totalPages;
downloads = downloads.slice( (scope.currentPage - 1) * scope.pageSize ); downloads = downloads.slice( (scope.currentPage - 1) * scope.pageSize );
downloads.splice( scope.pageSize ); downloads.splice( scope.pageSize );
return downloads; return downloads;
} }
scope.setPage = function(pageNumber) {
scope.currentPage = pageNumber;
scope.currentPage = Math.max(Math.min(scope.currentPage, scope.totalPages), 1);
return false;
};
scope.advancePage = function(num) {
return scope.setPage(scope.currentPage + num);
};
// get the pages to be displayed
scope.getPages = function() {
var minPage = scope.currentPage - scope.pageControlRadius;
if (minPage < 1) minPage = 1;
var maxPage = scope.currentPage + scope.pageControlRadius;
if (maxPage > scope.totalPages)
maxPage = scope.totalPages;
return _.range(minPage, maxPage + 1);
}
// convert the donwload form aria2 to once used by the view, // convert the donwload form aria2 to once used by the view,
// minor additions of some fields and checks // minor additions of some fields and checks
scope.getCtx = function(d, ctx) { scope.getCtx = function(d, ctx) {