From 7fdf733a64670fceefc3ded35cfa581e1c458179 Mon Sep 17 00:00:00 2001 From: Einav Weiss Keidar Date: Tue, 20 Mar 2018 14:45:40 +0200 Subject: Adding Prettier and fixing up eslint version Issue-ID: SDC-1094 Change-Id: Ie83ad95a03899345dd90235daf0323cbe3bc6afd Signed-off-by: Einav Weiss Keidar --- openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js | 69 ++++++++++++++--------- 1 file changed, 41 insertions(+), 28 deletions(-) (limited to 'openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js') diff --git a/openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js b/openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js index bddd49c700..990701c6f0 100644 --- a/openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js +++ b/openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js @@ -15,35 +15,48 @@ */ function getTimestampString() { - let date = new Date(); - let z = n => n < 10 ? '0' + n : n; - return `${date.getFullYear()}-${z(date.getMonth())}-${z(date.getDate())}_${z(date.getHours())}-${z(date.getMinutes())}`; + let date = new Date(); + let z = n => (n < 10 ? '0' + n : n); + return `${date.getFullYear()}-${z(date.getMonth())}-${z( + date.getDate() + )}_${z(date.getHours())}-${z(date.getMinutes())}`; } +export default function showFileSaveDialog({ + blob, + headers, + defaultFilename, + addTimestamp +}) { + let filename; + let contentDisposition = headers['content-disposition'] + ? headers['content-disposition'] + : ''; + let match = contentDisposition + ? contentDisposition.match(/filename=(.*?)(;|$)/) + : false; + if (match) { + filename = match[1]; + } else { + filename = defaultFilename; + } -export default function showFileSaveDialog({blob, headers, defaultFilename, addTimestamp}) { - let filename; - let contentDisposition = headers['content-disposition'] ? headers['content-disposition'] : ''; - let match = contentDisposition ? contentDisposition.match(/filename=(.*?)(;|$)/) : false; - if (match) { - filename = match[1]; - } else { - filename = defaultFilename; - } + if (addTimestamp) { + filename = filename.replace( + /(^.*?)\.([^.]+$)/, + `$1_${getTimestampString()}.$2` + ); + } - if (addTimestamp) { - filename = filename.replace(/(^.*?)\.([^.]+$)/, `$1_${getTimestampString()}.$2`); - } - - let link = document.createElement('a'); - let url = URL.createObjectURL(blob); - link.href = url; - link.download = filename; - link.style.display = 'none'; - document.body.appendChild(link); - link.click(); - setTimeout(function(){ - document.body.removeChild(link); - URL.revokeObjectURL(url); - }, 0); -}; + let link = document.createElement('a'); + let url = URL.createObjectURL(blob); + link.href = url; + link.download = filename; + link.style.display = 'none'; + document.body.appendChild(link); + link.click(); + setTimeout(function() { + document.body.removeChild(link); + URL.revokeObjectURL(url); + }, 0); +} -- cgit 1.2.3-korg