Skip to content

Commit

Permalink
#1410 Use APIs v1 to list task logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 16, 2020
1 parent 948dee1 commit 0b2bc51
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 53 deletions.
69 changes: 21 additions & 48 deletions frontend/app/scripts/controllers/case/CaseTasksItemCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
'use strict';
angular.module('theHiveControllers').controller('CaseTasksItemCtrl',
function ($scope, $rootScope, $state, $stateParams, $timeout, $uibModal, SecuritySrv, ModalSrv, CaseSrv, AuthenticationSrv, OrganisationSrv, CaseTabsSrv, CaseTaskSrv, PSearchSrv, TaskLogSrv, NotificationSrv, CortexSrv, StatSrv, task) {
function ($scope, $rootScope, $state, $stateParams, $timeout, $uibModal, PaginatedQuerySrv, SecuritySrv, ModalSrv, CaseSrv, AuthenticationSrv, OrganisationSrv, CaseTabsSrv, CaseTaskSrv, PSearchSrv, TaskLogSrv, NotificationSrv, CortexSrv, StatSrv, task) {
var caseId = $stateParams.caseId,
taskId = $stateParams.itemId;

Expand All @@ -15,16 +15,16 @@
message: ''
};
$scope.sortOptions = {
'+startDate': 'Oldest first',
'-startDate': 'Newest first'
'+date': 'Oldest first',
'-date': 'Newest first'
};
$scope.state = {
editing: false,
isCollapsed: false,
dropdownOpen: false,
attachmentCollapsed: true,
logMissing: '',
sort: '-startDate'
sort: '-date'
};

$scope.markdownEditorOptions = {
Expand All @@ -35,51 +35,24 @@

$scope.initScope = function () {

$scope.logs = PSearchSrv(caseId, 'case_task_log', {
$scope.logs = new PaginatedQuerySrv({
root: caseId,
objectType: 'case_task_log',
version: 'v1',
scope: $scope,
filter: {
_and: [{
_parent: {
_type: 'case_task',
_query: {
_id: taskId
}
}
}, {
_not: {
'status': 'Deleted'
}
}]
},
'sort': $scope.state.sort,
'pageSize': 10,
onUpdate: function() {
var ids = _.pluck($scope.logs.values, 'id');

StatSrv.getPromise({
objectType: 'connector/cortex/action',
field: 'objectId',
limit: 1000,
skipTotal: true,
query: {
_and: [{
_field: 'objectType',
_value: 'case_task_log'
},
{
_in: {
_field: 'objectId',
_values: ids
}
}]
}
}).then(function(response) {
var counts = response.data;
_.each($scope.logs.values, function(log) {
log.nbActions = counts[log.id] ? counts[log.id].count : 0;
});
});
}
sort: $scope.state.sort,
loadAll: false,
pageSize: 10,
operations: [
{
'_name': 'getTask',
'idOrName': taskId
},
{
'_name': 'logs'
}
],
extraData: ['actionCount']
});

var connectors = $scope.appConfig.connectors;
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/scripts/directives/logEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

scope.confirmDropLog = function() {
TaskLogSrv.delete({
logId: scope.log.id
logId: scope.log._id
}).$promise.then(function() {
scope.deleteModal.dismiss();
});
Expand All @@ -89,7 +89,7 @@

scope.updateLog = function() {
return TaskLogSrv.update({
logId: scope.log.id
logId: scope.log._id
}, {message: scope.log.message}, function() {}, function(response) {
NotificationSrv.error('CaseTaskLog', response.data, response.status);
});
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/views/directives/log-entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
</div>
</div>

<div class="row" ng-if="log.nbActions > 0">
<div class="row" ng-if="log.extraData.actionCount > 0">
<div class="col-md-12">
<a href ng-show="showActions" ng-click="showActions=false">Hide Responder Jobs ({{log.nbActions}})</a>
<a href ng-show="!showActions" ng-click="showActions=true; getActions(log.id)">Show Responder Jobs ({{log.nbActions}})</a>
<a href ng-show="showActions" ng-click="showActions=false">Hide Responder Jobs ({{log.extraData.actionCount}})</a>
<a href ng-show="!showActions" ng-click="showActions=true; getActions(log._id)">Show Responder Jobs ({{log.extraData.actionCount}})</a>
</div>
<div class="col-md-12" ng-show="showActions && actions">
<responder-actions header="" actions="actions"></responder-actions>
Expand Down

0 comments on commit 0b2bc51

Please sign in to comment.