Add rename feature
parent
f29eaa28ba
commit
c971189286
|
@ -5,3 +5,4 @@ node_modules
|
|||
.idea
|
||||
dist
|
||||
dockerui
|
||||
*.iml
|
||||
|
|
|
@ -15,4 +15,4 @@ angular.module('dockerui', ['dockerui.templates', 'ngRoute', 'dockerui.services'
|
|||
.constant('DOCKER_ENDPOINT', 'dockerapi')
|
||||
.constant('DOCKER_PORT', '') // Docker port, leave as an empty string if no port is requred. If you have a port, prefix it with a ':' i.e. :4243
|
||||
.constant('UI_VERSION', 'v0.6.0')
|
||||
.constant('DOCKER_API_VERSION', 'v1.16');
|
||||
.constant('DOCKER_API_VERSION', 'v1.17');
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
<div class="detail">
|
||||
|
||||
<h4>Container: {{ container.Name }}</h4>
|
||||
<div ng-if="!container.edit">
|
||||
<h4>Container: {{ container.Name }}
|
||||
<button class="btn btn-primary"
|
||||
ng-click="container.edit = true;">Rename</button>
|
||||
</h4>
|
||||
</div>
|
||||
<div ng-if="container.edit">
|
||||
<h4>
|
||||
Container:
|
||||
<input type="text" ng-model="container.newContainerName">
|
||||
<button class="btn btn-success"
|
||||
ng-click="renameContainer()">Edit</button>
|
||||
<button class="btn btn-danger"
|
||||
ng-click="container.edit = false;">×</button>
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
<div class="btn-group detail">
|
||||
<button class="btn btn-success"
|
||||
|
|
|
@ -2,11 +2,14 @@ angular.module('container', [])
|
|||
.controller('ContainerController', ['$scope', '$routeParams', '$location', 'Container', 'Messages', 'ViewSpinner',
|
||||
function($scope, $routeParams, $location, Container, Messages, ViewSpinner) {
|
||||
$scope.changes = [];
|
||||
$scope.edit = false;
|
||||
|
||||
var update = function() {
|
||||
ViewSpinner.spin();
|
||||
Container.get({id: $routeParams.id}, function(d) {
|
||||
$scope.container = d;
|
||||
$scope.container.edit = false;
|
||||
$scope.container.newContainerName = d.Name;
|
||||
ViewSpinner.stop();
|
||||
}, function(e) {
|
||||
if (e.status === 404) {
|
||||
|
@ -100,6 +103,20 @@ function($scope, $routeParams, $location, Container, Messages, ViewSpinner) {
|
|||
});
|
||||
};
|
||||
|
||||
$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;
|
||||
};
|
||||
|
||||
update();
|
||||
$scope.getChanges();
|
||||
}]);
|
||||
|
|
|
@ -16,7 +16,8 @@ angular.module('dockerui.services', ['ngResource'])
|
|||
unpause: {method: 'POST', params: {id: '@id', action: 'unpause'}},
|
||||
changes: {method: 'GET', params: {action:'changes'}, isArray: true},
|
||||
create: {method: 'POST', params: {action:'create'}},
|
||||
remove: {method: 'DELETE', params: {id: '@id', v:0}}
|
||||
remove: {method: 'DELETE', params: {id: '@id', v:0}},
|
||||
rename: {method: 'POST', params: {id: '@id', action: 'rename'}, isArray: false}
|
||||
});
|
||||
})
|
||||
.factory('ContainerLogs', function($resource, $http, Settings) {
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
describe('ContainerController', function() {
|
||||
var $scope, $httpBackend, mockContainer, $routeParams;
|
||||
|
||||
beforeEach(module('dockerui'));
|
||||
|
||||
|
||||
beforeEach(inject(function ($rootScope, $controller, _$routeParams_) {
|
||||
|
||||
$scope = $rootScope.$new();
|
||||
$routeParams = _$routeParams_;
|
||||
$controller('ContainerController', {
|
||||
$scope: $scope
|
||||
});
|
||||
|
||||
angular.mock.inject(function (_$httpBackend_, _Container_) {
|
||||
mockContainer = _Container_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
});
|
||||
}));
|
||||
|
||||
function expectGetContainer() {
|
||||
$httpBackend.expectGET('dockerapi/containers/json?').respond({
|
||||
'Created': 1421817232,
|
||||
'id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
|
||||
'Image': 'dockerui:latest',
|
||||
'Name': '/dockerui'
|
||||
});
|
||||
}
|
||||
|
||||
it("a correct create request to the Docker remote API", function () {
|
||||
|
||||
$routeParams.id = 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f';
|
||||
$scope.container = {
|
||||
'Created': 1421817232,
|
||||
'id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f',
|
||||
'Image': 'dockerui:latest',
|
||||
'Name': '/dockerui'
|
||||
};
|
||||
$scope.container.newContainerName = "newName";
|
||||
|
||||
var newContainerName = "newName";
|
||||
expectGetContainer();
|
||||
|
||||
$httpBackend.expectGET('dockerapi/containers/changes?').respond([{"Kind":1,"Path":"/docker.sock"}]);
|
||||
|
||||
$httpBackend.expectPOST('dockerapi/containers/' + $routeParams.id + '/rename?name=newName').
|
||||
respond({
|
||||
'name': newContainerName
|
||||
});
|
||||
|
||||
$scope.renameContainer();
|
||||
|
||||
$httpBackend.flush();
|
||||
expect($scope.container.Name).toBe(newContainerName);
|
||||
expect($scope.container.edit).toBeFalsy();
|
||||
});
|
||||
});
|
|
@ -41,15 +41,15 @@ describe('startContainerController', function() {
|
|||
var expectedBody = {
|
||||
'name': 'container-name',
|
||||
'ExposedPorts': {
|
||||
'9000/tcp': {},
|
||||
'9000/tcp': {}
|
||||
},
|
||||
'HostConfig': {
|
||||
'PortBindings': {
|
||||
'9000/tcp': [{
|
||||
'HostPort': '9999',
|
||||
'HostIp': '10.20.10.15',
|
||||
'HostIp': '10.20.10.15'
|
||||
}]
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -69,7 +69,7 @@ describe('startContainerController', function() {
|
|||
ip: '10.20.10.15',
|
||||
extPort: '9999',
|
||||
intPort: '9000'
|
||||
}]
|
||||
}];
|
||||
|
||||
scope.create();
|
||||
$httpBackend.flush();
|
|
@ -8,6 +8,7 @@ files = [
|
|||
'assets/js/jquery-1.11.1.min.js',
|
||||
'assets/js/jquery.gritter.min.js',
|
||||
'assets/js/bootstrap.min.js',
|
||||
'assets/js/spin.js',
|
||||
'assets/js/angularjs/1.2.6/angular.min.js',
|
||||
'assets/js/angularjs/1.2.6/angular-route.min.js',
|
||||
'assets/js/angularjs/1.2.6/angular-resource.min.js',
|
||||
|
|
Loading…
Reference in New Issue