diff options
author | Einav Weiss Keidar <einavw@amdocs.com> | 2018-03-20 14:45:40 +0200 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-03-20 13:52:31 +0000 |
commit | 7fdf733a64670fceefc3ded35cfa581e1c458179 (patch) | |
tree | b3623ac9a331473830cb0167c0b487f2a176427c /openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js | |
parent | c7916a4e5955ccc5f0f5252307363b791ec5c7b9 (diff) |
Adding Prettier and fixing up eslint version
Issue-ID: SDC-1094
Change-Id: Ie83ad95a03899345dd90235daf0323cbe3bc6afd
Signed-off-by: Einav Weiss Keidar <einavw@amdocs.com>
Diffstat (limited to 'openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js')
-rw-r--r-- | openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js | 69 |
1 files changed, 41 insertions, 28 deletions
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); +} |