Added browsing galleries from dashboard

This commit is contained in:
Pitu 2017-01-18 04:05:56 -03:00
parent 512e9f46eb
commit 0dcaf36332
3 changed files with 24 additions and 6 deletions

View File

@ -15,6 +15,9 @@ albumsController.list = function(req, res, next){
db.table('albums').select(fields).then((albums) => {
if(req.headers.extended === undefined)
return res.json({ success: true, albums })
let ids = []
for(let album of albums){
album.date = new Date(album.timestamp * 1000)
@ -23,9 +26,6 @@ albumsController.list = function(req, res, next){
ids.push(album.id)
}
if(req.headers.extended === undefined)
return res.json({ success: true, albums })
db.table('files').whereIn('albumid', ids).select('albumid').then((files) => {
let albumsCount = {}

View File

@ -77,7 +77,14 @@ uploadsController.list = function(req, res){
if(req.headers.auth !== config.adminToken)
return res.status(401).send('not-authorized')
db.table('files').then((files) => {
db.table('files')
.where(function(){
if(req.headers.albumid === undefined)
this.where('id', '<>', '')
else
this.where('albumid', req.headers.albumid)
})
.then((files) => {
db.table('albums').then((albums) => {
for(let file of files){

View File

@ -65,7 +65,7 @@ panel.prepareDashboard = function(){
panel.getAlbumsSidebar();
}
panel.getUploads = function(){
panel.getUploads = function(album = undefined){
panel.page.innerHTML = '';
var xhr = new XMLHttpRequest();
@ -114,6 +114,8 @@ panel.getUploads = function(){
}
}
xhr.open('GET', '/api/uploads', true);
if(album !== undefined)
xhr.setRequestHeader('albumid', album);
xhr.setRequestHeader('auth', panel.token);
xhr.send(null);
}
@ -225,7 +227,6 @@ panel.getAlbumsSidebar = function(){
return panel.verifyToken(panel.token);
var json = JSON.parse(xhr.responseText);
console.log(json);
if(json.success === false)
return swal("An error ocurred", json.description, "error");
@ -235,10 +236,16 @@ panel.getAlbumsSidebar = function(){
if(json.albums === undefined) return;
for(var album of json.albums){
li = document.createElement('li');
a = document.createElement('a');
a.id = album.id;
a.innerHTML = album.name;
a.addEventListener('click', function(){
panel.getAlbum(this);
});
li.appendChild(a);
albumsContainer.appendChild(li);
}
@ -250,6 +257,10 @@ panel.getAlbumsSidebar = function(){
xhr.send(null);
}
panel.getAlbum = function(item){
panel.getUploads(item.id);
}
window.onload = function () {
panel.preparePage();
}