wiring up pagesize controls
This commit is contained in:
parent
806ffee304
commit
6600006df4
@ -26,9 +26,6 @@
|
|||||||
<a href='https://github.com/maxogden/removalist'>Fork this project on Github</a>. The <a href="http://github.com/michenriksen/css3buttons">pretty CSS3 Buttons</a> were created by <a href="http://michaelhenriksen.dk" title="Website of Michael Henriksen">Michael Henriksen</a>
|
<a href='https://github.com/maxogden/removalist'>Fork this project on Github</a>. The <a href="http://github.com/michenriksen/css3buttons">pretty CSS3 Buttons</a> were created by <a href="http://michaelhenriksen.dk" title="Website of Michael Henriksen">Michael Henriksen</a>
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type='text/mustache' id="homeTemplate">
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script type='text/mustache' id="dbTemplate">
|
<script type='text/mustache' id="dbTemplate">
|
||||||
<div id="database" class="single_database">
|
<div id="database" class="single_database">
|
||||||
|
|||||||
@ -22,35 +22,65 @@ var removalist = function() {
|
|||||||
rows: tableRows,
|
rows: tableRows,
|
||||||
headers: app.headers
|
headers: app.headers
|
||||||
})
|
})
|
||||||
|
app.newest = rows[0].id;
|
||||||
|
app.oldest = rows[rows.length - 1].id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function gotHeaders( headers ) {
|
function getPageSize() {
|
||||||
app.headers = headers;
|
return $(".viewpanel-pagesize .selected").text();
|
||||||
app.csvUrl = app.baseURL + 'api/csv?headers=' + escape(JSON.stringify(headers));
|
|
||||||
util.render( 'actions', 'project-controls', $.extend({}, app.dbInfo, {url: app.csvUrl}) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gotDb( dbInfo ) {
|
function fetchRows(id) {
|
||||||
|
|
||||||
app.dbInfo = dbInfo;
|
|
||||||
|
|
||||||
$.extend(app.dbInfo, {
|
var query = {
|
||||||
"host": window.location.host,
|
"limit" : getPageSize()
|
||||||
"disk_size": formatDiskSize(app.dbInfo.disk_size)
|
}
|
||||||
|
|
||||||
|
if ( id ) {
|
||||||
|
$.extend( query, {
|
||||||
|
"startkey_docid": id,
|
||||||
|
"skip": 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var req = {url: app.baseURL + 'api/rows?' + $.param(query)};
|
||||||
|
|
||||||
|
couch.request(req).then(function(response) {
|
||||||
|
removalist.renderRows(response.rows);
|
||||||
});
|
});
|
||||||
|
|
||||||
if( util.inURL("_rewrite", app.baseURL) ) app.dbInfo.db_name = "api";
|
}
|
||||||
|
|
||||||
util.render('tableContainer', app.container, app.dbInfo);
|
function bootstrap() {
|
||||||
util.render('title', 'project-title', app.dbInfo);
|
couch.request({url: app.baseURL + "api"}).then(function( dbInfo ) {
|
||||||
util.render( 'generating', 'project-controls' );
|
|
||||||
|
app.dbInfo = dbInfo;
|
||||||
|
|
||||||
|
$.extend(app.dbInfo, {
|
||||||
|
"host": window.location.host,
|
||||||
|
"disk_size": formatDiskSize(app.dbInfo.disk_size)
|
||||||
|
});
|
||||||
|
|
||||||
|
if( util.inURL("_rewrite", app.baseURL) ) app.dbInfo.db_name = "api";
|
||||||
|
|
||||||
|
util.render('tableContainer', app.container, app.dbInfo);
|
||||||
|
util.render('title', 'project-title', app.dbInfo);
|
||||||
|
util.render( 'generating', 'project-controls' );
|
||||||
|
|
||||||
|
couch.request({url: app.baseURL + 'api/headers'}).then(function ( headers ) {
|
||||||
|
app.headers = headers;
|
||||||
|
app.csvUrl = app.baseURL + 'api/csv?headers=' + escape(JSON.stringify(headers));
|
||||||
|
util.render( 'actions', 'project-controls', $.extend({}, app.dbInfo, {url: app.csvUrl}) );
|
||||||
|
fetchRows();
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
formatDiskSize: formatDiskSize,
|
formatDiskSize: formatDiskSize,
|
||||||
renderRows: renderRows,
|
bootstrap: bootstrap,
|
||||||
gotHeaders: gotHeaders,
|
fetchRows: fetchRows,
|
||||||
gotDb: gotDb
|
getPageSize: getPageSize,
|
||||||
|
renderRows: renderRows
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
@ -4,53 +4,36 @@ var app = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.handler = function(route) {
|
app.handler = function(route) {
|
||||||
route = route.path.slice(1, route.path.length);
|
if (route.params && route.params.route) {
|
||||||
if (route.length < 1) route = "home";
|
var path = route.params.route;
|
||||||
util.render( route, app.container);
|
app.routes[path](route.params.id);
|
||||||
window.scrollTo(0, 0);
|
} else {
|
||||||
|
app.routes['home']();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// var query = {
|
app.routes = {
|
||||||
// "descending" : true,
|
|
||||||
// "limit" : 20,
|
|
||||||
// success: function( data ) {
|
|
||||||
// if( data.rows.length === 0 ) {
|
|
||||||
// monocles.oldestDoc = false;
|
|
||||||
// monocles.hideLoader();
|
|
||||||
// posts = [];
|
|
||||||
// } else {
|
|
||||||
// monocles.oldestDoc = data.rows[ data.rows.length - 1 ];
|
|
||||||
// posts = data.rows;
|
|
||||||
// }
|
|
||||||
// renderStream();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if ( opts.offsetDoc ) {
|
|
||||||
// $.extend( query, {
|
|
||||||
// "startkey": opts.offsetDoc.key,
|
|
||||||
// "startkey_docid": opts.offsetDoc.id,
|
|
||||||
// "skip": 1
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
app.after = {
|
|
||||||
home: function() {
|
home: function() {
|
||||||
|
removalist.bootstrap();
|
||||||
couch.request({url: app.baseURL + "api"}).then(function(db) {
|
|
||||||
removalist.gotDb(db);
|
|
||||||
couch.request({url: app.baseURL + 'api/headers'}).then(function(headers) {
|
|
||||||
removalist.gotHeaders(headers);
|
|
||||||
couch.request({url: app.baseURL + 'api/rows?limit=10'}).then(function(response) {
|
|
||||||
removalist.renderRows(response.rows);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
$( '.csv' ).live('click', ( function( e ) {
|
$( '.csv' ).live('click', ( function( e ) {
|
||||||
window.location.href = app.csvUrl;
|
window.location.href = app.csvUrl;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
},
|
||||||
|
page: function(id) {
|
||||||
|
removalist.getPageSize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.after = {
|
||||||
|
tableContainer: function() {
|
||||||
|
$( '.viewPanel-pagingControls-page' ).click(function( e ) {
|
||||||
|
$(".viewpanel-pagesize .selected").removeClass('selected');
|
||||||
|
$(e.target).addClass('selected');
|
||||||
|
removalist.fetchRows(app.newest);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +41,7 @@ app.sammy = $.sammy(function () {
|
|||||||
this.get('', app.handler);
|
this.get('', app.handler);
|
||||||
this.get("#/", app.handler);
|
this.get("#/", app.handler);
|
||||||
this.get("#:route", app.handler);
|
this.get("#:route", app.handler);
|
||||||
|
this.get("#:route/:id", app.handler);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user