Skip to content

Commit

Permalink
#1410 Add a StreeamQuerySrv and replace some stat queries using it
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 22, 2020
1 parent 0a0ad3a commit 3c0ebae
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 34 deletions.
1 change: 1 addition & 0 deletions frontend/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
<script src="scripts/services/common/data/PSearchSrv.js"></script>
<script src="scripts/services/common/data/SearchSrv.js"></script>
<script src="scripts/services/common/data/StatSrv.js"></script>
<script src="scripts/services/common/data/StreamQuerySrv.js"></script>
<script src="scripts/services/common/data/StreamSrv.js"></script>
<script src="scripts/services/common/data/StreamStatSrv.js"></script>
<script src="scripts/services/common/HtmlSanitizeSrv.js"></script>
Expand Down
62 changes: 31 additions & 31 deletions frontend/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveControllers').controller('CaseMainCtrl',
function($scope, $rootScope, $state, $stateParams, $q, $uibModal, CaseTabsSrv, CaseSrv, UserSrv, MispSrv, StreamSrv, StreamStatSrv, NotificationSrv, UtilsSrv, CaseResolutionStatus, CaseImpactStatus, CortexSrv, caze) {
function($scope, $rootScope, $state, $stateParams, $q, $uibModal, CaseTabsSrv, CaseSrv, UserSrv, MispSrv, StreamSrv, StreamQuerySrv, StreamStatSrv, NotificationSrv, UtilsSrv, CaseResolutionStatus, CaseImpactStatus, CortexSrv, caze) {
$scope.CaseResolutionStatus = CaseResolutionStatus;
$scope.CaseImpactStatus = CaseImpactStatus;
$scope.caseResponders = null;
Expand Down Expand Up @@ -81,46 +81,46 @@
}
});

$scope.tasks = StreamStatSrv({
StreamQuerySrv('v1', [
{_name: 'getCase', idOrName: caseId},
{_name: 'tasks'},
{_name: 'filter',
_not: {
'_field': 'status',
'_value': 'Cancel'
}
},
{_name: 'count'}
], {
scope: $scope,
rootId: caseId,
objectType: 'case_task',
query: {
'_and': [{
'_parent': {
"_type": "case",
"_query": {
"_id": caseId
}
}
}, {
'_not': {
'status': 'Cancel'
}
}]
params: {
name: 'task-stats-' + caseId
}
},
result: {},
objectType: 'case_task',
field: 'status'
onUpdate: function(updates) {
$scope.tasksCount = updates;
}
});

$scope.artifactStats = StreamStatSrv({
StreamQuerySrv('v1', [
{_name: 'getCase', idOrName: caseId},
{_name: 'observables'},
{_name: 'count'}
], {
scope: $scope,
rootId: caseId,
objectType: 'case_artifact',
query: {
'_and': [{
'_parent': {
"_type": "case",
"_query": {
"_id": caseId
}
}
}, {
'status': 'Ok'
}]
params: {
name: 'observable-stats-' + caseId
}
},
result: {},
objectType: 'case_artifact',
field: 'status'
onUpdate: function(updates) {
$scope.observableCount = updates;
}
});

$scope.alerts = StreamStatSrv({
Expand Down
24 changes: 24 additions & 0 deletions frontend/app/scripts/services/common/data/StreamQuerySrv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(function() {
'use strict';
angular.module('theHiveServices')
.factory('StreamQuerySrv', function($http, StreamSrv, QuerySrv) {
return function(version, operations, config) {
StreamSrv.addListener({
rootId: config.rootId,
objectType: config.objectType,
scope: config.scope,
callback:function() {
QuerySrv.query(version, operations, config.query)
.then(function(response) {
config.onUpdate(response.data);
});
}
});

QuerySrv.query(version, operations, config.query)
.then(function(response) {
config.onUpdate(response.data);
});
};
});
})();
4 changes: 2 additions & 2 deletions frontend/app/views/app.case.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

<span ng-switch-when="tasks">
<i class="glyphicon glyphicon-tasks"></i>&nbsp;&nbsp;{{tab.label}}&nbsp;&nbsp;
<span class="badge">{{tasks.count}}</span>
<span class="badge">{{tasksCount}}</span>
</span>

<span ng-switch-when="observables">
<i class="glyphicon glyphicon-pushpin"></i>&nbsp;&nbsp; Observables&nbsp;&nbsp;
<span class="badge badge-primary">{{artifactStats.count}}</span>
<span class="badge badge-primary">{{observableCount}}</span>
</span>

<span ng-switch-default>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="col-md-12 mb-s clearfix">
<div class="pull-left">
<h4>
Observable List ({{artifacts.total || 0}} of {{artifactStats.count}})
Observable List ({{artifacts.total || 0}} of {{observableCount}})
<small class="ml-xxs" ng-if="selection.artifacts.length > 0 ">
({{selection.artifacts.length}} selected)
</small>
Expand Down

0 comments on commit 3c0ebae

Please sign in to comment.