From e857c676db63d626b2b60e2ed32d99da8a4dd801 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 21 Feb 2018 16:38:21 -0500 Subject: [PATCH] Have cor-checkable-menus reflect the filtered set of items Fixes https://jira.coreos.com/browse/QUAY-837 --- .../directives/repo-view/repo-panel-tags.html | 2 +- static/directives/set-repo-permissions.html | 2 +- static/js/core-ui.js | 7 ++++--- static/js/services/ui-service.js | 19 +++++++++++++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/static/directives/repo-view/repo-panel-tags.html b/static/directives/repo-view/repo-panel-tags.html index d37d061b6..450b4f802 100644 --- a/static/directives/repo-view/repo-panel-tags.html +++ b/static/directives/repo-view/repo-panel-tags.html @@ -21,7 +21,7 @@
- +
All Tags
diff --git a/static/directives/set-repo-permissions.html b/static/directives/set-repo-permissions.html index 296fbef4a..15c167e40 100644 --- a/static/directives/set-repo-permissions.html +++ b/static/directives/set-repo-permissions.html @@ -15,7 +15,7 @@
- +
All Repositories
diff --git a/static/js/core-ui.js b/static/js/core-ui.js index 4e9f9814e..9b57e529b 100644 --- a/static/js/core-ui.js +++ b/static/js/core-ui.js @@ -359,7 +359,8 @@ angular.module("core-ui", []) transclude: true, restrict: 'C', scope: { - 'controller': '=controller' + 'controller': '=controller', + 'filter': '=?filter' }, controller: function($rootScope, $scope, $element) { $scope.getClass = function(items, checked) { @@ -381,7 +382,7 @@ angular.module("core-ui", []) $scope.toggleItems = function($event) { $event.stopPropagation(); if ($scope.controller) { - $scope.controller.toggleItems(); + $scope.controller.toggleItems($scope.filter); } }; @@ -389,7 +390,7 @@ angular.module("core-ui", []) if ($scope.controller) { $scope.controller.checkByFilter(function(item) { return filter({'item': item}); - }); + }, $scope.filter); } }; } diff --git a/static/js/services/ui-service.js b/static/js/services/ui-service.js index 40c0d914a..ca9290796 100644 --- a/static/js/services/ui-service.js +++ b/static/js/services/ui-service.js @@ -54,14 +54,18 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio } }; - CheckStateController.prototype.toggleItems = function() { + CheckStateController.prototype.toggleItems = function(opt_filter) { this.lastChanged_= null; this.updateMap_(this.checked, false); if (this.checked.length) { this.checked = []; } else { - this.checked = this.items.slice(); + if (opt_filter) { + this.checked = this.items.filter((item) => (opt_filter.indexOf(item) >= 0)); + } else { + this.checked = this.items.slice(); + } } this.updateMap_(this.checked, true); @@ -99,9 +103,16 @@ angular.module('quay').factory('UIService', ['$timeout', '$rootScope', '$locatio }); }; - CheckStateController.prototype.checkByFilter = function(filter) { + CheckStateController.prototype.checkByFilter = function(filter, opt_secondaryFilter) { this.updateMap_(this.checked, false); - this.checked = $.grep(this.items, filter); + + var filterFunc = filter; + if (opt_secondaryFilter) { + filterFunc = (item) => (opt_secondaryFilter.indexOf(item) >= 0 && filter(item)); + } + + this.checked = $.grep(this.items, filterFunc); + this.updateMap_(this.checked, true); this.callListeners_(); };