Better tables and showing album on upload view

This commit is contained in:
Pitu 2017-01-18 03:29:46 -03:00
parent 7e82e4304f
commit cf98005c4f
3 changed files with 32 additions and 16 deletions

View File

@ -14,14 +14,18 @@ albumsController.list = function(req, res, next){
fields.push('timestamp')
db.table('albums').select(fields).then((albums) => {
let ids = []
for(let album of albums){
album.date = new Date(album.timestamp * 1000)
album.date = album.date.getFullYear() + '-' + album.date.getMonth() + '-' + album.date.getDate() + ' ' + (album.date.getHours() < 10 ? '0' : '') + album.date.getHours() + ':' + (album.date.getMinutes() < 10 ? '0' : '') + album.date.getMinutes() + ':' + (album.date.getSeconds() < 10 ? '0' : '') + album.date.getSeconds()
ids.push(album.id)
}
if(req.headers.extended === undefined)
return res.json({ success: true, albums })
let ids = []
for(let album of albums)
ids.push(album.id)
db.table('files').whereIn('albumid', ids).select('albumid').then((files) => {
let albumsCount = {}

View File

@ -78,15 +78,27 @@ uploadsController.list = function(req, res){
return res.status(401).send('not-authorized')
db.table('files').then((files) => {
db.table('albums').then((albums) => {
for(let file of files){
file.file = config.basedomain + config.uploads.prefix + file.name
file.ext = file.name.split('.').pop()
file.date = new Date(file.created_at * 1000)
file.date = file.date.getFullYear() + '-' + file.date.getMonth() + '-' + file.date.getDate() + ' ' + (file.date.getHours() < 10 ? '0' : '') + file.date.getHours() + ':' + (file.date.getMinutes() < 10 ? '0' : '') + file.date.getMinutes() + ':' + (file.date.getSeconds() < 10 ? '0' : '') + file.date.getSeconds()
}
console.log(files)
for(let file of files){
file.file = config.basedomain + config.uploads.prefix + file.name
file.date = new Date(file.timestamp * 1000)
file.date = file.date.getFullYear() + '-' + file.date.getMonth() + '-' + file.date.getDate() + ' ' + (file.date.getHours() < 10 ? '0' : '') + file.date.getHours() + ':' + (file.date.getMinutes() < 10 ? '0' : '') + file.date.getMinutes() + ':' + (file.date.getSeconds() < 10 ? '0' : '') + file.date.getSeconds()
file.album = ''
if(file.albumid !== undefined)
for(let album of albums)
if(file.albumid === album.id)
file.album = album.name
}
return res.json(files)
})
return res.json(files)
})
}

View File

@ -82,7 +82,7 @@ panel.getUploads = function(){
var container = document.createElement('div');
container.innerHTML = `
<table class="table">
<table class="table is-striped is-narrow">
<thead>
<tr>
<th>File</th>
@ -104,7 +104,7 @@ panel.getUploads = function(){
<tr>
<th><a href="${item.file}" target="_blank">${item.file}</a></th>
<th>${item.album}</th>
<td>${item.timestamp}</td>
<td>${item.date}</td>
</tr>
`;
@ -134,7 +134,7 @@ panel.getAlbums = function(){
<h2 class="subtitle">List of albums</h2>
<table class="table">
<table class="table is-striped is-narrow">
<thead>
<tr>
<th>Name</th>
@ -167,7 +167,7 @@ panel.getAlbums = function(){
<tr>
<th>${item.name}</th>
<th>${item.files}</th>
<td>${item.timestamp}</td>
<td>${item.date}</td>
</tr>
`;
@ -231,7 +231,7 @@ panel.getAlbumsSidebar = function(){
var albumsContainer = document.getElementById('albumsContainer');
albumsContainer.innerHTML = '';
if(json.albums === undefined) return;
for(var album of json.albums){