Fix metadata tree available filter
This patch updates the filtering of the available metadata items in the Update Metadata modal so that any leaf with either a display value or property name that matches will be displayed. Parent items of any matching leaf are also displayed so context and the tree structure are preserved. Closes-Bug: #1519535 Closes-Bug: #1519567 Closes-Bug: #1463733 Change-Id: I11caf506a851807cb3b079184dd260db6862b3d9
This commit is contained in:
parent
0dc7d4c434
commit
94c4f7b3d0
@ -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