-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathimages.js
92 lines (81 loc) · 3.18 KB
/
images.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
/**
* @ngdoc function
* @name openshiftConsole.controller:ImagesController
* @description
* # ProjectController
* Controller of the openshiftConsole
*/
angular.module('openshiftConsole')
.controller('ImagesController', function (
$filter,
$routeParams,
$scope,
APIService,
DataService,
LabelFilter,
Logger,
ProjectsService) {
$scope.projectName = $routeParams.project;
$scope.imageStreams = {};
$scope.unfilteredImageStreams = {};
$scope.missingStatusTagsByImageStream = {};
$scope.builds = {};
$scope.labelSuggestions = {};
$scope.clearFilter = function() {
LabelFilter.clear();
};
var imageStreamsVersion = APIService.getPreferredVersion('imagestreams');
var watches = [];
ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;
watches.push(DataService.watch(imageStreamsVersion, context, function(imageStreams) {
$scope.imageStreamsLoaded = true;
$scope.unfilteredImageStreams = imageStreams.by("metadata.name");
LabelFilter.addLabelSuggestionsFromResources($scope.unfilteredImageStreams, $scope.labelSuggestions);
LabelFilter.setLabelSuggestions($scope.labelSuggestions);
$scope.imageStreams = LabelFilter.getLabelSelector().select($scope.unfilteredImageStreams);
updateMissingStatusTags();
updateFilterMessage();
Logger.log("image streams (subscribe)", $scope.imageStreams);
}));
// Check each image stream to see if the spec tags resolve to status tags.
// We call out missing status tags with a warning.
function updateMissingStatusTags() {
angular.forEach($scope.unfilteredImageStreams, function(is, name) {
var missingStatusTags = $scope.missingStatusTagsByImageStream[name] = {};
if (!is.spec || !is.spec.tags) {
return;
}
// Index the status tags for this image stream to avoid iterating the list for every spec tag.
var statusTagMap = {};
if (is.status && is.status.tags) {
angular.forEach(is.status.tags, function(tag) {
statusTagMap[tag.tag] = true;
});
}
// Make sure each spec tag has a corresponding status tag.
angular.forEach(is.spec.tags, function(specTag) {
if (!statusTagMap[specTag.name]) {
missingStatusTags[specTag.name] = specTag;
}
});
});
}
function updateFilterMessage() {
$scope.filterWithZeroResults = !LabelFilter.getLabelSelector().isEmpty() && _.isEmpty($scope.imageStreams) && !_.isEmpty($scope.unfilteredImageStreams);
}
LabelFilter.onActiveFiltersChanged(function(labelSelector) {
// trigger a digest loop
$scope.$evalAsync(function() {
$scope.imageStreams = labelSelector.select($scope.unfilteredImageStreams);
updateFilterMessage();
});
});
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
});