Skip to content

Commit 17b4f12

Browse files
committed
added pagination to client display, closes mitreid-connect#439
1 parent 5c861c4 commit 17b4f12

File tree

4 files changed

+174
-13
lines changed

4 files changed

+174
-13
lines changed

openid-connect-server-webapp/src/main/webapp/WEB-INF/tags/footer.tag

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<script type="text/javascript" src="resources/js/lib/purl.js"></script>
2222
<script type="text/javascript" src="resources/js/lib/bootstrapx-clickover.js"></script>
2323
<script type="text/javascript" src="resources/js/lib/moment.js"></script>
24-
<script type="text/javascript" src="resources/js/lib/retina.js"></script>
2524
<script type="text/javascript" src="resources/js/lib/bootstrap-sheet.js"></script>
25+
<script type="text/javascript" src="resources/js/lib/bootpag.js"></script>
2626
<c:if test="${js != null && js != ''}">
2727
<script type="text/javascript" src="resources/js/client.js"></script>
2828
<script type="text/javascript" src="resources/js/grant.js"></script>
@@ -32,5 +32,6 @@
3232
<script type="text/javascript" src="resources/js/token.js"></script>
3333
<script type="text/javascript" src="resources/js/admin.js"></script>
3434
</c:if>
35+
<script type="text/javascript" src="resources/js/lib/retina.js"></script>
3536
</body>
3637
</html>

openid-connect-server-webapp/src/main/webapp/resources/js/client.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ var ClientListView = Backbone.View.extend({
303303
"click .new-client":"newClient",
304304
"click .refresh-table":"refreshTable",
305305
'keyup .search-query':'searchTable',
306-
'click .form-search button':'clearSearch'
306+
'click .form-search button':'clearSearch',
307+
'page #paginator':'changePage'
307308
},
308309

309310
newClient:function (e) {
@@ -323,18 +324,36 @@ var ClientListView = Backbone.View.extend({
323324
},
324325

325326
renderInner:function(eventName) {
326-
327-
_.each(this.filteredModel.models, function (client) {
328-
$("#client-table",this.el).append(
329-
new ClientView({
330-
model:client,
331-
count:this.options.stats.get(client.get('id')),
332-
systemScopeList: this.options.systemScopeList,
333-
whiteList: this.options.whiteListList.getByClientId(client.get('clientId'))
334-
}).render().el);
327+
328+
// set up pagination
329+
var numPages = Math.ceil(this.filteredModel.length / 10);
330+
if (numPages > 1) {
331+
$('#paginator').show();
332+
$('#paginator', this.el).bootpag({
333+
total: numPages,
334+
page: 1
335+
});
336+
} else {
337+
$('#paginator', this.el).hide();
338+
}
339+
340+
// render the rows
341+
_.each(this.filteredModel.models, function (client, index) {
342+
var element = new ClientView({
343+
model:client,
344+
count:this.options.stats.get(client.get('id')),
345+
systemScopeList: this.options.systemScopeList,
346+
whiteList: this.options.whiteListList.getByClientId(client.get('clientId'))
347+
}).render().el;
348+
$("#client-table",this.el).append(element);
349+
if (Math.ceil((index + 1) / 10) != 1) {
350+
$(element).hide();
351+
}
335352
}, this);
336353

337-
this.togglePlaceholder();
354+
this.togglePlaceholder();
355+
356+
338357
},
339358

340359
togglePlaceholder:function() {
@@ -357,6 +376,18 @@ var ClientListView = Backbone.View.extend({
357376
}
358377
},
359378

379+
changePage:function(event, num) {
380+
this.page = num;
381+
$('#client-table tbody tr', this.el).each(function(index, element) {
382+
console.log([num, index]);
383+
if (Math.ceil((index + 1) / 10) != num) {
384+
$(element).hide();
385+
} else {
386+
$(element).show();
387+
}
388+
});
389+
},
390+
360391
refreshTable:function(e) {
361392
e.preventDefault();
362393
$('#loadingbox').sheet('show');
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* @preserve
3+
* bootpag - jQuery plugin for dynamic pagination
4+
*
5+
* Copyright (c) 2013 botmonster@7items.com
6+
*
7+
* Licensed under the MIT license:
8+
* http://www.opensource.org/licenses/mit-license.php
9+
*
10+
* Project home:
11+
* http://botmonster.com/jquery-bootpag/
12+
*
13+
* Version: 1.0.5
14+
*
15+
*/
16+
(function($, window) {
17+
18+
$.fn.bootpag = function(options){
19+
20+
var $owner = this,
21+
settings = $.extend({
22+
total: 0,
23+
page: 1,
24+
maxVisible: null,
25+
leaps: true,
26+
href: 'javascript:void(0);',
27+
hrefVariable: '{{number}}',
28+
next: '&raquo;',
29+
prev: '&laquo;'
30+
},
31+
$owner.data('settings') || {},
32+
options || {});
33+
34+
if(settings.total <= 0)
35+
return this;
36+
37+
if(!$.isNumeric(settings.maxVisible) && !settings.maxVisible){
38+
settings.maxVisible = settings.total;
39+
}
40+
41+
$owner.data('settings', settings);
42+
43+
function renderPage($bootpag, page){
44+
45+
var lp,
46+
maxV = settings.maxVisible == 0 ? 1 : settings.maxVisible,
47+
step = settings.maxVisible == 1 ? 0 : 1,
48+
vis = Math.floor((page - 1) / maxV) * maxV,
49+
$page = $bootpag.find('li');
50+
settings.page = page = page < 0 ? 0 : page > settings.total ? settings.total : page;
51+
$page.removeClass('disabled');
52+
lp = page - 1 < 1 ? 1 :
53+
settings.leaps && page - 1 >= settings.maxVisible ?
54+
Math.floor((page - 1) / maxV) * maxV : page - 1;
55+
$page
56+
.first()
57+
.toggleClass('disabled', page === 1)
58+
.attr('data-lp', lp)
59+
.find('a').attr('href', href(lp));
60+
61+
var step = settings.maxVisible == 1 ? 0 : 1;
62+
63+
lp = page + 1 > settings.total ? settings.total :
64+
settings.leaps && page + 1 < settings.total - settings.maxVisible ?
65+
vis + settings.maxVisible + step: page + 1;
66+
67+
$page
68+
.last()
69+
.toggleClass('disabled', page === settings.total)
70+
.attr('data-lp', lp)
71+
.find('a').attr('href', href(lp));;
72+
73+
var $currPage = $page.filter('[data-lp='+page+']');
74+
if(!$currPage.not('.next,.prev').length){
75+
var d = page <= vis ? -settings.maxVisible : 0;
76+
$page.not('.next,.prev').each(function(index){
77+
lp = index + 1 + vis + d;
78+
$(this)
79+
.attr('data-lp', lp)
80+
.toggle(lp <= settings.total)
81+
.find('a').html(lp).attr('href', href(lp));
82+
});
83+
$currPage = $page.filter('[data-lp='+page+']');
84+
}
85+
$currPage.addClass('disabled');
86+
$owner.data('settings', settings);
87+
}
88+
89+
function href(c){
90+
91+
return settings.href.replace(settings.hrefVariable, c);
92+
}
93+
94+
return this.each(function(){
95+
96+
var $bootpag, lp, me = $(this),
97+
p = ['<ul class="pagination bootpag">'];
98+
99+
if(settings.prev){
100+
p.push('<li data-lp="1" class="prev"><a href="'+href(1)+'">'+settings.prev+'</a></li>');
101+
}
102+
for(var c = 1; c <= Math.min(settings.total, settings.maxVisible); c++){
103+
p.push('<li data-lp="'+c+'"><a href="'+href(c)+'">'+c+'</a></li>');
104+
}
105+
if(settings.next){
106+
lp = settings.leaps && settings.total > settings.maxVisible
107+
? Math.min(settings.maxVisible + 1, settings.total) : 2;
108+
p.push('<li data-lp="'+lp+'" class="next"><a href="'+href(lp)+'">'+settings.next+'</a></li>');
109+
}
110+
p.push('</ul>');
111+
me.find('ul.bootpag').remove();
112+
me.append(p.join(''));
113+
$bootpag = me.find('ul.bootpag');
114+
me.find('li').click(function paginationClick(){
115+
116+
var me = $(this);
117+
if(me.hasClass('disabled')){
118+
return;
119+
}
120+
var page = parseInt(me.attr('data-lp'), 10);
121+
renderPage($bootpag, page);
122+
$owner.trigger('page', page);
123+
});
124+
renderPage($bootpag, settings.page);
125+
});
126+
}
127+
128+
})(jQuery, window);

openid-connect-server-webapp/src/main/webapp/resources/template/client.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
</tbody>
115115
</table>
116116

117+
<div id="paginator" class="pagination"> </div>
118+
117119
<div class="well well-small">
118120
<button class="btn btn-small refresh-table"><i class="icon-refresh"></i> Refresh</button> &nbsp;
119121
<button class="btn btn-small btn-primary new-client"><i class="icon-plus icon-white"></i> New Client</button>
@@ -708,4 +710,3 @@ <h1><%=(id == null ? 'New' : 'Edit')%> Client</h1>
708710
<% } %>
709711

710712
</script>
711-

0 commit comments

Comments
 (0)