This commit is contained in:
Daniela Arcese 2017-07-13 10:05:45 -04:00
parent 52173bf6e7
commit 9032e42912
27 changed files with 1388 additions and 354 deletions

View file

@ -1,27 +1,29 @@
const FileSender = require('./fileSender');
const { notify, gcmCompliant } = require('./utils');
const $ = require('jquery');
require('jquery-circle-progress');
const Raven = window.Raven;
$(document).ready(function() {
gcmCompliant().catch(err => {
$('#page-one').hide();
$('#compliance-error').show();
$('#unsupported-browser').show();
});
$('#file-upload').change(onUpload);
$('#page-one').on('dragover', allowDrop).on('drop', onUpload);
$('body').on('dragover', allowDrop).on('drop', onUpload);
// reset copy button
const $copyBtn = $('#copy-btn');
$copyBtn.attr('disabled', false);
$copyBtn.html('Copy');
$('#link').attr('disabled', false);
$copyBtn.html('Copy to Clipboard');
$('#page-one').show();
$('#file-list').show();
$('#upload-progress').hide();
$('#share-link').hide();
$('#upload-error').hide();
$('#unsupported-browser').hide();
$('#compliance-error').hide();
if (localStorage.length === 0) {
@ -44,24 +46,42 @@ $(document).ready(function() {
document.body.removeChild(aux);
//disable button for 3s
$copyBtn.attr('disabled', true);
$copyBtn.html('Copied!');
$('#link').attr('disabled', true);
$copyBtn.html("<span class='icon-check'></span>");
window.setTimeout(() => {
$copyBtn.attr('disabled', false);
$copyBtn.html('Copy');
$('#link').attr('disabled', false);
$copyBtn.html('Copy to Clipboard');
}, 3000);
});
$('.upload-window').on('dragover', () => {
$('.upload-window').addClass('ondrag');
});
$('.upload-window').on('dragleave', () => {
$('.upload-window').removeClass('ondrag');
});
//initiate progress bar
$('#ul-progress').circleProgress({
value: 0.0,
startAngle: -Math.PI/2,
fill: '#3B9DFF',
size: 158
});
// link back to home page
$('.send-new').click(() => {
$('#page-one').show();
$('#file-list').show();
$('#upload-progress').hide();
$('#share-link').hide();
$('#upload-error').hide();
$copyBtn.attr('disabled', false);
$copyBtn.html('Copy');
$('#link').attr('disabled', false);
$copyBtn.html('Copy to Clipboard');
});
//cancel the upload
$('#cancel-upload').click(() => {
});
// on file upload by browse or drag & drop
function onUpload(event) {
event.preventDefault();
@ -74,17 +94,19 @@ $(document).ready(function() {
const expiration = 24 * 60 * 60 * 1000; //will eventually come from a field
const fileSender = new FileSender(file);
fileSender.on('progress', percentComplete => {
fileSender.on('progress', progress => {
$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').show();
$('#upload-error').hide();
$('#upload-filename').innerHTML += file.name;
let percent = progress[0]/progress[1];
// update progress bar
document
.querySelector('#progress-bar')
.style.setProperty('--progress', percentComplete + '%');
$('#progress-text').html(`${percentComplete}%`);
$('#ul-progress').circleProgress('value', percent );
$('.percent-number').html(`${Math.floor(percent*100)}`);
if(progress[1] < 1000000000){
$('.progress-text').html(`${file.name} (${(progress[0]/1000000).toFixed(1)}MB of ${(progress[1]/1000000).toFixed(1)}MB)`);
} else {
$('.progress-text').html(`${file.name} (${(progress[0]/1000000).toFixed(1)}MB of ${(progress[1]/1000000000).toFixed(1)}GB)`);
}
});
fileSender.on('loading', isStillLoading => {
@ -117,8 +139,6 @@ $(document).ready(function() {
fileSender
.upload()
.then(info => {
const url = info.url.trim() + `#${info.secretKey}`.trim();
$('#link').attr('value', url);
const fileData = {
name: file.name,
fileId: info.fileId,
@ -129,12 +149,13 @@ $(document).ready(function() {
expiry: expiration
};
localStorage.setItem(info.fileId, JSON.stringify(fileData));
$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').hide();
$('#share-link').show();
$('#upload-error').hide();
$('#upload-filename').html('Ready to Send');
const t = window.setTimeout(() => {
$('#page-one').hide();
$('#upload-progress').hide();
$('#share-link').show();
$('#upload-error').hide();
}, 2000);
populateFileList(JSON.stringify(fileData));
notify('Your upload has finished.');
@ -143,7 +164,9 @@ $(document).ready(function() {
Raven.captureException(err);
console.log(err);
$('#page-one').hide();
$('#upload-progress').hide();
$('#upload-error').show();
window.clearTimeout(t);
});
}
@ -181,19 +204,31 @@ $(document).ready(function() {
const link = document.createElement('td');
const expiry = document.createElement('td');
const del = document.createElement('td');
del.setAttribute('align', 'center');
const btn = document.createElement('button');
const popupDiv = document.createElement('div');
const $popupText = $('<span>', { class: 'popuptext' });
const $popupText = $('<div>', { class: 'popuptext' });
const cellText = document.createTextNode(file.name);
const url = file.url.trim() + `#${file.secretKey}`.trim();
$('#link').attr('value', url);
$('#copy-text').html('Copy and share the link to send your file: ' + file.name);
$popupText.attr('tabindex', '-1');
name.appendChild(cellText);
// create delete button
btn.innerHTML = 'x';
btn.classList.add('delete-btn');
del.innerHTML = "<span class='icon-cancel-1' title='Delete' style='margin-left: -7px'></span>";
link.innerHTML = file.url.trim() + `#${file.secretKey}`.trim();
link.innerHTML = "<span class='icon-docs' title='Copy URL'></span>"
//copy link to clipboard when icon clicked
$(link).click(function() {
const aux = document.createElement('input');
aux.setAttribute('value', url);
document.body.appendChild(aux);
aux.select();
document.execCommand('copy');
document.body.removeChild(aux);
notify('The link has been copied to your clipboard.');
});
file.creationDate = new Date(file.creationDate);
@ -215,18 +250,13 @@ $(document).ready(function() {
seconds = Math.floor(countdown / 1000 % 60);
let t;
if (hours > 1) {
expiry.innerHTML = hours + 'h';
t = window.setTimeout(() => {
poll();
}, 3600000);
} else if (hours === 1) {
expiry.innerHTML = hours + 'h';
if (hours >= 1) {
expiry.innerHTML = hours + 'h ' + minutes % 60 + 'm';
t = window.setTimeout(() => {
poll();
}, 60000);
} else if (hours === 0) {
expiry.innerHTML = minutes + 'm' + seconds + 's';
expiry.innerHTML = minutes + 'm ' + seconds + 's';
t = window.setTimeout(() => {
poll();
}, 1000);
@ -236,6 +266,7 @@ $(document).ready(function() {
localStorage.removeItem(file.fileId);
$(expiry).parents('tr').remove();
window.clearTimeout(t);
toggleHeader();
}
}
@ -253,32 +284,42 @@ $(document).ready(function() {
toggleHeader();
});
});
document.getElementById('delete-file').onclick = e => {
FileSender.delete(file.fileId, file.deleteToken).then(() => {
localStorage.removeItem(file.fileId);
toggleHeader();
$('.send-new').click();
});
};
// add data cells to table row
row.appendChild(name);
row.appendChild(link);
row.appendChild(expiry);
popupDiv.appendChild(btn);
//popupDiv.appendChild(btn);
$(popupDiv).append($popupText);
del.appendChild(popupDiv);
row.appendChild(del);
// show popup
del.addEventListener('click', toggleShow);
del.addEventListener('click', function(){
$popupText.addClass('show');
$popupText.focus();
});
// hide popup
$popupText.find('.nvm').click(function(e) {
e.stopPropagation();
toggleShow();
$popupText.removeClass('show');
});
$popupText.click(function(e) {
e.stopPropagation();
});
//close when popup loses focus
$popupText.blur(() => {
$popupText.removeClass('show');
});
$('tbody').append(row); //add row to table
function toggleShow() {
$popupText.toggleClass('show');
}
toggleHeader();
}
function toggleHeader() {