diff --git a/app/scripts/directives/catalog/catalogImage.js b/app/scripts/directives/catalog/catalogImage.js index dfee0a8c0c..a4266098fb 100644 --- a/app/scripts/directives/catalog/catalogImage.js +++ b/app/scripts/directives/catalog/catalogImage.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('openshiftConsole') - .directive('catalogImage', function($filter) { + .directive('catalogImage', function($filter, CatalogService) { return { restrict: 'E', // Replace the catalog-template element so that the tiles are all equal height as flexbox items. @@ -23,10 +23,7 @@ angular.module('openshiftConsole') var tagTags = {}; _.each(specTags, function(tag) { tagTags[tag.name] = imageStreamTagTags($scope.imageStream, tag.name); - if (tag.from && - tag.from.kind === 'ImageStreamTag' && - tag.from.name.indexOf(':') === -1 && - !tag.from.namespace) { + if (CatalogService.referencesSameImageStream(tag)) { referenceTags[tag.name] = true; $scope.referencedBy[tag.from.name] = $scope.referencedBy[tag.from.name] || []; $scope.referencedBy[tag.from.name].push(tag.name); diff --git a/app/scripts/services/catalog.js b/app/scripts/services/catalog.js index e437d5ec47..3ae62991d8 100644 --- a/app/scripts/services/catalog.js +++ b/app/scripts/services/catalog.js @@ -123,6 +123,13 @@ angular.module("openshiftConsole") return templatesByCategory; }; + var referencesSameImageStream = function(specTag) { + return specTag.from && + specTag.from.kind === 'ImageStreamTag' && + specTag.from.name.indexOf(':') === -1 && + !specTag.from.namespace; + }; + // Don't use KeywordService for image stream filtering so we can add // special handling for image stream tags. Match keywords (array of regex) // against image streams and image stream tags, returning a copy of the @@ -137,7 +144,23 @@ angular.module("openshiftConsole") _.each(imageStreams, function(imageStream) { var name = _.get(imageStream, 'metadata.name', ''); var displayName = getDisplayName(imageStream, true); - var matchingTags = _.indexBy(imageStream.spec.tags, 'name'); + var specTags = []; + var references = {}; + var referencedBy = {}; + _.each(imageStream.spec.tags, function(tag) { + // If the tag follows another, track the reference. + if (referencesSameImageStream(tag)) { + references[tag.name] = tag.from.name; + referencedBy[tag.from.name] = referencedBy[tag.from.name] || []; + referencedBy[tag.from.name].push(tag.name); + return; + } + + // If the tag doesn't follow another, consider it in the search. + specTags.push(tag); + }); + + var matchingTags = _.indexBy(specTags, 'name'); // Find tags that match every keyword. Search image stream name, image // stream display name, and tag names, and tag descriptions. If a @@ -153,7 +176,7 @@ angular.module("openshiftConsole") } // Check tag descriptions. - _.each(imageStream.spec.tags, function(tag) { + _.each(specTags, function(tag) { // If this is not a builder or is hidden, don't match the tag. var tagTags = _.get(tag, 'annotations.tags', ''); if (!/\bbuilder\b/.test(tagTags) || /\bhidden\b/.test(tagTags)) { @@ -166,6 +189,16 @@ angular.module("openshiftConsole") return; } + // Search any tag names that reference this tag as well. For + // instance, searching for "latest" should match nodejs:4 if + // nodejs:latest references nodejs:4 + var matches = function(referenceName) { + return regex.test(referenceName); + }; + if (_.some(referencedBy[tag.name], matches)) { + return; + } + var description = _.get(tag, 'annotations.description'); if (!description || !regex.test(description)) { delete matchingTags[tag.name]; @@ -178,8 +211,16 @@ angular.module("openshiftConsole") if (!_.isEmpty(matchingTags)) { imageStreamCopy = angular.copy(imageStream); imageStreamCopy.status.tags = _.filter(imageStreamCopy.status.tags, function(tag) { + // If this tag follow another tag, include it if the other tag matches the search. + var fromTag = references[tag.tag]; + if (fromTag) { + return matchingTags[fromTag]; + } + + // Otherwise check if this tag was a match. return matchingTags[tag.tag]; }); + filteredImageStreams.push(imageStreamCopy); } }); @@ -201,6 +242,7 @@ angular.module("openshiftConsole") getCategoryItem: getCategoryItem, categorizeImageStreams: categorizeImageStreams, categorizeTemplates: categorizeTemplates, + referencesSameImageStream: referencesSameImageStream, filterImageStreams: filterImageStreams, filterTemplates: filterTemplates }; diff --git a/dist/scripts/scripts.js b/dist/scripts/scripts.js index a3244fbd51..40f9cc0218 100644 --- a/dist/scripts/scripts.js +++ b/dist/scripts/scripts.js @@ -4123,35 +4123,48 @@ _.each(e, function(d) { h(d, c) && (b[d.id] = b[d.id] || [], b[d.id].push(a), f = !0); }), f || (b[""] = b[""] || [], b[""].push(a)); }), b; -}, k = a("displayName"), l = function(a, b) { +}, k = function(a) { +return a.from && "ImageStreamTag" === a.from.kind && a.from.name.indexOf(":") === -1 && !a.from.namespace; +}, l = a("displayName"), m = function(a, b) { if (!b.length) return a; var c = []; return _.each(a, function(a) { -var d = _.get(a, "metadata.name", ""), e = k(a, !0), f = _.indexBy(a.spec.tags, "name"); -_.each(b, function(b) { -b.test(d) || e && b.test(e) || _.each(a.spec.tags, function(a) { -var c = _.get(a, "annotations.tags", ""); -if (!/\bbuilder\b/.test(c) || /\bhidden\b/.test(c)) return void delete f[a.name]; -if (!b.test(a.name)) { -var d = _.get(a, "annotations.description"); -d && b.test(d) || delete f[a.name]; +var d = _.get(a, "metadata.name", ""), e = l(a, !0), f = [], g = {}, h = {}; +_.each(a.spec.tags, function(a) { +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); +}); +var i = _.indexBy(f, "name"); +_.each(b, function(a) { +a.test(d) || e && a.test(e) || _.each(f, function(b) { +var c = _.get(b, "annotations.tags", ""); +if (!/\bbuilder\b/.test(c) || /\bhidden\b/.test(c)) return void delete i[b.name]; +if (!a.test(b.name)) { +var d = function(b) { +return a.test(b); +}; +if (!_.some(h[b.name], d)) { +var e = _.get(b, "annotations.description"); +e && a.test(e) || delete i[b.name]; +} } }); }); -var g; -_.isEmpty(f) || (g = angular.copy(a), g.status.tags = _.filter(g.status.tags, function(a) { -return f[a.tag]; -}), c.push(g)); +var j; +_.isEmpty(i) || (j = angular.copy(a), j.status.tags = _.filter(j.status.tags, function(a) { +var b = g[a.tag]; +return b ? i[b] :i[a.tag]; +}), c.push(j)); }), c; -}, m = [ "metadata.name", 'metadata.annotations["openshift.io/display-name"]', "metadata.annotations.description" ], n = function(a, b) { -return c.filterForKeywords(a, m, b); +}, n = [ "metadata.name", 'metadata.annotations["openshift.io/display-name"]', "metadata.annotations.description" ], o = function(a, b) { +return c.filterForKeywords(a, n, b); }; return { getCategoryItem:f, categorizeImageStreams:i, categorizeTemplates:j, -filterImageStreams:l, -filterTemplates:n +referencesSameImageStream:k, +filterImageStreams:m, +filterTemplates:o }; } ]), angular.module("openshiftConsole").factory("ModalsService", [ "$uibModal", function(a) { return { @@ -11489,7 +11502,7 @@ keyword:"" }, b.$watch("filter.keyword", e), b.$watchGroup([ "openshiftImageStreams", "projectImageStreams" ], g), b.$watchGroup([ "openshiftTemplates", "projectTemplates" ], i); } }; -} ]), angular.module("openshiftConsole").directive("catalogImage", [ "$filter", function(a) { +} ]), angular.module("openshiftConsole").directive("catalogImage", [ "$filter", "CatalogService", function(a, b) { return { restrict:"E", replace:!0, @@ -11501,25 +11514,25 @@ isBuilder:"=?", keywords:"=" }, templateUrl:"views/catalog/_image.html", -link:function(b) { -var c = a("imageStreamTagTags"), d = {}; -b.referencedBy = {}; -var e = _.get(b, "imageStream.spec.tags", []), f = {}; -_.each(e, function(a) { -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)); +link:function(c) { +var d = a("imageStreamTagTags"), e = {}; +c.referencedBy = {}; +var f = _.get(c, "imageStream.spec.tags", []), g = {}; +_.each(f, function(a) { +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)); }); -var g = function(a) { -var b = _.get(f, [ a ], []); +var h = function(a) { +var b = _.get(g, [ a ], []); return _.includes(b, "builder") && !_.includes(b, "hidden"); }; -b.$watch("imageStream.status.tags", function(a) { -b.tags = _.filter(a, function(a) { -return g(a.tag) && !d[a.tag]; +c.$watch("imageStream.status.tags", function(a) { +c.tags = _.filter(a, function(a) { +return h(a.tag) && !e[a.tag]; }); -var c = _.get(b, "is.tag.tag"); -c && _.some(b.tags, { -tag:c -}) || _.set(b, "is.tag", _.head(b.tags)); +var b = _.get(c, "is.tag.tag"); +b && _.some(c.tags, { +tag:b +}) || _.set(c, "is.tag", _.head(c.tags)); }); } };