Skip to content

Commit

Permalink
#1670 Update tags filters, bulk edit modals and case template forms t…
Browse files Browse the repository at this point in the history
…o support taxonomy tags selection
  • Loading branch information
nadouani authored and rriclet committed Feb 23, 2021
1 parent 761b996 commit 847809d
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 158 deletions.
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, $filter, CaseTemplateSrv, TagSrv, UserSrv, TaxonomyCacheSrv, AuthenticationSrv, NotificationSrv, UtilsSrv, ModalUtilsSrv) {
controller: function($uibModal, $scope, CaseTemplateSrv, TagSrv, UserSrv, TaxonomyCacheSrv, AuthenticationSrv, NotificationSrv, UtilsSrv, ModalUtilsSrv) {
var self = this;

self.task = '';
Expand Down Expand Up @@ -122,37 +122,10 @@
};

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)
});
});

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

self.newTemplate = function() {
Expand Down
33 changes: 3 additions & 30 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, $uibModal, $filter, $uibModalInstance, CaseSrv, TaxonomyCacheSrv, NotificationSrv, TagSrv, template) {
function ($rootScope, $scope, $uibModalInstance, CaseSrv, TaxonomyCacheSrv, NotificationSrv, TagSrv, template) {

$rootScope.title = 'New case';
$scope.activeTlp = 'active';
Expand Down Expand Up @@ -89,37 +89,10 @@
};

$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)
});
});

TaxonomyCacheSrv.openTagLibrary()
.then(function(tags){
$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) {
Expand Down
15 changes: 14 additions & 1 deletion frontend/app/scripts/controllers/case/CaseUpdateCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveControllers').controller('CaseUpdateCtrl',
function($scope, $uibModalInstance, TagSrv, selection) {
function($scope, $uibModalInstance, TagSrv, TaxonomyCacheSrv, selection) {
var self = this;

this.selection = selection;
Expand Down Expand Up @@ -137,6 +137,19 @@
return TagSrv.fromCases(query);
};

self.fromTagLibrary = function(field) {
TaxonomyCacheSrv.openTagLibrary()
.then(function(tags){
if(field === 'add') {
self.params.addTags = (self.params.addTags || []).concat(tags);
self.toggleAddTags();
} else if (field === 'remove') {
self.params.removeTags = (self.params.removeTags || []).concat(tags);
self.toggleRemoveTags();
}
})
};

this.toggleTlp = function(value) {
this.params.tlp = value;
this.activeTlp = 'active';
Expand Down
33 changes: 3 additions & 30 deletions 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, $uibModal, $uibModalInstance, $filter, TaxonomyCacheSrv, clipboard, CaseArtifactSrv, ObservableTypeSrv, NotificationSrv, TagSrv, params) {
function($scope, $stateParams, $uibModalInstance, TaxonomyCacheSrv, clipboard, CaseArtifactSrv, ObservableTypeSrv, NotificationSrv, TagSrv, params) {

$scope.activeTlp = 'active';
$scope.pendingAsync = false;
Expand Down Expand Up @@ -65,37 +65,10 @@
};

$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)
});
});

TaxonomyCacheSrv.openTagLibrary()
.then(function(tags){
$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) {
Expand Down
15 changes: 14 additions & 1 deletion frontend/app/scripts/controllers/case/ObservableUpdateCtrl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveControllers').controller('ObservableUpdateCtrl',
function($scope, $uibModalInstance, TagSrv, selection) {
function($scope, $uibModalInstance, TagSrv, TaxonomyCacheSrv, selection) {
var self = this;

this.selection = selection;
Expand Down Expand Up @@ -140,6 +140,19 @@
return TagSrv.fromObservables(query);
};

self.fromTagLibrary = function(field) {
TaxonomyCacheSrv.openTagLibrary()
.then(function(tags){
if(field === 'add') {
self.params.addTags = (self.params.addTags || []).concat(tags);
self.toggleAddTags();
} else if (field === 'remove') {
self.params.removeTags = (self.params.removeTags || []).concat(tags);
self.toggleRemoveTags();
}
})
};

this.toogleIoc = function() {
this.params.ioc = !this.params.ioc;
this.state.enableIoc = true;
Expand Down
9 changes: 8 additions & 1 deletion frontend/app/scripts/directives/dashboard/filter-editor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
'use strict';
angular.module('theHiveDirectives').directive('filterEditor', function($q, AuthenticationSrv, UserSrv, TagSrv, UtilsSrv) {
angular.module('theHiveDirectives').directive('filterEditor', function($q, AuthenticationSrv, TaxonomyCacheSrv, UserSrv, TagSrv, UtilsSrv) {
return {
restrict: 'E',
scope: {
Expand Down Expand Up @@ -64,6 +64,13 @@
return filter.type;
};

scope.fromTagLibrary = function(filter) {
TaxonomyCacheSrv.openTagLibrary()
.then(function(tags){
filter.value.list = filter.value.list.concat(tags);
})
}

scope.promiseFor = function(filter, query) {
var field = scope.metadata[scope.entity].attributes[filter.field];

Expand Down
42 changes: 41 additions & 1 deletion frontend/app/scripts/services/api/TaxonomyCacheSrv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices')
.service('TaxonomyCacheSrv', function($http, $q, $filter, QuerySrv) {
.service('TaxonomyCacheSrv', function($http, $q, $filter, $uibModal, QuerySrv) {
var self = this;

this.cache = null;
Expand Down Expand Up @@ -67,5 +67,45 @@

return deferred.promise;
};

self.openTagLibrary = function() {
var defer = $q.defer();

var modalInstance = $uibModal.open({
controller: 'TaxonomySelectionModalCtrl',
controllerAs: '$modal',
animation: true,
templateUrl: 'views/partials/misc/taxonomy-selection.modal.html',
size: 'lg',
resolve: {
taxonomies: function() {
return self.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);
defer.resolve(tags);
})
.catch(function(err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Tag selection', err.data, err.status);
}
defer.rejeect(err);
});

return defer.promise;
};
});
})();
20 changes: 17 additions & 3 deletions frontend/app/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -788,11 +788,11 @@ tags-input.ti-tag-selector .tags .tag-item {
border: none;
padding: 0;
padding-right: 5px;
line-height: 22px;
line-height: 26px;
}

tags-input.ti-tag-selector .tags .tag-item ti-tag-item{

tags-input.ti-tag-selector.ti-input-sm .tags .tag-item {
line-height: 22px;
}

tags-input.ti-tag-selector .tags .tag-item span.tag-item-border{
Expand All @@ -804,3 +804,17 @@ tags-input.ti-tag-selector .tags .tag-item span.tag-item-border{
border-top-left-radius: .25em;
border-bottom-left-radius: .25em;
}

tags-input.ti-tag-selector.ti-input-sm .tags .tag-item span.tag-item-border{
position: relative;
left:0;
width: 8px;
background-color: red;
display: inline-block;
border-top-left-radius: .25em;
border-bottom-left-radius: .25em;
}

.vtop {
vertical-align: top;
}
29 changes: 9 additions & 20 deletions frontend/app/views/components/org/case-template/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,18 @@ <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 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>
<div class="input-group">
<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>

<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
<span class="input-group-btn vtop">
<button type="button" class="btn btn-block btn-primary" ng-click="$vm.fromTagLibrary()" uib-tooltip="Add tag from library" tooltip-placement="left">
<span class="fa fa-plus"></span>
</button>
</div>
</span>
</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> -->


<p class="help-block small">These will be the default case tags</p>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error' : templateEditForm.description.$invalid && !templateEditForm.description.$pristine }">
Expand Down
19 changes: 14 additions & 5 deletions frontend/app/views/directives/dashboard/filter-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@
</ul>
</div>
<div class="col-xs-10 pl-xxxs clear">
<tags-input class="form-control-wrapper"
ng-model="filter.value.list"
placeholder="ex: Enter a tag"
replace-spaces-with-dashes="false">
<auto-complete source="promiseFor(filter, $query)" min-length="3" debounce-delay="400"></auto-complete>
<div class="input-group">
<tags-input class="form-control-wrapper ti-tag-selector"
ng-model="filter.value.list"
placeholder="ex: Enter a tag"
replace-spaces-with-dashes="false"
template="views/directives/tag-input-item.html">
<auto-complete source="promiseFor(filter, $query)" min-length="3" debounce-delay="400"></auto-complete>
</tags-input>

<span class="input-group-btn vtop">
<button type="button" class="btn btn-block btn-default" ng-click="fromTagLibrary(filter)" uib-tooltip="Add tag from library" tooltip-placement="left">
<span class="fa fa-plus"></span>
</button>
</span>
</div>
</div>
</div>

Expand Down
Loading

0 comments on commit 847809d

Please sign in to comment.