Skip to content

Commit 46c6d8b

Browse files
author
OpenShift Bot
authored
Merge pull request #1193 from spadgett/catalog-item-no-subcategory
Merged by openshift-bot
2 parents 9989eef + a359023 commit 46c6d8b

File tree

5 files changed

+160
-36
lines changed

5 files changed

+160
-36
lines changed

app/scripts/controllers/create/browseCategory.js

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ angular.module('openshiftConsole')
1515
$routeParams,
1616
$uibModal,
1717
AlertMessageService,
18-
CatalogService,
1918
Constants,
2019
DataService,
2120
LabelFilter,

app/scripts/directives/catalog.js

+52-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ angular.module('openshiftConsole')
4848
var categoryKeywords = _.reject(keywords, matchesCategoryLabel);
4949
$scope.filteredBuildersByCategory[id] = CatalogService.filterImageStreams(builders, categoryKeywords);
5050
});
51+
$scope.filteredBuildersNoSubcategory = CatalogService.filterImageStreams($scope.buildersNoSubcategory, keywords);
5152

5253
$scope.filteredTemplatesByCategory = {};
5354
_.each($scope.templatesByCategory, function(templates, id) {
@@ -59,6 +60,7 @@ angular.module('openshiftConsole')
5960
var categoryKeywords = _.reject(keywords, matchesCategoryLabel);
6061
$scope.filteredTemplatesByCategory[id] = CatalogService.filterTemplates(templates, categoryKeywords);
6162
});
63+
$scope.filteredTemplatesNoSubcategory = CatalogService.filterTemplates($scope.templatesNoSubcategory, keywords);
6264
}
6365

6466
// Filter the catalog when the keyword or tag changes.
@@ -69,14 +71,41 @@ angular.module('openshiftConsole')
6971
});
7072
}, 200, { maxWait: 1000, trailing: true }));
7173

74+
function findItemsWithNoSubcategory(itemsByCategory) {
75+
var subcategories = _.get($scope, 'parentCategory.subcategories', []);
76+
if (_.isEmpty(subcategories)) {
77+
return [];
78+
}
79+
80+
// Set of items in a subcategory indexed by UID.
81+
var uidInSubcategory = {};
82+
_.each(subcategories, function(subcategory) {
83+
_.each(subcategory.items, function(subcategoryItem) {
84+
_.each(itemsByCategory[subcategoryItem.id], function(item) {
85+
var uid = _.get(item, 'metadata.uid');
86+
uidInSubcategory[uid] = true;
87+
});
88+
});
89+
});
90+
91+
var isInSubcategory = function(item) {
92+
var uid = _.get(item, 'metadata.uid');
93+
return !!uidInSubcategory[uid];
94+
};
95+
96+
var parentID = $scope.parentCategory.id;
97+
return _.reject(itemsByCategory[parentID], isInSubcategory);
98+
}
99+
72100
function updateImageStreams() {
73101
if (!$scope.projectImageStreams || !$scope.openshiftImageStreams) {
74102
return;
75103
}
76104

77105
var imageStreams = _.toArray($scope.projectImageStreams).concat(_.toArray($scope.openshiftImageStreams));
78106
$scope.buildersByCategory = CatalogService.categorizeImageStreams(imageStreams);
79-
$scope.emptyCatalog = $scope.emptyCatalog && _.every($scope.buildersByCategory, _.isEmpty);
107+
$scope.buildersNoSubcategory = findItemsWithNoSubcategory($scope.buildersByCategory);
108+
$scope.emptyCatalog = $scope.emptyCatalog && _.every($scope.buildersByCategory, _.isEmpty) && _.isEmpty($scope.buildersNoSubcategory);
80109
updateState();
81110
}
82111

@@ -87,7 +116,8 @@ angular.module('openshiftConsole')
87116

88117
var templates = _.toArray($scope.projectTemplates).concat(_.toArray($scope.openshiftTemplates));
89118
$scope.templatesByCategory = CatalogService.categorizeTemplates(templates);
90-
$scope.emptyCatalog = $scope.emptyCatalog && _.every($scope.templatesByCategory, _.isEmpty);
119+
$scope.templatesNoSubcategory = findItemsWithNoSubcategory($scope.templatesByCategory);
120+
$scope.emptyCatalog = $scope.emptyCatalog && _.every($scope.templatesByCategory, _.isEmpty) && _.isEmpty($scope.templatesNoSubcategory);
91121
updateState();
92122
}
93123

@@ -120,6 +150,24 @@ angular.module('openshiftConsole')
120150
}
121151
});
122152
$scope.countByCategory = countByCategory;
153+
154+
$scope.hasItemsNoSubcategory = !_.isEmpty($scope.buildersNoSubcategory) || !_.isEmpty($scope.templatesNoSubcategory);
155+
$scope.countFilteredNoSubcategory = _.size($scope.filteredBuildersNoSubcategory) + _.size($scope.filteredTemplatesNoSubcategory);
156+
if ($scope.countFilteredNoSubcategory) {
157+
$scope.allContentHidden = false;
158+
}
159+
}
160+
161+
function hasSingleCategory() {
162+
if (!$scope.parentCategory) {
163+
return false;
164+
}
165+
166+
if (nonEmptyCategories.length !== 1) {
167+
return false;
168+
}
169+
170+
return !$scope.hasItemsNoSubcategory;
123171
}
124172

125173
function updateState() {
@@ -136,8 +184,8 @@ angular.module('openshiftConsole')
136184
updateCategoryCounts();
137185

138186
if ($scope.loaded) {
139-
if ($scope.parentCategory && nonEmptyCategories.length === 1) {
140-
// If there is only one subcategory with items, just show the items.
187+
// If there is only one subcategory with items, just show the items.
188+
if (hasSingleCategory()) {
141189
$scope.singleCategory = _.head(nonEmptyCategories);
142190
}
143191

app/views/catalog/catalog.html

+37-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ <h2 class="text-center">No images or templates.</h2>
5757
<div ng-repeat="category in categories" ng-if="hasContent[category.id]">
5858
<h2 class="h3" ng-if="category.label">{{category.label}}</h2>
5959
<div class="row tile-row" ng-class="{ 'mar-top-xl': !category.label || category.items.length < 2 }">
60-
<div ng-repeat="item in category.items" ng-if="countByCategory[item.id]" class="col-xxs-12 col-xs-6 col-sm-4 col-md-4 col-lg-3">
60+
<div ng-repeat="item in category.items" ng-if="countByCategory[item.id]" class="col-xxs-12 col-xs-6 col-sm-6 col-md-4">
6161
<div class="tile tile-click" ng-class="{ 'tile-sans-icon' : !item.iconClass, 'tile-sans-description' : !item.description }">
6262
<div class="tile-title">
6363
<div ng-if="item.iconClass || category.iconClassDefault" class="image-icon">
@@ -80,6 +80,21 @@ <h3>
8080
</div>
8181
</div>
8282
</div>
83+
<div ng-if="hasItemsNoSubcategory">
84+
<div class="row row-cards-pf row-cards-pf-flex">
85+
<catalog-image
86+
image-stream="builder"
87+
project="{{projectName}}"
88+
is-builder="true"
89+
ng-repeat="builder in buildersNoSubcategory track by (builder | uid)">
90+
</catalog-image>
91+
<catalog-template
92+
template="template"
93+
project="{{projectName}}"
94+
ng-repeat="template in templatesNoSubcategory | orderBy : ['metadata.name', 'metadata.namespace'] track by (template | uid)">
95+
</catalog-template>
96+
</div>
97+
</div>
8398
</div>
8499

85100
<div ng-if="filterActive">
@@ -106,6 +121,27 @@ <h2 class="h3">
106121
</div><!-- /row-cards-pf -->
107122
</div>
108123
</div>
124+
<div ng-if="countFilteredNoSubcategory">
125+
<h2 class="h3">
126+
Other {{parentCategory.label}}
127+
<span class="tile-item-count badge">{{countFilteredNoSubcategory}}</span>
128+
</h2>
129+
<div class="row row-cards-pf row-cards-pf-flex mar-top-xl">
130+
<catalog-image
131+
image-stream="builder"
132+
project="{{projectName}}"
133+
is-builder="true"
134+
keywords="keywords"
135+
ng-repeat="builder in filteredBuildersNoSubcategory track by (builder | uid)">
136+
</catalog-image>
137+
<catalog-template
138+
template="template"
139+
project="{{projectName}}"
140+
keywords="keywords"
141+
ng-repeat="template in filteredTemplatesNoSubcategory | orderBy : ['metadata.name', 'metadata.namespace'] track by (template | uid)">
142+
</catalog-template>
143+
</div>
144+
</div>
109145
</div>
110146
</div>
111147

dist/scripts/scripts.js

+50-29
Original file line numberDiff line numberDiff line change
@@ -8009,9 +8009,9 @@ k.toErrorPage("Could not load " + m(d.kind) + " '" + d.name + "'. " + b("getErro
80098009
j.unwatchAll(p);
80108010
})) :void k.toErrorPage("You do not have authority to update " + m(d.kind) + " " + d.name + ".", "access_denied");
80118011
}));
8012-
} ]), angular.module("openshiftConsole").controller("BrowseCategoryController", [ "$scope", "$filter", "$location", "$q", "$routeParams", "$uibModal", "AlertMessageService", "CatalogService", "Constants", "DataService", "LabelFilter", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h, i, j, k, l, m) {
8012+
} ]), angular.module("openshiftConsole").controller("BrowseCategoryController", [ "$scope", "$filter", "$location", "$q", "$routeParams", "$uibModal", "AlertMessageService", "Constants", "DataService", "LabelFilter", "Navigate", "ProjectsService", function(a, b, c, d, e, f, g, h, i, j, k, l) {
80138013
a.projectName = e.project;
8014-
var n = function(b, c) {
8014+
var m = function(b, c) {
80158015
var d;
80168016
return _.some(b, function(b) {
80178017
if (d = _.find(b.items, {
@@ -8026,10 +8026,10 @@ label:""
80268026
}
80278027
return !1;
80288028
}), d;
8029-
}, o = i.CATALOG_CATEGORIES, p = "none" === e.category ? "" :e.category;
8030-
if (a.category = n(o, p), !a.category) return void l.toErrorPage("Catalog category " + e.category + " not found.");
8031-
var q, r;
8032-
return e.subcategory && (q = a.category, p = "none" === e.subcategory ? "" :e.subcategory, r = _.get(a.category, "subcategories", []), a.category = n(r, p), !a.category) ? void l.toErrorPage("Catalog category " + e.category + "/" + e.subcategory + " not found.") :(a.alerts = a.alerts || {}, g.getAlerts().forEach(function(b) {
8029+
}, n = h.CATALOG_CATEGORIES, o = "none" === e.category ? "" :e.category;
8030+
if (a.category = m(n, o), !a.category) return void k.toErrorPage("Catalog category " + e.category + " not found.");
8031+
var p, q;
8032+
return e.subcategory && (p = a.category, o = "none" === e.subcategory ? "" :e.subcategory, q = _.get(a.category, "subcategories", []), a.category = m(q, o), !a.category) ? void k.toErrorPage("Catalog category " + e.category + "/" + e.subcategory + " not found.") :(a.alerts = a.alerts || {}, g.getAlerts().forEach(function(b) {
80338033
a.alerts[b.name] = b.data;
80348034
}), g.clearAlerts(), a.breadcrumbs = [ {
80358035
title:a.projectName,
@@ -8040,23 +8040,23 @@ link:"project/" + a.projectName + "/create"
80408040
}, {
80418041
title:"Catalog",
80428042
link:"project/" + a.projectName + "/create?tab=fromCatalog"
8043-
} ], q && a.breadcrumbs.push({
8044-
title:q.label,
8045-
link:"project/" + a.projectName + "/create/category/" + q.id
8043+
} ], p && a.breadcrumbs.push({
8044+
title:p.label,
8045+
link:"project/" + a.projectName + "/create/category/" + p.id
80468046
}), a.breadcrumbs.push({
80478047
title:a.category.label
8048-
}), void m.get(e.project).then(_.spread(function(c, d) {
8049-
a.project = c, a.context = d, a.breadcrumbs[0].title = b("displayName")(c), j.list("imagestreams", {
8048+
}), void l.get(e.project).then(_.spread(function(c, d) {
8049+
a.project = c, a.context = d, a.breadcrumbs[0].title = b("displayName")(c), i.list("imagestreams", {
80508050
namespace:"openshift"
80518051
}, function(b) {
80528052
a.openshiftImageStreams = b.by("metadata.name");
8053-
}), j.list("templates", {
8053+
}), i.list("templates", {
80548054
namespace:"openshift"
80558055
}, function(b) {
80568056
a.openshiftTemplates = b.by("metadata.name");
8057-
}), "openshift" === e.project ? (a.projectImageStreams = [], a.projectTemplates = []) :(j.list("imagestreams", d, function(b) {
8057+
}), "openshift" === e.project ? (a.projectImageStreams = [], a.projectTemplates = []) :(i.list("imagestreams", d, function(b) {
80588058
a.projectImageStreams = b.by("metadata.name");
8059-
}), j.list("templates", d, function(b) {
8059+
}), i.list("templates", d, function(b) {
80608060
a.projectTemplates = b.by("metadata.name");
80618061
}));
80628062
})));
@@ -11358,27 +11358,45 @@ var f = a.getCategoryItem(d), g = function(a) {
1135811358
return a.test(f.label);
1135911359
}, h = _.reject(b, g);
1136011360
e.filteredBuildersByCategory[d] = a.filterImageStreams(c, h);
11361-
}), e.filteredTemplatesByCategory = {}, void _.each(e.templatesByCategory, function(c, d) {
11361+
}), e.filteredBuildersNoSubcategory = a.filterImageStreams(e.buildersNoSubcategory, b), e.filteredTemplatesByCategory = {}, _.each(e.templatesByCategory, function(c, d) {
1136211362
var f = a.getCategoryItem(d), g = function(a) {
1136311363
return a.test(f.label);
1136411364
}, h = _.reject(b, g);
1136511365
e.filteredTemplatesByCategory[d] = a.filterTemplates(c, h);
11366-
}));
11366+
}), void (e.filteredTemplatesNoSubcategory = a.filterTemplates(e.templatesNoSubcategory, b)));
1136711367
}
11368-
function g() {
11368+
function g(a) {
11369+
var b = _.get(e, "parentCategory.subcategories", []);
11370+
if (_.isEmpty(b)) return [];
11371+
var c = {};
11372+
_.each(b, function(b) {
11373+
_.each(b.items, function(b) {
11374+
_.each(a[b.id], function(a) {
11375+
var b = _.get(a, "metadata.uid");
11376+
c[b] = !0;
11377+
});
11378+
});
11379+
});
11380+
var d = function(a) {
11381+
var b = _.get(a, "metadata.uid");
11382+
return !!c[b];
11383+
}, f = e.parentCategory.id;
11384+
return _.reject(a[f], d);
11385+
}
11386+
function h() {
1136911387
if (e.projectImageStreams && e.openshiftImageStreams) {
1137011388
var b = _.toArray(e.projectImageStreams).concat(_.toArray(e.openshiftImageStreams));
11371-
e.buildersByCategory = a.categorizeImageStreams(b), e.emptyCatalog = e.emptyCatalog && _.every(e.buildersByCategory, _.isEmpty), j();
11389+
e.buildersByCategory = a.categorizeImageStreams(b), e.buildersNoSubcategory = g(e.buildersByCategory), e.emptyCatalog = e.emptyCatalog && _.every(e.buildersByCategory, _.isEmpty) && _.isEmpty(e.buildersNoSubcategory), l();
1137211390
}
1137311391
}
11374-
function h() {
11392+
function i() {
1137511393
if (e.projectTemplates && e.openshiftTemplates) {
1137611394
var b = _.toArray(e.projectTemplates).concat(_.toArray(e.openshiftTemplates));
11377-
e.templatesByCategory = a.categorizeTemplates(b), e.emptyCatalog = e.emptyCatalog && _.every(e.templatesByCategory, _.isEmpty), j();
11395+
e.templatesByCategory = a.categorizeTemplates(b), e.templatesNoSubcategory = g(e.templatesByCategory), e.emptyCatalog = e.emptyCatalog && _.every(e.templatesByCategory, _.isEmpty) && _.isEmpty(e.templatesNoSubcategory), l();
1137811396
}
1137911397
}
11380-
function i() {
11381-
e.noFilterMatches = !0, k = [];
11398+
function j() {
11399+
e.noFilterMatches = !0, m = [];
1138211400
var a = {};
1138311401
_.each(e.filteredBuildersByCategory, function(b, c) {
1138411402
a[c] = _.size(b);
@@ -11387,25 +11405,28 @@ a[c] = (a[c] || 0) + _.size(b);
1138711405
}), e.allContentHidden = !0, _.each(e.categories, function(b) {
1138811406
var c = !1;
1138911407
_.each(b.items, function(b) {
11390-
a[b.id] && (k.push(b), c = !0);
11408+
a[b.id] && (m.push(b), c = !0);
1139111409
}), _.set(e, [ "hasContent", b.id ], c), c && (e.allContentHidden = !1);
11392-
}), e.countByCategory = a;
11410+
}), e.countByCategory = a, e.hasItemsNoSubcategory = !_.isEmpty(e.buildersNoSubcategory) || !_.isEmpty(e.templatesNoSubcategory), e.countFilteredNoSubcategory = _.size(e.filteredBuildersNoSubcategory) + _.size(e.filteredTemplatesNoSubcategory), e.countFilteredNoSubcategory && (e.allContentHidden = !1);
1139311411
}
11394-
function j() {
11395-
e.loaded = e.projectTemplates && e.openshiftTemplates && e.projectImageStreams && e.openshiftImageStreams, f(), i(), e.loaded && (e.parentCategory && 1 === k.length && (e.singleCategory = _.head(k)), d.log("templates by category", e.templatesByCategory), d.log("builder images", e.buildersByCategory));
11412+
function k() {
11413+
return !!e.parentCategory && (1 === m.length && !e.hasItemsNoSubcategory);
11414+
}
11415+
function l() {
11416+
e.loaded = e.projectTemplates && e.openshiftTemplates && e.projectImageStreams && e.openshiftImageStreams, f(), j(), e.loaded && (k() && (e.singleCategory = _.head(m)), d.log("templates by category", e.templatesByCategory), d.log("builder images", e.buildersByCategory));
1139611417
}
1139711418
e.categories = _.get(e, "parentCategory.subcategories", b.CATALOG_CATEGORIES), e.loaded = !1, e.emptyCatalog = !0, e.filter = {
1139811419
keyword:""
1139911420
}, e.$watch("filter.keyword", _.debounce(function() {
1140011421
e.$apply(function() {
11401-
f(), i();
11422+
f(), j();
1140211423
});
1140311424
}, 200, {
1140411425
maxWait:1e3,
1140511426
trailing:!0
1140611427
}));
11407-
var k;
11408-
e.$watchGroup([ "openshiftImageStreams", "projectImageStreams" ], g), e.$watchGroup([ "openshiftTemplates", "projectTemplates" ], h);
11428+
var m;
11429+
e.$watchGroup([ "openshiftImageStreams", "projectImageStreams" ], h), e.$watchGroup([ "openshiftTemplates", "projectTemplates" ], i);
1140911430
}
1141011431
};
1141111432
} ]), angular.module("openshiftConsole").directive("categoryContent", [ "CatalogService", "Constants", "KeywordService", "Logger", function(a, b, c, d) {

dist/scripts/templates.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -4522,7 +4522,7 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
45224522
"<div ng-repeat=\"category in categories\" ng-if=\"hasContent[category.id]\">\n" +
45234523
"<h2 class=\"h3\" ng-if=\"category.label\">{{category.label}}</h2>\n" +
45244524
"<div class=\"row tile-row\" ng-class=\"{ 'mar-top-xl': !category.label || category.items.length < 2 }\">\n" +
4525-
"<div ng-repeat=\"item in category.items\" ng-if=\"countByCategory[item.id]\" class=\"col-xxs-12 col-xs-6 col-sm-4 col-md-4 col-lg-3\">\n" +
4525+
"<div ng-repeat=\"item in category.items\" ng-if=\"countByCategory[item.id]\" class=\"col-xxs-12 col-xs-6 col-sm-6 col-md-4\">\n" +
45264526
"<div class=\"tile tile-click\" ng-class=\"{ 'tile-sans-icon' : !item.iconClass, 'tile-sans-description' : !item.description }\">\n" +
45274527
"<div class=\"tile-title\">\n" +
45284528
"<div ng-if=\"item.iconClass || category.iconClassDefault\" class=\"image-icon\">\n" +
@@ -4545,6 +4545,14 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
45454545
"</div>\n" +
45464546
"</div>\n" +
45474547
"</div>\n" +
4548+
"<div ng-if=\"hasItemsNoSubcategory\">\n" +
4549+
"<div class=\"row row-cards-pf row-cards-pf-flex\">\n" +
4550+
"<catalog-image image-stream=\"builder\" project=\"{{projectName}}\" is-builder=\"true\" ng-repeat=\"builder in buildersNoSubcategory track by (builder | uid)\">\n" +
4551+
"</catalog-image>\n" +
4552+
"<catalog-template template=\"template\" project=\"{{projectName}}\" ng-repeat=\"template in templatesNoSubcategory | orderBy : ['metadata.name', 'metadata.namespace'] track by (template | uid)\">\n" +
4553+
"</catalog-template>\n" +
4554+
"</div>\n" +
4555+
"</div>\n" +
45484556
"</div>\n" +
45494557
"<div ng-if=\"filterActive\">\n" +
45504558
"<div ng-repeat=\"category in categories\" ng-if=\"hasContent[category.id]\">\n" +
@@ -4561,6 +4569,18 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
45614569
"</div>\n" +
45624570
"</div>\n" +
45634571
"</div>\n" +
4572+
"<div ng-if=\"countFilteredNoSubcategory\">\n" +
4573+
"<h2 class=\"h3\">\n" +
4574+
"Other {{parentCategory.label}}\n" +
4575+
"<span class=\"tile-item-count badge\">{{countFilteredNoSubcategory}}</span>\n" +
4576+
"</h2>\n" +
4577+
"<div class=\"row row-cards-pf row-cards-pf-flex mar-top-xl\">\n" +
4578+
"<catalog-image image-stream=\"builder\" project=\"{{projectName}}\" is-builder=\"true\" keywords=\"keywords\" ng-repeat=\"builder in filteredBuildersNoSubcategory track by (builder | uid)\">\n" +
4579+
"</catalog-image>\n" +
4580+
"<catalog-template template=\"template\" project=\"{{projectName}}\" keywords=\"keywords\" ng-repeat=\"template in filteredTemplatesNoSubcategory | orderBy : ['metadata.name', 'metadata.namespace'] track by (template | uid)\">\n" +
4581+
"</catalog-template>\n" +
4582+
"</div>\n" +
4583+
"</div>\n" +
45644584
"</div>\n" +
45654585
"</div>\n" +
45664586
"\n" +

0 commit comments

Comments
 (0)