2014-11-12 17:48:13 +00:00
|
|
|
angular.module('container', [])
|
2016-02-22 06:10:16 +00:00
|
|
|
.controller('ContainerController', ['$scope', '$routeParams', '$location', 'Container', 'ContainerCommit', 'Image', 'Messages', 'ViewSpinner', '$timeout',
|
|
|
|
function ($scope, $routeParams, $location, Container, ContainerCommit, Image, Messages, ViewSpinner, $timeout) {
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.changes = [];
|
|
|
|
$scope.edit = false;
|
2016-02-22 06:10:16 +00:00
|
|
|
$scope.newCfg = {
|
|
|
|
Env: []
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
var update = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.get({id: $routeParams.id}, function (d) {
|
|
|
|
$scope.container = d;
|
|
|
|
$scope.container.edit = false;
|
|
|
|
$scope.container.newContainerName = d.Name;
|
2016-02-22 06:10:16 +00:00
|
|
|
$scope.newCfg.Env = d.Config.Env.map(function(entry) {
|
|
|
|
return {name: entry.split('=')[0], value: entry.split('=')[1]};
|
|
|
|
});
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
ViewSpinner.stop();
|
|
|
|
}, function (e) {
|
|
|
|
if (e.status === 404) {
|
|
|
|
$('.detail').hide();
|
|
|
|
Messages.error("Not found", "Container not found.");
|
|
|
|
} else {
|
|
|
|
Messages.error("Failure", e.data);
|
|
|
|
}
|
|
|
|
ViewSpinner.stop();
|
|
|
|
});
|
2016-02-22 06:10:16 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.start = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.start({
|
|
|
|
id: $scope.container.Id,
|
|
|
|
HostConfig: $scope.container.HostConfig
|
|
|
|
}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container started", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to start." + e.data);
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.stop = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.stop({id: $routeParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container stopped", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to stop." + e.data);
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.kill = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.kill({id: $routeParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container killed", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to die." + e.data);
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2016-02-22 06:10:16 +00:00
|
|
|
$scope.restartEnv = function () {
|
|
|
|
var config = angular.copy($scope.container.Config);
|
|
|
|
|
|
|
|
config.Env = $scope.newCfg.Env.map(function(entry) {
|
|
|
|
return entry.name+"="+entry.value;
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(config);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ViewSpinner.spin();
|
|
|
|
ContainerCommit.commit({id: $routeParams.id, tag: $scope.container.Config.Image, config: config }, function (d) {
|
|
|
|
console.log(d.Id);
|
|
|
|
if ('Id' in d) {
|
|
|
|
var imageId = d.Id;
|
|
|
|
Image.inspect({id: imageId}, function(imageData) {
|
|
|
|
console.log(imageData);
|
|
|
|
Container.create(imageData.Config, function(containerData) {
|
|
|
|
console.log(containerData);
|
|
|
|
// Stop current if running
|
|
|
|
if ($scope.container.State.Running) {
|
|
|
|
Container.stop({id: $routeParams.id}, function (d) {
|
|
|
|
Messages.send("Container stopped", $routeParams.id);
|
|
|
|
// start new
|
|
|
|
Container.start({
|
|
|
|
id: containerData.Id
|
|
|
|
// HostConfig: $scope.container.HostConfig we really need this?
|
|
|
|
}, function (d) {
|
|
|
|
$location.url('/containers/' + containerData.Id + '/');
|
|
|
|
Messages.send("Container started", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to start." + e.data);
|
|
|
|
});
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to stop." + e.data);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// start new
|
|
|
|
Container.start({
|
|
|
|
id: containerData.Id
|
|
|
|
// HostConfig: $scope.container.HostConfig we really need this?
|
|
|
|
}, function (d) {
|
|
|
|
$location.url('/containers/'+containerData.Id+'/');
|
|
|
|
Messages.send("Container started", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to start." + e.data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}, function(e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Image failed to get." + e.data);
|
|
|
|
});
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Image failed to get." + e.data);
|
|
|
|
})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
update();
|
|
|
|
Messages.send("Container commit failed", $routeParams.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to commit." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.commit = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
ContainerCommit.commit({id: $routeParams.id, repo: $scope.container.Config.Image}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container commited", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to commit." + e.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.pause = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.pause({id: $routeParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container paused", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to pause." + e.data);
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.unpause = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.unpause({id: $routeParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container unpaused", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to unpause." + e.data);
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.remove = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.remove({id: $routeParams.id}, function (d) {
|
|
|
|
update();
|
2015-12-24 06:04:47 +00:00
|
|
|
$location.path('/containers');
|
2015-08-25 05:59:54 +00:00
|
|
|
Messages.send("Container removed", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to remove." + e.data);
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.restart = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.restart({id: $routeParams.id}, function (d) {
|
|
|
|
update();
|
|
|
|
Messages.send("Container restarted", $routeParams.id);
|
|
|
|
}, function (e) {
|
|
|
|
update();
|
|
|
|
Messages.error("Failure", "Container failed to restart." + e.data);
|
|
|
|
});
|
|
|
|
};
|
2015-05-12 05:52:12 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.hasContent = function (data) {
|
|
|
|
return data !== null && data !== undefined;
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.getChanges = function () {
|
|
|
|
ViewSpinner.spin();
|
|
|
|
Container.changes({id: $routeParams.id}, function (d) {
|
|
|
|
$scope.changes = d;
|
|
|
|
ViewSpinner.stop();
|
|
|
|
});
|
|
|
|
};
|
2014-11-12 17:48:13 +00:00
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
$scope.renameContainer = function () {
|
|
|
|
// #FIXME fix me later to handle http status to show the correct error message
|
|
|
|
Container.rename({id: $routeParams.id, 'name': $scope.container.newContainerName}, function (data) {
|
|
|
|
if (data.name) {
|
|
|
|
$scope.container.Name = data.name;
|
|
|
|
Messages.send("Container renamed", $routeParams.id);
|
|
|
|
} else {
|
|
|
|
$scope.container.newContainerName = $scope.container.Name;
|
|
|
|
Messages.error("Failure", "Container failed to rename.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$scope.container.edit = false;
|
|
|
|
};
|
2015-03-12 21:28:01 +00:00
|
|
|
|
2016-02-22 06:10:16 +00:00
|
|
|
$scope.addEntry = function (array, entry) {
|
|
|
|
array.push(entry);
|
|
|
|
};
|
|
|
|
$scope.rmEntry = function (array, entry) {
|
|
|
|
var idx = array.indexOf(entry);
|
|
|
|
array.splice(idx, 1);
|
|
|
|
};
|
|
|
|
|
2015-08-25 05:59:54 +00:00
|
|
|
update();
|
|
|
|
$scope.getChanges();
|
|
|
|
}]);
|
2016-02-22 06:10:16 +00:00
|
|
|
|