diff --git a/frontend/app/index.html b/frontend/app/index.html index 4768bf07e1..d244e6bc19 100644 --- a/frontend/app/index.html +++ b/frontend/app/index.html @@ -254,6 +254,7 @@ + @@ -276,6 +277,7 @@ + @@ -297,6 +299,7 @@ + diff --git a/frontend/app/scripts/directives/updatableTagList.js b/frontend/app/scripts/directives/updatableTagList.js new file mode 100644 index 0000000000..516de74754 --- /dev/null +++ b/frontend/app/scripts/directives/updatableTagList.js @@ -0,0 +1,91 @@ +(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', + link: UtilsSrv.updatableLink, + templateUrl: 'views/directives/updatable-tag-list.html', + scope: { + value: '=?', + onUpdate: '&', + active: '=?', + source: '=', + clearable: '' + }, + controllerAs: '$cmp', + controller: function($scope) { + this.state = { + type: null, + }; + + this.fromLibrary = function() { + this.state.type = 'library'; + + var modalInstance = $uibModal.open({ + controller: 'UpdatableTagListModalCtrl', + controllerAs: '$modal', + animation: true, + templateUrl: 'views/directives/updatable-tag-list-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.value = $scope.value.concat(tags); + }) + .catch(function(err) { + if (err && !_.isString(err)) { + NotificationSrv.error('Tag selection', err.data, err.status); + } + }); + }; + + } + }; + }); +})(); diff --git a/frontend/app/scripts/filters/tag-value.js b/frontend/app/scripts/filters/tag-value.js new file mode 100644 index 0000000000..d3ed8630d5 --- /dev/null +++ b/frontend/app/scripts/filters/tag-value.js @@ -0,0 +1,18 @@ +(function() { + 'use strict'; + + angular.module('theHiveFilters').filter('tagValue', function () { + return function (tag) { + if (!tag) { + return ''; + } + + return _.without([ + tag.namespace, + ':', + tag.predicate, + tag.value ? ("=\"" + tag.value + "\"") : null + ], null).join(''); + }; + }); +})(); diff --git a/frontend/app/scripts/services/api/TaxonomyCacheSrv.js b/frontend/app/scripts/services/api/TaxonomyCacheSrv.js new file mode 100644 index 0000000000..8fc04297aa --- /dev/null +++ b/frontend/app/scripts/services/api/TaxonomyCacheSrv.js @@ -0,0 +1,50 @@ +(function() { + 'use strict'; + angular.module('theHiveServices') + .service('TaxonomyCacheSrv', function($http, $q, QuerySrv) { + var self = this; + + this.cache = null; + + this.list = function() { + return QuerySrv.call('v1', [ + { _name: 'listTaxonomy' } + ], { + name:'list-taxonomies' + }, { + name: 'filter', + _field: 'enabled', + _value: true + }); + }; + + this.clearCache = function() { + self.cache = null; + }; + + this.getCache = function(name) { + return self.cache[name]; + }; + + this.all = function(reload) { + var deferred = $q.defer(); + + if (self.cache === null || reload === true) { + self.list() + .then(function(response) { + self.cache = {}; + + _.each(response, function(taxonomy) { + self.cache[taxonomy.namespace] = taxonomy; + }); + + deferred.resolve(self.cache); + }); + } else { + deferred.resolve(self.cache); + } + + return deferred.promise; + }; + }); +})(); diff --git a/frontend/app/views/directives/updatable-tag-list-modal.html b/frontend/app/views/directives/updatable-tag-list-modal.html new file mode 100644 index 0000000000..bab83eeaaf --- /dev/null +++ b/frontend/app/views/directives/updatable-tag-list-modal.html @@ -0,0 +1,53 @@ +
diff --git a/frontend/app/views/directives/updatable-tag-list.html b/frontend/app/views/directives/updatable-tag-list.html new file mode 100644 index 0000000000..83a59e3e15 --- /dev/null +++ b/frontend/app/views/directives/updatable-tag-list.html @@ -0,0 +1,37 @@ + diff --git a/frontend/app/views/partials/case/case.details.html b/frontend/app/views/partials/case/case.details.html index bb252c4fd4..c1f873355e 100644 --- a/frontend/app/views/partials/case/case.details.html +++ b/frontend/app/views/partials/case/case.details.html @@ -71,7 +71,7 @@