Skip to content

Commit

Permalink
#1410 Use API v1 to load task by id
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 15, 2020
1 parent 5dd8280 commit 5314e32
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
35 changes: 18 additions & 17 deletions frontend/app/scripts/controllers/case/CaseTasksItemCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// Initialize controller
$scope.task = task;
$scope.tabName = 'task-' + task.id;
$scope.tabName = 'task-' + task._id;
$scope.taskResponders = null;

$scope.loading = false;
Expand Down Expand Up @@ -125,7 +125,7 @@
var field = {};
field[fieldName] = newValue;
return CaseTaskSrv.update({
taskId: $scope.task.id
taskId: $scope.task._id
}, field, function () {}, function (response) {
NotificationSrv.error('taskDetails', response.data, response.status);
});
Expand All @@ -147,14 +147,15 @@
};

$scope.startTask = function() {
var taskId = $scope.task.id;
var taskId = $scope.task._id;

CaseTaskSrv.update({
'taskId': taskId
}, {
'status': 'InProgress'
}, function(data) {
$scope.task = data;
}, function(/*data*/) {
// $scope.task = data;
$scope.reloadTask();
}, function(response) {
NotificationSrv.error('taskDetails', response.data, response.status);
});
Expand All @@ -179,7 +180,7 @@
}

TaskLogSrv.save({
'taskId': $scope.task.id
'taskId': $scope.task._id
}, $scope.newLog, function () {
if($scope.task.status === 'Waiting') {
// Reload the task
Expand Down Expand Up @@ -227,7 +228,7 @@
}

$scope.taskResponders = null;
CortexSrv.getResponders('case_task', $scope.task.id)
CortexSrv.getResponders('case_task', $scope.task._id)
.then(function(responders) {
$scope.taskResponders = responders;
return CortexSrv.promntForResponder(responders);
Expand All @@ -247,16 +248,16 @@
NotificationSrv.error('taskDetails', err.data, err.status);
}
});
};
};

$scope.reloadTask = function() {
CaseTaskSrv.get({
'taskId': $scope.task.id
}, function(data) {
$scope.task = data;
}, function(response) {
NotificationSrv.error('taskDetails', response.data, response.status);
});
CaseTaskSrv.getById($scope.task._id)
.then(function(data) {
$scope.task = data;
})
.catch(function(response) {
NotificationSrv.error('taskDetails', response.data, response.status);
});
};

$scope.loadShares = function () {
Expand All @@ -277,7 +278,7 @@

modalInstance.result
.then(function() {
return CaseTaskSrv.removeShare($scope.task.id, share);
return CaseTaskSrv.removeShare($scope.task._id, share);
})
.then(function(/*response*/) {
$scope.loadShares();
Expand Down Expand Up @@ -338,7 +339,7 @@
closable: true,
state: 'app.case.tasks-item',
params: {
itemId: task.id
itemId: task._id
}
});

Expand Down
22 changes: 21 additions & 1 deletion frontend/app/scripts/services/api/CaseTaskSrv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices')
.service('CaseTaskSrv', function($resource, $http) {
.service('CaseTaskSrv', function($resource, $http, $q, QuerySrv) {
var resource = $resource('./api/case/:caseId/task/:taskId', {}, {
update: {
method: 'PATCH'
Expand All @@ -13,6 +13,26 @@
this.query = resource.query;
this.save = resource.save;

this.getById = function(id) {
var defer = $q.defer();

QuerySrv.call('v1', [{
'_name': 'getTask',
'idOrName': id
}], {
page: {
from: 0,
to: 1
}
}).then(function(response) {
defer.resolve(response[0]);
}).catch(function(err){
defer.reject(err);
});

return defer.promise;
};

this.getShares = function(caseId, taskId) {
return $http.get('./api/case/' + caseId + '/task/' + taskId + '/shares');
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/views/partials/case/case.tasks.item.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ <h4 class="mb-xs text-primary">
<dl class="dl-horizontal">
<dt class="pull-left">Assignee</dt>
<dd ng-if="canEdit">
<updatable-user on-update="updateField('owner', newValue)" value="task.owner"/>
<updatable-user on-update="updateField('owner', newValue)" value="task.assignee"/>
</dd>
<dd ng-if="!canEdit">
<user-info value="task.owner" field="name"></user-info>
<user-info value="task.assignee" field="name"></user-info>
</dd>
</dl>
</div>
Expand Down

0 comments on commit 5314e32

Please sign in to comment.