Skip to content

Commit

Permalink
#1444 Update the updatable-user directive to rely on the assignable u…
Browse files Browse the repository at this point in the history
…sers input.
  • Loading branch information
nadouani committed Jul 22, 2020
1 parent 7b78d9e commit bcec72c
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 25 deletions.
5 changes: 5 additions & 0 deletions frontend/app/scripts/controllers/case/CaseDetailsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
]
});

$scope.assignableUsersQuery = [
{_name: 'getCase', idOrName: $scope.caseId},
{_name: 'assignableUsers'}
];

var connectors = $scope.appConfig.connectors;
if(connectors.cortex && connectors.cortex.enabled) {
$scope.actions = new PaginatedQuerySrv({
Expand Down
2 changes: 0 additions & 2 deletions frontend/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@
});

modal.result.then(function(operations) {
console.log(operations);

$q.all(_.map(operations, function(operation) {
return CaseSrv.bulkUpdate(operation.ids, operation.patch);
})).then(function(/*responses*/) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
{ '_name': 'actions' }
],
guard: function(updates) {
console.log('Guard function of observable actions', updates);
return _.find(updates, function(item) {
return (item.base.details.objectType === 'Observable') && (item.base.details.objectId === artifact.id);
}) !== undefined;
Expand Down
7 changes: 7 additions & 0 deletions frontend/app/scripts/controllers/case/CaseTasksCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
});
};

$scope.getAssignableUsers = function(taskId) {
return [
{_name: 'getTask', idOrName: taskId},
{_name: 'assignableUsers'}
];
};

$scope.load = function() {
$scope.tasks = new PaginatedQuerySrv({
name: 'case-tasks',
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/scripts/controllers/case/CaseTasksItemCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
$scope.tabName = 'task-' + task._id;
$scope.taskResponders = null;

$scope.assignableUsersQuery = [
{_name: 'getTask', idOrName: task._id},
{_name: 'assignableUsers'}
];

$scope.loading = false;
$scope.newLog = {
message: ''
Expand Down
40 changes: 24 additions & 16 deletions frontend/app/scripts/directives/updatableUser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveDirectives')
.directive('updatableUser', function(UserSrv, UtilsSrv, AuthenticationSrv, NotificationSrv) {
.directive('updatableUser', function(UserSrv, QuerySrv, UtilsSrv, AuthenticationSrv, NotificationSrv) {
return {
restrict: 'E',
link: function(scope, element, attrs, ctrl, transclude) {
Expand All @@ -17,31 +17,39 @@
scope.$watch('updatable.updating', function(value) {

if(value === true && !cached) {
// TODO nadouani use {"_field": "locked": "_value": false}
UserSrv.list(AuthenticationSrv.currentUser.organisation, {
var assignableUsers = [];

if(_.isFunction(scope.query)) {
assignableUsers = scope.query.apply(this, scope.queryParams);
} else {
assignableUsers = scope.query;
}

QuerySrv.call('v1', assignableUsers, {
filter: {
_is: {
_field: 'locked',
_value: false
}
_field: 'locked',
_value: false
},
sort: ['+name']
})
.then(function(users) {
scope.userList = users;
})
.catch(function(err) {
NotificationSrv.error('Fetching users', err.data, err.status);
});
.then(function(users) {
scope.userList = users;
})
.catch(function(err) {
NotificationSrv.error('Fetching users', err.data, err.status);
});

cached = true;
}
});
},
templateUrl: 'views/directives/updatable-user.html',
scope: {
'value': '=?',
'onUpdate': '&',
'active': '=?'
value: '=?',
query: '=',
queryParams: '=',
onUpdate: '&',
active: '=?'
}
};
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/views/partials/case/case.details.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h4 class="vpad10 text-primary">Summary</h4>
<dl class="dl-horizontal">
<dt class="pull-left">Assignee</dt>
<dd ng-if="canEdit">
<updatable-user on-update="updateField('owner', newValue)" value="caze.assignee"/>
<updatable-user on-update="updateField('owner', newValue)" value="caze.assignee" query="assignableUsersQuery"/>
</dd>
<dd ng-if="!canEdit">
<user-info value="caze.assignee" field="name"></user-info>
Expand Down
8 changes: 4 additions & 4 deletions frontend/app/views/partials/case/case.tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ <h4>
<td>{{task.startDate | shortDate}}</td>
<td ng-if="canEdit">
<span ng-show="task.assignee">
<updatable-user on-update="updateField('owner', newValue, task)" value="task.assignee"/>
<updatable-user on-update="updateField('owner', newValue, task)" value="task.assignee" query="getAssignableUsers" query-params="[task._id]"/>
</span>
<span ng-show="!task.assignee">
<updatable-user on-update="updateField('owner', newValue, task)" value="notassigned"/>
<updatable-user on-update="updateField('owner', newValue, task)" value="notassigned" query="getAssignableUsers" query-params="[task._id]"/>
</span>
</td>
<td ng-if="!canEdit">
Expand Down Expand Up @@ -236,10 +236,10 @@ <h4>
<td>{{task.startDate | shortDate}}</td>
<td ng-if="canEdit">
<span ng-show="task.assignee">
<updatable-user on-update="updateField('owner', newValue, task)" value="task.assignee"/>
<updatable-user on-update="updateField('owner', newValue, task)" value="task.assignee" query="getAssignableUsers" query-params="[task._id]"/>
</span>
<span ng-show="!task.assignee">
<updatable-user on-update="updateField('owner', newValue, task)" value="notassigned"/>
<updatable-user on-update="updateField('owner', newValue, task)" value="notassigned" query="getAssignableUsers" query-params="[task._id]"/>
</span>
</td>
<td ng-if="!canEdit">
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/views/partials/case/case.tasks.item.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <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.assignee"/>
<updatable-user on-update="updateField('owner', newValue)" value="task.assignee" query="assignableUsersQuery"/>
</dd>
<dd ng-if="!canEdit">
<user-info value="task.assignee" field="name"></user-info>
Expand Down

0 comments on commit bcec72c

Please sign in to comment.