From a7c4be43294e7d419223529296448ef9e2b85e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20=C3=81ngel=20Gonz=C3=A1lez?= Date: Mon, 23 Apr 2018 13:05:35 +0200 Subject: [PATCH] Removed visTimestamp from visualization directive --- .../kibana-visualization.js | 97 +++++++++---------- 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/public/kibana-integrations/kibana-visualization.js b/public/kibana-integrations/kibana-visualization.js index 5416c3dcf..8ae51a0f8 100644 --- a/public/kibana-integrations/kibana-visualization.js +++ b/public/kibana-integrations/kibana-visualization.js @@ -39,59 +39,58 @@ const app = modules.get('apps/webinar_app', []) if(!visualization && !rendered && !renderInProgress) { // There's no visualization object -> create it with proper filters renderInProgress = true; - if ($rootScope.visTimestamp) { - const rawVis = raw.filter(item => item.id === $scope.visID + "-" + $rootScope.visTimestamp); - wzsavedVisualizations.get($scope.visID + "-" + $rootScope.visTimestamp,rawVis[0]).then(savedObj => { - originalImplicitFilter = savedObj.searchSource.get('query')['query']; - visTitle = savedObj.vis.title; - visualization = savedObj; + const rawVis = raw.filter(item => item.id === $scope.visID); + wzsavedVisualizations.get($scope.visID,rawVis[0]).then(savedObj => { + originalImplicitFilter = savedObj.searchSource.get('query')['query']; + visTitle = savedObj.vis.title; + visualization = savedObj; - // There's an original filter - if (originalImplicitFilter.length > 0 ) { - // And also a pending one -> concatenate them - if ($rootScope.discoverPendingUpdates && typeof $rootScope.discoverPendingUpdates[0].query === 'string' && $rootScope.discoverPendingUpdates[0].query.length > 0) { - implicitFilter = originalImplicitFilter + ' AND ' + $rootScope.discoverPendingUpdates[0].query; - } else { - // Only the original filter - implicitFilter = originalImplicitFilter; - } + // There's an original filter + if (originalImplicitFilter.length > 0 ) { + // And also a pending one -> concatenate them + if ($rootScope.discoverPendingUpdates && typeof $rootScope.discoverPendingUpdates[0].query === 'string' && $rootScope.discoverPendingUpdates[0].query.length > 0) { + implicitFilter = originalImplicitFilter + ' AND ' + $rootScope.discoverPendingUpdates[0].query; } else { - // Other case, use the pending one, if it is empty, it won't matter - implicitFilter = $rootScope.discoverPendingUpdates ? $rootScope.discoverPendingUpdates[0].query : ''; + // Only the original filter + implicitFilter = originalImplicitFilter; } + } else { + // Other case, use the pending one, if it is empty, it won't matter + implicitFilter = $rootScope.discoverPendingUpdates ? $rootScope.discoverPendingUpdates[0].query : ''; + } - if (visTitle !== 'Wazuh App Overview General Agents status') { // We don't want to filter that visualization as it uses another index-pattern - visualization.searchSource - .query({ language: 'lucene', query: implicitFilter }) - .set('filter', $rootScope.discoverPendingUpdates ? $rootScope.discoverPendingUpdates[1] : {}); - } + if (visTitle !== 'Wazuh App Overview General Agents status') { // We don't want to filter that visualization as it uses another index-pattern + visualization.searchSource + .query({ language: 'lucene', query: implicitFilter }) + .set('filter', $rootScope.discoverPendingUpdates ? $rootScope.discoverPendingUpdates[1] : {}); + } - let params = {}; + let params = {}; - if ($scope.specificTimeRange) { - const timeRange = { - from: 'now-1d/d', - to: 'now' - }; - params = {timeRange: timeRange} - } - $(`[vis-id="'${$scope.visID}'"]`).on('renderStart', () => { - //$("#"+$scope.visID).on('renderStart', () => { - // TBD: Use renderStart to couple it with renderComplete? - }); - - visHandler = loader.embedVisualizationWithSavedObject($(`[vis-id="'${$scope.visID}'"]`), visualization, params); - - $rootScope.ownHandlers.push(visHandler); - visHandler.addRenderCompleteListener(renderComplete); - }).catch(error => { - if(error && error.message && error.message.includes('not locate that index-pattern-field')){ - errorHandler.handle(`${error.message}, please restart Kibana and refresh this page once done`,'Visualize') - } else { - errorHandler.handle(error,'Visualize') - } - }); - } + if ($scope.specificTimeRange) { + const timeRange = { + from: 'now-1d/d', + to: 'now' + }; + params = {timeRange: timeRange} + } + $(`[vis-id="'${$scope.visID}'"]`).on('renderStart', () => { + //$("#"+$scope.visID).on('renderStart', () => { + // TBD: Use renderStart to couple it with renderComplete? + }); + + visHandler = loader.embedVisualizationWithSavedObject($(`[vis-id="'${$scope.visID}'"]`), visualization, params); + + $rootScope.ownHandlers.push(visHandler); + visHandler.addRenderCompleteListener(renderComplete); + }).catch(error => { + if(error && error.message && error.message.includes('not locate that index-pattern-field')){ + errorHandler.handle(`${error.message}, please restart Kibana and refresh this page once done`,'Visualize') + } else { + errorHandler.handle(error,'Visualize') + } + }); + } else if (rendered) { // There's a visualization object -> just update its filters // There's an original filter @@ -133,10 +132,6 @@ const app = modules.get('apps/webinar_app', []) if (currentCompleted >= 100) { - if ($rootScope.visTimestamp) { - $rootScope.visTimestamp = null; - } - if (!visTitle !== 'Wazuh App Overview General Agents status') $rootScope.rendered = true; // Forcing a digest cycle if(!$rootScope.$$phase) $rootScope.$digest();