Prevents app load if empty array

This commit is contained in:
Jesús Ángel González 2018-03-21 15:47:35 +01:00
parent 2804e440e1
commit 4d96063b52
2 changed files with 15 additions and 1 deletions

View File

@ -129,6 +129,13 @@ app.controller('settingsController', function ($scope, $rootScope, $http, $route
try { try {
const patternList = await genericReq.request('GET','/get-list',{}); const patternList = await genericReq.request('GET','/get-list',{});
$scope.indexPatterns = patternList.data.data; $scope.indexPatterns = patternList.data.data;
if(!patternList.data.data.length){
$rootScope.blankScreenError = 'Sorry but your user has no access to any valid index pattern'
$location.search('tab',null);
$location.path('/blank-screen');
return;
}
const data = await genericReq.request('GET', '/api/wazuh-api/apiEntries'); const data = await genericReq.request('GET', '/api/wazuh-api/apiEntries');
for(const entry of data.data) $scope.showEditForm[entry._id] = false; for(const entry of data.data) $scope.showEditForm[entry._id] = false;

View File

@ -1,9 +1,16 @@
require('ui/modules').get('app/wazuh', []) require('ui/modules').get('app/wazuh', [])
.service('patternHandler', function ($rootScope, $route, genericReq, courier, appState, errorHandler) { .service('patternHandler', function ($rootScope, $route, $location, genericReq, courier, appState, errorHandler) {
return { return {
getPatternList: async () => { getPatternList: async () => {
try { try {
const patternList = await genericReq.request('GET','/get-list',{}); const patternList = await genericReq.request('GET','/get-list',{});
if(!patternList.data.data.length){
$rootScope.blankScreenError = 'Sorry but your user has no access to any valid index pattern'
$location.search('tab',null);
$location.path('/blank-screen');
return;
}
return patternList.data.data; return patternList.data.data;
} catch (error) { } catch (error) {
errorHandler.handle(error,'Pattern Handler (getPatternList)'); errorHandler.handle(error,'Pattern Handler (getPatternList)');