Skip to content

Commit 9b47dfc

Browse files
author
OpenShift Bot
authored
Merge pull request #1243 from spadgett/catalog-empty-version-dropdown
Merged by openshift-bot
2 parents e812e57 + 0677dee commit 9b47dfc

File tree

3 files changed

+92
-40
lines changed

3 files changed

+92
-40
lines changed

app/scripts/directives/catalog/catalogImage.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
angular.module('openshiftConsole')
4-
.directive('catalogImage', function($filter) {
4+
.directive('catalogImage', function($filter, CatalogService) {
55
return {
66
restrict: 'E',
77
// Replace the catalog-template element so that the tiles are all equal height as flexbox items.
@@ -23,10 +23,7 @@ angular.module('openshiftConsole')
2323
var tagTags = {};
2424
_.each(specTags, function(tag) {
2525
tagTags[tag.name] = imageStreamTagTags($scope.imageStream, tag.name);
26-
if (tag.from &&
27-
tag.from.kind === 'ImageStreamTag' &&
28-
tag.from.name.indexOf(':') === -1 &&
29-
!tag.from.namespace) {
26+
if (CatalogService.referencesSameImageStream(tag)) {
3027
referenceTags[tag.name] = true;
3128
$scope.referencedBy[tag.from.name] = $scope.referencedBy[tag.from.name] || [];
3229
$scope.referencedBy[tag.from.name].push(tag.name);

app/scripts/services/catalog.js

+44-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ angular.module("openshiftConsole")
123123
return templatesByCategory;
124124
};
125125

126+
var referencesSameImageStream = function(specTag) {
127+
return specTag.from &&
128+
specTag.from.kind === 'ImageStreamTag' &&
129+
specTag.from.name.indexOf(':') === -1 &&
130+
!specTag.from.namespace;
131+
};
132+
126133
// Don't use KeywordService for image stream filtering so we can add
127134
// special handling for image stream tags. Match keywords (array of regex)
128135
// against image streams and image stream tags, returning a copy of the
@@ -137,7 +144,23 @@ angular.module("openshiftConsole")
137144
_.each(imageStreams, function(imageStream) {
138145
var name = _.get(imageStream, 'metadata.name', '');
139146
var displayName = getDisplayName(imageStream, true);
140-
var matchingTags = _.indexBy(imageStream.spec.tags, 'name');
147+
var specTags = [];
148+
var references = {};
149+
var referencedBy = {};
150+
_.each(imageStream.spec.tags, function(tag) {
151+
// If the tag follows another, track the reference.
152+
if (referencesSameImageStream(tag)) {
153+
references[tag.name] = tag.from.name;
154+
referencedBy[tag.from.name] = referencedBy[tag.from.name] || [];
155+
referencedBy[tag.from.name].push(tag.name);
156+
return;
157+
}
158+
159+
// If the tag doesn't follow another, consider it in the search.
160+
specTags.push(tag);
161+
});
162+
163+
var matchingTags = _.indexBy(specTags, 'name');
141164

142165
// Find tags that match every keyword. Search image stream name, image
143166
// stream display name, and tag names, and tag descriptions. If a
@@ -153,7 +176,7 @@ angular.module("openshiftConsole")
153176
}
154177

155178
// Check tag descriptions.
156-
_.each(imageStream.spec.tags, function(tag) {
179+
_.each(specTags, function(tag) {
157180
// If this is not a builder or is hidden, don't match the tag.
158181
var tagTags = _.get(tag, 'annotations.tags', '');
159182
if (!/\bbuilder\b/.test(tagTags) || /\bhidden\b/.test(tagTags)) {
@@ -166,6 +189,16 @@ angular.module("openshiftConsole")
166189
return;
167190
}
168191

192+
// Search any tag names that reference this tag as well. For
193+
// instance, searching for "latest" should match nodejs:4 if
194+
// nodejs:latest references nodejs:4
195+
var matches = function(referenceName) {
196+
return regex.test(referenceName);
197+
};
198+
if (_.some(referencedBy[tag.name], matches)) {
199+
return;
200+
}
201+
169202
var description = _.get(tag, 'annotations.description');
170203
if (!description || !regex.test(description)) {
171204
delete matchingTags[tag.name];
@@ -178,8 +211,16 @@ angular.module("openshiftConsole")
178211
if (!_.isEmpty(matchingTags)) {
179212
imageStreamCopy = angular.copy(imageStream);
180213
imageStreamCopy.status.tags = _.filter(imageStreamCopy.status.tags, function(tag) {
214+
// If this tag follow another tag, include it if the other tag matches the search.
215+
var fromTag = references[tag.tag];
216+
if (fromTag) {
217+
return matchingTags[fromTag];
218+
}
219+
220+
// Otherwise check if this tag was a match.
181221
return matchingTags[tag.tag];
182222
});
223+
183224
filteredImageStreams.push(imageStreamCopy);
184225
}
185226
});
@@ -201,6 +242,7 @@ angular.module("openshiftConsole")
201242
getCategoryItem: getCategoryItem,
202243
categorizeImageStreams: categorizeImageStreams,
203244
categorizeTemplates: categorizeTemplates,
245+
referencesSameImageStream: referencesSameImageStream,
204246
filterImageStreams: filterImageStreams,
205247
filterTemplates: filterTemplates
206248
};

dist/scripts/scripts.js

+46-33
Original file line numberDiff line numberDiff line change
@@ -4116,35 +4116,48 @@ _.each(e, function(d) {
41164116
h(d, c) && (b[d.id] = b[d.id] || [], b[d.id].push(a), f = !0);
41174117
}), f || (b[""] = b[""] || [], b[""].push(a));
41184118
}), b;
4119-
}, k = a("displayName"), l = function(a, b) {
4119+
}, k = function(a) {
4120+
return a.from && "ImageStreamTag" === a.from.kind && a.from.name.indexOf(":") === -1 && !a.from.namespace;
4121+
}, l = a("displayName"), m = function(a, b) {
41204122
if (!b.length) return a;
41214123
var c = [];
41224124
return _.each(a, function(a) {
4123-
var d = _.get(a, "metadata.name", ""), e = k(a, !0), f = _.indexBy(a.spec.tags, "name");
4124-
_.each(b, function(b) {
4125-
b.test(d) || e && b.test(e) || _.each(a.spec.tags, function(a) {
4126-
var c = _.get(a, "annotations.tags", "");
4127-
if (!/\bbuilder\b/.test(c) || /\bhidden\b/.test(c)) return void delete f[a.name];
4128-
if (!b.test(a.name)) {
4129-
var d = _.get(a, "annotations.description");
4130-
d && b.test(d) || delete f[a.name];
4125+
var d = _.get(a, "metadata.name", ""), e = l(a, !0), f = [], g = {}, h = {};
4126+
_.each(a.spec.tags, function(a) {
4127+
return k(a) ? (g[a.name] = a.from.name, h[a.from.name] = h[a.from.name] || [], void h[a.from.name].push(a.name)) :void f.push(a);
4128+
});
4129+
var i = _.indexBy(f, "name");
4130+
_.each(b, function(a) {
4131+
a.test(d) || e && a.test(e) || _.each(f, function(b) {
4132+
var c = _.get(b, "annotations.tags", "");
4133+
if (!/\bbuilder\b/.test(c) || /\bhidden\b/.test(c)) return void delete i[b.name];
4134+
if (!a.test(b.name)) {
4135+
var d = function(b) {
4136+
return a.test(b);
4137+
};
4138+
if (!_.some(h[b.name], d)) {
4139+
var e = _.get(b, "annotations.description");
4140+
e && a.test(e) || delete i[b.name];
4141+
}
41314142
}
41324143
});
41334144
});
4134-
var g;
4135-
_.isEmpty(f) || (g = angular.copy(a), g.status.tags = _.filter(g.status.tags, function(a) {
4136-
return f[a.tag];
4137-
}), c.push(g));
4145+
var j;
4146+
_.isEmpty(i) || (j = angular.copy(a), j.status.tags = _.filter(j.status.tags, function(a) {
4147+
var b = g[a.tag];
4148+
return b ? i[b] :i[a.tag];
4149+
}), c.push(j));
41384150
}), c;
4139-
}, m = [ "metadata.name", 'metadata.annotations["openshift.io/display-name"]', "metadata.annotations.description" ], n = function(a, b) {
4140-
return c.filterForKeywords(a, m, b);
4151+
}, n = [ "metadata.name", 'metadata.annotations["openshift.io/display-name"]', "metadata.annotations.description" ], o = function(a, b) {
4152+
return c.filterForKeywords(a, n, b);
41414153
};
41424154
return {
41434155
getCategoryItem:f,
41444156
categorizeImageStreams:i,
41454157
categorizeTemplates:j,
4146-
filterImageStreams:l,
4147-
filterTemplates:n
4158+
referencesSameImageStream:k,
4159+
filterImageStreams:m,
4160+
filterTemplates:o
41484161
};
41494162
} ]), angular.module("openshiftConsole").factory("ModalsService", [ "$uibModal", function(a) {
41504163
return {
@@ -11701,7 +11714,7 @@ keyword:""
1170111714
}, b.$watch("filter.keyword", e), b.$watchGroup([ "openshiftImageStreams", "projectImageStreams" ], g), b.$watchGroup([ "openshiftTemplates", "projectTemplates" ], i);
1170211715
}
1170311716
};
11704-
} ]), angular.module("openshiftConsole").directive("catalogImage", [ "$filter", function(a) {
11717+
} ]), angular.module("openshiftConsole").directive("catalogImage", [ "$filter", "CatalogService", function(a, b) {
1170511718
return {
1170611719
restrict:"E",
1170711720
replace:!0,
@@ -11713,25 +11726,25 @@ isBuilder:"=?",
1171311726
keywords:"="
1171411727
},
1171511728
templateUrl:"views/catalog/_image.html",
11716-
link:function(b) {
11717-
var c = a("imageStreamTagTags"), d = {};
11718-
b.referencedBy = {};
11719-
var e = _.get(b, "imageStream.spec.tags", []), f = {};
11720-
_.each(e, function(a) {
11721-
f[a.name] = c(b.imageStream, a.name), a.from && "ImageStreamTag" === a.from.kind && a.from.name.indexOf(":") === -1 && !a.from.namespace && (d[a.name] = !0, b.referencedBy[a.from.name] = b.referencedBy[a.from.name] || [], b.referencedBy[a.from.name].push(a.name));
11729+
link:function(c) {
11730+
var d = a("imageStreamTagTags"), e = {};
11731+
c.referencedBy = {};
11732+
var f = _.get(c, "imageStream.spec.tags", []), g = {};
11733+
_.each(f, function(a) {
11734+
g[a.name] = d(c.imageStream, a.name), b.referencesSameImageStream(a) && (e[a.name] = !0, c.referencedBy[a.from.name] = c.referencedBy[a.from.name] || [], c.referencedBy[a.from.name].push(a.name));
1172211735
});
11723-
var g = function(a) {
11724-
var b = _.get(f, [ a ], []);
11736+
var h = function(a) {
11737+
var b = _.get(g, [ a ], []);
1172511738
return _.includes(b, "builder") && !_.includes(b, "hidden");
1172611739
};
11727-
b.$watch("imageStream.status.tags", function(a) {
11728-
b.tags = _.filter(a, function(a) {
11729-
return g(a.tag) && !d[a.tag];
11740+
c.$watch("imageStream.status.tags", function(a) {
11741+
c.tags = _.filter(a, function(a) {
11742+
return h(a.tag) && !e[a.tag];
1173011743
});
11731-
var c = _.get(b, "is.tag.tag");
11732-
c && _.some(b.tags, {
11733-
tag:c
11734-
}) || _.set(b, "is.tag", _.head(b.tags));
11744+
var b = _.get(c, "is.tag.tag");
11745+
b && _.some(c.tags, {
11746+
tag:b
11747+
}) || _.set(c, "is.tag", _.head(c.tags));
1173511748
});
1173611749
}
1173711750
};

0 commit comments

Comments
 (0)