diff --git a/angular.html b/angular.html index daad12f..db9d8ed 100644 --- a/angular.html +++ b/angular.html @@ -489,6 +489,29 @@ + + + + diff --git a/js/ctrls/download.js b/js/ctrls/download.js index ef47012..a05fd4c 100644 --- a/js/ctrls/download.js +++ b/js/ctrls/download.js @@ -68,10 +68,55 @@ function( utils.mergeMap(data[0], scope.stopped, scope.getCtx); }); + // max downloads shown in one page + scope.pageSize = 10; + + // current displayed page + scope.currentPage = 1; + + // the number of page controls displayed, i.e for 3 it will show + // x - 1 | x | x + 1 + scope.maxPageControls = 3; + + // total number of downloads, updates dynamically as downloads are + // stored in scope + scope.totalDownloads = 0; + + // total maximum pages + scope.totalPages = 0; + // actual downloads used by the view scope.getDownloads = function() { - return scope.active - .concat(scope.waiting).concat(scope.stopped); + var downloads = scope.active + .concat( scope.waiting ).concat( scope.stopped ) + + scope.totalDownloads = downloads.length; + + scope.totalPages = Math.ceil(scope.totalDownloads / scope.pageSize) + + downloads = downloads.slice( (scope.currentPage - 1) * scope.pageSize ); + downloads.splice( scope.pageSize ); + + return downloads; + } + + scope.setPage = function(pageNumber) { + scope.currentPage = pageNumber; + return false; + } + + // get the pages to be displayed + scope.getPages = function() { + var minPage = scope.currentPage - scope.maxPageControls; + + if (minPage < 1) minPage = 1; + + var maxPage = scope.currentPage + scope.maxPageControls; + + if (maxPage > scope.totalPages) + maxPage = scope.totalPages; + + return _.range(minPage, maxPage + 1); } // convert the donwload form aria2 to once used by the view, @@ -145,7 +190,7 @@ function( }; scope.showSettings = function(d) { - var type = this.getType(d) + var type = scope.getType(d) , settings = {}; rpc.once('getOption', [d.gid], function(data) { diff --git a/js/filters/bytes.js b/js/filters/bytes.js index 37d0d9f..a60122c 100644 --- a/js/filters/bytes.js +++ b/js/filters/bytes.js @@ -3,7 +3,7 @@ angular .filter('changeLength', function() { return function(len, pref) { len = parseFloat(len); - if(len <= (1<<10)) return len.toFixed(1) + " " + pref; + if (len <= (1<<10)) return len.toFixed(1) + " " + pref; else if(len <= (1<<20)) return (len/(1<<10)).toFixed(1) + " K" + pref; else if(len <= (1<<30)) return (len/(1<<20)).toFixed(1) + " M" + pref; else return (len/(1<<30)).toFixed(1) + " G" + pref;