1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-23 07:19:41 +02:00
portainer/js/controllers.js

358 lines
11 KiB
JavaScript
Raw Normal View History

2013-06-08 16:20:29 -09:00
function MastheadController($scope) {
$scope.template = 'partials/masthead.html';
}
2013-06-10 15:42:34 -09:00
function DashboardController($scope, Container) {
2013-06-08 16:20:29 -09:00
}
2013-06-19 17:40:58 -09:00
function MessageController($scope, Messages) {
$scope.template = 'partials/messages.html';
$scope.messages = [];
$scope.$watch('messages.length', function(o, n) {
2013-06-22 09:23:25 -09:00
$('#message-display').show();
2013-06-19 17:40:58 -09:00
});
$scope.$on(Messages.event, function(e, msg) {
$scope.messages.push(msg);
setTimeout(function() {
2013-06-22 09:23:25 -09:00
$('#message-display').hide('slow');
}, 30000);
2013-06-19 17:40:58 -09:00
});
}
function StatusBarController($scope, Settings) {
$scope.template = 'partials/statusbar.html';
$scope.uiVersion = Settings.uiVersion;
$scope.apiVersion = Settings.version;
}
function SideBarController($scope, Container, Settings) {
$scope.template = 'partials/sidebar.html';
$scope.containers = [];
$scope.endpoint = Settings.endpoint;
Container.query({all: 0}, function(d) {
2013-06-18 18:01:22 -09:00
$scope.containers = d;
2013-06-19 17:40:58 -09:00
});
}
2013-06-22 09:23:25 -09:00
function SettingsController($scope, System, Docker, Settings, Messages) {
2013-06-09 16:31:05 -09:00
$scope.info = {};
$scope.docker = {};
2013-06-10 15:10:43 -09:00
$scope.endpoint = Settings.endpoint;
$scope.apiVersion = Settings.version;
2013-06-09 16:31:05 -09:00
2013-06-19 18:10:08 -09:00
Docker.get({}, function(d) { $scope.docker = d; });
System.get({}, function(d) { $scope.info = d; });
2013-06-08 16:20:29 -09:00
}
// Controls the page that displays a single container and actions on that container.
2013-06-22 09:23:25 -09:00
function ContainerController($scope, $routeParams, $location, Container, Messages, ViewSpinner) {
2013-06-19 18:10:08 -09:00
$scope.changes = [];
2013-06-08 16:20:29 -09:00
$scope.start = function(){
2013-06-22 09:23:25 -09:00
ViewSpinner.spin();
2013-06-08 16:20:29 -09:00
Container.start({id: $routeParams.id}, function(d) {
2013-06-19 18:10:08 -09:00
Messages.send({class: 'text-success', data: 'Container started.'});
2013-06-22 09:23:25 -09:00
ViewSpinner.stop();
}, function(e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
2013-06-22 09:23:25 -09:00
ViewSpinner.stop();
2013-06-19 18:10:08 -09:00
});
2013-06-08 15:12:14 -09:00
};
2013-06-08 16:20:29 -09:00
$scope.stop = function() {
2013-06-22 09:23:25 -09:00
ViewSpinner.spin();
2013-06-08 16:20:29 -09:00
Container.stop({id: $routeParams.id}, function(d) {
2013-06-19 18:10:08 -09:00
Messages.send({class: 'text-success', data: 'Container stopped.'});
2013-06-22 09:23:25 -09:00
ViewSpinner.stop();
}, function(e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
2013-06-22 09:23:25 -09:00
ViewSpinner.stop();
2013-06-08 15:12:14 -09:00
});
};
2013-06-08 16:20:29 -09:00
2013-06-09 16:31:05 -09:00
$scope.kill = function() {
2013-06-22 09:23:25 -09:00
ViewSpinner.spin();
2013-06-09 16:31:05 -09:00
Container.kill({id: $routeParams.id}, function(d) {
2013-06-19 18:10:08 -09:00
Messages.send({class: 'text-success', data: 'Container killed.'});
2013-06-22 09:23:25 -09:00
ViewSpinner.stop();
2013-06-09 16:31:05 -09:00
}, function(e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
2013-06-22 09:23:25 -09:00
ViewSpinner.stop();
2013-06-09 16:31:05 -09:00
});
};
2013-06-08 16:20:29 -09:00
$scope.remove = function() {
2013-06-22 09:23:25 -09:00
ViewSpinner.spin();
Container.remove({id: $routeParams.id}, function(d) {
Messages.send({class: 'text-success', data: 'Container removed.'});
ViewSpinner.stop();
}, function(e){
failedRequestHandler(e, Messages);
ViewSpinner.stop();
});
2013-06-08 15:12:14 -09:00
};
2013-06-08 16:20:29 -09:00
2013-06-14 16:15:14 -09:00
$scope.hasContent = function(data) {
return data !== null && data !== undefined && data.length > 1;
};
2013-06-08 16:20:29 -09:00
$scope.getChanges = function() {
Container.changes({id: $routeParams.id}, function(d) {
2013-06-18 18:01:22 -09:00
$scope.changes = d;
2013-06-08 15:12:14 -09:00
});
2013-06-08 16:20:29 -09:00
};
Container.get({id: $routeParams.id}, function(d) {
2013-06-18 18:01:22 -09:00
$scope.container = d;
2013-06-09 16:31:05 -09:00
}, function(e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
if (e.status === 404) {
$('.detail').hide();
}
2013-06-18 18:01:22 -09:00
});
2013-06-08 16:20:29 -09:00
$scope.getChanges();
}
// Controller for the list of containers
2013-06-19 18:10:08 -09:00
function ContainersController($scope, Container, Settings, Messages, ViewSpinner) {
2013-06-09 14:56:54 -09:00
$scope.displayAll = Settings.displayAll;
$scope.predicate = '-Created';
2013-06-19 12:39:33 -09:00
$scope.toggle = false;
2013-06-09 14:56:54 -09:00
var update = function(data) {
2013-06-18 18:01:22 -09:00
ViewSpinner.spin();
2013-06-09 14:56:54 -09:00
Container.query(data, function(d) {
2013-06-19 12:39:33 -09:00
$scope.containers = d.map(function(item) { return new ContainerViewModel(item); });
2013-06-18 18:01:22 -09:00
ViewSpinner.stop();
});
2013-06-09 14:56:54 -09:00
};
2013-06-19 12:39:33 -09:00
var batch = function(items, action) {
2013-06-22 09:23:25 -09:00
ViewSpinner.spin();
var counter = 0;
var complete = function() {
counter = counter -1;
if (counter === 0) {
ViewSpinner.stop();
}
};
2013-06-19 12:39:33 -09:00
angular.forEach(items, function(c) {
if (c.Checked) {
2013-06-22 09:23:25 -09:00
counter = counter + 1;
2013-06-19 12:39:33 -09:00
action({id: c.Id}, function(d) {
2013-06-22 09:23:25 -09:00
Messages.send({class: 'text-success', data: 'Container ' + c.Id + ' Removed.'});
var index = $scope.containers.indexOf(c);
$scope.containers.splice(index, 1);
complete();
2013-06-19 18:10:08 -09:00
}, function(e) {
failedRequestHandler(e, Messages);
2013-06-22 09:23:25 -09:00
complete();
2013-06-19 12:39:33 -09:00
});
}
});
};
$scope.toggleSelectAll = function() {
angular.forEach($scope.containers, function(i) {
i.Checked = $scope.toggle;
});
};
2013-06-22 09:23:25 -09:00
2013-06-09 14:56:54 -09:00
$scope.toggleGetAll = function() {
Settings.displayAll = $scope.displayAll;
var data = {all: 0};
2013-06-09 14:56:54 -09:00
if ($scope.displayAll) {
data.all = 1;
}
2013-06-19 18:10:08 -09:00
update(data);
2013-06-09 14:56:54 -09:00
};
2013-06-19 12:39:33 -09:00
$scope.startAction = function() {
batch($scope.containers, Container.start);
};
$scope.stopAction = function() {
batch($scope.containers, Container.stop);
};
$scope.killAction = function() {
batch($scope.containers, Container.kill);
};
$scope.removeAction = function() {
batch($scope.containers, Container.remove);
};
2013-06-18 18:01:22 -09:00
update({all: $scope.displayAll ? 1 : 0});
}
2013-06-09 14:11:40 -09:00
// Controller for the list of images
2013-06-19 17:40:58 -09:00
function ImagesController($scope, Image, ViewSpinner, Messages) {
2013-06-18 19:08:17 -09:00
$scope.toggle = false;
2013-06-22 09:23:25 -09:00
$scope.predicate = '-Created';
2013-06-18 16:21:27 -09:00
$scope.showBuilder = function() {
$('#build-modal').modal('show');
};
2013-06-18 19:08:17 -09:00
$scope.removeAction = function() {
2013-06-19 17:40:58 -09:00
ViewSpinner.spin();
var counter = 0;
var complete = function() {
counter = counter - 1;
if (counter === 0) {
ViewSpinner.stop();
}
};
2013-06-22 09:23:25 -09:00
angular.forEach($scope.images, function(i) {
2013-06-18 19:08:17 -09:00
if (i.Checked) {
2013-06-19 17:40:58 -09:00
counter = counter + 1;
2013-06-18 19:08:17 -09:00
Image.remove({id: i.Id}, function(d) {
2013-06-19 17:40:58 -09:00
angular.forEach(d, function(resource) {
Messages.send({class: 'text-success', data: 'Deleted: ' + resource.Deleted});
});
2013-06-19 18:10:08 -09:00
//Remove the image from the list
2013-06-19 17:40:58 -09:00
var index = $scope.images.indexOf(i);
$scope.images.splice(index, 1);
complete();
}, function(e) {
Messages.send({class: 'text-error', data: e.data});
complete();
2013-06-18 19:08:17 -09:00
});
}
});
};
2013-06-22 09:23:25 -09:00
2013-06-18 19:08:17 -09:00
$scope.toggleSelectAll = function() {
angular.forEach($scope.images, function(i) {
i.Checked = $scope.toggle;
});
};
2013-06-18 18:01:22 -09:00
ViewSpinner.spin();
2013-06-09 14:11:40 -09:00
Image.query({}, function(d) {
2013-06-18 19:08:17 -09:00
$scope.images = d.map(function(item) { return new ImageViewModel(item); });
2013-06-18 18:01:22 -09:00
ViewSpinner.stop();
}, function (e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
2013-06-18 18:01:22 -09:00
ViewSpinner.stop();
2013-06-18 16:21:27 -09:00
});
2013-06-09 14:11:40 -09:00
}
// Controller for a single image and actions on that image
2013-06-19 18:10:08 -09:00
function ImageController($scope, $routeParams, $location, Image, Messages) {
2013-06-09 14:11:40 -09:00
$scope.history = [];
2013-06-09 14:56:54 -09:00
$scope.tag = {repo: '', force: false};
2013-06-22 09:23:25 -09:00
2013-06-09 14:11:40 -09:00
$scope.remove = function() {
2013-06-22 09:23:25 -09:00
Image.remove({id: $routeParams.id}, function(d) {
Messages.send({class: 'text-success', data: 'Image removed.'});
}, function(e) {
failedRequestHandler(e, Messages);
});
2013-06-09 14:11:40 -09:00
};
$scope.getHistory = function() {
Image.history({id: $routeParams.id}, function(d) {
2013-06-18 14:28:22 -09:00
$scope.history = d;
});
2013-06-09 14:11:40 -09:00
};
$scope.updateTag = function() {
var tag = $scope.tag;
2013-06-09 14:56:54 -09:00
Image.tag({id: $routeParams.id, repo: tag.repo, force: tag.force ? 1 : 0}, function(d) {
2013-06-19 18:10:08 -09:00
Messages.send({class: 'text-success', data: 'Tag added.'});
}, function(e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
2013-06-09 14:11:40 -09:00
});
};
2013-06-18 14:28:22 -09:00
$scope.create = function() {
$('#create-modal').modal('show');
};
2013-06-09 14:11:40 -09:00
Image.get({id: $routeParams.id}, function(d) {
$scope.image = d;
2013-06-09 16:31:05 -09:00
}, function(e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
if (e.status === 404) {
$('.detail').hide();
}
2013-06-09 14:11:40 -09:00
});
$scope.getHistory();
}
2013-06-19 18:10:08 -09:00
function StartContainerController($scope, $routeParams, $location, Container, Messages) {
$scope.template = 'partials/startcontainer.html';
2013-06-14 16:46:41 -09:00
$scope.config = {
memory: 0,
memorySwap: 0,
env: '',
commands: '',
volumesFrom: ''
};
$scope.commandPlaceholder = '["/bin/echo", "Hello world"]';
2013-06-18 14:28:22 -09:00
$scope.create = function() {
var cmds = null;
2013-06-14 16:46:41 -09:00
if ($scope.config.commands !== '') {
cmds = angular.fromJson($scope.config.commands);
}
var id = $routeParams.id;
var ctor = Container;
var loc = $location;
var s = $scope;
Container.create({
2013-06-22 09:23:25 -09:00
Image: id,
Memory: $scope.config.memory,
MemorySwap: $scope.config.memorySwap,
Cmd: cmds,
2013-06-14 16:46:41 -09:00
VolumesFrom: $scope.config.volumesFrom
}, function(d) {
if (d.Id) {
ctor.start({id: d.Id}, function(cd) {
2013-06-18 14:28:22 -09:00
$('#create-modal').modal('hide');
loc.path('/containers/' + d.Id + '/');
}, function(e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
});
}
}, function(e) {
2013-06-19 18:10:08 -09:00
failedRequestHandler(e, Messages);
});
};
}
2013-06-10 15:42:34 -09:00
2013-06-19 17:40:58 -09:00
function BuilderController($scope, Dockerfile, Messages) {
2013-06-18 16:21:27 -09:00
$scope.template = '/partials/builder.html';
ace.config.set('basePath', '/lib/ace-builds/src-noconflict/');
2013-06-22 09:23:25 -09:00
var spinner = new Spinner();
2013-06-18 16:21:27 -09:00
$scope.build = function() {
2013-06-22 09:23:25 -09:00
spinner.spin(document.getElementById('build-modal'));
2013-06-19 17:40:58 -09:00
Dockerfile.build(editor.getValue(), function(d) {
2013-06-22 09:23:25 -09:00
console.log(d.currentTarget.response);
$scope.messages = d.currentTarget.response;
$scope.$apply();
spinner.stop();
2013-06-19 17:40:58 -09:00
}, function(e) {
2013-06-22 09:23:25 -09:00
$scope.messages = e;
$scope.$apply();
spinner.stop();
2013-06-18 16:50:35 -09:00
});
2013-06-18 16:21:27 -09:00
};
2013-06-18 15:10:13 -09:00
}
2013-06-19 18:10:08 -09:00
function failedRequestHandler(e, Messages) {
Messages.send({class: 'text-error', data: e.data});
2013-06-10 15:42:34 -09:00
}