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

Commit

Permalink
Merge pull request #100 from nreese/filterSavedSearches
Browse files Browse the repository at this point in the history
enable saved search selection filtering
  • Loading branch information
scampi authored Feb 1, 2017
2 parents 9f76a30 + 19a91c6 commit 0e69f0c
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion public/kibi_timeline_vis_params.html
Original file line number Diff line number Diff line change
@@ -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>

2 changes: 2 additions & 0 deletions public/lib/directives/kibi_select.html
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 8 additions & 2 deletions public/lib/directives/kibi_select.js
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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);
@@ -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();
});
22 changes: 10 additions & 12 deletions public/lib/directives/kibi_select_helper.js
Original file line number Diff line number Diff line change
@@ -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() {
@@ -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;
});
};

0 comments on commit 0e69f0c

Please sign in to comment.