From 06bc97b4d0a51f9985cec488c10d72ec69b95d86 Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Fri, 6 Jan 2017 16:38:27 +0100 Subject: [PATCH] #76 add stats section to case listing page --- ui/app/index.html | 1 + .../scripts/controllers/case/CaseStatsCtrl.js | 79 +++++++++++++++++++ ui/app/scripts/services/CasesUISrv.js | 5 ++ ui/app/views/partials/case/case.list.html | 2 +- .../views/partials/case/list/mini-stats.html | 16 ++-- 5 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 ui/app/scripts/controllers/case/CaseStatsCtrl.js diff --git a/ui/app/index.html b/ui/app/index.html index 11e036c760..9e6c2d9c72 100644 --- a/ui/app/index.html +++ b/ui/app/index.html @@ -131,6 +131,7 @@ + diff --git a/ui/app/scripts/controllers/case/CaseStatsCtrl.js b/ui/app/scripts/controllers/case/CaseStatsCtrl.js new file mode 100644 index 0000000000..d23899f021 --- /dev/null +++ b/ui/app/scripts/controllers/case/CaseStatsCtrl.js @@ -0,0 +1,79 @@ +/** + * Controller for About The Hive modal page + */ +(function() { + 'use strict'; + + angular.module('theHiveControllers').controller('CaseStatsCtrl', + function($rootScope, $stateParams, $timeout, StatSrv, StreamStatSrv, CasesUISrv) { + var self = this; + + this.uiSrv = CasesUISrv; + + this.byResolution = {}; + this.byStatus = {}; + this.byTags = {}; + + // Get stats by tags + StreamStatSrv({ + rootId: 'any', + query: {}, + objectType: 'case', + field: 'tags', + sort: ['-count'], + limit: 5, + result: {}, + success: function(data){ + self.byTags = self.prepareResult(data); + } + }); + + // Get stats by type + StreamStatSrv({ + rootId: 'any', + query: {}, + objectType: 'case', + field: 'status', + result: {}, + success: function(data){ + self.byStatus = self.prepareResult(data); + } + }); + + // Get stats by ioc + StreamStatSrv({ + rootId: 'any', + query: {}, + objectType: 'case', + field: 'resolutionStatus', + result: {}, + success: function(data){ + self.byResolution = self.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 + }; + }).sort(function(a, b) { + return a.count <= b.count; + }); + + return { + total: total, + details: columns + }; + }; + + this.filterBy = function(field, value) { + this.uiSrv.addFilter(field, value); + }; + } + ); +})(); diff --git a/ui/app/scripts/services/CasesUISrv.js b/ui/app/scripts/services/CasesUISrv.js index af6bf89b33..b81d8bc61a 100644 --- a/ui/app/scripts/services/CasesUISrv.js +++ b/ui/app/scripts/services/CasesUISrv.js @@ -20,6 +20,11 @@ type: 'list', defaultValue: [] }, + resolutionStatus: { + field: 'resolutionStatus', + type: 'list', + defaultValue: [] + }, tags: { field: 'tags', type: 'list', diff --git a/ui/app/views/partials/case/case.list.html b/ui/app/views/partials/case/case.list.html index 1059726ee3..0d5b53ae29 100644 --- a/ui/app/views/partials/case/case.list.html +++ b/ui/app/views/partials/case/case.list.html @@ -12,7 +12,7 @@
- +
diff --git a/ui/app/views/partials/case/list/mini-stats.html b/ui/app/views/partials/case/list/mini-stats.html index f8835ff26b..7cc02b8da2 100644 --- a/ui/app/views/partials/case/list/mini-stats.html +++ b/ui/app/views/partials/case/list/mini-stats.html @@ -7,10 +7,10 @@

Statistics

Cases by Status
- +
{{item.key}} - {{item.count}} + {{item.count}}
@@ -20,13 +20,13 @@

Statistics

-
Observables as IOC
+
Case by Resolution
- - + +
{{(item.key === '0') ? 'Not IOC' : 'IOC' }}
{{item.key}} - {{item.count}} + {{item.count}}
@@ -36,13 +36,13 @@

Statistics

-
Top 10 tags
+
Top 5 tags
{{item.key}} - {{item.count}} + {{item.count}}