summaryrefslogtreecommitdiffstats
path: root/openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js
diff options
context:
space:
mode:
authorilanap <ilanap@amdocs.com>2018-01-04 11:34:59 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-01-04 12:43:23 +0000
commit1965d1663135b880b9774bca2630260e6f28d198 (patch)
tree41e257652bee2451402df284fd43138cf2fa91a2 /openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js
parentbd33bd2374a63b10414e1b14d32d596188fb1957 (diff)
Replace restful-js with Axios
Change-Id: If47c5b7708885e84d632255557543d292f3ccd69 Issue-ID: SDC-869 Signed-off-by: ilanap <ilanap@amdocs.com>
Diffstat (limited to 'openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js')
-rw-r--r--openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js b/openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js
new file mode 100644
index 0000000000..bddd49c700
--- /dev/null
+++ b/openecomp-ui/src/nfvo-utils/ShowFileSaveDialog.js
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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())}`;
+}
+
+
+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`);
+ }
+
+ 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);
+};