diff --git a/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js b/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js index 2f11a8a8..1b890eaf 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/show-certificate/show-certificate.service.js @@ -27,12 +27,13 @@ showCertificateService); showCertificateService.$inject = [ - 'horizon.framework.util.q.extensions', - 'horizon.app.core.openstack-service-api.magnum' + 'horizon.app.core.openstack-service-api.magnum', + 'horizon.framework.util.file.text-download', + 'horizon.framework.util.q.extensions' ]; function showCertificateService( - $qExtensions, magnum + magnum, textDownload, $qExtensions ) { var service = { @@ -51,7 +52,7 @@ function perform(selected) { // get certificate return magnum.showCertificate(selected.id).success(function(response) { - magnum.downloadTextAsFile(response.pem, selected.name + "_ca.pem"); + textDownload.downloadTextFile(response.pem, selected.name + "_ca.pem"); }); } diff --git a/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.js b/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.js index ee258b6c..5cffbfe3 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.js @@ -29,17 +29,19 @@ signCertificateService.$inject = [ '$uibModal', 'horizon.app.core.openstack-service-api.magnum', - 'horizon.framework.util.actions.action-result.service', - 'horizon.framework.util.i18n.gettext', - 'horizon.framework.util.q.extensions', - 'horizon.framework.widgets.toast.service', 'horizon.dashboard.container-infra.clusters.basePath', 'horizon.dashboard.container-infra.clusters.resourceType', - 'horizon.dashboard.container-infra.clusters.sign-certificate-model' + 'horizon.dashboard.container-infra.clusters.sign-certificate-model', + 'horizon.framework.util.actions.action-result.service', + 'horizon.framework.util.file.text-download', + 'horizon.framework.util.i18n.gettext', + 'horizon.framework.util.q.extensions', + 'horizon.framework.widgets.toast.service' ]; function signCertificateService( - $uibModal, magnum, actionResult, gettext, $qExtensions, toast, basePath, resourceType, model + $uibModal, magnum, basePath, resourceType, model, actionResult, textDownload, + gettext, $qExtensions, toast ) { var message = { @@ -82,7 +84,7 @@ } function success(response) { - magnum.downloadTextAsFile(response.data.pem, model.cluster_name + "_cert.pem"); + textDownload.downloadTextFile(response.data.pem, model.cluster_name + "_cert.pem"); response.data.id = response.data.uuid; toast.add('success', interpolate(message.success, [response.data.id])); diff --git a/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.spec.js b/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.spec.js index 28adfd35..3b29861c 100644 --- a/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.spec.js +++ b/magnum_ui/static/dashboard/container-infra/clusters/sign-certificate/sign-certificate.service.spec.js @@ -20,7 +20,7 @@ describe('horizon.dashboard.container-infra.clusters.sign-certificate.service', function() { - var $q, service, magnum, deferred, fakeDeferred, model; + var $q, service, textDownload, deferred, fakeDeferred, model; var fakeModal = { result: { @@ -44,10 +44,10 @@ $q = _$q_; service = $injector.get( 'horizon.dashboard.container-infra.clusters.sign-certificate.service'); - magnum = $injector.get('horizon.app.core.openstack-service-api.magnum'); + textDownload = $injector.get('horizon.framework.util.file.text-download'); deferred = $q.defer(); deferred.resolve({data: {uuid: 1}}); - spyOn(magnum, 'downloadTextAsFile').and.returnValue(deferred.promise); + spyOn(textDownload, 'downloadTextFile').and.returnValue(deferred.promise); model = $injector.get('horizon.dashboard.container-infra.clusters.sign-certificate-model'); fakeDeferred = $q.defer(); @@ -70,7 +70,7 @@ $timeout.flush(); expect(model.signCertificate).toHaveBeenCalled(); - expect(magnum.downloadTextAsFile).toHaveBeenCalled(); + expect(textDownload.downloadTextFile).toHaveBeenCalled(); })); diff --git a/magnum_ui/static/dashboard/container-infra/magnum.service.js b/magnum_ui/static/dashboard/container-infra/magnum.service.js index 85a01e2a..e3e87ebc 100644 --- a/magnum_ui/static/dashboard/container-infra/magnum.service.js +++ b/magnum_ui/static/dashboard/container-infra/magnum.service.js @@ -50,8 +50,7 @@ createQuota: createQuota, updateQuota: updateQuota, deleteQuota: deleteQuota, - getNetworks: getNetworks, - downloadTextAsFile: downloadTextAsFile + getNetworks: getNetworks }; return service; @@ -247,28 +246,5 @@ toastService.add('error', gettext('Unable to retrieve the networks.')); }); } - - /////////// - // Utils // - /////////// - - function downloadTextAsFile(text, filename) { - // create text file as object url - var blob = new Blob([ text ], { "type" : "text/plain" }); - window.URL = window.URL || window.webkitURL; - var fileurl = window.URL.createObjectURL(blob); - - // provide text as downloaded file - $timeout(function() { - //Update view - var a = angular.element(''); - a.attr("href", fileurl); - a.attr("download", filename); - a.attr("target", "_blank"); - angular.element(document.body).append(a); - a[0].click(); - a.remove(); - }, 0); - } } }());