Skip to content

Commit 75f6fe4

Browse files
author
OpenShift Bot
authored
Merge pull request openshift#814 from spadgett/search-istag-description
Merged by openshift-bot
2 parents a51c2d0 + 06c3937 commit 75f6fe4

File tree

3 files changed

+101
-20
lines changed

3 files changed

+101
-20
lines changed

app/scripts/directives/catalog/catalogImage.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,19 @@ angular.module('openshiftConsole')
3737
return _.includes(tags, 'builder');
3838
};
3939

40-
var tags = _.get($scope, 'imageStream.status.tags', []);
41-
$scope.tags = _.filter(tags, function(tag) {
42-
return isBuilder(tag.tag) && !referenceTags[tag.tag];
43-
});
40+
// Watch status tags. Some tags might be removed from the list if they
41+
// don't match the current filter.
42+
$scope.$watch('imageStream.status.tags', function(tags) {
43+
$scope.tags = _.filter(tags, function(tag) {
44+
return isBuilder(tag.tag) && !referenceTags[tag.tag];
45+
});
4446

45-
// Preselect the first tag value.
46-
var firstTag = _.head($scope.tags);
47-
_.set($scope, 'is.tag', firstTag);
47+
var selected = _.get($scope, 'is.tag.tag');
48+
if (!selected || !_.some($scope.tags, { tag: selected })) {
49+
// Preselect the first tag value.
50+
_.set($scope, 'is.tag', _.head($scope.tags));
51+
}
52+
});
4853
}
4954
};
5055
});

app/scripts/services/catalog.js

+61-7
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,68 @@ angular.module("openshiftConsole")
121121
return templatesByCategory;
122122
};
123123

124-
// TODO: Filter by description
125-
var imageStreamFilterFields = [
126-
'metadata.name',
127-
'metadata.annotations["openshift.io/display-name"]'
128-
];
129-
124+
// Don't use KeywordService for image stream filtering so we can add
125+
// special handling for image stream tags. Match keywords (array of regex)
126+
// against image streams and image stream tags, returning a copy of the
127+
// image streams with only matching status tags.
128+
var getDisplayName = $filter('displayName');
130129
var filterImageStreams = function(imageStreams, keywords) {
131-
return KeywordService.filterForKeywords(imageStreams, imageStreamFilterFields, keywords);
130+
if (!keywords.length) {
131+
return imageStreams;
132+
}
133+
134+
var filteredImageStreams = [];
135+
_.each(imageStreams, function(imageStream) {
136+
var name = _.get(imageStream, 'metadata.name', '');
137+
var displayName = getDisplayName(imageStream, true);
138+
var matchingTags = _.indexBy(imageStream.spec.tags, 'name');
139+
140+
// Find tags that match every keyword. Search image stream name, image
141+
// stream display name, and tag names, and tag descriptions. If a
142+
// keyword matches the image stream name or display name, it's
143+
// considered to match all tags.
144+
_.each(keywords, function(regex) {
145+
if (regex.test(name)) {
146+
return;
147+
}
148+
149+
if (displayName && regex.test(displayName)) {
150+
return;
151+
}
152+
153+
// Check tag descriptions.
154+
_.each(imageStream.spec.tags, function(tag) {
155+
// If this is not a builder, don't match the tag.
156+
var tagTags = _.get(tag, 'annotations.tags', '');
157+
if (!/\bbuilder\b/.test(tagTags)) {
158+
delete matchingTags[tag.name];
159+
return;
160+
}
161+
162+
// If the keyword matches the tag name, accept it.
163+
if (regex.test(tag.name)) {
164+
return;
165+
}
166+
167+
var description = _.get(tag, 'annotations.description');
168+
if (!description || !regex.test(description)) {
169+
delete matchingTags[tag.name];
170+
}
171+
});
172+
});
173+
174+
// Make a copy of the image stream with only the matching tags.
175+
var imageStreamCopy;
176+
if (!_.isEmpty(matchingTags)) {
177+
imageStreamCopy = angular.copy(imageStream);
178+
imageStreamCopy.status.tags = _.filter(imageStreamCopy.status.tags, function(tag) {
179+
return matchingTags[tag.tag];
180+
});
181+
filteredImageStreams.push(imageStreamCopy);
182+
}
183+
});
184+
185+
return filteredImageStreams;
132186
};
133187

134188
var templateFilterFields = [

dist/scripts/scripts.js

+28-6
Original file line numberDiff line numberDiff line change
@@ -3794,8 +3794,26 @@ _.each(e, function(d) {
37943794
h(d, c) && (b[d.id] = b[d.id] || [], b[d.id].push(a), f = !0);
37953795
}), f || (b[""] = b[""] || [], b[""].push(a));
37963796
}), b;
3797-
}, k = [ "metadata.name", 'metadata.annotations["openshift.io/display-name"]' ], l = function(a, b) {
3798-
return c.filterForKeywords(a, k, b);
3797+
}, k = a("displayName"), l = function(a, b) {
3798+
if (!b.length) return a;
3799+
var c = [];
3800+
return _.each(a, function(a) {
3801+
var d = _.get(a, "metadata.name", ""), e = k(a, !0), f = _.indexBy(a.spec.tags, "name");
3802+
_.each(b, function(b) {
3803+
b.test(d) || e && b.test(e) || _.each(a.spec.tags, function(a) {
3804+
var c = _.get(a, "annotations.tags", "");
3805+
if (!/\bbuilder\b/.test(c)) return void delete f[a.name];
3806+
if (!b.test(a.name)) {
3807+
var d = _.get(a, "annotations.description");
3808+
d && b.test(d) || delete f[a.name];
3809+
}
3810+
});
3811+
});
3812+
var g;
3813+
_.isEmpty(f) || (g = angular.copy(a), g.status.tags = _.filter(g.status.tags, function(a) {
3814+
return f[a.tag];
3815+
}), c.push(g));
3816+
}), c;
37993817
}, m = [ "metadata.name", 'metadata.annotations["openshift.io/display-name"]', "metadata.annotations.description" ], n = function(a, b) {
38003818
return c.filterForKeywords(a, m, b);
38013819
};
@@ -10118,12 +10136,16 @@ f[a.name] = c(b.imageStream, a.name), a.from && "ImageStreamTag" === a.from.kind
1011810136
var g = function(a) {
1011910137
var b = _.get(f, [ a ], []);
1012010138
return _.includes(b, "builder");
10121-
}, h = _.get(b, "imageStream.status.tags", []);
10122-
b.tags = _.filter(h, function(a) {
10139+
};
10140+
b.$watch("imageStream.status.tags", function(a) {
10141+
b.tags = _.filter(a, function(a) {
1012310142
return g(a.tag) && !d[a.tag];
1012410143
});
10125-
var i = _.head(b.tags);
10126-
_.set(b, "is.tag", i);
10144+
var c = _.get(b, "is.tag.tag");
10145+
c && _.some(b.tags, {
10146+
tag:c
10147+
}) || _.set(b, "is.tag", _.head(b.tags));
10148+
});
1012710149
}
1012810150
};
1012910151
} ]), angular.module("openshiftConsole").directive("catalogTemplate", function() {

0 commit comments

Comments
 (0)