diff --git a/app/components/containerConsole/containerConsole.html b/app/components/containerConsole/containerConsole.html
index 410481b37..716b5ffb8 100644
--- a/app/components/containerConsole/containerConsole.html
+++ b/app/components/containerConsole/containerConsole.html
@@ -60,7 +60,7 @@
-
+
diff --git a/app/components/containerConsole/containerConsoleController.js b/app/components/containerConsole/containerConsoleController.js
index 9a221f365..2ff1214ad 100644
--- a/app/components/containerConsole/containerConsoleController.js
+++ b/app/components/containerConsole/containerConsoleController.js
@@ -1,6 +1,6 @@
angular.module('containerConsole', [])
-.controller('ContainerConsoleController', ['$scope', '$stateParams', 'Container', 'Image', 'Exec', '$timeout', 'EndpointProvider', 'Notifications', 'ContainerHelper',
-function ($scope, $stateParams, Container, Image, Exec, $timeout, EndpointProvider, Notifications, ContainerHelper) {
+.controller('ContainerConsoleController', ['$scope', '$stateParams', 'Container', 'Image', 'EndpointProvider', 'Notifications', 'ContainerHelper', 'ContainerService', 'ExecService',
+function ($scope, $stateParams, Container, Image, EndpointProvider, Notifications, ContainerHelper, ContainerService, ExecService) {
$scope.state = {};
$scope.state.loaded = false;
$scope.state.connected = false;
@@ -52,24 +52,24 @@ function ($scope, $stateParams, Container, Image, Exec, $timeout, EndpointProvid
Cmd: ContainerHelper.commandStringToArray(command)
};
- Container.exec(execConfig, function(d) {
- if (d.message) {
- $('#loadConsoleSpinner').hide();
- Notifications.error('Error', {}, d.message);
+ var execId;
+ ContainerService.createExec(execConfig)
+ .then(function success(data) {
+ execId = data.Id;
+ var url = window.location.href.split('#')[0] + 'api/websocket/exec?id=' + execId + '&endpointId=' + EndpointProvider.endpointID();
+ if (url.indexOf('https') > -1) {
+ url = url.replace('https://', 'wss://');
} else {
- var execId = d.Id;
- resizeTTY(execId, termHeight, termWidth);
- var url = window.location.href.split('#')[0] + 'api/websocket/exec?id=' + execId + '&endpointId=' + EndpointProvider.endpointID();
- if (url.indexOf('https') > -1) {
- url = url.replace('https://', 'wss://');
- } else {
- url = url.replace('http://', 'ws://');
- }
- initTerm(url, termHeight, termWidth);
+ url = url.replace('http://', 'ws://');
}
- }, function (e) {
+ initTerm(url, termHeight, termWidth);
+ return ExecService.resizeTTY(execId, termHeight, termWidth, 2000);
+ })
+ .catch(function error(err) {
+ Notifications.error('Failure', err, 'Unable to exec into container');
+ })
+ .finally(function final() {
$('#loadConsoleSpinner').hide();
- Notifications.error('Failure', e, 'Unable to start an exec instance');
});
};
@@ -83,19 +83,6 @@ function ($scope, $stateParams, Container, Image, Exec, $timeout, EndpointProvid
}
};
- function resizeTTY(execId, height, width) {
- $timeout(function() {
- Exec.resize({id: execId, height: height, width: width}, function (d) {
- if (d.message) {
- Notifications.error('Error', {}, 'Unable to resize TTY');
- }
- }, function (e) {
- Notifications.error('Failure', {}, 'Unable to resize TTY');
- });
- }, 2000);
-
- }
-
function initTerm(url, height, width) {
socket = new WebSocket(url);
diff --git a/app/services/docker/containerService.js b/app/services/docker/containerService.js
index 39d1494ed..001b2203d 100644
--- a/app/services/docker/containerService.js
+++ b/app/services/docker/containerService.js
@@ -87,5 +87,23 @@ angular.module('portainer.services')
return deferred.promise;
};
+ service.createExec = function(execConfig) {
+ var deferred = $q.defer();
+
+ Container.exec(execConfig).$promise
+ .then(function success(data) {
+ if (data.message) {
+ deferred.reject({ msg: data.message, err: data.message });
+ } else {
+ deferred.resolve(data);
+ }
+ })
+ .catch(function error(err) {
+ deferred.reject(err);
+ });
+
+ return deferred.promise;
+ };
+
return service;
}]);
diff --git a/app/services/docker/execService.js b/app/services/docker/execService.js
new file mode 100644
index 000000000..5f88846ec
--- /dev/null
+++ b/app/services/docker/execService.js
@@ -0,0 +1,27 @@
+angular.module('portainer.services')
+.factory('ExecService', ['$q', '$timeout', 'Exec', function ExecServiceFactory($q, $timeout, Exec) {
+ 'use strict';
+ var service = {};
+
+ service.resizeTTY = function(execId, height, width, timeout) {
+ var deferred = $q.defer();
+
+ $timeout(function() {
+ Exec.resize({id: execId, height: height, width: width}).$promise
+ .then(function success(data) {
+ if (data.message) {
+ deferred.reject({ msg: 'Unable to exec into container', err: data.message });
+ } else {
+ deferred.resolve(data);
+ }
+ })
+ .catch(function error(err) {
+ deferred.reject({ msg: 'Unable to exec into container', err: err });
+ });
+ }, timeout);
+
+ return deferred.promise;
+ };
+
+ return service;
+}]);