Adding implicit filters to the integrations

This commit is contained in:
havidarou 2017-11-17 03:58:16 -05:00
parent 7c80333b98
commit fb20bece33
2 changed files with 41 additions and 9 deletions

View File

@ -3,13 +3,15 @@ import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
const app = require('ui/modules').get('apps/webinar_app', []);
app.controller('kibanaSearchbar', function ($scope, timefilter, AppState, $timeout, Private, $rootScope, savedVisualizations, getAppState) {
app.controller('kibanaSearchbar', function ($scope, timefilter, AppState, $timeout, Private, $rootScope, savedVisualizations, appState) {
const filterBar = Private(FilterBarQueryFilterProvider);
timefilter.enabled = true;
let visualizeLoader = null;
let currentAppState = getAppState();
let implicitFilter = null;
let currentAppState = null;
$scope.indexPattern = [];
// This is embarrassing, but currently I don't know of any other way to get the index-pattern object
savedVisualizations.get('Alert-level-evolution').then(savedObj => {
$scope.indexPattern[0] = savedObj.vis.indexPattern;
@ -23,13 +25,17 @@ app.controller('kibanaSearchbar', function ($scope, timefilter, AppState, $timeo
function getStateDefaults() {
return {
query: {'language': 'lucene', 'query': '' },
query: {'language': 'lucene', 'query': ''},
index: $scope.indexPattern[0].id,
interval: 'auto',
filters: {}
};
}
$scope.showWholeSearchbar = function () {
return $(".kuiLocalSearchAssistedInput").length >= 1;
};
$scope.showFilterBar = function () {
if (filterBar.getFilters().length == 0) return false;
else return true;
@ -43,7 +49,17 @@ app.controller('kibanaSearchbar', function ($scope, timefilter, AppState, $timeo
$scope.state.query = query;
$scope.state.save();
$rootScope.$broadcast('updateVis', query, filterBar.getFilters());
let fullFilter = null;
// Build the full query using the implicit filter
// The implicit filter should be have two parts: the cluster name and the page related query
if ($rootScope.currentImplicitFilter === "") implicitFilter = 'cluster.name : "' + appState.getClusterInfo().cluster + '"';
else implicitFilter = 'cluster.name : "' + appState.getClusterInfo().cluster + '" AND ' + $rootScope.currentImplicitFilter;
if (query.query === '')
fullFilter = implicitFilter;
else fullFilter = implicitFilter + ' AND ' + query.query;
$rootScope.$broadcast('updateVis', {'language': 'lucene', 'query': fullFilter}, filterBar.getFilters());
$rootScope.$broadcast('fetch');
};
});

View File

@ -8,25 +8,41 @@ var app = require('ui/modules').get('apps/webinar_app', [])
scope: {
visID: '=visId',
},
controller: function VisController($scope, savedVisualizations) {
controller: function VisController($scope, $rootScope, savedVisualizations) {
$scope.implicitFilter = '';
$scope.visTitle = '';
$scope.fullFilter = '';
// Listen for changes
var updateSearchSource = $scope.$on('updateVis', function (event, query, filters) {
if ($scope.implicitFilter !== '') query.query = $scope.implicitFilter + ' AND ' + query.query;
$scope.savedObj.searchSource.set('query', query);
if (query.query == '') {
$scope.fullFilter = $scope.implicitFilter;
}
else {
if ($scope.implicitFilter != '') {
$scope.fullFilter = $scope.implicitFilter + ' AND ' + query.query;
}
else {
$scope.fullFilter = query.query;
}
}
$scope.savedObj.searchSource.set('query', {
language: 'lucene',
query: $scope.fullFilter
});
$scope.savedObj.searchSource.set('filter', filters);
});
// Initializing the visualization
getVisualizeLoader().then(loader => {
savedVisualizations.get($scope.visID).then(savedObj => {
if ($scope.implicitFilter.endsWith("AND ")) $scope.implicitFilter = $scope.implicitFilter.substring(0, $scope.implicitFilter.indexOf("AND "));
$scope.implicitFilter = savedObj.searchSource.get('query')['query'];
$scope.visTitle = savedObj.vis.title;
$scope.savedObj = savedObj;
loader.embedVisualizationWithSavedObject($("#"+$scope.visID), $scope.savedObj, {})
.then(handler => {
console.log('render complete', handler);
console.log('render complete', $scope.visTitle);
});
});
});