Skip to content

Commit

Permalink
#13 Refactor the “app.case.tasks-item” and fetch the task object thro…
Browse files Browse the repository at this point in the history
…ugh the route resolve, to make sure the template is loaded with the complete task data
  • Loading branch information
nadouani committed Nov 15, 2016
1 parent 72395a9 commit db0c3f2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
20 changes: 18 additions & 2 deletions ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,23 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ui.bootstrap', 'ui.router
.state('app.case.tasks-item', {
url: '/tasks/{itemId}',
templateUrl: 'views/partials/case/case.tasks.item.html',
controller: 'CaseTasksItemCtrl'
controller: 'CaseTasksItemCtrl',
resolve: {
task: function($q, $stateParams, CaseTaskSrv, AlertSrv) {
var deferred = $q.defer();

CaseTaskSrv.get({
'taskId': $stateParams.itemId
}, function(data) {
deferred.resolve(data);
}, function(response) {
deferred.reject(response);
AlertSrv.error('taskDetails', response.data, response.status);
});

return deferred.promise;
}
}
})
.state('app.case.observables', {
url: '/observables',
Expand Down Expand Up @@ -244,7 +260,7 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ui.bootstrap', 'ui.router
})
.config(['markedProvider', 'hljsServiceProvider', function(markedProvider, hljsServiceProvider) {
'use strict';

// marked config
markedProvider.setOptions({
gfm: true,
Expand Down
56 changes: 23 additions & 33 deletions ui/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, $state, $stateParams, CaseTabsSrv, CaseTaskSrv, PSearchSrv, TaskLogSrv, AlertSrv) {
function($scope, $state, $stateParams, CaseTabsSrv, CaseTaskSrv, PSearchSrv, TaskLogSrv, AlertSrv, task) {
var caseId = $stateParams.caseId,
taskId = $stateParams.itemId;

Expand All @@ -16,39 +16,8 @@
attachmentCollapsed: true,
logMissing: ''
};
$scope.task = {};

CaseTaskSrv.get({
'taskId': taskId
}, function(data) {

var task = data,
taskName = 'task-' + task.id;

// Add tabs
CaseTabsSrv.addTab(taskName, {
name: taskName,
label: task.title,
closable: true,
state: 'app.case.tasks-item',
params: {
itemId: task.id
}
});

// Select tab
CaseTabsSrv.activateTab(taskName);

// Prepare the scope data
$scope.initScope(data);

}, function(response) {
AlertSrv.error('taskDetails', response.data, response.status);
CaseTabsSrv.activateTab('tasks');
});

$scope.initScope = function(task) {
$scope.task = task;
$scope.initScope = function() {

$scope.logs = PSearchSrv(caseId, 'case_task_log', {
'filter': {
Expand Down Expand Up @@ -128,6 +97,27 @@

return true;
};

// Initialize controller
$scope.task = task;
var taskName = 'task-' + task.id;

// Add tabs
CaseTabsSrv.addTab(taskName, {
name: taskName,
label: task.title,
closable: true,
state: 'app.case.tasks-item',
params: {
itemId: task.id
}
});

// Select tab
CaseTabsSrv.activateTab(taskName);

// Prepare the scope data
$scope.initScope(task);
}
);
}());

0 comments on commit db0c3f2

Please sign in to comment.