wazuh-kibana-app/public/factories/vis-handlers.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-05-15 14:21:44 +00:00
/*
* Wazuh app - Factory to store visualizations handlers
*
* Copyright (C) 2018 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
import * as modules from 'ui/modules'
2018-05-29 15:42:22 +00:00
import dateMath from '@elastic/datemath';
2018-05-15 14:21:44 +00:00
const app = modules.get('app/wazuh', []);
app.factory('visHandlers', function() {
let list = [];
const addItem = item => {
list.push(item);
}
const getList = () => {
return list;
}
2018-05-29 15:42:22 +00:00
const getAppliedFilters = () => {
let appliedFilters = {};
if(list && list.length) {
const filters = list[0]._scope.savedObj.vis.API.queryFilter.getFilters()
const { from, to } = list[0]._scope.savedObj.vis.API.timeFilter.time;
appliedFilters = {
filters,
time:{
from: dateMath.parse(from),
to: dateMath.parse(to)
},
searchBar: list[0] && list[0]._scope && list[0]._scope.appState && list[0]._scope.appState.query && list[0]._scope.appState.query.query ?
list[0]._scope.appState.query.query :
false
2018-05-29 15:42:22 +00:00
}
}
return appliedFilters;
}
2018-05-18 09:47:29 +00:00
const hasData = () => {
for(const item of list) {
if(item && item._scope && item._scope.savedObj && item._scope.savedObj.searchSource &&
item._scope.savedObj.searchSource.rawResponse &&
item._scope.savedObj.searchSource.rawResponse.hits &&
item._scope.savedObj.searchSource.rawResponse.hits.total){
return true;
}
}
return false;
}
2018-05-15 14:21:44 +00:00
const removeAll = () => {
for(const item of list){
if(item && item._scope){
item._scope.$destroy();
}
2018-05-15 14:46:52 +00:00
if(item && item._scope && item._scope.savedObj){
item._scope.savedObj.destroy();
}
2018-05-15 14:21:44 +00:00
}
list = [];
}
return {
2018-05-29 15:42:22 +00:00
addItem,
getList,
removeAll,
hasData,
getAppliedFilters
2018-05-15 14:21:44 +00:00
};
});