Repository: incubator-zeppelin Updated Branches: refs/heads/master 4b94aa701 -> 498fdd6b2
ZEPPELIN-372 : fix for Export not working on Firefox and Safari With reference to bug in https://github.com/apache/incubator-zeppelin/pull/376#issuecomment-154801136 The export link was not working on Firefox and Safari. Have made a fix, this should enable download on Firefox and Safari. Author: Prabhjyot Singh <[email protected]> Closes #408 from prabhjyotsingh/ZEPPELIN-372_fix and squashes the following commits: cc20de6 [Prabhjyot Singh] refactoring function into service and remove jQuery call 0833eb2 [Prabhjyot Singh] ZEPPELIN-372: fix for Export not working on IE 91fd7f9 [Prabhjyot Singh] fix for not working on Firefox and Safari Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/498fdd6b Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/498fdd6b Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/498fdd6b Branch: refs/heads/master Commit: 498fdd6b2ebb5f62864918649f30c72e75c8a75c Parents: 4b94aa7 Author: Prabhjyot Singh <[email protected]> Authored: Tue Nov 10 12:04:08 2015 +0530 Committer: Damien CORNEAU <[email protected]> Committed: Mon Nov 16 16:40:56 2015 +0900 ---------------------------------------------------------------------- .../src/app/notebook/notebook.controller.js | 12 ++--- .../browser-detect/browserDetect.service.js | 40 ++++++++++++++++ .../src/components/saveAs/saveAs.service.js | 48 ++++++++++++++++++++ zeppelin-web/src/index.html | 2 + 4 files changed, 95 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/498fdd6b/zeppelin-web/src/app/notebook/notebook.controller.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/notebook/notebook.controller.js b/zeppelin-web/src/app/notebook/notebook.controller.js index b671ead..848d66d 100644 --- a/zeppelin-web/src/app/notebook/notebook.controller.js +++ b/zeppelin-web/src/app/notebook/notebook.controller.js @@ -15,7 +15,9 @@ */ 'use strict'; -angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $route, $routeParams, $location, $rootScope, $http, websocketMsgSrv, baseUrlSrv, $timeout) { +angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $route, $routeParams, $location, + $rootScope, $http, websocketMsgSrv, baseUrlSrv, + $timeout, SaveAsService) { $scope.note = null; $scope.showEditor = false; $scope.editorToggled = false; @@ -81,12 +83,8 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro //Export notebook $scope.exportNotebook = function() { - var jsonContent = 'data:text/json;charset=utf-8,' + JSON.stringify($scope.note); - var encodedUri = encodeURI(jsonContent); - var link = document.createElement('a'); - link.setAttribute('href', encodedUri); - link.setAttribute('download', $scope.note.name + '.json'); - link.click(); + var jsonContent = JSON.stringify($scope.note); + SaveAsService.SaveAs(jsonContent, $scope.note.name, 'json'); }; //Clone note http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/498fdd6b/zeppelin-web/src/components/browser-detect/browserDetect.service.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/components/browser-detect/browserDetect.service.js b/zeppelin-web/src/components/browser-detect/browserDetect.service.js new file mode 100644 index 0000000..2e70175 --- /dev/null +++ b/zeppelin-web/src/components/browser-detect/browserDetect.service.js @@ -0,0 +1,40 @@ +/* + * 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. + */ +'use strict'; + +angular.module('zeppelinWebApp').service('browserDetectService', function() { + + this.detectIE = function() { + var ua = window.navigator.userAgent; + var msie = ua.indexOf('MSIE '); + if (msie > 0) { + // IE 10 or older => return version number + return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10); + } + var trident = ua.indexOf('Trident/'); + if (trident > 0) { + // IE 11 => return version number + var rv = ua.indexOf('rv:'); + return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10); + } + var edge = ua.indexOf('Edge/'); + if (edge > 0) { + // IE 12 (aka Edge) => return version number + return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); + } + // other browser + return false; + }; + +}); http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/498fdd6b/zeppelin-web/src/components/saveAs/saveAs.service.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/components/saveAs/saveAs.service.js b/zeppelin-web/src/components/saveAs/saveAs.service.js new file mode 100644 index 0000000..7026594 --- /dev/null +++ b/zeppelin-web/src/components/saveAs/saveAs.service.js @@ -0,0 +1,48 @@ +/* + * 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. + */ +'use strict'; + +angular.module('zeppelinWebApp').service('SaveAsService', function(browserDetectService) { + + this.SaveAs = function(content, filename, extension) { + if (browserDetectService.detectIE()) { + angular.element('body').append('<iframe id="SaveAsId" style="display: none"></iframe>'); + var frameSaveAs = angular.element('body > iframe#SaveAsId')[0].contentWindow; + frameSaveAs.document.open('text/json', 'replace'); + frameSaveAs.document.write(content); + frameSaveAs.document.close(); + frameSaveAs.focus(); + var t1 = Date.now(); + frameSaveAs.document.execCommand('SaveAs', false, filename + '.' + extension); + var t2 = Date.now(); + + //This means, this version of IE dosen't support auto download of a file with extension provided in param + //falling back to ".txt" + if (t1 === t2) { + frameSaveAs.document.execCommand('SaveAs', true, filename + '.txt'); + } + angular.element('body > iframe#SaveAsId').remove(); + } else { + content = 'data:image/svg;charset=utf-8,' + encodeURIComponent(content); + angular.element('body').append('<a id="SaveAsId"></a>'); + var saveAsElement = angular.element('body > a#SaveAsId'); + saveAsElement.attr('href', content); + saveAsElement.attr('download', filename + '.' + extension); + saveAsElement.attr('target', '_blank'); + saveAsElement[0].click(); + saveAsElement.remove(); + } + }; + +}); http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/498fdd6b/zeppelin-web/src/index.html ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/index.html b/zeppelin-web/src/index.html index ea485e1..b8dd489 100644 --- a/zeppelin-web/src/index.html +++ b/zeppelin-web/src/index.html @@ -138,6 +138,8 @@ limitations under the License. <script src="components/websocketEvents/websocketEvents.factory.js"></script> <script src="components/notebookListDataFactory/notebookList.datafactory.js"></script> <script src="components/baseUrl/baseUrl.service.js"></script> + <script src="components/browser-detect/browserDetect.service.js"></script> + <script src="components/saveAs/saveAs.service.js"></script> <!-- endbuild --> </body> </html>
