Skip to content

Commit

Permalink
Human readbable file size and search on enter key press
Browse files Browse the repository at this point in the history
  • Loading branch information
shishirsharma committed Feb 3, 2017
1 parent 723bce0 commit d65744d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Binary file modified app/images/screenshots/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/images/screenshots/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/images/screenshots/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 26 additions & 2 deletions app/scripts.babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ var state = {};
// }
// });

function humanFileSize(bytes, si) {
var thresh = si ? 1000 : 1024;
if(Math.abs(bytes) < thresh) {
return bytes + ' B';
}
var units = si
? ['KB','MB','GB','TB','PB','EB','ZB','YB']
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
var u = -1;
do {
bytes /= thresh;
++u;
} while(Math.abs(bytes) >= thresh && u < units.length - 1);
return bytes.toFixed(1)+' '+units[u];
}

function listBuckets(s3, s3Bucket) {
if (window.console) { console.log('Done'); }
s3.listBuckets(function(err, buckets) {
Expand Down Expand Up @@ -157,7 +173,7 @@ function listObjects(s3, s3Bucket, s3_prefix, s3_marker='') {
).append(
$('<td>').html(file.LastModified)
).append(
$('<td>').html(file.Size)
$('<td>').html(humanFileSize(file.Size, true))
).appendTo(tbody);
});
if(files.IsTruncated) {
Expand Down Expand Up @@ -386,12 +402,20 @@ function setup() {
if (window.console) { console.log('nothing to upload'); }
}
});
$('#buckets-search').click(function() {
function aws_prefix_search() {
var search_query = $('#buckets-search-query').val();
var tags = state.prefix.split('/');
tags.pop();
var search_prefix = listObjects(s3, state.s3Bucket, tags.join('/') + '/' + search_query);
window.history.pushState(state, state.prefix+':'+state.marker);
}
$('#buckets-search').click(function() {
aws_prefix_search();
});
$('#buckets-search-query').keydown(function(e) {
var keypressed = event.keyCode || event.which;
// Enter is pressed
if (keypressed == 13) { aws_prefix_search(); }
});
}

Expand Down

0 comments on commit d65744d

Please sign in to comment.