Skip to content

Commit

Permalink
#65 Apply tasks' descriptions to cases created from templates
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Dec 19, 2016
1 parent f852166 commit 465e4bd
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions ui/app/scripts/controllers/case/CaseCreationCtrl.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Controller for new case modal page
*/
(function() {
(function () {
'use strict';
angular.module('theHiveControllers').controller('CaseCreationCtrl',
function($rootScope, $scope, $state, $modalInstance, CaseSrv, AlertSrv, MetricsCacheSrv, template) {
function ($rootScope, $scope, $state, $modalInstance, CaseSrv, AlertSrv, MetricsCacheSrv, template) {

$rootScope.title = 'New case';
$scope.activeTlp = 'active';
Expand All @@ -20,7 +20,7 @@

if ($scope.fromTemplate === true) {

MetricsCacheSrv.all().then(function(list) {
MetricsCacheSrv.all().then(function (list) {
// Set basic info from template
$scope.newCase = {
status: 'Open',
Expand All @@ -33,7 +33,7 @@
// Set metrics from template
$scope.metricsCache = list;
var metrics = {};
_.each(template.metricNames, function(m) {
_.each(template.metricNames, function (m) {
metrics[m] = null;
});
$scope.newCase.metrics = metrics;
Expand All @@ -42,7 +42,7 @@
$scope.tags = template.tags;

// Set tasks from template
$scope.tasks = _.map(template.tasks, function(t) {
$scope.tasks = _.map(template.tasks, function (t) {
return t.title;
});
});
Expand All @@ -54,59 +54,70 @@
};
}

$scope.updateTlp = function(tlp) {
$scope.updateTlp = function (tlp) {
$scope.newCase.tlp = tlp;
};

$scope.createNewCase = function(isValid) {
$scope.createNewCase = function (isValid) {
if (!isValid) {
return;
}

$scope.newCase.tags = [];
angular.forEach($scope.tags, function(tag) {
angular.forEach($scope.tags, function (tag) {
$scope.newCase.tags.push(tag.text);
});
$scope.newCase.tags = $.unique($scope.newCase.tags.sort());

// Append title prefix
if ($scope.fromTemplate) {
$scope.newCase.title = $scope.template.titlePrefix + ' ' + $scope.temp.titleSuffix;

$scope.newCase.tasks = _.map($scope.template.tasks, function (task) {
return {
title: task.title,
description: task.description,
flag: false,
status: 'Waiting'
};
});

} else {
$scope.newCase.tasks = _.map($scope.tasks, function (task) {
return {
title: task,
flag: false,
status: 'Waiting'
};
});
}

$scope.newCase.tasks = _.map($scope.tasks, function(task) {
return {
title: task,
flag: false,
status: 'Waiting'
};
});

$scope.pendingAsync = true;
CaseSrv.save({}, $scope.newCase, function(data) {
CaseSrv.save({}, $scope.newCase, function (data) {
$state.go('app.case.details', {
caseId: data.id
});
$modalInstance.close();
}, function(response) {
}, function (response) {
$scope.pendingAsync = false;
AlertSrv.error('CaseCreationCtrl', response.data, response.status);
});
};

$scope.addTask = function(task) {
$scope.addTask = function (task) {
if ($scope.tasks.indexOf(task) === -1) {
$scope.tasks.push(task);
}
$scope.temp.task = '';
angular.element('.task-input').focus();
};

$scope.removeTask = function(task) {
$scope.removeTask = function (task) {
$scope.tasks = _.without($scope.tasks, task);
};

$scope.cancel = function() {
$scope.cancel = function () {
$modalInstance.dismiss();
};
}
Expand Down

0 comments on commit 465e4bd

Please sign in to comment.