2017-08-24 23:54:02 +02:00
|
|
|
const html = require('choo/html');
|
|
|
|
const assets = require('../../common/assets');
|
2018-02-08 04:46:18 +01:00
|
|
|
const number = require('../utils').number;
|
2017-08-24 23:54:02 +02:00
|
|
|
|
2018-01-24 19:23:13 +01:00
|
|
|
function timeLeft(milliseconds, state) {
|
2017-08-24 23:54:02 +02:00
|
|
|
const minutes = Math.floor(milliseconds / 1000 / 60);
|
|
|
|
const hours = Math.floor(minutes / 60);
|
|
|
|
if (hours >= 1) {
|
2018-01-24 19:23:13 +01:00
|
|
|
return state.translate('expiresHoursMinutes', {
|
|
|
|
hours,
|
|
|
|
minutes: minutes % 60
|
|
|
|
});
|
2017-08-24 23:54:02 +02:00
|
|
|
} else if (hours === 0) {
|
2018-01-24 19:23:13 +01:00
|
|
|
if (minutes === 0) {
|
|
|
|
return state.translate('expiresMinutes', { minutes: '< 1' });
|
|
|
|
}
|
|
|
|
return state.translate('expiresMinutes', { minutes });
|
2017-08-24 23:54:02 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function(file, state, emit) {
|
|
|
|
const ttl = file.expiresAt - Date.now();
|
2018-01-24 19:23:13 +01:00
|
|
|
const remainingTime =
|
|
|
|
timeLeft(ttl, state) || state.translate('linkExpiredAlt');
|
2018-01-23 03:11:48 +01:00
|
|
|
const downloadLimit = file.dlimit || 1;
|
|
|
|
const totalDownloads = file.dtotal || 0;
|
2017-08-24 23:54:02 +02:00
|
|
|
const row = html`
|
|
|
|
<tr id="${file.id}">
|
2018-01-24 19:23:13 +01:00
|
|
|
<td class="overflow-col" title="${file.name}">
|
|
|
|
<a class="link" href="/share/${file.id}">${file.name}</a>
|
|
|
|
</td>
|
2017-09-06 23:09:17 +02:00
|
|
|
<td class="center-col">
|
2018-01-24 19:23:13 +01:00
|
|
|
<img
|
|
|
|
onclick=${copyClick}
|
|
|
|
src="${assets.get('copy-16.svg')}"
|
|
|
|
class="icon-copy"
|
|
|
|
title="${state.translate('copyUrlHover')}">
|
|
|
|
<span class="text-copied" hidden="true">
|
|
|
|
${state.translate('copiedUrl')}
|
|
|
|
</span>
|
2017-08-24 23:54:02 +02:00
|
|
|
</td>
|
2018-02-02 19:37:28 +01:00
|
|
|
<td class="overflow-col">${remainingTime}</td>
|
2018-02-08 04:46:18 +01:00
|
|
|
<td class="center-col">${number(totalDownloads)} / ${number(
|
|
|
|
downloadLimit
|
|
|
|
)}</td>
|
2017-09-06 23:09:17 +02:00
|
|
|
<td class="center-col">
|
2018-01-24 19:23:13 +01:00
|
|
|
<img
|
|
|
|
onclick=${showPopup}
|
|
|
|
src="${assets.get('close-16.svg')}"
|
|
|
|
class="icon-delete"
|
|
|
|
title="${state.translate('deleteButtonHover')}">
|
2017-08-24 23:54:02 +02:00
|
|
|
<div class="popup">
|
|
|
|
<div class="popuptext" onblur=${cancel} tabindex="-1">
|
|
|
|
<div class="popup-message">${state.translate('deletePopupText')}</div>
|
|
|
|
<div class="popup-action">
|
2018-01-24 19:23:13 +01:00
|
|
|
<span class="popup-no" onclick=${cancel}>
|
|
|
|
${state.translate('deletePopupCancel')}
|
|
|
|
</span>
|
|
|
|
<span class="popup-yes" onclick=${deleteFile}>
|
|
|
|
${state.translate('deletePopupYes')}
|
|
|
|
</span>
|
2017-08-24 23:54:02 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
`;
|
|
|
|
|
|
|
|
function copyClick(e) {
|
|
|
|
emit('copy', { url: file.url, location: 'upload-list' });
|
|
|
|
const icon = e.target;
|
|
|
|
const text = e.target.nextSibling;
|
|
|
|
icon.hidden = true;
|
|
|
|
text.hidden = false;
|
|
|
|
setTimeout(() => {
|
|
|
|
icon.hidden = false;
|
|
|
|
text.hidden = true;
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPopup() {
|
|
|
|
const tr = document.getElementById(file.id);
|
|
|
|
const popup = tr.querySelector('.popuptext');
|
|
|
|
popup.classList.add('show');
|
|
|
|
popup.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancel(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
const tr = document.getElementById(file.id);
|
|
|
|
const popup = tr.querySelector('.popuptext');
|
|
|
|
popup.classList.remove('show');
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteFile() {
|
|
|
|
emit('delete', { file, location: 'upload-list' });
|
|
|
|
emit('render');
|
|
|
|
}
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|