diff --git a/frontend/app/index.html b/frontend/app/index.html index dfdb2865af..61bbbc08cb 100644 --- a/frontend/app/index.html +++ b/frontend/app/index.html @@ -247,6 +247,8 @@ + + diff --git a/frontend/app/scripts/app.js b/frontend/app/scripts/app.js index 9676fea0b4..581b5bf4bd 100644 --- a/frontend/app/scripts/app.js +++ b/frontend/app/scripts/app.js @@ -116,6 +116,9 @@ angular.module('thehive', [ }, uiConfig: function($q, UiSettingsSrv) { return UiSettingsSrv.all(); + }, + taxonomyCache: function(TaxonomyCacheSrv) { + return TaxonomyCacheSrv.all(); } } }) diff --git a/frontend/app/scripts/directives/tag-colour.js b/frontend/app/scripts/directives/tag-colour.js new file mode 100644 index 0000000000..10e62b5ad7 --- /dev/null +++ b/frontend/app/scripts/directives/tag-colour.js @@ -0,0 +1,22 @@ +(function() { + 'use strict'; + angular.module('theHiveDirectives').directive('tagColour', function($timeout, TaxonomyCacheSrv) { + return { + restrict: 'A', + scope: { + tag: '=' + }, + link: function(scope, element/*, attrs*/) { + if(!scope.tag) { + return; + } + + scope.bgColour = TaxonomyCacheSrv.getColour(scope.tag) || '#3c8dbc'; + + $timeout(function() { + angular.element(element[0]).attr('style', 'background-color:' + scope.bgColour); + }); + } + }; + }); +})(); diff --git a/frontend/app/scripts/directives/tag-item.js b/frontend/app/scripts/directives/tag-item.js new file mode 100644 index 0000000000..598bc7facc --- /dev/null +++ b/frontend/app/scripts/directives/tag-item.js @@ -0,0 +1,31 @@ +(function() { + 'use strict'; + angular.module('theHiveDirectives').directive('tagItem', function(TaxonomyCacheSrv) { + return { + restrict: 'E', + replace: true, + scope: { + value: '=' + }, + templateUrl: 'views/directives/tag-item.html', + link: function(scope/*, element, attrs*/) { + if(!scope.value) { + return; + } + if(_.isString(scope.value)) { + scope.tag = scope.value; + scope.bgColor = TaxonomyCacheSrv.getColour(scope.value) || '#3c8dbc'; + } else { + scope.tag = _.without([ + scope.value.namespace, + ':', + scope.value.predicate, + scope.value.value ? ("=\"" + scope.value.value + "\"") : null + ], null).join(''); + scope.bgColor = scope.value.colour || '#3c8dbc'; + } + } + }; + }); + +})(); diff --git a/frontend/app/scripts/services/api/TaxonomyCacheSrv.js b/frontend/app/scripts/services/api/TaxonomyCacheSrv.js index 8fc04297aa..d68a65ab70 100644 --- a/frontend/app/scripts/services/api/TaxonomyCacheSrv.js +++ b/frontend/app/scripts/services/api/TaxonomyCacheSrv.js @@ -1,10 +1,11 @@ (function() { 'use strict'; angular.module('theHiveServices') - .service('TaxonomyCacheSrv', function($http, $q, QuerySrv) { + .service('TaxonomyCacheSrv', function($http, $q, $filter, QuerySrv) { var self = this; this.cache = null; + this.tagsCache = null; this.list = function() { return QuerySrv.call('v1', [ @@ -20,12 +21,29 @@ this.clearCache = function() { self.cache = null; + self.tagsCache = null; }; this.getCache = function(name) { return self.cache[name]; }; + this.getColour = function(tag) { + return self.tagsCache[tag]; + }; + + this.cacheTagColors = function(tags) { + var fn = $filter('tagValue'); + + _.each(tags, function(tag) { + var name = fn(tag); + + if(!_.isEmpty(name)) { + self.tagsCache[name] = tag.colour; + } + }); + }; + this.all = function(reload) { var deferred = $q.defer(); @@ -33,9 +51,12 @@ self.list() .then(function(response) { self.cache = {}; + self.tagsCache = {}; _.each(response, function(taxonomy) { self.cache[taxonomy.namespace] = taxonomy; + + self.cacheTagColors(taxonomy.tags); }); deferred.resolve(self.cache); diff --git a/frontend/app/styles/main.css b/frontend/app/styles/main.css index cacda48614..4f46e49eff 100644 --- a/frontend/app/styles/main.css +++ b/frontend/app/styles/main.css @@ -779,3 +779,28 @@ table.tbody-stripped > tbody > tr > td { overflow: hidden; text-overflow: ellipsis; } + +/* Customise tags input */ + +tags-input.ti-tag-selector .tags .tag-item { + background-color: #d2d6de; + color: #444; + border: none; + padding: 0; + padding-right: 5px; + line-height: 22px; +} + +tags-input.ti-tag-selector .tags .tag-item ti-tag-item{ + +} + +tags-input.ti-tag-selector .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; +} diff --git a/frontend/app/views/components/common/tag.component.html b/frontend/app/views/components/common/tag.component.html index a5da190b79..c52f5c9b2b 100644 --- a/frontend/app/views/components/common/tag.component.html +++ b/frontend/app/views/components/common/tag.component.html @@ -1 +1 @@ -{{$ctrl.tag}} +{{$ctrl.tag}} diff --git a/frontend/app/views/directives/flow/alert.html b/frontend/app/views/directives/flow/alert.html index 1941efcc91..c6cb860356 100644 --- a/frontend/app/views/directives/flow/alert.html +++ b/frontend/app/views/directives/flow/alert.html @@ -42,7 +42,7 @@