2017-08-24 21:54:02 +00:00
|
|
|
const html = require('choo/html');
|
2018-02-13 19:32:59 +00:00
|
|
|
const assets = require('../../../common/assets');
|
|
|
|
const number = require('../../utils').number;
|
|
|
|
const deletePopup = require('../popup');
|
2017-08-24 21:54:02 +00:00
|
|
|
|
2018-01-24 18:23:13 +00:00
|
|
|
function timeLeft(milliseconds, state) {
|
2017-08-24 21:54:02 +00:00
|
|
|
const minutes = Math.floor(milliseconds / 1000 / 60);
|
|
|
|
const hours = Math.floor(minutes / 60);
|
|
|
|
if (hours >= 1) {
|
2018-01-24 18:23:13 +00:00
|
|
|
return state.translate('expiresHoursMinutes', {
|
|
|
|
hours,
|
|
|
|
minutes: minutes % 60
|
|
|
|
});
|
2017-08-24 21:54:02 +00:00
|
|
|
} else if (hours === 0) {
|
2018-01-24 18:23:13 +00:00
|
|
|
if (minutes === 0) {
|
|
|
|
return state.translate('expiresMinutes', { minutes: '< 1' });
|
|
|
|
}
|
|
|
|
return state.translate('expiresMinutes', { minutes });
|
2017-08-24 21:54:02 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function(file, state, emit) {
|
|
|
|
const ttl = file.expiresAt - Date.now();
|
2018-01-24 18:23:13 +00:00
|
|
|
const remainingTime =
|
|
|
|
timeLeft(ttl, state) || state.translate('linkExpiredAlt');
|
2018-01-23 02:11:48 +00:00
|
|
|
const downloadLimit = file.dlimit || 1;
|
|
|
|
const totalDownloads = file.dtotal || 0;
|
2017-08-24 21:54:02 +00:00
|
|
|
const row = html`
|
|
|
|
<tr id="${file.id}">
|
2018-02-13 19:32:59 +00:00
|
|
|
<td class="fileData fileData--overflow" title="${file.name}">
|
2018-01-24 18:23:13 +00:00
|
|
|
<a class="link" href="/share/${file.id}">${file.name}</a>
|
|
|
|
</td>
|
2018-02-13 19:32:59 +00:00
|
|
|
<td class="fileData fileData--center">
|
2018-01-24 18:23:13 +00:00
|
|
|
<img
|
|
|
|
onclick=${copyClick}
|
|
|
|
src="${assets.get('copy-16.svg')}"
|
2018-02-13 19:32:59 +00:00
|
|
|
class="cursor--pointer"
|
2018-01-24 18:23:13 +00:00
|
|
|
title="${state.translate('copyUrlHover')}">
|
2018-02-13 19:32:59 +00:00
|
|
|
<span hidden="true">
|
2018-01-24 18:23:13 +00:00
|
|
|
${state.translate('copiedUrl')}
|
|
|
|
</span>
|
2017-08-24 21:54:02 +00:00
|
|
|
</td>
|
2018-02-13 19:32:59 +00:00
|
|
|
<td class="fileData fileData--overflow">${remainingTime}</td>
|
|
|
|
<td class="fileData fileData--center">${number(totalDownloads)} / ${number(
|
2018-02-08 03:46:18 +00:00
|
|
|
downloadLimit
|
|
|
|
)}</td>
|
2018-02-13 19:32:59 +00:00
|
|
|
<td class="fileData fileData--center">
|
2018-01-24 18:23:13 +00:00
|
|
|
<img
|
|
|
|
onclick=${showPopup}
|
|
|
|
src="${assets.get('close-16.svg')}"
|
2018-02-13 19:32:59 +00:00
|
|
|
class="cursor--pointer"
|
2018-01-24 18:23:13 +00:00
|
|
|
title="${state.translate('deleteButtonHover')}">
|
2018-02-13 19:32:59 +00:00
|
|
|
${deletePopup(
|
|
|
|
state.translate('deletePopupText'),
|
|
|
|
state.translate('deletePopupYes'),
|
|
|
|
state.translate('deletePopupCancel'),
|
|
|
|
deleteFile
|
|
|
|
)}
|
2017-08-24 21:54:02 +00:00
|
|
|
</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);
|
2018-02-13 19:32:59 +00:00
|
|
|
const popup = tr.querySelector('.popup');
|
|
|
|
popup.classList.add('popup--show');
|
2017-08-24 21:54:02 +00:00
|
|
|
popup.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteFile() {
|
|
|
|
emit('delete', { file, location: 'upload-list' });
|
|
|
|
emit('render');
|
|
|
|
}
|
|
|
|
|
|
|
|
return row;
|
|
|
|
};
|