Skip to content

Commit

Permalink
#79 Fix an issue with tab activation in case section
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Feb 10, 2017
1 parent 9b6bdfb commit e99865a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 50 deletions.
6 changes: 4 additions & 2 deletions ui/app/scripts/controllers/case/CaseLinksCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveControllers').controller('CaseLinksCtrl',
function($scope, $state, $stateParams, $uibModal, CaseTabsSrv) {
function($scope, $state, $stateParams, $uibModal, $timeout, CaseTabsSrv) {
$scope.caseId = $stateParams.caseId;
var tabName = 'links-' + $scope.caseId;

Expand All @@ -16,7 +16,9 @@
});

// Select tab
CaseTabsSrv.activateTab(tabName);
$timeout(function() {
CaseTabsSrv.activateTab(tabName);
}, 0);
}
);
})();
1 change: 1 addition & 0 deletions ui/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CaseTabsSrv.initTabs();
}

$scope.tabSrv = CaseTabsSrv;
$scope.tabs = CaseTabsSrv.getTabs();
$scope.getUserInfo = UserInfoSrv;
$scope.caseId = caseId;
Expand Down
7 changes: 5 additions & 2 deletions ui/app/scripts/controllers/case/CaseObservablesItemCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('theHiveControllers').controller('CaseObservablesItemCtrl',
function ($scope, $state, $stateParams, $q, CaseTabsSrv, CaseArtifactSrv, CortexSrv, PSearchSrv, AnalyzerSrv, JobSrv, AlertSrv, VersionSrv, appConfig) {
function ($scope, $state, $stateParams, $q, $timeout, CaseTabsSrv, CaseArtifactSrv, CortexSrv, PSearchSrv, AnalyzerSrv, JobSrv, AlertSrv, VersionSrv, appConfig) {
var observableId = $stateParams.itemId,
observableName = 'observable-' + observableId;

Expand Down Expand Up @@ -46,7 +46,10 @@
});

// Select tab
CaseTabsSrv.activateTab(observableName);
$timeout(function() {
CaseTabsSrv.activateTab(observableName);
}, 0);


// Prepare the scope data
$scope.initScope(observable);
Expand Down
7 changes: 5 additions & 2 deletions ui/app/scripts/controllers/case/CaseTasksItemCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('theHiveControllers').controller('CaseTasksItemCtrl',
function ($scope, $rootScope, $state, $stateParams, CaseTabsSrv, CaseTaskSrv, PSearchSrv, TaskLogSrv, AlertSrv, task) {
function ($scope, $rootScope, $state, $stateParams, $timeout, CaseTabsSrv, CaseTaskSrv, PSearchSrv, TaskLogSrv, AlertSrv, task) {
var caseId = $stateParams.caseId,
taskId = $stateParams.itemId;

Expand Down Expand Up @@ -129,7 +129,10 @@
});

// Select tab
CaseTabsSrv.activateTab($scope.tabName);
$timeout(function() {
CaseTabsSrv.activateTab($scope.tabName);
}, 0);


// Prepare the scope data
$scope.initScope(task);
Expand Down
88 changes: 46 additions & 42 deletions ui/app/scripts/services/CaseTabsSrv.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices').factory('CaseTabsSrv', function() {
angular.module('theHiveServices').service('CaseTabsSrv', function() {

var tabs = {
'details': {
name: 'details',
Expand All @@ -22,60 +23,63 @@
}
};

return {

initTabs: function() {
angular.forEach(tabs, function(tab, key) {
if (tab.closable === true) {
delete tabs[key];
}
});
},
this.activeIndex = 0;

getTabs: function() {
return tabs;
},
this.initTabs = function() {
angular.forEach(tabs, function(tab, key) {
if (tab.closable === true) {
delete tabs[key];
}
});
};

getTab: function(name) {
return tabs[name];
},
this.getTabs = function() {
return tabs;
};

activateTab: function(tab) {
angular.forEach(tabs, function(tab) {
tab.active = false;
});
this.getTab = function(name) {
return tabs[name];
};

if (tabs[tab]) {
tabs[tab].active = true;
} else {
tabs.details.active = true;
}
},
this.activateTab = function(tab) {
angular.forEach(tabs, function(tab) {
tab.active = false;
});

addTab: function(tab, options) {
options.closable = true;
if (tabs[tab]) {
tabs[tab].active = true;
this.activeIndex = Object.keys(tabs).indexOf(tab);
} else {
tabs.details.active = true;
this.activeIndex = 0;
}
};

tabs[tab] = options;
},
this.addTab = function(tab, options) {
options.closable = true;

removeTab: function(tab) {
var tabItem = tabs[tab];
tabs[tab] = options;
this.activeIndex = Object.keys(tabs).length - 1;
};

if(!tabItem) {
return;
}
this.removeTab = function(tab) {
var tabItem = tabs[tab];

var currentIsActive = tabItem.active;
if (!tabItem) {
return;
}

delete tabs[tab];
var currentIsActive = tabItem.active;

if (currentIsActive) {
return true;
} else {
return false;
}
delete tabs[tab];

if (currentIsActive) {
return true;
} else {
return false;
}

};

});
})();
4 changes: 2 additions & 2 deletions ui/app/views/app.case.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<div class="row">
<div class="col-md-9">
<uib-tabset type="tabs">
<uib-tab active="tabs[name].active" ng-click="openTab(name)" ng-init="tab = tabs[name]" ng-repeat="name in notSorted(tabs)">
<uib-tabset type="tabs" active="tabSrv.activeIndex">
<uib-tab ng-click="openTab(name)" ng-init="tab = tabs[name];" ng-repeat="name in notSorted(tabs)">
<uib-tab-heading ng-switch on="name">
<span ng-switch-when="details">
<i class="glyphicon glyphicon-folder-open"></i>&nbsp;&nbsp;
Expand Down

0 comments on commit e99865a

Please sign in to comment.