Skip to content

Commit

Permalink
#1446 Use Query API for stats widgets in case/alert/observable list
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 23, 2020
1 parent 6f5b879 commit 01250f0
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 114 deletions.
78 changes: 57 additions & 21 deletions frontend/app/scripts/controllers/alert/AlertStatsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

angular.module('theHiveControllers').controller('AlertStatsCtrl',
function($rootScope, $scope, $stateParams, $timeout, StatSrv, StreamStatSrv, FilteringSrv) {
function($rootScope, $scope, $stateParams, $timeout, StatSrv, StreamQuerySrv, FilteringSrv) {
var self = this;

this.filtering = FilteringSrv;
Expand All @@ -17,44 +17,80 @@
self.$onInit = function() {

// Get stats by tags
StreamStatSrv({
StreamQuerySrv('v1', [
{ _name: 'listAlert' },
{
_name: 'aggregation',
_agg: 'field',
_field: 'tags',
_select: [
{ _agg: 'count' }
],
_order: [ '-count' ],
_size: 5
}
], {
scope: $scope,
rootId: 'any',
query: {},
objectType: 'alert',
field: 'tags',
sort: ['-count'],
limit: 5,
result: {},
success: function(data){
query: {
params: {
name: 'alert-by-tags-stats'
}
},
onUpdate: function(data) {
self.byTags = StatSrv.prepareResult(data);
}
});

// Get stats by type
StreamStatSrv({
// Get stats by read status
StreamQuerySrv('v1', [
{ _name: 'listAlert' },
{
_name: 'aggregation',
_agg: 'field',
_field: 'read',
_select: [
{ _agg: 'count' }
]
}
], {
scope: $scope,
rootId: 'any',
query: {},
objectType: 'alert',
field: 'status',
result: {},
success: function(data){
query: {
params: {
name: 'alert-by-read-status-stats'
}
},
onUpdate: function(data) {
self.byStatus = StatSrv.prepareResult(data);
}
});

// Get stats by ioc
StreamStatSrv({
StreamQuerySrv('v1', [
{ _name: 'listAlert' },
{
_name: 'aggregation',
_agg: 'field',
_field: 'type',
_select: [
{ _agg: 'count' }
],
_order: [ '-count' ],
_size: 5
}
], {
scope: $scope,
rootId: 'any',
query: {},
objectType: 'alert',
field: 'type',
sort: ['-count'],
limit: 5,
result: {},
success: function(data){
query: {
params: {
name: 'alert-by-type-stats'
}
},
onUpdate: function(data) {
self.byType = StatSrv.prepareResult(data);
}
});
Expand Down
36 changes: 28 additions & 8 deletions frontend/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@
});


// Case stats to build quick filter menu
StreamQuerySrv('v1', [
{
"_name": "listCase"
_name: 'listCase'
},
{
"_name": "aggregation",
"_agg": "field",
"_field": "status",
"_select": [
{"_agg": "count"}
_name: 'aggregation',
_agg: 'field',
_field: 'status',
_select: [
{_agg: 'count'}
]
}
], {
Expand All @@ -67,13 +68,32 @@
objectType: 'case',
query: {
params: {
name: "case-status-stats"
name: 'case-status-stats'
}
},
onUpdate: function(updates) {
self.caseStats = updates;
}
});

// Case total
StreamQuerySrv('v1', [
{_name: 'listCase'},
{_name: 'count'}
], {
scope: $scope,
rootId: 'any',
objectType: 'case',
query: {
params: {
name: 'case-count-stats'
}
},
onUpdate: function(updates) {
self.caseCount = updates;
}
});

};

this.load = function() {
Expand All @@ -91,7 +111,7 @@
operations: [
{'_name': 'listCase'}
],
extraData: ["observableStats", "taskStats", "isOwner", "shareCount", "permissions"],
extraData: ['observableStats', 'taskStats', 'isOwner', 'shareCount', 'permissions'],
onUpdate: function() {
self.resetSelection();
}
Expand Down
9 changes: 0 additions & 9 deletions frontend/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@
}
});

// $scope.alerts = StreamStatSrv({
// scope: $scope,
// rootId: caseId,
// query: { 'case': caseId },
// result: {},
// objectType: 'alert',
// field: 'type'
// });

$scope.$on('tasks:task-removed', function(event, task) {
CaseTabsSrv.removeTab('task-' + task._id);
});
Expand Down
94 changes: 56 additions & 38 deletions frontend/app/scripts/controllers/case/CaseStatsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,91 @@
'use strict';

angular.module('theHiveControllers').controller('CaseStatsCtrl',
function($rootScope, $scope, $stateParams, $timeout, StatSrv, StreamStatSrv) {
function($rootScope, $scope, $stateParams, $timeout, StatSrv, StreamQuerySrv) {
var self = this;

this.byResolution = {};
this.byStatus = {};
this.byTags = {};

self.$onInit = function() {

// Get stats by tags
StreamStatSrv({
StreamQuerySrv('v1', [
{ _name: 'listCase' },
{
_name: 'aggregation',
_agg: 'field',
_field: 'tags',
_select: [
{ _agg: 'count' }
],
_order: [ '-count' ],
_size: 5
}
], {
scope: $scope,
rootId: 'any',
query: {},
objectType: 'case',
field: 'tags',
sort: ['-count'],
limit: 5,
result: {},
success: function(data){
query: {
params: {
name: 'case-by-tags-stats'
}
},
onUpdate: function(data) {
self.byTags = StatSrv.prepareResult(data);
}
});

// Get stats by type
StreamStatSrv({
// Get stats by status
StreamQuerySrv('v1', [
{ _name: 'listCase' },
{
_name: 'aggregation',
_agg: 'field',
_field: 'status',
_select: [
{ _agg: 'count' }
]
}
], {
scope: $scope,
rootId: 'any',
query: {},
objectType: 'case',
field: 'status',
result: {},
success: function(data){
query: {
params: {
name: 'case-by-status-stats'
}
},
onUpdate: function(data) {
self.byStatus = StatSrv.prepareResult(data);
}
});

// Get stats by ioc
StreamStatSrv({
// Get stats by resolution status
StreamQuerySrv('v1', [
{ _name: 'listCase' },
{
_name: 'aggregation',
_agg: 'field',
_field: 'resolutionStatus',
_select: [
{ _agg: 'count' }
]
}
], {
scope: $scope,
rootId: 'any',
query: {},
objectType: 'case',
field: 'resolutionStatus',
result: {},
success: function(data){
query: {
params: {
name: 'case-by-resolution-status-stats'
}
},
onUpdate: function(data) {
self.byResolution = StatSrv.prepareResult(data);
}
});
};

// this.prepareResult = function(rawStats) {
// var total = rawStats.count;
//
// var keys = _.without(_.keys(rawStats), 'count');
// var columns = keys.map(function(key) {
// return {
// key: key,
// count: rawStats[key].count
// };
// });
//
// return {
// total: total,
// details: _.sortBy(columns, 'count').reverse()
// };
// };
}
);
})();
Loading

0 comments on commit 01250f0

Please sign in to comment.