2016-06-02 05:34:03 +00:00
|
|
|
angular.module('container', [])
|
2016-08-19 06:41:45 +00:00
|
|
|
.controller('ContainerController', ['$scope', '$state','$stateParams', '$filter', 'Container', 'ContainerCommit', 'Messages', 'errorMsgFilter',
|
|
|
|
function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Messages, errorMsgFilter) {
|
|
|
|
$scope.activityTime = 0;
|
|
|
|
$scope.portBindings = [];
|
|
|
|
$scope.config = {
|
|
|
|
Image: '',
|
|
|
|
Registry: ''
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var update = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.get({id: $stateParams.id}, function (d) {
|
|
|
|
$scope.container = d;
|
|
|
|
$scope.container.edit = false;
|
|
|
|
$scope.container.newContainerName = $filter('trimcontainername')(d.Name);
|
|
|
|
|
2016-08-19 06:41:45 +00:00
|
|
|
if (d.State.Running) {
|
|
|
|
$scope.activityTime = moment.duration(moment(d.State.StartedAt).utc().diff(moment().utc())).humanize();
|
|
|
|
} else {
|
|
|
|
$scope.activityTime = moment.duration(moment().utc().diff(moment(d.State.FinishedAt).utc())).humanize();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-19 06:41:45 +00:00
|
|
|
$scope.portBindings = [];
|
|
|
|
if (d.NetworkSettings.Ports) {
|
|
|
|
angular.forEach(Object.keys(d.NetworkSettings.Ports), function(portMapping) {
|
|
|
|
if (d.NetworkSettings.Ports[portMapping]) {
|
|
|
|
var mapping = {};
|
|
|
|
mapping.container = portMapping;
|
|
|
|
mapping.host = d.NetworkSettings.Ports[portMapping][0].HostIp + ':' + d.NetworkSettings.Ports[portMapping][0].HostPort;
|
|
|
|
$scope.portBindings.push(mapping);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
if (e.status === 404) {
|
|
|
|
$('.detail').hide();
|
|
|
|
Messages.error("Not found", "Container not found.");
|
|
|
|
} else {
|
|
|
|
Messages.error("Failure", e.data);
|
|
|
|
}
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.start = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.start({
|
|
|
|
id: $scope.container.Id,
|
|
|
|
HostConfig: $scope.container.HostConfig
|
|
|
|
}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container started", $stateParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to start." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.stop = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.stop({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container stopped", $stateParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to stop." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.kill = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.kill({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container killed", $stateParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to die." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-19 06:41:45 +00:00
|
|
|
//TODO: centralize createImageConfig (also used in imageController)
|
|
|
|
function createImageConfig(imageName, registry) {
|
|
|
|
var imageNameAndTag = imageName.split(':');
|
|
|
|
var image = imageNameAndTag[0];
|
|
|
|
if (registry) {
|
|
|
|
image = registry + '/' + imageNameAndTag[0];
|
|
|
|
}
|
|
|
|
var imageConfig = {
|
|
|
|
repo: image,
|
|
|
|
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'
|
|
|
|
};
|
|
|
|
return imageConfig;
|
|
|
|
}
|
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.commit = function () {
|
2016-08-19 06:41:45 +00:00
|
|
|
$('#createImageSpinner').show();
|
|
|
|
var image = _.toLower($scope.config.Image);
|
|
|
|
var registry = _.toLower($scope.config.Registry);
|
|
|
|
var imageConfig = createImageConfig(image, registry);
|
|
|
|
ContainerCommit.commit({id: $stateParams.id, tag: imageConfig.tag, repo: imageConfig.repo}, function (d) {
|
|
|
|
update();
|
|
|
|
$('#createImageSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
Messages.send("Container commited", $stateParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
2016-08-19 06:41:45 +00:00
|
|
|
$('#createImageSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
Messages.error("Failure", "Container failed to commit." + e.data);
|
|
|
|
});
|
|
|
|
};
|
2016-08-19 06:41:45 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.pause = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.pause({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container paused", $stateParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to pause." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.unpause = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.unpause({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container unpaused", $stateParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to unpause." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.remove = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.remove({id: $stateParams.id}, function (d) {
|
|
|
|
$state.go('containers', {}, {reload: true});
|
|
|
|
Messages.send("Container removed", $stateParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to remove." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.restart = function () {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.restart({id: $stateParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container restarted", $stateParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to restart." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.renameContainer = function () {
|
2016-08-19 06:41:45 +00:00
|
|
|
Container.rename({id: $stateParams.id, 'name': $scope.container.newContainerName}, function (d) {
|
|
|
|
if (d.name) {
|
|
|
|
$scope.container.Name = d.name;
|
|
|
|
Messages.send("Container successfully renamed", d.name);
|
2016-06-02 05:34:03 +00:00
|
|
|
} else {
|
2016-08-19 06:41:45 +00:00
|
|
|
var error = errorMsgFilter(d);
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.container.newContainerName = $scope.container.Name;
|
2016-08-19 06:41:45 +00:00
|
|
|
Messages.error("Unable to rename container", error);
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$scope.container.edit = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
update();
|
|
|
|
}]);
|