wazuh-kibana-app/public/services/pattern-handler.js

39 lines
1.6 KiB
JavaScript
Raw Normal View History

require('ui/modules').get('app/wazuh', [])
2018-03-21 14:47:35 +00:00
.service('patternHandler', function ($rootScope, $route, $location, genericReq, courier, appState, errorHandler) {
return {
2018-01-31 16:05:27 +00:00
getPatternList: async () => {
try {
const patternList = await genericReq.request('GET','/get-list',{});
2018-03-21 14:47:35 +00:00
if(!patternList.data.data.length){
2018-03-21 14:47:35 +00:00
$rootScope.blankScreenError = 'Sorry but no valid index patterns were found'
2018-03-21 14:47:35 +00:00
$location.search('tab',null);
$location.path('/blank-screen');
return;
}
2018-03-24 10:44:30 +00:00
2018-03-23 12:40:44 +00:00
if(appState.getCurrentPattern()){
let filtered = patternList.data.data.filter(item => item.id.includes(appState.getCurrentPattern()))
if(!filtered.length) appState.setCurrentPattern(patternList.data.data[0].id)
}
2018-03-24 10:44:30 +00:00
return patternList.data.data;
2018-01-31 16:05:27 +00:00
} catch (error) {
errorHandler.handle(error,'Pattern Handler (getPatternList)');
if(!$rootScope.$$phase) $rootScope.$digest();
}
},
2018-01-31 16:05:27 +00:00
changePattern: async selectedPattern => {
try {
appState.setCurrentPattern(selectedPattern);
await genericReq.request('GET',`/refresh-fields/${selectedPattern}`,{})
2018-01-31 16:05:27 +00:00
return appState.getCurrentPattern();
} catch (error) {
errorHandler.handle(error,'Pattern Handler (changePattern)');
if(!$rootScope.$$phase) $rootScope.$digest();
}
}
};
});