Skip to content

Commit

Permalink
#166 Add render function to TLP filter in observables list page
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Apr 7, 2017
1 parent 6775270 commit cba1f05
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 5 additions & 1 deletion ui/app/scripts/controllers/case/CaseObservablesCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('theHiveControllers').controller('CaseObservablesCtrl',
function ($scope, $q, $state, $stateParams, $uibModal, CaseTabsSrv, PSearchSrv, CaseArtifactSrv, AlertSrv, AnalyzerSrv, CortexSrv, ObservablesUISrv, VersionSrv) {
function ($scope, $q, $state, $stateParams, $uibModal, CaseTabsSrv, PSearchSrv, CaseArtifactSrv, AlertSrv, AnalyzerSrv, CortexSrv, ObservablesUISrv, VersionSrv, Tlp) {

CaseTabsSrv.activateTab($state.current.data.tab);

Expand Down Expand Up @@ -130,6 +130,10 @@
$scope.filter();
};

$scope.filterByTlp = function(value) {
$scope.addFilterValue('tlp', Tlp.values[value]);
};

$scope.countReports = function(observable) {
return _.keys(observable.reports).length;
};
Expand Down
18 changes: 10 additions & 8 deletions ui/app/scripts/services/ObservablesUISrv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices')
.factory('ObservablesUISrv', function($q, localStorageService) {
.factory('ObservablesUISrv', function($q, localStorageService, Tlp) {

var factory = {
actions: {
Expand Down Expand Up @@ -43,7 +43,11 @@
tlp: {
field: 'tlp',
type: 'number',
defaultValue: null
defaultValue: null,
convert: function(value) {
// Convert the text value to its numeric representation
return Tlp.keys[value];
}
},
message: {
field: 'description',
Expand Down Expand Up @@ -80,7 +84,6 @@
factory.filters = storedContext.filters || {};
factory.activeFilters = storedContext.activeFilters || {};

console.log('Init Observables from localstorage');
return;
}
}
Expand All @@ -97,8 +100,6 @@
factory.activeFilters = {};

factory.storeContext();

console.log('Init Observables context');
}
},

Expand Down Expand Up @@ -145,7 +146,8 @@

addFilter: function(field, value) {
var query,
filterDef = factory.filterDefs[field];
filterDef = factory.filterDefs[field],
convertFn = filterDef.convert || angular.identity;

// Prepare the filter value
/*
Expand All @@ -163,7 +165,7 @@
query = value;
} else if (angular.isArray(value) && value.length > 0) {
query = _.map(value, function(val) {
return field + ':"' + val.text + '"';
return field + ':"' + convertFn(val.text) + '"';
}).join(' OR ');
query = '(' + query + ')';
} else if (filterDef.type === 'date') {
Expand All @@ -173,7 +175,7 @@
query = field + ':[ ' + fromDate + ' TO ' + toDate + ' ]';

} else {
query = field + ':' + value;
query = field + ':' + convertFn(value);
}

factory.filters[field] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h4>List of observables ({{artifacts.total || 0}} of {{artifactStats.count}})</h
</thead>
<tbody>
<tr ng-repeat="artifact in artifacts.values">
<td class="p-0 bg-tlp-{{artifact.tlp}} clickable" ng-click="addFilterValue('tlp', artifact.tlp)"></td>
<td class="p-0 bg-tlp-{{artifact.tlp}} clickable" ng-click="filterByTlp(artifact.tlp)"></td>
<td>
<input type="checkbox" ng-change="selectArtifact(artifact)" ng-model="selection.list[artifact.id]">
</td>
Expand Down

0 comments on commit cba1f05

Please sign in to comment.