Change code to pass lint checks and add angular-vis to karma config for tests to pass.

pull/2/head
Roger Abelenda 2015-04-28 23:09:03 -03:00
parent 230bfd15ac
commit 008884ec59
2 changed files with 50 additions and 44 deletions

View File

@ -16,14 +16,34 @@ angular.module('containersNetwork', ['ngVis'])
} }
} }
}; };
$scope.data = new ContainersNetwork();
$scope.events = { function ContainerNode(data) {
doubleClick : function(event) { this.Id = data.Id;
$scope.$apply( function() { // names have the following format: /Name
$location.path('/containers/' + event.nodes[0]); this.Name = data.Name.substring(1);
}); var dataLinks = data.HostConfig.Links;
} if (dataLinks != null) {
}; this.Links = [];
for (var i = 0; i < dataLinks.length; i++) {
// links have the following format: /TargetContainerName:/SourceContainerName/LinkAlias
var link = dataLinks[i].split(":");
var target = link[0].substring(1);
var alias = link[1].substring(link[1].lastIndexOf("/") + 1);
// only keep shortest alias
if (this.Links[target] == null || alias.length < this.Links[target].length) {
this.Links[target] = alias;
}
}
}
var dataVolumes = data.HostConfig.VolumesFrom;
//converting array into properties for simpler and faster access
if (dataVolumes != null) {
this.VolumesFrom = [];
for (var j = 0; j < dataVolumes.length; j++) {
this.VolumesFrom[dataVolumes[j]] = true;
}
}
}
function ContainersNetwork() { function ContainersNetwork() {
this.containers = []; this.containers = [];
@ -41,56 +61,41 @@ angular.module('containersNetwork', ['ngVis'])
this.addVolumeEdgeIfExists(container, otherContainer); this.addVolumeEdgeIfExists(container, otherContainer);
this.addVolumeEdgeIfExists(otherContainer, container); this.addVolumeEdgeIfExists(otherContainer, container);
} }
} };
this.addLinkEdgeIfExists = function(from, to) { this.addLinkEdgeIfExists = function(from, to) {
if (from.Links != null && from.Links[to.Name] != null) { if (from.Links != null && from.Links[to.Name] != null) {
this.edges.add({ from: from.Id, to: to.Id, label: from.Links[to.Name] }); this.edges.add({ from: from.Id, to: to.Id, label: from.Links[to.Name] });
} }
} };
this.addVolumeEdgeIfExists = function(from, to) { this.addVolumeEdgeIfExists = function(from, to) {
if (from.VolumesFrom != null && from.VolumesFrom[to.Id] != null) { if (from.VolumesFrom != null && from.VolumesFrom[to.Id] != null) {
this.edges.add({ from: from.Id, to: to.Id, color: { color: '#A0A0A0', highlight: '#A0A0A0', hover: '#848484'}}); this.edges.add({ from: from.Id, to: to.Id, color: { color: '#A0A0A0', highlight: '#A0A0A0', hover: '#848484'}});
} }
} };
} }
function ContainerNode(data) { $scope.data = new ContainersNetwork();
this.Id = data.Id; $scope.events = {
this.Name = data.Name.substring(1, data.Name.length); doubleClick : function(event) {
var dataLinks = data.HostConfig.Links; $scope.$apply( function() {
if (dataLinks != null) { $location.path('/containers/' + event.nodes[0]);
this.Links = []; });
for (var i = 0; i < dataLinks.length; i++) { }
// links have the following format: /TargetContainerName:/SourceContainerName/LinkAlias };
var link = dataLinks[i].split(":");
var target = link[0].split("/")[1]; var showFailure = function (event) {
var alias = link[1].split("/")[2]; Messages.error('Failure', e.data);
// only keep shortest alias };
if (this.Links[target] == null || alias.length < this.Links[target].length) {
this.Links[target] = alias; var addContainer = function (container) {
} $scope.data.add(container);
} };
}
var dataVolumes = data.HostConfig.VolumesFrom;
//converting array into properties for simpler and faster access
if (dataVolumes != null) {
this.VolumesFrom = [];
for (var i = 0; i < dataVolumes.length; i++) {
this.VolumesFrom[dataVolumes[i]] = true;
}
}
}
Container.query({all: 0}, function(d) { Container.query({all: 0}, function(d) {
for (var i = 0; i < d.length; i++) { for (var i = 0; i < d.length; i++) {
Container.get({id: d[i].Id}, function(d) { Container.get({id: d[i].Id}, addContainer, showFailure);
$scope.data.add(d);
}, function(e) {
Messages.error('Failure', e.data);
});
} }
}); });
}]); }]);

View File

@ -13,6 +13,7 @@ files = [
'assets/js/angularjs/1.2.6/angular-route.min.js', 'assets/js/angularjs/1.2.6/angular-route.min.js',
'assets/js/angularjs/1.2.6/angular-resource.min.js', 'assets/js/angularjs/1.2.6/angular-resource.min.js',
'assets/js/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.min.js', 'assets/js/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.min.js',
'assets/js/angular-vis.js',
'test/assets/angular/angular-mocks.js', 'test/assets/angular/angular-mocks.js',
'app/**/*.js', 'app/**/*.js',
'test/unit/**/*.spec.js', 'test/unit/**/*.spec.js',
@ -57,4 +58,4 @@ browsers = ['Chrome'];
// Continuous Integration mode // Continuous Integration mode
// if true, it capture browsers, run tests and exit // if true, it capture browsers, run tests and exit
singleRun = true; singleRun = true;