Merge "Fix metadata tree available filter"

This commit is contained in:
Jenkins 2016-01-29 19:11:30 +00:00 committed by Gerrit Code Review
commit 83113bf31e
3 changed files with 48 additions and 3 deletions

View File

@ -35,6 +35,7 @@
var ctrl = this; var ctrl = this;
ctrl.availableFilter = availableFilter; ctrl.availableFilter = availableFilter;
ctrl.quickFilter = quickFilter;
ctrl.text = angular.extend({}, defaults.text, ctrl.text); ctrl.text = angular.extend({}, defaults.text, ctrl.text);
if (!ctrl.tree) { if (!ctrl.tree) {
ctrl.tree = new metadataTreeService.Tree(ctrl.available, ctrl.existing); ctrl.tree = new metadataTreeService.Tree(ctrl.available, ctrl.existing);
@ -46,8 +47,29 @@
}; };
function availableFilter(item) { function availableFilter(item) {
return !item.added && ( return !item.added && item.visible;
ctrl.filterText.available.length === 0 ? item.visible : true); }
/**
* @ngdoc method
* @name MetadataTreeController.quickFilter
* @description
* Method used for filtering the list of available metadata items based on a user entered
* string value. The list of items is filtered such that any leaf with a display value or
* property name matching the provided string will be displayed. Parent items of any matching
* leaf are also displayed so context and the tree structure are preserved.
* @param {object} item The metadata tree item to filter.
* @return {boolean} true if item matches, false otherwise
*/
function quickFilter(item) {
var text = ctrl.filterText.available;
if (!text) {
return true;
}
if (item.children.length > 0) {
return item.children.filter(quickFilter).length > 0;
}
return item.label.indexOf(text) > -1 || item.leaf.name.indexOf(text) > -1;
} }
} }

View File

@ -47,7 +47,7 @@
</div> </div>
</li> </li>
<li ng-repeat="item in availableList = (ctrl.tree.flatTree | filter: {$: ctrl.filterText.available} | filter: ctrl.availableFilter)" <li ng-repeat="item in availableList = (ctrl.tree.flatTree | filter: ctrl.availableFilter | filter: ctrl.quickFilter)"
ng-class="'level-' + item.level + (ctrl.tree.selected===item?' active':'')" ng-class="'level-' + item.level + (ctrl.tree.selected===item?' active':'')"
ng-class-odd="'dark-stripe'" ng-class-odd="'dark-stripe'"
ng-class-even="'light-stripe'" ng-class-even="'light-stripe'"

View File

@ -172,6 +172,29 @@
var lastActive = $element.find('ul.list-group:last li[ng-repeat].active'); var lastActive = $element.find('ul.list-group:last li[ng-repeat].active');
expect(lastActive.scope().item.leaf.name).toBe('custom'); expect(lastActive.scope().item.leaf.name).toBe('custom');
}); });
it('should filter available items based on string', function () {
var input = $element.find('.panel-heading:first input');
$element.find('ul.list-group:first li[ng-repeat]:first').trigger('click');
$element.find('ul.list-group:first li[ng-repeat]:last').trigger('click');
// With no quick filter there are 10 items
input.val('').trigger('input');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(10);
// With filter set to 'Test A.5' there are 2 items
// - Test Namespace A
// -- Test A.5 - boolean
input.val('Test A.5').trigger('input');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(2);
// With filter set to 'test:B' there are 3 items
// - Test Namespace B
// -- Test Object A
// -- Test Object B
input.val('test:B').trigger('input');
expect($element.find('ul.list-group:first li[ng-repeat]').length).toBe(3);
});
}); });
describe('metadataTreeItem directive', function () { describe('metadataTreeItem directive', function () {