Skip to content

Commit

Permalink
Merge pull request #28 from timl/paginate_node
Browse files Browse the repository at this point in the history
Paginate reports in node detail view
  • Loading branch information
dalen committed Jul 3, 2015
2 parents 71909f4 + c08c484 commit 025ff8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/controllers/nodedetail/nodedetail.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@ angular.module("app").controller "NodeDetailCtrl", class
constructor: (@$location, @$routeParams, @$scope, @PuppetDB) ->
@node = @$routeParams.node
# Reload nodes if either the page changes
@$scope.$on('pageChange', @reset)
@$scope.$on('pageChange', @fetchReports)
@$scope.perPage = 10
@reset()

reset: =>
@reports = undefined
@$location.search('page', null)
@$scope.numItems = undefined
@fetchReports()
@fetchFacts()

# Public: Fetches reports for node and stores them in @reports
fetchReports: () =>
@reports = @PuppetDB.parseAndQuery(
"reports"
null
@$location.search().query
["=", "certname", @node]
{
'order-by': angular.toJson([field: "end-time", order: "desc"])
'limit': 10
'offset': @$scope.perPage * ((@$location.search().page || 1) - 1)
'limit': @$scope.perPage
}
(data, total) =>
@reports = data
@$scope.numItems = total
@reports.forEach (report) =>
@PuppetDB.parseAndQuery(
"event-counts"
Expand Down
1 change: 1 addition & 0 deletions app/controllers/nodedetail/nodedetail.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h3>{{nodeDetail.node}}</h3>
</tr>
</tbody>
</table>
<pagination ng-if="numItems > 10" ng-change="changePage(page)" ng-model="page" num-pages="numPages" items-per-page="10" boundary-links="numItems > 250" max-size="5" total-items="numItems" rotate="false" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="&laquo;" last-text="&raquo;">
</div>
</div>
<div class="col-md-6" ng-if="nodeDetail.facts">
Expand Down

0 comments on commit 025ff8e

Please sign in to comment.