Fix filters (in progress)

This commit is contained in:
Jesús Ángel González 2018-05-13 12:34:28 +02:00 committed by Javier Castro
parent 773ccd1057
commit 6d89553f6d
7 changed files with 62 additions and 58 deletions

5
.gitignore vendored
View File

@ -59,3 +59,8 @@ typings/
# dotenv environment variables file
.env
kibana/
*.zip

View File

@ -15,9 +15,10 @@ import rison from 'rison'
const app = modules.get('app/wazuh', []);
app.controller('agentsController',
function ($timeout, $scope, $location, $q, $rootScope, appState, genericReq, apiReq, AgentsAutoComplete, errorHandler) {
app.controller('agentsController', function ($timeout, $scope, $location, $q, $rootScope, appState, genericReq, apiReq, AgentsAutoComplete, errorHandler, $window) {
$window.sessionStorage.setItem('lasta',$location.search()._a)
$rootScope.completedAgent = false;
$rootScope.wazuhLoadFilters =false;
$rootScope.page = 'agents';
$scope.extensions = appState.getExtensions().extensions;
$scope.agentsAutoComplete = AgentsAutoComplete;
@ -198,18 +199,6 @@ app.controller('agentsController',
});
$scope.$watch('tab', () => {
const str = $location.search()._a;
if(str){
const decoded = rison.decode(str);
const tmp = decoded.filters.filter(item => !(
(item.query && item.query.match && item.query.match['rule.groups']) ||
(item.exists && item.exists.field === 'rule.pci_dss'))
);
decoded.filters = tmp;
const encoded = rison.encode(decoded);
$location.search('_a', encoded)
}
$location.search('tab', $scope.tab);
$scope.tabView = 'panels';
@ -226,7 +215,6 @@ app.controller('agentsController',
// Update the implicit filter
if (typeof tabFilters[$scope.tab] !== 'undefined' && tabFilters[$scope.tab].group === "") $rootScope.currentImplicitFilter = "";
else $rootScope.currentImplicitFilter = (typeof tabFilters[$scope.tab] !== 'undefined') ? tabFilters[$scope.tab].group : '';
if($scope.tab === 'configuration'){
firstLoad();
}
@ -285,48 +273,26 @@ app.controller('agentsController',
/** Prevents from double agent and come from autocomplete */
let lastAgent = null;
const checkDouble = id => {
if(lastAgent && lastAgent !== id){
$rootScope.agentsAutoCompleteFired = true;
if(!$rootScope.$$phase) $rootScope.$digest();
}
}
$scope.getAgent = async (newAgentId,fromAutocomplete) => {
try {
$rootScope.completedAgent = false;
if($scope.tab === 'configuration'){
return $scope.getAgentConfig(newAgentId);
}
try {
// Try to parse the _a trace and detect if there is any agent.id filter
// in order to delete it from the _a trace
const str = $location.search()._a;
if(str){
const decoded = rison.decode(str);
const tmp = decoded.filters.filter(item => !item.query.match['agent.id']);
decoded.filters = tmp;
const encoded = rison.encode(decoded);
$location.search('_a', encoded)
}
} catch (error) {
// If some rison.js related error is generated we simply clean the _a trace
console.log(error.message || error); // not blocking action
}
let id = null;
// They passed an id
if (newAgentId) {
id = newAgentId;
checkDouble(id);
$location.search('agent', id);
} else {
if ($location.search().agent && !$rootScope.globalAgent) { // There's one in the url
id = $location.search().agent;
checkDouble(id);
} else { // We pick the one in the rootScope
id = $rootScope.globalAgent;
checkDouble(id);
$location.search('agent', id);
delete $rootScope.globalAgent;
}
@ -359,6 +325,7 @@ app.controller('agentsController',
$scope.agent.rootcheck = data[2].data.data;
validateRootCheck();
$rootScope.completedAgent = true;
if(!$scope.$$phase) $scope.$digest();
return;
} catch (error) {
@ -377,7 +344,7 @@ app.controller('agentsController',
}
$rootScope.ownHandlers = [];
$rootScope.comeFrom = 'agents';
$location.search('_a',null);
//$location.search('_a',null);
$location.search('tab', 'groups');
$location.path('/manager');
};
@ -464,6 +431,7 @@ app.controller('agentsController',
const firstLoad = async () => {
try{
$rootScope.completedAgent = false;
$scope.configurationError = false;
$scope.load = true;
let id;
@ -509,6 +477,7 @@ app.controller('agentsController',
$scope.isSynchronized = (($scope.agentMergedSum === $scope.groupMergedSum) && !([$scope.agentMergedSum,$scope.groupMergedSum].includes('Unknown')) ) ? true : false;
$scope.load = false;
$rootScope.completedAgent = true;
if(!$scope.$$phase) $scope.$digest();
return;
} catch (error){

View File

@ -14,7 +14,8 @@ import * as modules from 'ui/modules'
const app = modules.get('app/wazuh', []);
app.controller('overviewController', function ($scope, $location, $rootScope, appState, genericReq, errorHandler, apiReq) {
app.controller('overviewController', function ($scope, $location, $rootScope, appState, genericReq, errorHandler, apiReq,$window) {
$rootScope.rawVisualizations = null;
$rootScope.page = 'overview';
@ -210,7 +211,7 @@ app.controller('overviewController', function ($scope, $location, $rootScope, ap
checkMetrics(tab, 'panels');
// Deleting app state traces in the url
$location.search('_a', null);
//$location.search('_a', null);
})
.catch(error => errorHandler.handle(error, 'Overview'));

View File

@ -44,7 +44,7 @@ import 'ui/pager_control';
import 'ui/pager';
import { UtilsBrushEventProvider } from 'ui/utils/brush_event';
import { documentationLinks } from 'ui/documentation_links/documentation_links';
import chrome from 'ui/chrome'
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -758,8 +758,26 @@ function discoverController(
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function loadFilters() {
if($scope.tab !== 'general' && !$rootScope.currentImplicitFilter) {
return;
}
if ($scope.tab) {
let implicitFilter = [];
const current = queryFilter.getFilters();
const implicitFilter = [];
for(const item of current){
if((item && item.query && item.query.match && item.query.match['rule.groups']) ||
(item && item.query && item.query.match && item.query.match['agent.id']) ||
(item && item.query && item.query.match && item.query.match['manager.name']) ||
(item && item.exists && item.exists.field && item.exists.field === 'rule.pci_dss'))
continue;
else
implicitFilter.push(item)
}
queryFilter.removeAll()
if (appState.getClusterInfo().status == 'enabled') {
// The cluster filter
@ -908,7 +926,10 @@ function discoverController(
}
}
queryFilter.addFilters(implicitFilter);
queryFilter.addFilters(implicitFilter).then(data => {
if($rootScope.page === 'agents') $rootScope.wazuhLoadFilters = !$rootScope.wazuhLoadFilters
});
}
}
@ -922,7 +943,6 @@ function discoverController(
// Watch for changes in the location
$scope.$on('$routeUpdate', () => {
if ($location.search().tabView != $scope.tabView) { // No need to change the filters
if ($scope.tabView !== "discover") { // Should do this the first time, to avoid the squeezing of the visualization
$scope.updateQueryAndFetch($state.query);

View File

@ -13,10 +13,10 @@ import { FilterBarLibChangeTimeFilterProvider } from 'ui/filter_bar/lib/change_t
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { compareFilters } from 'ui/filter_bar/lib/compare_filters';
import { uiModules } from 'ui/modules';
import rison from 'rison'
const module = uiModules.get('kibana');
module.directive('filterBarW', function (Private, Promise, getAppState) {
module.directive('filterBarW', function (Private, Promise, getAppState,$location, $rootScope) {
const mapAndFlattenFilters = Private(FilterBarLibMapAndFlattenFiltersProvider);
const mapFlattenAndWrapFilters = Private(FilterBarLibMapFlattenAndWrapFiltersProvider);
const extractTimeFilter = Private(FilterBarLibExtractTimeFilterProvider);
@ -96,9 +96,17 @@ module.directive('filterBarW', function (Private, Promise, getAppState) {
// update the scope filter list on filter changes
$scope.$listen(queryFilter, 'update', function () {
updateFilters();
if(queryFilter.getFilters().length) updateFilters();
});
$scope.$watch('wazuhLoadFilters',() => {
if(queryFilter.getFilters().length) updateFilters();
})
$rootScope.$watch('completedAgent',() => {
if(queryFilter.getFilters().length) updateFilters();
})
// when appState changes, update scope's state
$scope.$watch(getAppState, function (appState) {
$scope.state = appState;
@ -157,6 +165,7 @@ module.directive('filterBarW', function (Private, Promise, getAppState) {
function updateFilters() {
const filters = queryFilter.getFilters();
if(!queryFilter.getFilters().length || ($rootScope.page === 'agents' && !$rootScope.completedAgent)) return;
mapAndFlattenFilters(filters).then(function (results) {
// used to display the current filters in the state
$scope.filters = _.sortBy(results, function (filter) {

View File

@ -5,7 +5,7 @@
<div data-transclude-slots>
<!-- Breadcrumbs. -->
<div data-transclude-slot="topLeftCorner" class="kuiLocalBreadcrumbs">
<h1 tabindex="0" id="kui_local_breadcrumb" class="kuiLocalBreadcrumb" ng-show="tabView === 'discover'">
<h1 tabindex="0" id="kui_local_breadcrumb" class="kuiLocalBreadcrumb">
<span ng-show="opts.savedSearch.id" class="kuiLocalBreadcrumb__emphasis">
<span data-test-subj="discoverCurrentQuery" ng-bind="opts.savedSearch.lastSavedTitle"></span>
<span