Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Commit

Permalink
enable saved search selection filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Dec 30, 2016
1 parent 4c6cd64 commit 8484b1c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion public/kibi_timeline_vis_params.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<div class="form-group">
<label>Saved search id</label>
<kibi-select-port required object-type="search" ng-model="group.savedSearchId">
<kibi-select-port required object-type="search" filterable="true" ng-model="group.savedSearchId">
</kibi-select-port>
</div>

Expand Down
2 changes: 2 additions & 0 deletions public/lib/directives/kibi_select.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

<input ng-show="getVariable" type="text" ng-model="modelObject.value" class="form-control"/>

<input ng-show="filterable" placeholder="Filter" ng-model="itemsFilter" ng-change="filterItems()" ng-model-options="{debounce:750}" class="form-control"/>

<select
ng-class="{ 'red-border' : !isValid }"
ng-show="!getVariable"
Expand Down
10 changes: 8 additions & 2 deletions public/lib/directives/kibi_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ define(function (require) {
modelDisabled: '=?', // use to disable the underlying select
modelRequired: '=?', // use to disable the underlying select
include: '=?', // extra values can be passed here
analyzedWarning: '@' // set to true or false to disable/enable analyzed field warning
analyzedWarning: '@', // set to true or false to disable/enable analyzed field warning
filterable: '=?' // optional - enable selection filtering
},
template: require('./kibi_select.html'),
link: function (scope, element, attrs, ngModelCtrl) {
Expand Down Expand Up @@ -168,7 +169,7 @@ define(function (require) {

switch (scope.objectType) {
case 'search':
promise = selectHelper.getObjects(scope.objectType);
promise = selectHelper.getObjects(scope.objectType, scope.itemsFilter);
break;
case 'field':
promise = selectHelper.getFields(scope.indexPatternId, scope.fieldTypes);
Expand All @@ -184,6 +185,11 @@ define(function (require) {
}
};

scope.filterItems = function () {
scope.itemsFilter = this.itemsFilter;
_render();
};

scope.$watchMulti(['indexPatternId', 'indexPatternType', 'queryId', 'include', 'modelDisabled', 'modelRequired'], function () {
_render();
});
Expand Down
22 changes: 11 additions & 11 deletions public/lib/directives/kibi_select_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ define(function (require) {
config, $http, courier, indexPatterns, timefilter, Private, Promise, kbnIndex
) {

const searchService = Private(require('ui/saved_objects/saved_object_registry')).byLoaderPropertiesName.searches;

function KibiSelectHelper() {
}

Expand All @@ -15,17 +17,15 @@ define(function (require) {
return $http.get(chrome.getBasePath() + '/elasticsearch/' + kbnIndex + '/' + type + '/_search?size=100');
};

KibiSelectHelper.prototype.getObjects = function (type) {
return searchRequest(type).then(function (objects) {
if (objects.data.hits && objects.data.hits.hits) {
const items = _.map(objects.data.hits.hits, function (hit) {
return {
label: hit._source.title,
value: hit._id
};
});
return items;
}
KibiSelectHelper.prototype.getObjects = function (type, filter) {
return searchService.find(filter).then(function (resp) {
const items = _.map(resp.hits, function (hit) {
return {
label: hit.title,
value: hit.id
};
});
return items;
});
};

Expand Down

0 comments on commit 8484b1c

Please sign in to comment.