diff --git a/frontend/app/index.html b/frontend/app/index.html index 58448256be..3dba14c63f 100644 --- a/frontend/app/index.html +++ b/frontend/app/index.html @@ -261,6 +261,7 @@ + diff --git a/frontend/app/scripts/components/organisation/OrgCustomTagsListCmp.js b/frontend/app/scripts/components/organisation/OrgCustomTagsListCmp.js index 306008d0a9..a4b691f371 100644 --- a/frontend/app/scripts/components/organisation/OrgCustomTagsListCmp.js +++ b/frontend/app/scripts/components/organisation/OrgCustomTagsListCmp.js @@ -3,7 +3,7 @@ angular.module('theHiveComponents') .component('orgCustomTagsList', { - controller: function($uibModal, $scope, PaginatedQuerySrv, FilteringSrv, UserSrv, NotificationSrv, ModalUtilsSrv) { + controller: function($scope, PaginatedQuerySrv, FilteringSrv, TagSrv, UserSrv, NotificationSrv) { var self = this; self.tags = []; @@ -11,7 +11,7 @@ this.$onInit = function() { // TODO: FIXME - self.filtering = new FilteringSrv('taxonomy', 'custom-tags.list', { + self.filtering = new FilteringSrv('tag', 'custom-tags.list', { version: 'v1', defaults: { showFilters: true, @@ -59,6 +59,16 @@ }); }; + self.updateColour = function(id, colour) { + TagSrv.updateTag(id, {colour: colour}) + .then(function(/*response*/) { + NotificationSrv.success('Tag list', 'Tag colour updated successfully'); + }) + .catch(function(err) { + NotificationSrv.error('Tag list', err.data, err.status); + }) + } + // Filtering this.toggleFilters = function () { this.filtering.toggleFilters(); diff --git a/frontend/app/scripts/directives/tag-item.js b/frontend/app/scripts/directives/tag-item.js index 598bc7facc..c868207b61 100644 --- a/frontend/app/scripts/directives/tag-item.js +++ b/frontend/app/scripts/directives/tag-item.js @@ -5,7 +5,8 @@ restrict: 'E', replace: true, scope: { - value: '=' + value: '=', + colour: '=' }, templateUrl: 'views/directives/tag-item.html', link: function(scope/*, element, attrs*/) { @@ -14,7 +15,10 @@ } if(_.isString(scope.value)) { scope.tag = scope.value; - scope.bgColor = TaxonomyCacheSrv.getColour(scope.value) || '#3c8dbc'; + scope.bgColor = scope.colour || + TaxonomyCacheSrv.getColour(scope.value) || + TaxonomyCacheSrv.getColour('_freetags_:' + scope.value) || + '#3c8dbc'; } else { scope.tag = _.without([ scope.value.namespace, @@ -22,8 +26,15 @@ scope.value.predicate, scope.value.value ? ("=\"" + scope.value.value + "\"") : null ], null).join(''); - scope.bgColor = scope.value.colour || '#3c8dbc'; + scope.bgColor = scope.value.colour || scope.colour || '#3c8dbc'; } + + scope.$watch('colour', function(value) { + if(!value) { + return; + } + scope.bgColor = value; + }); } }; }); diff --git a/frontend/app/scripts/directives/updatableColour.js b/frontend/app/scripts/directives/updatableColour.js new file mode 100644 index 0000000000..1ffbda4fae --- /dev/null +++ b/frontend/app/scripts/directives/updatableColour.js @@ -0,0 +1,18 @@ +(function() { + 'use strict'; + angular.module('theHiveDirectives') + .directive('updatableColour', function(UtilsSrv) { + return { + 'restrict': 'E', + 'link': UtilsSrv.updatableLink, + 'templateUrl': 'views/directives/updatable-colour.html', + 'scope': { + 'value': '=?', + 'onUpdate': '&', + 'active': '=?', + 'placeholder': '@', + 'clearable': '' + } + }; + }); +})(); diff --git a/frontend/app/scripts/services/api/TagSrv.js b/frontend/app/scripts/services/api/TagSrv.js index 7d73604788..42016d5482 100644 --- a/frontend/app/scripts/services/api/TagSrv.js +++ b/frontend/app/scripts/services/api/TagSrv.js @@ -1,21 +1,14 @@ (function() { 'use strict'; angular.module('theHiveServices') - .service('TagSrv', function(QuerySrv, $q) { + .service('TagSrv', function(QuerySrv, $q, $http) { - var self = this; - - this.getTags = function(term) { + this.getFreeTags = function() { var defer = $q.defer(); var operations = [ { _name: 'listTag'}, { _name: 'freetags'}, - { _name: 'filter', _like: {_field: 'predicate', _value: term+'*'}}, - { _name: 'sort', _fields: [{'predicate': 'asc'}]}, - { _name: 'text'}, - // { _name: 'page', from: 0, to: 20}, - // { _name: 'text'} ] QuerySrv.query('v1', operations, { @@ -23,14 +16,16 @@ name: 'list-tags' } }).then(function(response) { - defer.resolve(_.map(response.data, function(tag) { - return {text: tag}; - })); + defer.resolve(response.data); }); return defer.promise; }; + this.updateTag = function(id, patch) { + return $http.patch('./api/v1/tag/' + id, patch); + } + this.autoComplete = function(term) { var defer = $q.defer(); diff --git a/frontend/app/scripts/services/api/TaxonomyCacheSrv.js b/frontend/app/scripts/services/api/TaxonomyCacheSrv.js index a6ba27916b..3fd425a248 100644 --- a/frontend/app/scripts/services/api/TaxonomyCacheSrv.js +++ b/frontend/app/scripts/services/api/TaxonomyCacheSrv.js @@ -1,7 +1,7 @@ (function() { 'use strict'; angular.module('theHiveServices') - .service('TaxonomyCacheSrv', function($http, $q, $filter, $uibModal, QuerySrv) { + .service('TaxonomyCacheSrv', function($http, $q, $filter, $uibModal, TagSrv, QuerySrv) { var self = this; this.cache = null; @@ -58,6 +58,14 @@ self.cacheTagColors(taxonomy.tags); }); + }) + .then(function() { + return TagSrv.getFreeTags(); + }) + .then(function(freeTags) { + self.cacheTagColors(freeTags); + + console.log(self.cache); deferred.resolve(self.cache); }); diff --git a/frontend/app/views/components/org/custom-tags/tag-list.html b/frontend/app/views/components/org/custom-tags/tag-list.html index 364e8b1d60..83a0dd1cf2 100644 --- a/frontend/app/views/components/org/custom-tags/tag-list.html +++ b/frontend/app/views/components/org/custom-tags/tag-list.html @@ -38,7 +38,7 @@