[#53,#27,pagination][s]: pagination support (fixes #27).
* Also refactor to have doc count (which is dataset info) outside of query editor.
This commit is contained in:
@@ -12,6 +12,12 @@
|
|||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header .recline-results-info {
|
||||||
|
line-height: 28px;
|
||||||
|
margin-left: 20px;
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
.header .recline-query-editor {
|
.header .recline-query-editor {
|
||||||
float: right;
|
float: right;
|
||||||
margin: 4px;
|
margin: 4px;
|
||||||
@@ -25,6 +31,10 @@
|
|||||||
width: 30px;
|
width: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header .recline-query-editor .pagination a {
|
||||||
|
line-height: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
.data-view-container {
|
.data-view-container {
|
||||||
display: block;
|
display: block;
|
||||||
clear: both;
|
clear: both;
|
||||||
|
|||||||
32
src/view.js
32
src/view.js
@@ -62,6 +62,9 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
<li><a href="#{{id}}" class="btn">{{label}}</a> \
|
<li><a href="#{{id}}" class="btn">{{label}}</a> \
|
||||||
{{/views}} \
|
{{/views}} \
|
||||||
</ul> \
|
</ul> \
|
||||||
|
<div class="recline-results-info"> \
|
||||||
|
Results found <span class="doc-count">{{docCount}}</span> \
|
||||||
|
</div> \
|
||||||
</div> \
|
</div> \
|
||||||
<div class="data-view-container"></div> \
|
<div class="data-view-container"></div> \
|
||||||
<div class="dialog-overlay" style="display: none; z-index: 101; "> </div> \
|
<div class="dialog-overlay" style="display: none; z-index: 101; "> </div> \
|
||||||
@@ -106,6 +109,7 @@ my.DataExplorer = Backbone.View.extend({
|
|||||||
});
|
});
|
||||||
this.model.bind('query:done', function(eventName) {
|
this.model.bind('query:done', function(eventName) {
|
||||||
my.clearNotifications();
|
my.clearNotifications();
|
||||||
|
self.el.find('.doc-count').text(self.model.docCount || 'Unknown');
|
||||||
my.notify('Data loaded', {category: 'success'});
|
my.notify('Data loaded', {category: 'success'});
|
||||||
});
|
});
|
||||||
this.model.bind('query:fail', function(eventName, error) {
|
this.model.bind('query:fail', function(eventName, error) {
|
||||||
@@ -178,27 +182,47 @@ my.QueryEditor = Backbone.View.extend({
|
|||||||
className: 'recline-query-editor',
|
className: 'recline-query-editor',
|
||||||
template: ' \
|
template: ' \
|
||||||
<form action="" method="GET"> \
|
<form action="" method="GET"> \
|
||||||
Showing <input name="size" type="text" value="{{size}}" title="Edit and hit enter to change the number of rows displayed" /> starting at <input name="offset" type="text" value="{{offset}}" /> of <span class="doc-count">{{docCount}}</span> \
|
<div class="pagination"> \
|
||||||
<button type="submit" class="btn">Update »</button> \
|
<ul> \
|
||||||
|
<li class="prev action-pagination-update"><a>« back</a></li> \
|
||||||
|
<li class="active"><a><input name="offset" type="text" value="{{offset}}" /> – <input name="to" type="text" value="{{to}}" /> </a></li> \
|
||||||
|
<li class="next action-pagination-update"><a>next »</a></li> \
|
||||||
|
</ul> \
|
||||||
|
</div> \
|
||||||
|
<button type="submit" class="btn" style="">Update »</button> \
|
||||||
</form> \
|
</form> \
|
||||||
',
|
',
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'submit form': 'onFormSubmit'
|
'submit form': 'onFormSubmit',
|
||||||
|
'click .action-pagination-update': 'onPaginationUpdate'
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
_.bindAll(this, 'render');
|
||||||
this.el = $(this.el);
|
this.el = $(this.el);
|
||||||
|
this.model.bind('change', this.render);
|
||||||
this.render();
|
this.render();
|
||||||
},
|
},
|
||||||
onFormSubmit: function(e) {
|
onFormSubmit: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var newSize = parseInt(this.el.find('input[name="size"]').val());
|
|
||||||
var newOffset = parseInt(this.el.find('input[name="offset"]').val());
|
var newOffset = parseInt(this.el.find('input[name="offset"]').val());
|
||||||
|
var newSize = parseInt(this.el.find('input[name="to"]').val()) - newOffset;
|
||||||
this.model.set({size: newSize, offset: newOffset});
|
this.model.set({size: newSize, offset: newOffset});
|
||||||
},
|
},
|
||||||
|
onPaginationUpdate: function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var $el = $(e.target);
|
||||||
|
if ($el.parent().hasClass('prev')) {
|
||||||
|
var newOffset = this.model.get('offset') - Math.max(0, this.model.get('size'));
|
||||||
|
} else {
|
||||||
|
var newOffset = this.model.get('offset') + this.model.get('size');
|
||||||
|
}
|
||||||
|
this.model.set({offset: newOffset});
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var tmplData = this.model.toJSON();
|
var tmplData = this.model.toJSON();
|
||||||
|
tmplData.to = this.model.get('offset') + this.model.get('size');
|
||||||
var templated = $.mustache(this.template, tmplData);
|
var templated = $.mustache(this.template, tmplData);
|
||||||
this.el.html(templated);
|
this.el.html(templated);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user