2016-02-22 23:39:04 +00:00
|
|
|
/**
|
2018-03-28 20:03:18 +00:00
|
|
|
* An element which displays the features of a manifest.
|
2016-02-22 23:39:04 +00:00
|
|
|
*/
|
2018-03-28 20:03:18 +00:00
|
|
|
angular.module('quay').directive('manifestFeatureView', function () {
|
2016-02-22 23:39:04 +00:00
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
2018-03-28 20:03:18 +00:00
|
|
|
templateUrl: '/static/directives/manifest-feature-view.html',
|
2016-02-22 23:39:04 +00:00
|
|
|
replace: false,
|
|
|
|
transclude: true,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'repository': '=repository',
|
2018-03-28 20:03:18 +00:00
|
|
|
'manifest': '=manifest',
|
2016-02-22 23:39:04 +00:00
|
|
|
'isEnabled': '=isEnabled'
|
|
|
|
},
|
2017-06-23 18:53:02 +00:00
|
|
|
controller: function($scope, $element, Config, ApiService, VulnerabilityService, ViewArray, TableService) {
|
2016-02-22 23:39:04 +00:00
|
|
|
$scope.options = {
|
2016-03-09 20:28:21 +00:00
|
|
|
'filter': null,
|
2016-02-22 23:39:04 +00:00
|
|
|
'predicate': 'fixableScore',
|
|
|
|
'reverse': false,
|
|
|
|
};
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
$scope.TableService = TableService;
|
2016-12-14 05:50:06 +00:00
|
|
|
$scope.loading = false;
|
2016-02-22 23:39:04 +00:00
|
|
|
|
|
|
|
var buildOrderedFeatures = function() {
|
2016-03-09 20:28:21 +00:00
|
|
|
if (!$scope.featuresInfo) {
|
|
|
|
return;
|
2016-02-22 23:39:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-09 20:28:21 +00:00
|
|
|
var features = $scope.featuresInfo.features;
|
|
|
|
$scope.orderedFeatures = TableService.buildOrderedItems(features, $scope.options,
|
|
|
|
['name', 'version', 'imageId'],
|
|
|
|
['score', 'fixableScore', 'leftoverScore'])
|
2016-02-22 23:39:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var buildChart = function() {
|
2016-03-09 20:28:21 +00:00
|
|
|
var chartData = $scope.featuresInfo.severityBreakdown;
|
2016-02-22 23:39:04 +00:00
|
|
|
var colors = [];
|
|
|
|
for (var i = 0; i < chartData.length; ++i) {
|
|
|
|
colors.push(chartData[i].color);
|
|
|
|
}
|
|
|
|
|
|
|
|
nv.addGraph(function() {
|
|
|
|
var chart = nv.models.pieChart()
|
|
|
|
.x(function(d) { return d.label })
|
|
|
|
.y(function(d) { return d.value })
|
|
|
|
.margin({left: -10, right: -10, top: -10, bottom: -10})
|
|
|
|
.showLegend(false)
|
|
|
|
.showLabels(true)
|
|
|
|
.labelThreshold(.05)
|
|
|
|
.labelType("percent")
|
|
|
|
.donut(true)
|
|
|
|
.color(colors)
|
|
|
|
.donutRatio(0.5);
|
|
|
|
|
|
|
|
d3.select("#featureDonutChart svg")
|
|
|
|
.datum(chartData)
|
|
|
|
.transition()
|
|
|
|
.duration(350)
|
|
|
|
.call(chart);
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-03-28 20:03:18 +00:00
|
|
|
var loadManifestVulnerabilities = function() {
|
2016-12-14 05:50:06 +00:00
|
|
|
if ($scope.loading) {
|
2016-02-22 23:39:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-14 05:50:06 +00:00
|
|
|
$scope.loading = true;
|
2018-03-28 20:03:18 +00:00
|
|
|
VulnerabilityService.loadManifestVulnerabilities($scope.repository, $scope.manifest.digest, function(resp) {
|
2016-02-22 23:39:04 +00:00
|
|
|
$scope.securityStatus = resp.status;
|
2018-03-28 20:03:18 +00:00
|
|
|
$scope.featuresInfo = VulnerabilityService.buildFeaturesInfo($scope.manifest.image, resp);
|
2016-03-09 20:28:21 +00:00
|
|
|
|
|
|
|
buildOrderedFeatures();
|
2016-02-22 23:39:04 +00:00
|
|
|
buildChart();
|
|
|
|
return resp;
|
2016-12-14 05:50:06 +00:00
|
|
|
}, function() {
|
|
|
|
$scope.securityStatus = 'error';
|
2016-02-22 23:39:04 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('options.predicate', buildOrderedFeatures);
|
|
|
|
$scope.$watch('options.reverse', buildOrderedFeatures);
|
2016-03-09 20:28:21 +00:00
|
|
|
$scope.$watch('options.filter', buildOrderedFeatures);
|
2016-02-22 23:39:04 +00:00
|
|
|
|
2017-05-10 08:05:03 +00:00
|
|
|
$scope.$watch('repository', function(repository) {
|
2018-03-28 20:03:18 +00:00
|
|
|
if ($scope.isEnabled && $scope.repository && $scope.manifest) {
|
|
|
|
loadManifestVulnerabilities();
|
2017-05-10 08:05:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-03-28 20:03:18 +00:00
|
|
|
$scope.$watch('manifest', function(manifest) {
|
|
|
|
if ($scope.isEnabled && $scope.repository && $scope.manifest) {
|
|
|
|
loadManifestVulnerabilities();
|
2017-05-10 08:05:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-22 23:39:04 +00:00
|
|
|
$scope.$watch('isEnabled', function(isEnabled) {
|
2018-03-28 20:03:18 +00:00
|
|
|
if ($scope.isEnabled && $scope.repository && $scope.manifest) {
|
|
|
|
loadManifestVulnerabilities();
|
2016-02-22 23:39:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|