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

enable saved search selection filtering #100

Merged
merged 2 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 10 additions & 12 deletions public/lib/directives/kibi_select_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ define(function (require) {
const chrome = require('ui/chrome');

return function KibiSelectHelperFactory(
config, $http, courier, indexPatterns, timefilter, Private, Promise, kbnIndex
config, $http, courier, indexPatterns, timefilter, Private, Promise, kbnIndex, savedSearches
) {

function KibiSelectHelper() {
Expand All @@ -15,17 +15,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 savedSearches.find(filter).then(function (resp) {
const items = _.map(resp.hits, function (hit) {
return {
label: hit.title,
value: hit.id
};
});
return items;
});
};

Expand Down