2018-01-29 16:20:32 +00:00
|
|
|
require('ui/modules').get('app/wazuh', [])
|
2018-03-21 14:47:35 +00:00
|
|
|
.service('patternHandler', function ($rootScope, $route, $location, genericReq, courier, appState, errorHandler) {
|
2018-01-29 16:20:32 +00:00
|
|
|
return {
|
2018-01-31 16:05:27 +00:00
|
|
|
getPatternList: async () => {
|
|
|
|
try {
|
2018-03-17 11:32:21 +00:00
|
|
|
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
|
|
|
|
2018-03-17 11:32:21 +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-29 16:20:32 +00:00
|
|
|
}
|
|
|
|
},
|
2018-01-31 16:05:27 +00:00
|
|
|
changePattern: async selectedPattern => {
|
|
|
|
try {
|
2018-01-29 16:20:32 +00:00
|
|
|
appState.setCurrentPattern(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();
|
|
|
|
}
|
2018-01-29 16:20:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|