From 1a1257aa79a1dca2b5233447811bf5377f686c14 Mon Sep 17 00:00:00 2001 From: Nadja Heitmann Date: Wed, 11 Dec 2024 12:09:59 +0000 Subject: [PATCH] Fixes #38083 - Add repository filter to Debian packages page --- .../bastion_katello/debs/debs.controller.js | 66 +++++++++++++------ .../bastion_katello/debs/views/debs.html | 4 ++ .../test/debs/debs.controller.test.js | 25 ++++++- 3 files changed, 72 insertions(+), 23 deletions(-) diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/debs.controller.js b/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/debs.controller.js index 4cf9adb0c7d..2dc63a0aab9 100644 --- a/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/debs.controller.js +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/debs.controller.js @@ -1,23 +1,23 @@ -(function () { - 'use strict'; - - /** - * @ngdoc controller - * @name Bastion.debs.controller:DebsController - * - * @description - * Handles fetching deb packages and populating Nutupane based on the current - * ui-router state. - * - * @requires translate - * - */ - function DebsController($scope, $location, translate, Nutupane, Deb, CurrentOrganization) { +/** + * @ngdoc controller + * @name Bastion.debs.controller:DebsController + * + * @description + * Handles fetching deb packages and populating Nutupane based on the current + * ui-router state. + * + * @requires translate + * + */ +angular.module('Bastion.debs').controller('DebsController', + ['$scope', '$location', 'translate', 'Nutupane', 'Deb', 'Repository', 'CurrentOrganization', + function DebsController($scope, $location, translate, Nutupane, Deb, Repository, CurrentOrganization) { var nutupane; var params = { 'organization_id': CurrentOrganization, 'search': $location.search().search || "", + 'repository_id': $location.search().repositoryId || null, 'paged': true, 'sort_by': 'name', 'sort_order': 'ASC' @@ -30,9 +30,23 @@ // Labels so breadcrumb strings can be translated $scope.label = translate('Debs'); + $scope.repositoriesLabel = translate('Repositories'); $scope.controllerName = 'katello_debs'; + $scope.repository = {name: translate('All Repositories'), id: 'all'}; + + Repository.queryUnpaged({'organization_id': CurrentOrganization, 'content_type': 'deb', 'with_content': 'deb'}, function (response) { + $scope.repositories = [$scope.repository]; + $scope.repositories = $scope.repositories.concat(response.results); + + if ($location.search().repositoryId) { + $scope.repository = _.find($scope.repositories, function (repository) { + return repository.id === parseInt($location.search().repositoryId, 10); + }); + } + }); + Deb.queryPaged({'organization_id': CurrentOrganization}, function (result) { $scope.packageCount = result.total; }); @@ -50,12 +64,22 @@ nutupane.refresh(); }; - } + $scope.$watch('repository', function (repository) { + var nutupaneParams = nutupane.getParams(); - angular - .module('Bastion.debs') - .controller('DebsController', DebsController); + if (repository.id === 'all') { + nutupaneParams['repository_id'] = null; + nutupane.setParams(nutupaneParams); + } else { + $location.search('repositoryId', repository.id); + nutupaneParams['repository_id'] = repository.id; + nutupane.setParams(nutupaneParams); + } - DebsController.$inject = ['$scope', '$location', 'translate', 'Nutupane', 'Deb', 'CurrentOrganization']; + if (!nutupane.table.initialLoad) { + nutupane.refresh(); + } + }); -})(); + }] +); diff --git a/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/views/debs.html b/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/views/debs.html index 935a718c314..01c2219bdc4 100644 --- a/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/views/debs.html +++ b/engines/bastion_katello/app/assets/javascripts/bastion_katello/debs/views/debs.html @@ -6,6 +6,10 @@

Deb Packages

+
+ +
+