Use text-download service on horizon
The text-download service is ported on horizon, so we use it. Change-Id: I0ff3f1dd3f1ff702e799b709f8cf798e6aca127e
This commit is contained in:
parent
64b8af65b9
commit
1972ddfe8e
@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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]));
|
||||
|
@ -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();
|
||||
|
||||
}));
|
||||
|
||||
|
@ -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></a>');
|
||||
a.attr("href", fileurl);
|
||||
a.attr("download", filename);
|
||||
a.attr("target", "_blank");
|
||||
angular.element(document.body).append(a);
|
||||
a[0].click();
|
||||
a.remove();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
Loading…
x
Reference in New Issue
Block a user