Skip to content

Commit

Permalink
Properly destroying visualizations
Browse files Browse the repository at this point in the history
  • Loading branch information
havidarou committed Mar 14, 2018
1 parent fc0dd9d commit 9e44398
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
46 changes: 29 additions & 17 deletions public/controllers/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ app.controller('agentsController',
virustotal: { group: 'virustotal' }
};

const checkMetrics = (tab,subtab) => {
const checkMetrics = (tab, subtab) => {
metricService.destroyWatchers();

if(subtab === 'panels'){
Expand Down Expand Up @@ -109,36 +109,48 @@ app.controller('agentsController',
$scope.switchSubtab = subtab => {
if($scope.tabView === subtab) return;

$scope.tabView = subtab;
checkMetrics($scope.tab,subtab);
checkMetrics($scope.tab, subtab);
}
$scope.switchTab = tab => {

// Switch tab
$scope.switchTab = tab => {
if($scope.tab === tab) return;

checkMetrics(tab,'panels');

if($rootScope.ownHandlers){
for(let h of $rootScope.ownHandlers){
h._scope.$destroy();
}
}
$rootScope.ownHandlers = [];
checkMetrics(tab, 'panels');

// Deleting app state traces in the url
$location.search('_a', null);
$scope.tabView = 'panels';

$rootScope.loadedVisualizations = [];
};

// Watchers

// We watch the resultState provided by the discover
$scope.$watch('tabView', () => $location.search('tabView', $scope.tabView));
$scope.$watch('tabView', () => {
$location.search('tabView', $scope.tabView);

if ($rootScope.ownHandlers) {
for (let h of $rootScope.ownHandlers) {
h._scope.$destroy();
}
}
$rootScope.ownHandlers = [];

$rootScope.loadedVisualizations = [];
});

$scope.$watch('tab', () => {
$location.search('tab', $scope.tab);

$scope.tabView = 'panels';

if ($rootScope.ownHandlers) {
for (let h of $rootScope.ownHandlers) {
h._scope.$destroy();
}
}
$rootScope.ownHandlers = [];

$rootScope.loadedVisualizations = [];

// Update the implicit filter
if (typeof tabFilters[$scope.tab] !== 'undefined' && tabFilters[$scope.tab].group === "") $rootScope.currentImplicitFilter = "";
else $rootScope.currentImplicitFilter = (typeof tabFilters[$scope.tab] !== 'undefined') ? tabFilters[$scope.tab].group : '';
Expand Down
46 changes: 29 additions & 17 deletions public/controllers/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ app.controller('overviewController', function ($scope, $location, $rootScope, ap
virustotal: { group: 'virustotal' }
};

const checkMetrics = (tab,subtab) => {
const checkMetrics = (tab, subtab) => {
metricService.destroyWatchers();

if(subtab === 'panels'){
Expand Down Expand Up @@ -135,20 +135,28 @@ app.controller('overviewController', function ($scope, $location, $rootScope, ap
if(!$rootScope.$$phase) $rootScope.$digest();
}

checkMetrics($scope.tab,$scope.tabView);
checkMetrics($scope.tab, $scope.tabView);

// Switch subtab
$scope.switchSubtab = subtab => {
if ($scope.tabView === subtab) return;

$scope.tabView = subtab;

checkMetrics($scope.tab,subtab);
checkMetrics($scope.tab, subtab);
}

// Switch tab
$scope.switchTab = tab => {
if ($scope.tab === tab) return;
checkMetrics(tab,'panels');
checkMetrics(tab, 'panels');

// Deleting app state traces in the url
$location.search('_a', null);
};

// Watchers

$scope.$watch('tabView', () => {
$location.search('tabView', $scope.tabView);

if ($rootScope.ownHandlers) {
for (let h of $rootScope.ownHandlers) {
Expand All @@ -157,25 +165,31 @@ app.controller('overviewController', function ($scope, $location, $rootScope, ap
}
$rootScope.ownHandlers = [];

// Deleting app state traces in the url
$location.search('_a', null);
$scope.tabView = 'panels';

$rootScope.loadedVisualizations = [];
};

// Watchers
});

// We watch the resultState provided by the discover
$scope.$watch('tabView', () => $location.search('tabView', $scope.tabView));
$scope.$watch('tab', () => {

$location.search('tab', $scope.tab);

$scope.tabView = 'panels';

if ($rootScope.ownHandlers) {
for (let h of $rootScope.ownHandlers) {
h._scope.$destroy();
}
}
$rootScope.ownHandlers = [];

$rootScope.loadedVisualizations = [];

// Update the implicit filter
if (tabFilters[$scope.tab].group === "") $rootScope.currentImplicitFilter = "";
else $rootScope.currentImplicitFilter = tabFilters[$scope.tab].group;
});

$scope.$on('$destroy', () => {

if ($rootScope.ownHandlers) {
for (let h of $rootScope.ownHandlers) {
h._scope.$destroy();
Expand Down Expand Up @@ -206,6 +220,4 @@ app.controller('overviewController', function ($scope, $location, $rootScope, ap

$scope.tabs = tabs;
$scope.selectedIndex = 0;


});
2 changes: 1 addition & 1 deletion public/kibana-integrations/kibana-visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var app = require('ui/modules').get('apps/webinar_app', [])

var renderComplete = function() {
rendered = true;

if(typeof $rootScope.loadedVisualizations === 'undefined') $rootScope.loadedVisualizations = [];
$rootScope.loadedVisualizations.push(true);
let currentCompleted = Math.round(($rootScope.loadedVisualizations.length / $rootScope.tabVisualizations[$location.search().tab]) * 100);
Expand Down
2 changes: 1 addition & 1 deletion public/templates/overview/overview-fim.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<md-content flex layout="column" ng-if="tab == 'fim'">
<md-content flex layout="column" ng-if="tab === 'fim'">

<!-- View: Panels -->
<div ng-if="resultState === 'ready' && tabView === 'panels'">
Expand Down

0 comments on commit 9e44398

Please sign in to comment.