Web Console: ClusterLoginService should return "Credentials" modal as singleton.
@@ -22,6 +22,8 @@ import {CancellationError} from 'app/errors/CancellationError';
export default class ClusterLoginService {
static $inject = ['$modal', '$q'];
+ deferred;
+
/**
* @param {mgcrea.ngStrap.modal.IModalService} $modal
* @param {ng.IQService} $q
@@ -36,7 +38,12 @@ export default class ClusterLoginService {
* @returns {ng.IPromise<import('../../types/ClusterSecrets').ClusterSecrets>}
*/
askCredentials(baseSecrets) {
- const deferred = this.$q.defer();
+ if (this.deferred)
+ return this.deferred.promise;
+
+ this.deferred = this.$q.defer();
+
+ const self = this;
const modal = this.$modal({
template: `
@@ -50,11 +57,11 @@ export default class ClusterLoginService {
this.secrets = _.clone(baseSecrets);
this.onLogin = () => {
- deferred.resolve(this.secrets);
+ self.deferred.resolve(this.secrets);
};
this.onHide = () => {
- deferred.reject(new CancellationError());
+ self.deferred.reject(new CancellationError());
};
}],
controllerAs: '$ctrl',
@@ -63,7 +70,11 @@ export default class ClusterLoginService {
});
return modal.$promise
- .then(() => deferred.promise)
- .finally(modal.hide);
+ .then(() => this.deferred.promise)
+ .finally(() => {
+ this.deferred = null;
+
+ modal.hide();
+ });
}
}
