Merge "Fix metadata tree available filter"
This commit is contained in:
commit
83113bf31e
@ -35,6 +35,7 @@
|
||||
var ctrl = this;
|
||||
|
||||
ctrl.availableFilter = availableFilter;
|
||||
ctrl.quickFilter = quickFilter;
|
||||
ctrl.text = angular.extend({}, defaults.text, ctrl.text);
|
||||
if (!ctrl.tree) {
|
||||
ctrl.tree = new metadataTreeService.Tree(ctrl.available, ctrl.existing);
|
||||
@ -46,8 +47,29 @@
|
||||
};
|
||||
|
||||
function availableFilter(item) {
|
||||
return !item.added && (
|
||||
ctrl.filterText.available.length === 0 ? item.visible : true);
|
||||
return !item.added && item.visible;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@
|
||||
</div>
|
||||
</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-odd="'dark-stripe'"
|
||||
ng-class-even="'light-stripe'"
|
||||
|
@ -172,6 +172,29 @@
|
||||
var lastActive = $element.find('ul.list-group:last li[ng-repeat].active');
|
||||
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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user