Skip to content

Commit

Permalink
#1670 Add taxonomy tags selection in case and observable createion di…
Browse files Browse the repository at this point in the history
…alog + case template edition
  • Loading branch information
nadouani authored and rriclet committed Feb 23, 2021
1 parent a3aa6ed commit 761b996
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 71 deletions.
1 change: 1 addition & 0 deletions frontend/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
<script src="scripts/controllers/MigrationCtrl.js"></script>
<script src="scripts/controllers/misc/ResponderSelectorCtrl.js"></script>
<script src="scripts/controllers/misc/ServerInstanceDialogCtrl.js"></script>
<script src="scripts/controllers/misc/TaxonomySelectionModalCtrl.js"></script>
<script src="scripts/controllers/RootCtrl.js"></script>
<script src="scripts/controllers/SearchCtrl.js"></script>
<script src="scripts/controllers/SettingsCtrl.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

angular.module('theHiveComponents')
.component('orgCaseTemplateList', {
controller: function($uibModal, $scope, CaseTemplateSrv, TagSrv, UserSrv, AuthenticationSrv, NotificationSrv, UtilsSrv, ModalUtilsSrv) {
controller: function($uibModal, $scope, $filter, CaseTemplateSrv, TagSrv, UserSrv, TaxonomyCacheSrv, AuthenticationSrv, NotificationSrv, UtilsSrv, ModalUtilsSrv) {
var self = this;

self.task = '';
Expand Down Expand Up @@ -121,6 +121,40 @@
});
};

self.fromTagLibrary = function() {
var modalInstance = $uibModal.open({
controller: 'TaxonomySelectionModalCtrl',
controllerAs: '$modal',
animation: true,
templateUrl: 'views/partials/misc/taxonomy-selection.modal.html',
size: 'lg',
resolve: {
taxonomies: function() {
return TaxonomyCacheSrv.all();
}
}
});

modalInstance.result
.then(function(selectedTags) {
var filterFn = $filter('tagValue'),
tags = [];

_.each(selectedTags, function(tag) {
tags.push({
text: filterFn(tag)
});
});

self.tags = self.tags.concat(tags);
})
.catch(function(err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Tag selection', err.data, err.status);
}
});
};

self.newTemplate = function() {
self.template = {
name: '',
Expand Down
40 changes: 38 additions & 2 deletions frontend/app/scripts/controllers/case/CaseCreationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(function () {
'use strict';
angular.module('theHiveControllers').controller('CaseCreationCtrl',
function ($rootScope, $scope, $uibModalInstance, CaseSrv, NotificationSrv, TagSrv, template) {
function ($rootScope, $scope, $uibModal, $filter, $uibModalInstance, CaseSrv, TaxonomyCacheSrv, NotificationSrv, TagSrv, template) {

$rootScope.title = 'New case';
$scope.activeTlp = 'active';
Expand All @@ -18,6 +18,8 @@
$scope.template = template;
$scope.fromTemplate = angular.isDefined(template) && !_.isEqual($scope.template, {});

$scope.tags = [];

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

// Set basic info from template
Expand All @@ -37,7 +39,7 @@
$scope.tasks = _.map(template.tasks, function (t) {
return t.title;
});

} else {
$scope.tasks = [];
$scope.newCase = {
Expand Down Expand Up @@ -86,6 +88,40 @@
});
};

$scope.fromTagLibrary = function() {
var modalInstance = $uibModal.open({
controller: 'TaxonomySelectionModalCtrl',
controllerAs: '$modal',
animation: true,
templateUrl: 'views/partials/misc/taxonomy-selection.modal.html',
size: 'lg',
resolve: {
taxonomies: function() {
return TaxonomyCacheSrv.all();
}
}
});

modalInstance.result
.then(function(selectedTags) {
var filterFn = $filter('tagValue'),
tags = [];

_.each(selectedTags, function(tag) {
tags.push({
text: filterFn(tag)
});
});

$scope.tags = $scope.tags.concat(tags);
})
.catch(function(err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Tag selection', err.data, err.status);
}
});
};

$scope.addTask = function (task) {
if ($scope.tasks.indexOf(task) === -1) {
$scope.tasks.push(task);
Expand Down
36 changes: 35 additions & 1 deletion frontend/app/scripts/controllers/case/ObservableCreationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

angular.module('theHiveControllers').controller('ObservableCreationCtrl',
function($scope, $stateParams, $uibModalInstance, clipboard, CaseArtifactSrv, ObservableTypeSrv, NotificationSrv, TagSrv, params) {
function($scope, $stateParams, $uibModal, $uibModalInstance, $filter, TaxonomyCacheSrv, clipboard, CaseArtifactSrv, ObservableTypeSrv, NotificationSrv, TagSrv, params) {

$scope.activeTlp = 'active';
$scope.pendingAsync = false;
Expand Down Expand Up @@ -64,6 +64,40 @@
})), '', null, undefined).length;
};

$scope.fromTagLibrary = function() {
var modalInstance = $uibModal.open({
controller: 'TaxonomySelectionModalCtrl',
controllerAs: '$modal',
animation: true,
templateUrl: 'views/partials/misc/taxonomy-selection.modal.html',
size: 'lg',
resolve: {
taxonomies: function() {
return TaxonomyCacheSrv.all();
}
}
});

modalInstance.result
.then(function(selectedTags) {
var filterFn = $filter('tagValue'),
tags = [];

_.each(selectedTags, function(tag) {
tags.push({
text: filterFn(tag)
});
});

$scope.params.tags = $scope.params.tags.concat(tags);
})
.catch(function(err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Tag selection', err.data, err.status);
}
});
};

$scope.add = function(form) {
if (!form.$valid) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(function() {
'use strict';
angular.module('theHiveDirectives')
.controller('TaxonomySelectionModalCtrl', function($uibModalInstance, taxonomies) {
var self = this;

this.taxonomies = angular.copy(taxonomies);

this.formData = {
selectedTaxonomy: null,
selectedTags: null
};

this.addSelectedTags = function() {
if (!self.formData.selectedTaxonomy) {
return;
}

var selection = _.filter(self.formData.selectedTaxonomy.tags, function(tag) {
return tag.selected;
});

if (selection.length === 0) {
return;
}

$uibModalInstance.close(selection);
};

this.cancel = function() {
$uibModalInstance.dismiss();
};
});
})();
34 changes: 2 additions & 32 deletions frontend/app/scripts/directives/updatableTagList.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
(function() {
'use strict';
angular.module('theHiveDirectives')
.controller('UpdatableTagListModalCtrl', function($uibModalInstance, taxonomies) {
var self = this;

this.taxonomies = angular.copy(taxonomies);

this.formData = {
selectedTaxonomy: null,
selectedTags: null
};

this.addSelectedTags = function() {
if (!self.formData.selectedTaxonomy) {
return;
}

var selection = _.filter(self.formData.selectedTaxonomy.tags, function(tag) {
return tag.selected;
});

if (selection.length === 0) {
return;
}

$uibModalInstance.close(selection);
};

this.cancel = function() {
$uibModalInstance.dismiss();
};
})
.directive('updatableTagList', function(UtilsSrv, $uibModal, $filter, NotificationSrv, TaxonomyCacheSrv) {
return {
restrict: 'E',
Expand All @@ -53,10 +23,10 @@
this.state.type = 'library';

var modalInstance = $uibModal.open({
controller: 'UpdatableTagListModalCtrl',
controller: 'TaxonomySelectionModalCtrl',
controllerAs: '$modal',
animation: true,
templateUrl: 'views/directives/updatable-tag-list-modal.html',
templateUrl: 'views/partials/misc/taxonomy-selection.modal.html',
size: 'lg',
resolve: {
taxonomies: function() {
Expand Down
23 changes: 21 additions & 2 deletions frontend/app/views/components/org/case-template/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,29 @@ <h4 class="vpad10 text-primary">Case basic information</h4>
<div class="form-group">
<label class="col-md-3 control-label">Tags</label>
<div class="col-md-9">
<tags-input min-length="2" name="tags" ng-model="$vm.tags" placeholder="Tags" replace-spaces-with-dashes="false">
<tags-input class="ti-tag-selector" min-length="2" name="tags" ng-model="$vm.tags" placeholder="Tags" replace-spaces-with-dashes="false" template="views/directives/tag-input-item.html">
<auto-complete min-length="3" debounce-delay="400" source="$vm.getTags($query)"></auto-complete>
</tags-input>
<p class="help-block small vpad5">These will be the default case tags</p>

<div class="btn-toolbar mt-xxs">
<div class="btn-group btn-group-sm">
<span class="help-block small">
These will be the default case tags
</span>
</div>

<div class="btn-group btn-group-sm pull-right">
<button class="btn btn-sm btn-default" type="button" ng-click="$vm.fromTagLibrary()">
<i class="glyphicon glyphicon-plus"></i> Add from Library
</button>
</div>
</div>

<!-- <tags-input name="tagsInput" template="views/directives/tag-input-item.html" ng-model="params.tags" class="ti-input-sm ti-tag-selector" placeholder="Add tags" replace-spaces-with-dashes="false" min-length="2">
<auto-complete min-length="3" debounce-delay="400" source="getTags($query)"></auto-complete>
</tags-input> -->


</div>
</div>
<div class="form-group" ng-class="{ 'has-error' : templateEditForm.description.$invalid && !templateEditForm.description.$pristine }">
Expand Down
Loading

0 comments on commit 761b996

Please sign in to comment.