Skip to content

Commit

Permalink
#1410 Use Query APIs in case task list
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jun 30, 2020
1 parent 475e23d commit b0b7032
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ tmp
/.idea/**
!/.idea/runConfigurations/
!/.idea/runConfigurations/*

dev
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
return _.extend({}, task);
},
users: function() {
// TODO nadouani use {"_field": "locked": "_value": false}
return UserSrv.list(
self.currentUser.organisation,
{
Expand Down
53 changes: 18 additions & 35 deletions frontend/app/scripts/controllers/case/CaseTasksCtrl.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('CaseTaskDeleteCtrl', CaseTaskDeleteCtrl)
.controller('CaseTasksCtrl', CaseTasksCtrl);

function CaseTasksCtrl($scope, $state, $stateParams, $q, $uibModal, FilteringSrv, CaseTabsSrv, PaginatedQuerySrv, CaseTaskSrv, UserSrv, NotificationSrv, CortexSrv, AppLayoutSrv) {
function CaseTasksCtrl($scope, $state, $stateParams, $q, $uibModal, ModalUtilsSrv, FilteringSrv, CaseTabsSrv, PaginatedQuerySrv, CaseTaskSrv, UserSrv, NotificationSrv, CortexSrv, AppLayoutSrv) {

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

Expand Down Expand Up @@ -76,7 +75,13 @@
loadAll: true,
pageSize: $scope.filtering.context.pageSize,
filter: $scope.filtering.buildQuery(),
withStats: true,
baseFilter: {
_not: {
_field: 'status',
_value: 'Cancel'
}
},
//withStats: true,
operations: [
{'_name': 'getCase', "idOrName": $scope.caseId},
{'_name': 'tasks'}
Expand Down Expand Up @@ -162,7 +167,7 @@
var field = {};
field[fieldName] = newValue;
return CaseTaskSrv.update({
taskId: task.id
taskId: task._id
}, field, function () {}, function (response) {
NotificationSrv.error('taskList', response.data, response.status);
});
Expand All @@ -184,21 +189,12 @@

$scope.removeTask = function(task) {

var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'views/partials/case/case.task.delete.html',
controller: 'CaseTaskDeleteCtrl',
controllerAs: 'vm',
resolve: {
title: function() {
return task.title;
}
}
});

modalInstance.result.then(function() {
ModalUtilsSrv.confirm('Delete task', 'Are you sure you want to delete the selected task?', {
okText: 'Yes, remove it',
flavor: 'danger'
}).then(function() {
CaseTaskSrv.update({
'taskId': task.id
'taskId': task._id
}, {
status: 'Cancel'
}, function() {
Expand All @@ -208,12 +204,11 @@
NotificationSrv.error('taskList', response.data, response.status);
});
});

};

// open task tab with its details
$scope.startTask = function(task) {
var taskId = task.id;
var taskId = task._id;

if (task.status === 'Waiting') {
$scope.updateTaskStatus(taskId, 'InProgress')
Expand All @@ -227,16 +222,16 @@

$scope.openTask = function(task) {
if (task.status === 'Completed') {
$scope.updateTaskStatus(task.id, 'InProgress')
$scope.updateTaskStatus(task._id, 'InProgress')
.then(function(/*response*/) {
$scope.showTask(task.id);
$scope.showTask(task._id);
});
}
};

$scope.closeTask = function(task) {
if (task.status === 'InProgress') {
$scope.updateTaskStatus(task.id, 'Completed')
$scope.updateTaskStatus(task._id, 'Completed')
.then(function() {
NotificationSrv.success('Task has been successfully closed');
});
Expand Down Expand Up @@ -287,16 +282,4 @@
});
};
}

function CaseTaskDeleteCtrl($uibModalInstance, title) {
this.title = title;

this.ok = function() {
$uibModalInstance.close();
};

this.cancel = function() {
$uibModalInstance.dismiss();
};
}
}());
32 changes: 29 additions & 3 deletions frontend/app/scripts/services/common/data/PaginatedQuerySrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
this.scope = options.scope;
this.loadAll = !!options.loadAll;
this.pageSize = options.pageSize || 10;
this.baseFilter = options.baseFilter;
this.filter = options.filter;
this.sort = options.sort;
this.onUpdate = options.onUpdate;
Expand Down Expand Up @@ -82,14 +83,39 @@
}, self.extraData ? {extraData: self.extraData} : {});
};


/**
* Prepare the filters collection to the Query service
*
* @return {type} filters definition
*/
this.getFilter = function() {
if(!this.baseFilter && !this.filter) {
return;
}

var predicates = _.without([this.baseFilter, this.filter], null, undefined, {});

return predicates.length === 1 ? predicates[0] : {'_and': predicates};
};

/**
* Prepare the sort attributes to the Query service
*
* @return {type} sort definition
*/
this.getSort = function() {
return self.sort;
};

/*
Function to change the page
*/
this.update = function(updates) {
// Get the list
QuerySrv.call(this.version, this.operations, {
filter: self.filter,
sort: self.sort,
filter: self.getFilter(),
sort: self.getSort(),
page: self.getPage(),
config: {},
withParent: false
Expand All @@ -112,7 +138,7 @@

// Compute the total again
QuerySrv.count('v1', this.operations, {
filter: self.filter,
filter: self.getFilter(),
config: {}
}).then(function(total) {
self.total = total;
Expand Down
10 changes: 0 additions & 10 deletions frontend/app/views/partials/case/case.task.delete.html

This file was deleted.

24 changes: 12 additions & 12 deletions frontend/app/views/partials/case/case.tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
<tbody ng-repeat="task in tasks.values">
<tr class="task-row" ng-class="{'warning': (task.status == 'InProgress' && task.flag == true)}">
<td>
<a href ng-click="collapseOptions[task.id] = !collapseOptions[task.id]" ng-show="task.description" uib-tooltip="Show/Hide description" tooltip-placement="right">
<a href ng-click="collapseOptions[task._id] = !collapseOptions[task._id]" ng-show="task.description" uib-tooltip="Show/Hide description" tooltip-placement="right">
<i class="fa" ng-class="{
true: 'fa-chevron-up',
false: 'fa-chevron-down'
}[!!collapseOptions[task.id]]"></i>
}[!!collapseOptions[task._id]]"></i>
</a>
</td>
<td class="task-status" align="center" ng-switch="task.status">
Expand All @@ -82,7 +82,7 @@
</td>
<td>
<div>
<a href ui-sref="app.case.tasks-item({caseId: caseId, itemId:task.id})">{{task.title}}</a>
<a href ui-sref="app.case.tasks-item({caseId: caseId, itemId:task._id})">{{task.title}}</a>
</div>
<div ng-show="task.status === 'Completed'" class="text-success">
Closed after <em>{{(task.endDate - task.startDate) | amDurationFormat : 'milliseconds'}}</em>
Expand Down Expand Up @@ -128,14 +128,14 @@
</span>

<span class="ml-xs" uib-dropdown ng-if="appConfig.connectors.cortex.enabled" if-permission="manageAction" allowed="{{userPermissions}}">
<a href class="text-primary noline nowrap" ng-click="getTaskResponders(task.id, true)" uib-dropdown-toggle>
<a href class="text-primary noline nowrap" ng-click="getTaskResponders(task._id, true)" uib-dropdown-toggle>
<i class="text-primary fa fa-cog"></i>
<!-- Responders
<i class="text-primary fa fa-angle-down"></i> -->
</a>
<ul class="dropdown-menu align-right" uib-dropdown-menu>
<li ng-if="taskResponders && taskResponders.length === 0">
<a href ng-click="getTaskResponders(task.id, true)">
<a href ng-click="getTaskResponders(task._id, true)">
<strong><i class="fa fa-refresh mr-xxs"></i> No responders available</strong>
</a>
</li>
Expand All @@ -150,7 +150,7 @@
</td>
</tr>

<tr ng-if="task.description && collapseOptions[task.id]">
<tr ng-if="task.description && collapseOptions[task._id]">
<td colspan="7" class="wrap">
<div marked="task.description" class="mt-xxs filter-panel markdown"></div>
</td>
Expand Down Expand Up @@ -182,11 +182,11 @@
<tbody ng-repeat="task in group.tasks">
<tr class="task-row" ng-class="{'warning': (task.status == 'InProgress' && task.flag == true)}">
<td>
<a href ng-click="collapseOptions[task.id] = !collapseOptions[task.id]" ng-show="task.description" uib-tooltip="Show/Hide description" tooltip-placement="right">
<a href ng-click="collapseOptions[task._id] = !collapseOptions[task._id]" ng-show="task.description" uib-tooltip="Show/Hide description" tooltip-placement="right">
<i class="fa" ng-class="{
true: 'fa-chevron-up',
false: 'fa-chevron-down'
}[!!collapseOptions[task.id]]"></i>
}[!!collapseOptions[task._id]]"></i>
</a>
</td>
<td class="task-status" align="center" ng-switch="task.status">
Expand All @@ -201,7 +201,7 @@
</td>
<td>
<div>
<a href ui-sref="app.case.tasks-item({caseId: caseId, itemId:task.id})">{{task.title}}</a>
<a href ui-sref="app.case.tasks-item({caseId: caseId, itemId:task._id})">{{task.title}}</a>
</div>
<div ng-show="task.status === 'Completed'" class="text-success">
Closed after <em>{{(task.endDate - task.startDate) | amDurationFormat : 'milliseconds'}}</em>
Expand Down Expand Up @@ -247,14 +247,14 @@
</span>

<span class="ml-xs" uib-dropdown ng-if="appConfig.connectors.cortex.enabled" if-permission="manageAction" allowed="{{userPermissions}}">
<a href class="text-primary noline nowrap" ng-click="getTaskResponders(task.id, true)" uib-dropdown-toggle>
<a href class="text-primary noline nowrap" ng-click="getTaskResponders(task._id, true)" uib-dropdown-toggle>
<i class="text-primary fa fa-cog"></i>
<!-- Responders
<i class="text-primary fa fa-angle-down"></i> -->
</a>
<ul class="dropdown-menu align-right" uib-dropdown-menu>
<li ng-if="taskResponders && taskResponders.length === 0">
<a href ng-click="getTaskResponders(task.id, true)">
<a href ng-click="getTaskResponders(task._id, true)">
<strong><i class="fa fa-refresh mr-xxs"></i> No responders available</strong>
</a>
</li>
Expand All @@ -268,7 +268,7 @@
</span>
</td>
</tr>
<tr ng-if="task.description && collapseOptions[task.id]">
<tr ng-if="task.description && collapseOptions[task._id]">
<td colspan="7" class="wrap">
<div marked="task.description" class="mt-xxs filter-panel markdown"></div>
</td>
Expand Down

0 comments on commit b0b7032

Please sign in to comment.