mirror of
https://github.com/valitydev/wazuh-kibana-app.git
synced 2024-11-07 10:18:57 +00:00
Adding implicit filters to the integrations
This commit is contained in:
parent
7c80333b98
commit
fb20bece33
@ -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');
|
||||
};
|
||||
});
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user