From 3c0ebae3f5d61fcad49ee9c41db8d282c9e430a4 Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Wed, 22 Jul 2020 16:56:38 +0200 Subject: [PATCH] #1410 Add a StreeamQuerySrv and replace some stat queries using it --- frontend/app/index.html | 1 + .../scripts/controllers/case/CaseMainCtrl.js | 62 +++++++++---------- .../services/common/data/StreamQuerySrv.js | 24 +++++++ frontend/app/views/app.case.html | 4 +- .../observables/list/observables.html | 2 +- 5 files changed, 59 insertions(+), 34 deletions(-) create mode 100644 frontend/app/scripts/services/common/data/StreamQuerySrv.js diff --git a/frontend/app/index.html b/frontend/app/index.html index b6ab17916e..2ed1e175d3 100644 --- a/frontend/app/index.html +++ b/frontend/app/index.html @@ -294,6 +294,7 @@ + diff --git a/frontend/app/scripts/controllers/case/CaseMainCtrl.js b/frontend/app/scripts/controllers/case/CaseMainCtrl.js index c16b42a209..ee81c87e24 100644 --- a/frontend/app/scripts/controllers/case/CaseMainCtrl.js +++ b/frontend/app/scripts/controllers/case/CaseMainCtrl.js @@ -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; @@ -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({ diff --git a/frontend/app/scripts/services/common/data/StreamQuerySrv.js b/frontend/app/scripts/services/common/data/StreamQuerySrv.js new file mode 100644 index 0000000000..7f08c58efd --- /dev/null +++ b/frontend/app/scripts/services/common/data/StreamQuerySrv.js @@ -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); + }); + }; + }); +})(); diff --git a/frontend/app/views/app.case.html b/frontend/app/views/app.case.html index 2fdeffc194..4a14ff4051 100644 --- a/frontend/app/views/app.case.html +++ b/frontend/app/views/app.case.html @@ -15,12 +15,12 @@   {{tab.label}}   - {{tasks.count}} + {{tasksCount}}    Observables   - {{artifactStats.count}} + {{observableCount}} diff --git a/frontend/app/views/partials/observables/list/observables.html b/frontend/app/views/partials/observables/list/observables.html index a3a43f9a7d..823c37e8df 100644 --- a/frontend/app/views/partials/observables/list/observables.html +++ b/frontend/app/views/partials/observables/list/observables.html @@ -2,7 +2,7 @@

- Observable List ({{artifacts.total || 0}} of {{artifactStats.count}}) + Observable List ({{artifacts.total || 0}} of {{observableCount}}) ({{selection.artifacts.length}} selected)