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