Skip to content

Commit

Permalink
#620 Fix the search service as use a dedicated service to global sear…
Browse files Browse the repository at this point in the history
…ch section
  • Loading branch information
nadouani committed Jun 27, 2018
1 parent 11dc5e0 commit ca3da90
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 27 deletions.
1 change: 1 addition & 0 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
<script src="scripts/services/EntitySrv.js"></script>
<script src="scripts/services/FileResource.js"></script>
<script src="scripts/services/FilteringSrv.js"></script>
<script src="scripts/services/GlobalSearchSrv.js"></script>
<script src="scripts/services/HtmlSanitizeSrv.js"></script>
<script src="scripts/services/JobSrv.js"></script>
<script src="scripts/services/ListSrv.js"></script>
Expand Down
29 changes: 4 additions & 25 deletions ui/app/scripts/controllers/SearchCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('SearchCtrl', function($scope, $q, $stateParams, $uibModal, PSearchSrv, CaseTemplateSrv, CaseTaskSrv, NotificationSrv, EntitySrv, UserInfoSrv, QueryBuilderSrv, localStorageService, metadata) {
.controller('SearchCtrl', function($scope, $q, $stateParams, $uibModal, PSearchSrv, CaseTemplateSrv, CaseTaskSrv, NotificationSrv, EntitySrv, UserInfoSrv, QueryBuilderSrv, GlobalSearchSrv, metadata) {
$scope.metadata = metadata;
$scope.toolbar = [
{name: 'case', label: 'Cases', icon: 'glyphicon glyphicon-folder-open'},
Expand All @@ -23,7 +23,6 @@
_not: {
'_in': {
'_field': '_type',
//'_values': ['dashboard', 'audit', 'data', 'user', 'analyzer', 'case_artifact_job_log']
'_values': ['dashboard', 'data', 'user', 'analyzer', 'caseTemplate']
}
}
Expand All @@ -32,27 +31,7 @@
};

$scope.getUserInfo = UserInfoSrv;
$scope.config = localStorageService.get('search-section') || {
entity: 'case',
case: {
filters: []
},
case_task: {
filters: []
},
case_artifact: {
filters: []
},
alert: {
filters: []
},
case_artifact_job: {
filters: []
},
audit: {
filters: []
}
}
$scope.config = GlobalSearchSrv.restore()

$scope.openEntity = EntitySrv.open;
$scope.isImage = function(contentType) {
Expand Down Expand Up @@ -97,7 +76,7 @@
$scope.config[$scope.config.entity].search = null;
$scope.searchResults = null;

localStorageService.set('search-section', $scope.config);
GlobalSearchSrv.save($scope.config);
}

$scope.setFilterField = function(filter, entity) {
Expand Down Expand Up @@ -144,7 +123,7 @@
var query = criterias.length === 0 ? undefined : criterias.length === 1 ? criterias[0] : { _and: criterias };

if(query) {
localStorageService.set('search-section', $scope.config);
GlobalSearchSrv.save($scope.config);

$scope.searchResults = PSearchSrv(undefined, $scope.metadata[entity].path, {
filter: query,
Expand Down
41 changes: 41 additions & 0 deletions ui/app/scripts/services/GlobalSearchSrv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(function() {
'use strict';
angular.module('theHiveServices').service('GlobalSearchSrv', function(localStorageService) {
this.save = function(config) {
localStorageService.set('search-section', config);
}

this.saveSection = function(entity, config) {
var cfg = this.restore();

cfg.entity = entity;
cfg[entity] = config;

this.save(cfg);
}

this.restore = function() {
return localStorageService.get('search-section') || {
entity: 'case',
case: {
filters: []
},
case_task: {
filters: []
},
case_artifact: {
filters: []
},
alert: {
filters: []
},
case_artifact_job: {
filters: []
},
audit: {
filters: []
}
}
}
});
})();
7 changes: 6 additions & 1 deletion ui/app/scripts/services/SearchSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
if (!angular.isString(objectType) || objectType === 'any') {
url = './api/_search';
} else {
url = './api/' + objectType.replace(/_/g, '/') + '/_search';
var entity = objectType.replace(/_/g, '/');
if(entity[0] === '/') {
entity = entity.substr(1);
}

url = './api/' + entity + '/_search';
}

var params = '';
Expand Down
2 changes: 1 addition & 1 deletion ui/app/views/components/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ul class="nav navbar-nav" ng-show="currentUser.id">
<li class="dropdown" uib-dropdown>
<a class="dropdown-toggle" uib-dropdown-toggle href>
<i class="text-default fa fa-plus"></i>
<i class="fa fa-plus"></i>
<span class="hpad5">New Case</span>
<span class="caret"></span>
</a>
Expand Down

0 comments on commit ca3da90

Please sign in to comment.