Browse Source

Add more info into the upload table

ghorsington 5 years ago
parent
commit
866b9a4240
2 changed files with 25 additions and 7 deletions
  1. 1 1
      controllers/uploadController.js
  2. 24 6
      public/js/dashboard.js

+ 1 - 1
controllers/uploadController.js

@@ -259,7 +259,7 @@ uploadsController.list = async (req, res) => {
 		.orderBy('id', 'DESC')
 		.limit(25)
 		.offset(25 * offset)
-		.select('id', 'albumid', 'timestamp', 'name', 'userid');
+		.select('id', 'albumid', 'timestamp', 'name', 'userid', 'original', 'size');
 
 	const albums = await db.table('albums');
 	let basedomain = config.domain;

+ 24 - 6
public/js/dashboard.js

@@ -79,6 +79,18 @@ panel.logout = function(){
 	location.reload('/');
 };
 
+panel.sizePrefixes = [[1, "B"], [1000, "kB"], [1000000, "MB"], [1000000000, "GB"]];
+panel.sizeToString = function(size){
+	let [baseLimit, baseUnit] = panel.sizePrefixes[0];
+	for(let [limit, unit] of panel.sizePrefixes){
+		if(size >= limit)
+			[baseLimit, baseUnit] = [limit, unit];
+		else
+			break;
+	}
+	return `${(size / baseLimit).toFixed(1)} ${baseUnit}`;
+};
+
 panel.getUploads = function(album = undefined, page = undefined){
 
 	if(page === undefined) page = 0;
@@ -160,10 +172,12 @@ panel.getUploads = function(album = undefined, page = undefined){
 				${pagination}
 				<hr>
 				${listType}
-				<table class="table is-striped is-narrow is-left">
+				<table class="table is-striped is-narrow is-left bold-children">
 					<thead>
 						<tr>
 							  <th>File</th>
+							  <th>Original name</th>
+							  <th>Size</th>
 							  <th>${albumOrUser}</th>
 							  <th>Date</th>
 							  <th></th>
@@ -192,9 +206,11 @@ panel.getUploads = function(album = undefined, page = undefined){
 					
 				tr.innerHTML = `
 					<tr>
-						<th><a href="${item.file}" target="_blank">${item.file}</a></th>
-						<th>${displayAlbumOrUser}</th>
-						<td>${item.date}</td>
+						<td class="valign"><a href="${item.file}" target="_blank">${item.name}</a></td>
+						<td class="original-name">${item.original}</td>
+						<td class="size-display">${panel.sizeToString(item.size)}</td>
+						<td>${displayAlbumOrUser}</td>
+						<td class="normal">${item.date}</td>
 						<td>
 							<a class="button is-small is-danger is-outlined" title="Delete album" onclick="panel.deleteFile(${item.id})">
 								<span class="icon is-small">
@@ -204,8 +220,10 @@ panel.getUploads = function(album = undefined, page = undefined){
 						</td>
 					</tr>
 					`;
-
-				table.appendChild(tr);
+				
+					
+					table.appendChild(tr);
+				//$clamp(tr.querySelector(".clamp"), {clamp: 1});
 			}
 		}
 	})