Skip to content

Commit

Permalink
#76 add stats section to case listing page
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jan 6, 2017
1 parent 0bbccb5 commit 06bc97b
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
1 change: 1 addition & 0 deletions ui/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<script src="scripts/controllers/case/CaseObservablesExportCtrl.js"></script>
<script src="scripts/controllers/case/CaseObservablesItemCtrl.js"></script>
<script src="scripts/controllers/case/CaseReopenModalCtrl.js"></script>
<script src="scripts/controllers/case/CaseStatsCtrl.js"></script>
<script src="scripts/controllers/case/CaseTasksCtrl.js"></script>
<script src="scripts/controllers/case/CaseTasksItemCtrl.js"></script>
<script src="scripts/controllers/case/ObservableCreationCtrl.js"></script>
Expand Down
79 changes: 79 additions & 0 deletions ui/app/scripts/controllers/case/CaseStatsCtrl.js
Original file line number Diff line number Diff line change
@@ -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);
};
}
);
})();
5 changes: 5 additions & 0 deletions ui/app/scripts/services/CasesUISrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
type: 'list',
defaultValue: []
},
resolutionStatus: {
field: 'resolutionStatus',
type: 'list',
defaultValue: []
},
tags: {
field: 'tags',
type: 'list',
Expand Down
2 changes: 1 addition & 1 deletion ui/app/views/partials/case/case.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div ng-include="'views/partials/case/list/toolbar.html'"></div>

<!-- <div class="mv-s filter-panel" ng-include="'views/partials/case/list/mini-stats.html'" ng-show="$vm.uiSrv.context.showStats"></div> -->
<div class="mv-s filter-panel" ng-include="'views/partials/case/list/mini-stats.html'" ng-show="$vm.uiSrv.context.showStats"></div>

<div class="mt-s filter-panel" ng-include="'views/partials/case/list/filters.html'" ng-show="$vm.uiSrv.context.showFilters"></div>

Expand Down
16 changes: 8 additions & 8 deletions ui/app/views/partials/case/list/mini-stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ <h4>Statistics</h4>
<div class="panel-heading">Cases by Status</div>
<div class="panel-body">
<table class="table table-condensed">
<tr ng-repeat="item in statsCtrl.byType.details">
<tr ng-repeat="item in statsCtrl.byStatus.details">
<td class="active">{{item.key}}</td>
<td>
<a href ng-click="addFilterValue('dataType', item.key)">{{item.count}}</a>
<a href ng-click="$vm.addFilterValue('status', item.key)">{{item.count}}</a>
</td>
</tr>
</table>
Expand All @@ -20,13 +20,13 @@ <h4>Statistics</h4>

<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Observables as IOC</div>
<div class="panel-heading">Case by Resolution</div>
<div class="panel-body">
<table class="table table-condensed">
<tr ng-repeat="item in statsCtrl.byIoc.details">
<td class="active">{{(item.key === '0') ? 'Not IOC' : 'IOC' }}</td>
<tr ng-repeat="item in statsCtrl.byResolution.details">
<td class="active">{{item.key}}</td>
<td>
<a href ng-click="addFilterValue('ioc', item.key === '0' ? false : true)">{{item.count}}</a>
<a href ng-click="$vm.addFilterValue('resolutionStatus', item.key)">{{item.count}}</a>
</td>
</tr>
</table>
Expand All @@ -36,13 +36,13 @@ <h4>Statistics</h4>

<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Top 10 tags</div>
<div class="panel-heading">Top 5 tags</div>
<div class="panel-body">
<table class="table table-condensed">
<tr ng-repeat="item in statsCtrl.byTags.details">
<td class="active">{{item.key}}</td>
<td>
<a href ng-click="addFilterValue('tags', item.key)">{{item.count}}</a>
<a href ng-click="$vm.addFilterValue('tags', item.key)">{{item.count}}</a>
</td>
</tr>
</table>
Expand Down

0 comments on commit 06bc97b

Please sign in to comment.