2014-11-12 17:54:49 +00:00
|
|
|
angular.module('containers', [])
|
2016-09-02 03:25:20 +00:00
|
|
|
.controller('ContainersController', ['$scope', 'Container', 'ContainerHelper', 'Info', 'Settings', 'Messages', 'Config',
|
|
|
|
function ($scope, Container, ContainerHelper, Info, Settings, Messages, Config) {
|
2016-06-02 05:34:03 +00:00
|
|
|
|
|
|
|
$scope.state = {};
|
|
|
|
$scope.state.displayAll = Settings.displayAll;
|
2016-07-12 22:53:03 +00:00
|
|
|
$scope.state.displayIP = false;
|
2016-06-29 09:04:29 +00:00
|
|
|
$scope.sortType = 'State';
|
2016-08-23 22:58:55 +00:00
|
|
|
$scope.sortReverse = false;
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state.selectedItemCount = 0;
|
|
|
|
|
|
|
|
$scope.order = function (sortType) {
|
|
|
|
$scope.sortReverse = ($scope.sortType === sortType) ? !$scope.sortReverse : false;
|
|
|
|
$scope.sortType = sortType;
|
|
|
|
};
|
|
|
|
|
2016-08-31 06:03:41 +00:00
|
|
|
var update = function (data, containersToHideLabels) {
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#loadContainersSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state.selectedItemCount = 0;
|
|
|
|
Container.query(data, function (d) {
|
2016-06-23 22:11:49 +00:00
|
|
|
var containers = d;
|
2016-08-31 06:03:41 +00:00
|
|
|
if (containersToHideLabels) {
|
|
|
|
containers = ContainerHelper.hideContainers(d, containersToHideLabels);
|
2016-06-23 22:11:49 +00:00
|
|
|
}
|
|
|
|
$scope.containers = containers.map(function (container) {
|
2016-07-12 22:53:03 +00:00
|
|
|
var model = new ContainerViewModel(container);
|
|
|
|
if (model.IP) {
|
|
|
|
$scope.state.displayIP = true;
|
|
|
|
}
|
2016-08-10 06:11:36 +00:00
|
|
|
if ($scope.swarm) {
|
|
|
|
model.hostIP = $scope.swarm_hosts[_.split(container.Names[0], '/')[1]];
|
|
|
|
}
|
2016-07-12 22:53:03 +00:00
|
|
|
return model;
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#loadContainersSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var batch = function (items, action, msg) {
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#loadContainersSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
var counter = 0;
|
|
|
|
var complete = function () {
|
|
|
|
counter = counter - 1;
|
|
|
|
if (counter === 0) {
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#loadContainersSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
update({all: Settings.displayAll ? 1 : 0});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
angular.forEach(items, function (c) {
|
|
|
|
if (c.Checked) {
|
2016-06-29 10:11:22 +00:00
|
|
|
counter = counter + 1;
|
2016-06-02 05:34:03 +00:00
|
|
|
if (action === Container.start) {
|
2016-09-02 01:51:49 +00:00
|
|
|
action({id: c.Id}, {}, function (d) {
|
|
|
|
Messages.send("Container " + msg, c.Id);
|
|
|
|
complete();
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Failure", e, "Unable to start container");
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
2016-06-29 10:11:22 +00:00
|
|
|
else if (action === Container.remove) {
|
|
|
|
action({id: c.Id}, function (d) {
|
2016-09-01 03:07:31 +00:00
|
|
|
if (d.message) {
|
|
|
|
Messages.send("Error", d.message);
|
2016-06-29 10:11:22 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
Messages.send("Container " + msg, c.Id);
|
|
|
|
}
|
|
|
|
complete();
|
|
|
|
}, function (e) {
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Failure", e, 'Unable to remove container');
|
2016-06-29 10:11:22 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
else {
|
|
|
|
action({id: c.Id}, function (d) {
|
|
|
|
Messages.send("Container " + msg, c.Id);
|
|
|
|
complete();
|
|
|
|
}, function (e) {
|
2016-09-02 05:40:03 +00:00
|
|
|
Messages.error("Failure", e, 'An error occured');
|
2016-06-02 05:34:03 +00:00
|
|
|
complete();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (counter === 0) {
|
2016-07-07 01:17:44 +00:00
|
|
|
$('#loadContainersSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.selectItem = function (item) {
|
|
|
|
if (item.Checked) {
|
|
|
|
$scope.state.selectedItemCount++;
|
|
|
|
} else {
|
|
|
|
$scope.state.selectedItemCount--;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleGetAll = function () {
|
|
|
|
Settings.displayAll = $scope.state.displayAll;
|
|
|
|
update({all: Settings.displayAll ? 1 : 0});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.startAction = function () {
|
|
|
|
batch($scope.containers, Container.start, "Started");
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.stopAction = function () {
|
|
|
|
batch($scope.containers, Container.stop, "Stopped");
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.restartAction = function () {
|
|
|
|
batch($scope.containers, Container.restart, "Restarted");
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.killAction = function () {
|
|
|
|
batch($scope.containers, Container.kill, "Killed");
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.pauseAction = function () {
|
|
|
|
batch($scope.containers, Container.pause, "Paused");
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.unpauseAction = function () {
|
|
|
|
batch($scope.containers, Container.unpause, "Unpaused");
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeAction = function () {
|
|
|
|
batch($scope.containers, Container.remove, "Removed");
|
|
|
|
};
|
|
|
|
|
2016-08-10 06:11:36 +00:00
|
|
|
function retrieveSwarmHostsInfo(data) {
|
|
|
|
var swarm_hosts = {};
|
|
|
|
var systemStatus = data.SystemStatus;
|
|
|
|
var node_count = parseInt(systemStatus[3][1], 10);
|
|
|
|
var node_offset = 4;
|
|
|
|
for (i = 0; i < node_count; i++) {
|
|
|
|
var host = {};
|
|
|
|
host.name = _.trim(systemStatus[node_offset][0]);
|
|
|
|
host.ip = _.split(systemStatus[node_offset][1], ':')[0];
|
|
|
|
swarm_hosts[host.name] = host.ip;
|
|
|
|
node_offset += 9;
|
|
|
|
}
|
|
|
|
return swarm_hosts;
|
|
|
|
}
|
|
|
|
|
2016-06-29 09:04:29 +00:00
|
|
|
$scope.swarm = false;
|
2016-06-23 22:11:49 +00:00
|
|
|
Config.$promise.then(function (c) {
|
2016-08-31 06:03:41 +00:00
|
|
|
var containersToHideLabels = c.hiddenLabels;
|
2016-06-29 09:04:29 +00:00
|
|
|
$scope.swarm = c.swarm;
|
2016-08-10 06:11:36 +00:00
|
|
|
if (c.swarm) {
|
|
|
|
Info.get({}, function (d) {
|
|
|
|
$scope.swarm_hosts = retrieveSwarmHostsInfo(d);
|
2016-08-31 06:03:41 +00:00
|
|
|
update({all: Settings.displayAll ? 1 : 0}, containersToHideLabels);
|
2016-08-10 06:11:36 +00:00
|
|
|
});
|
|
|
|
} else {
|
2016-08-31 06:03:41 +00:00
|
|
|
update({all: Settings.displayAll ? 1 : 0}, containersToHideLabels);
|
2016-08-10 06:11:36 +00:00
|
|
|
}
|
2016-06-23 22:11:49 +00:00
|
|
|
});
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|