mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 01:31:34 +00:00
Pagination is gucci
This commit is contained in:
parent
6f06bc930b
commit
1b2af2282f
@ -84,7 +84,7 @@ uploadsController.upload = function(req, res, next){
|
||||
}
|
||||
|
||||
if(iteration === req.files.length)
|
||||
return something(req, res, files, existingFiles)
|
||||
return uploadsController.processFilesForDisplay(req, res, files, existingFiles)
|
||||
iteration++
|
||||
})
|
||||
|
||||
@ -96,7 +96,7 @@ uploadsController.upload = function(req, res, next){
|
||||
|
||||
}
|
||||
|
||||
function something(req, res, files, existingFiles){
|
||||
uploadsController.processFilesForDisplay = function(req, res, files, existingFiles){
|
||||
|
||||
let basedomain = req.get('host')
|
||||
for(let domain of config.domains)
|
||||
@ -177,6 +177,9 @@ uploadsController.list = function(req, res){
|
||||
if(req.headers.auth !== config.adminToken)
|
||||
return res.status(401).json({ success: false, description: 'not-authorized'})
|
||||
|
||||
let offset = req.params.page
|
||||
if(offset === undefined) offset = 0
|
||||
|
||||
db.table('files')
|
||||
.where(function(){
|
||||
if(req.params.id === undefined)
|
||||
@ -185,6 +188,8 @@ uploadsController.list = function(req, res){
|
||||
this.where('albumid', req.params.id)
|
||||
})
|
||||
.orderBy('id', 'DESC')
|
||||
.limit(25)
|
||||
.offset(25 * offset)
|
||||
.then((files) => {
|
||||
db.table('albums').then((albums) => {
|
||||
|
||||
|
@ -69,11 +69,13 @@ panel.prepareDashboard = function(){
|
||||
panel.getAlbumsSidebar();
|
||||
}
|
||||
|
||||
panel.getUploads = function(album = undefined){
|
||||
panel.getUploads = function(album = undefined, page = undefined){
|
||||
|
||||
let url = '/api/uploads'
|
||||
if(page === undefined) page = 0;
|
||||
|
||||
let url = '/api/uploads/' + page
|
||||
if(album !== undefined)
|
||||
url = '/api/album/' + album
|
||||
url = '/api/album/' + album + '/' + page
|
||||
|
||||
axios.get(url)
|
||||
.then(function (response) {
|
||||
@ -82,9 +84,27 @@ panel.getUploads = function(album = undefined){
|
||||
else return swal("An error ocurred", response.data.description, "error");
|
||||
}
|
||||
|
||||
|
||||
var prevPage = 0;
|
||||
var nextPage = page + 1;
|
||||
|
||||
if(response.data.files.length < 25)
|
||||
nextPage = page;
|
||||
|
||||
if(page > 0) prevPage = page - 1;
|
||||
|
||||
panel.page.innerHTML = '';
|
||||
var container = document.createElement('div');
|
||||
container.innerHTML = `
|
||||
<div class='columns'>
|
||||
<div class="column">
|
||||
<nav class="pagination is-centered">
|
||||
<a class="pagination-previous" onclick="panel.getUploads(${album}, ${prevPage} )">Previous</a>
|
||||
<a class="pagination-next" onclick="panel.getUploads(${album}, ${nextPage} )">Next page</a>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="table is-striped is-narrow">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -96,7 +116,17 @@ panel.getUploads = function(album = undefined){
|
||||
</thead>
|
||||
<tbody id="table">
|
||||
</tbody>
|
||||
</table>`;
|
||||
</table>
|
||||
|
||||
<div class='columns'>
|
||||
<div class="column">
|
||||
<nav class="pagination is-centered">
|
||||
<a class="pagination-previous" onclick="panel.getUploads(${album}, ${prevPage} )">Previous</a>
|
||||
<a class="pagination-next" onclick="panel.getUploads(${album}, ${nextPage} )">Next page</a>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
panel.page.appendChild(container);
|
||||
|
||||
var table = document.getElementById('table');
|
||||
|
@ -12,11 +12,14 @@ routes.get ('/check', (req, res, next) => {
|
||||
})
|
||||
|
||||
routes.get ('/uploads', (req, res, next) => uploadController.list(req, res))
|
||||
routes.get ('/uploads/:page', (req, res, next) => uploadController.list(req, res))
|
||||
routes.post ('/upload', (req, res, next) => uploadController.upload(req, res, next))
|
||||
routes.post ('/upload/delete', (req, res, next) => uploadController.delete(req, res, next))
|
||||
routes.post ('/upload/:albumid', (req, res, next) => uploadController.upload(req, res, next))
|
||||
|
||||
routes.get ('/album/:id', (req, res, next) => uploadController.list(req, res, next))
|
||||
routes.get ('/album/:id/:page', (req, res, next) => uploadController.list(req, res, next))
|
||||
|
||||
routes.get ('/albums', (req, res, next) => albumsController.list(req, res, next))
|
||||
routes.get ('/albums/:sidebar', (req, res, next) => albumsController.list(req, res, next))
|
||||
routes.post ('/albums', (req, res, next) => albumsController.create(req, res, next))
|
||||
|
Loading…
Reference in New Issue
Block a user