From 2e6b6105278cd11f45bdc63fdc12f4ebfa3d9722 Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Sun, 11 Apr 2021 22:27:03 +0200 Subject: [PATCH] #1948 WIP: Fix pagination in task list --- .../scripts/controllers/case/CaseTasksCtrl.js | 178 +++--- frontend/app/views/directives/psearch.html | 4 +- .../app/views/partials/case/case.tasks.html | 540 +++++++++--------- .../views/partials/case/tasks/toolbar.html | 16 +- 4 files changed, 377 insertions(+), 361 deletions(-) diff --git a/frontend/app/scripts/controllers/case/CaseTasksCtrl.js b/frontend/app/scripts/controllers/case/CaseTasksCtrl.js index 039b1aafaa..14a370d284 100755 --- a/frontend/app/scripts/controllers/case/CaseTasksCtrl.js +++ b/frontend/app/scripts/controllers/case/CaseTasksCtrl.js @@ -1,9 +1,9 @@ -(function() { +(function () { 'use strict'; angular.module('theHiveControllers') .controller('CaseTasksCtrl', CaseTasksCtrl); - function CaseTasksCtrl($scope, $state, $stateParams, $q, $uibModal, AuthenticationSrv, ModalUtilsSrv, FilteringSrv, CaseTabsSrv, PaginatedQuerySrv, CaseTaskSrv, UserSrv, NotificationSrv, CortexSrv, AppLayoutSrv) { + function CaseTasksCtrl($scope, $state, $stateParams, $q, AuthenticationSrv, ModalUtilsSrv, FilteringSrv, CaseTabsSrv, PaginatedQuerySrv, CaseTaskSrv, NotificationSrv, CortexSrv, AppLayoutSrv) { CaseTabsSrv.activateTab($state.current.data.tab); @@ -23,7 +23,7 @@ selectAll: false }; - this.$onInit = function() { + this.$onInit = function () { $scope.filtering = new FilteringSrv('task', 'task.list', { version: 'v1', defaults: { @@ -36,53 +36,55 @@ }); $scope.filtering.initContext($scope.caseId) - .then(function() { + .then(function () { $scope.load(); - $scope.$watchCollection('tasks.pageSize', function (newValue) { + $scope.$watch('list.pageSize', function (newValue) { $scope.filtering.setPageSize(newValue); }); }); }; - $scope.getAssignableUsers = function(taskId) { + $scope.getAssignableUsers = function (taskId) { return [ - {_name: 'getTask', idOrName: taskId}, - {_name: 'assignableUsers'} + { _name: 'getTask', idOrName: taskId }, + { _name: 'assignableUsers' } ]; }; - $scope.load = function() { + $scope.load = function () { $scope.list = new PaginatedQuerySrv({ name: 'case-tasks', root: $scope.caseId, - objectType: 'case_task', + objectType: 'task', + streamObjectType: 'case_task', version: 'v1', scope: $scope, sort: $scope.filtering.context.sort, loadAll: false, + limitedCount: true, pageSize: $scope.filtering.context.pageSize, filter: $scope.filtering.buildQuery(), baseFilter: { - _not: { + _ne: { _field: 'status', _value: 'Cancel' } }, operations: [ - {'_name': 'getCase', "idOrName": $scope.caseId}, - {'_name': 'tasks'} + { '_name': 'getCase', "idOrName": $scope.caseId }, + { '_name': 'tasks' } ], extraData: ['shareCount', 'actionRequired'], //extraData: ['isOwner', 'shareCount'], - onUpdate: function() { + onUpdate: function () { $scope.buildTaskGroups($scope.list.values); $scope.resetSelection(); } }); }; - $scope.resetSelection = function() { + $scope.resetSelection = function () { if ($scope.menu.selectAll) { $scope.selectAll(); } else { @@ -92,7 +94,7 @@ } }; - $scope.updateMenu = function() { + $scope.updateMenu = function () { // Handle flag/unflag menu items var temp = _.uniq(_.pluck($scope.selection, 'flag')); $scope.menu.unflag = temp.length === 1 && temp[0] === true; @@ -113,28 +115,28 @@ $scope.menu.delete = $scope.selection.length > 0; }; - $scope.select = function(task) { + $scope.select = function (task) { if (task.selected) { $scope.selection.push(task); } else { - $scope.selection = _.reject($scope.selection, function(item) { + $scope.selection = _.reject($scope.selection, function (item) { return item._id === task._id; }); } $scope.updateMenu(); }; - $scope.selectAll = function() { + $scope.selectAll = function () { var selected = $scope.menu.selectAll; - _.each($scope.list.values, function(item) { + _.each($scope.list.values, function (item) { // if(SecuritySrv.checkPermissions(['manageCase'], item.extraData.permissions)) { item.selected = selected; // } }); if (selected) { - $scope.selection = _.filter($scope.list.values, function(item) { + $scope.selection = _.filter($scope.list.values, function (item) { return !!item.selected; }); } else { @@ -144,8 +146,6 @@ $scope.updateMenu(); }; - // ######################@@@ - $scope.toggleStats = function () { $scope.filtering.toggleStats(); }; @@ -177,16 +177,16 @@ $scope.search(); }; - $scope.filterBy = function(field, value) { + $scope.filterBy = function (field, value) { $scope.filtering.clearFilters() - .then(function() { + .then(function () { $scope.addFilterValue(field, value); }); }; - $scope.filterMyTasks = function() { + $scope.filterMyTasks = function () { $scope.filtering.clearFilters() - .then(function() { + .then(function () { var currentUser = AuthenticationSrv.currentUser; $scope.filtering.addFilter({ field: 'assignee', @@ -202,31 +202,31 @@ }); }; - $scope.toggleGroupedView = function() { + $scope.toggleGroupedView = function () { $scope.state.showGrouped = !$scope.state.showGrouped; AppLayoutSrv.groupTasks($scope.state.showGrouped); }; - $scope.buildTaskGroups = function(tasks) { + $scope.buildTaskGroups = function (tasks) { // Sort tasks by order - var orderedTasks = _.sortBy(_.map(tasks, function(t) { + var orderedTasks = _.sortBy(_.map(tasks, function (t) { return _.pick(t, 'group', 'order'); }), 'order'); var groups = []; // Get group names by keeping the group orders - _.each(orderedTasks, function(task) { - if(groups.indexOf(task.group) === -1) { + _.each(orderedTasks, function (task) { + if (groups.indexOf(task.group) === -1) { groups.push(task.group); } }); var groupedTasks = []; - _.each(groups, function(group) { + _.each(groups, function (group) { groupedTasks.push({ group: group, - tasks: _.filter(tasks, function(t) { + tasks: _.filter(tasks, function (t) { return t.group === group; }) }); @@ -236,7 +236,7 @@ $scope.groupedTasks = groupedTasks; }; - $scope.showTask = function(taskId) { + $scope.showTask = function (taskId) { $state.go('app.case.tasks-item', { itemId: taskId }); @@ -247,98 +247,98 @@ field[fieldName] = newValue; return CaseTaskSrv.update({ taskId: task._id - }, field, function () {}, function (response) { + }, field, function () { }, function (response) { NotificationSrv.error('taskList', response.data, response.status); }); }; - $scope.addTask = function() { + $scope.addTask = function () { CaseTaskSrv.save({ 'caseId': $scope.caseId, 'flag': false - }, $scope.newTask, function() { + }, $scope.newTask, function () { $scope.isNewTask = false; $scope.newTask.title = ''; $scope.newTask.group = ''; NotificationSrv.success('Task has been successfully added'); - }, function(response) { + }, function (response) { NotificationSrv.error('taskList', response.data, response.status); }); }; - $scope.removeTask = function(task) { + $scope.removeTask = function (task) { ModalUtilsSrv.confirm('Delete task', 'Are you sure you want to delete the selected task?', { okText: 'Yes, remove it', flavor: 'danger' - }).then(function() { + }).then(function () { CaseTaskSrv.update({ 'taskId': task._id }, { status: 'Cancel' - }, function() { + }, function () { $scope.$emit('tasks:task-removed', task); NotificationSrv.success('Task has been successfully removed'); - }, function(response) { + }, function (response) { NotificationSrv.error('taskList', response.data, response.status); }); }); }; - $scope.bulkUpdate = function(ids, patch) { + $scope.bulkUpdate = function (ids, patch) { return CaseTaskSrv.bulkUpdate(ids, patch) - .then(function(/*responses*/) { + .then(function (/*responses*/) { NotificationSrv.log('Selected tasks have been updated successfully', 'success'); }) - .catch(function(err) { + .catch(function (err) { NotificationSrv.error('Bulk update tasks', err.data, err.status); }); } - $scope.bulkFlag = function(flag) { + $scope.bulkFlag = function (flag) { var ids = _.pluck($scope.selection, '_id'); - return $scope.bulkUpdate(ids, {flag: flag}); + return $scope.bulkUpdate(ids, { flag: flag }); } - $scope.bulkStatus = function(status) { + $scope.bulkStatus = function (status) { var ids = _.pluck($scope.selection, '_id'); - return $scope.bulkUpdate(ids, {status: status}); + return $scope.bulkUpdate(ids, { status: status }); } - $scope.bulkRemove = function() { + $scope.bulkRemove = function () { var ids = _.pluck($scope.selection, '_id'); ModalUtilsSrv.confirm('Delete selected tasks', 'Are you sure you want to delete the selected tasks?', { okText: 'Yes, proceed', flavor: 'danger' - }).then(function() { - return CaseTaskSrv.bulkUpdate(ids, {status: 'Cancel'}) - .then(function(/*responses*/) { + }).then(function () { + return CaseTaskSrv.bulkUpdate(ids, { status: 'Cancel' }) + .then(function (/*responses*/) { NotificationSrv.log('Selected tasks have been successfully removed', 'success'); - _.each($scope.selection, function(task) { + _.each($scope.selection, function (task) { $scope.$emit('tasks:task-removed', task); }); }) - .catch(function(err) { + .catch(function (err) { NotificationSrv.error('Bulk remove tasks', err.data, err.status); }); - }).catch(function(err) { - if(err && !_.isString(err)) { + }).catch(function (err) { + if (err && !_.isString(err)) { NotificationSrv.error('Bulk remove tasks', err.data, err.status); } }) } // open task tab with its details - $scope.startTask = function(task) { + $scope.startTask = function (task) { var taskId = task._id; if (task.status === 'Waiting') { $scope.updateTaskStatus(taskId, 'InProgress') - .then(function(/*response*/) { + .then(function (/*response*/) { $scope.showTask(taskId); }); } else { @@ -346,34 +346,34 @@ } }; - $scope.openTask = function(task) { + $scope.openTask = function (task) { if (task.status === 'Completed') { $scope.updateTaskStatus(task._id, 'InProgress') - .then(function(/*response*/) { + .then(function (/*response*/) { $scope.showTask(task._id); }); } }; - $scope.closeTask = function(task) { + $scope.closeTask = function (task) { if (task.status === 'InProgress') { $scope.updateTaskStatus(task._id, 'Completed') - .then(function() { + .then(function () { NotificationSrv.success('Task has been successfully closed'); }); } }; - $scope.updateTaskStatus = function(taskId, status) { + $scope.updateTaskStatus = function (taskId, status) { var defer = $q.defer(); CaseTaskSrv.update({ 'taskId': taskId }, { 'status': status - }, function(data) { + }, function (data) { defer.resolve(data); - }, function(response) { + }, function (response) { NotificationSrv.error('taskList', response.data, response.status); defer.reject(response); }); @@ -381,32 +381,32 @@ return defer.promise; }; - $scope.getTaskResponders = function(task, force) { - if(!force && $scope.taskResponders !== null) { - return; + $scope.getTaskResponders = function (task, force) { + if (!force && $scope.taskResponders !== null) { + return; } $scope.taskResponders = null; CortexSrv.getResponders('case_task', task._id) - .then(function(responders) { - $scope.taskResponders = responders; - return CortexSrv.promntForResponder(responders); - }) - .then(function(response) { - if(response && _.isString(response)) { - NotificationSrv.log(response, 'warning'); - } else { - return CortexSrv.runResponder(response.id, response.name, 'case_task', _.pick(task, '_id')); - } - }) - .then(function(response){ - NotificationSrv.success(['Responder', response.data.responderName, 'started successfully on task', task.title].join(' ')); - }) - .catch(function(err) { - if(err && !_.isString(err)) { - NotificationSrv.error('taskList', err.data, err.status); - } - }); + .then(function (responders) { + $scope.taskResponders = responders; + return CortexSrv.promntForResponder(responders); + }) + .then(function (response) { + if (response && _.isString(response)) { + NotificationSrv.log(response, 'warning'); + } else { + return CortexSrv.runResponder(response.id, response.name, 'case_task', _.pick(task, '_id')); + } + }) + .then(function (response) { + NotificationSrv.success(['Responder', response.data.responderName, 'started successfully on task', task.title].join(' ')); + }) + .catch(function (err) { + if (err && !_.isString(err)) { + NotificationSrv.error('taskList', err.data, err.status); + } + }); }; // $scope.runResponder = function(responderId, responderName, task) { diff --git a/frontend/app/views/directives/psearch.html b/frontend/app/views/directives/psearch.html index dbcbeb9cd9..72fe794a29 100644 --- a/frontend/app/views/directives/psearch.html +++ b/frontend/app/views/directives/psearch.html @@ -1,11 +1,11 @@
-
+
-
+
    diff --git a/frontend/app/views/partials/case/case.tasks.html b/frontend/app/views/partials/case/case.tasks.html index 99dae58ae0..ab13974183 100755 --- a/frontend/app/views/partials/case/case.tasks.html +++ b/frontend/app/views/partials/case/case.tasks.html @@ -53,290 +53,300 @@

    -
    +
    - - - - - - - - - - - - - - - - - - - - - + - - - + + + + +
    - - GroupTaskDateAssigneeActions
    - - - - - - - {{task.group}} - - -
    - Closed after {{(task.endDate - task.startDate) | amDurationFormat : - 'milliseconds'}} -
    -
    - Started -
    -
    - + +
    + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + - - - -
    + + GroupTaskDateAssigneeActions
    + + + + + + + + + + {{task.group}} + + +
    + Closed after {{(task.endDate - task.startDate) | amDurationFormat : + 'milliseconds'}} +
    +
    + Started +
    +
    +
    + -
    {{task.startDate | shortDate}} - - - - - - - - - - - - Not Assigned - - + + ({{task.extraData.shareCount || 0}}) + + - - - - - - - - - - - - - - - -
    {{task.startDate | shortDate}} + + + + + + + + + + + + Not Assigned + + -
    -
    -
    + + + + + + + + + + + + + + + +
    +
    +
    +
    - diff --git a/frontend/app/views/partials/case/tasks/toolbar.html b/frontend/app/views/partials/case/tasks/toolbar.html index 8fe46997a2..d47a7eae3e 100644 --- a/frontend/app/views/partials/case/tasks/toolbar.html +++ b/frontend/app/views/partials/case/tasks/toolbar.html @@ -3,8 +3,11 @@