Skip to content

Commit

Permalink
#1950 Use tag colour in tag-list component and refresh custom tags ca…
Browse files Browse the repository at this point in the history
…che on tag update
  • Loading branch information
nadouani committed Apr 9, 2021
1 parent 4e1e25a commit df58be8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(function() {
(function () {
'use strict';

angular.module('theHiveComponents')
.component('orgCustomTagsList', {
controller: function($scope, PaginatedQuerySrv, FilteringSrv, TagSrv, UserSrv, ModalUtilsSrv, NotificationSrv) {
controller: function ($scope, PaginatedQuerySrv, FilteringSrv, TaxonomyCacheSrv, TagSrv, UserSrv, ModalUtilsSrv, NotificationSrv) {
var self = this;

self.tags = [];
self.getUserInfo = UserSrv.getCache;

this.$onInit = function() {
this.$onInit = function () {
// TODO: FIXME
self.filtering = new FilteringSrv('tag', 'custom-tags.list', {
version: 'v1',
Expand All @@ -23,7 +23,7 @@
});

self.filtering.initContext(self.organisation.name)
.then(function() {
.then(function () {
self.load();

$scope.$watch('$vm.list.pageSize', function (newValue) {
Expand All @@ -32,7 +32,7 @@
});
};

this.load = function() {
this.load = function () {

self.list = new PaginatedQuerySrv({
name: 'organisation-custom-tags',
Expand All @@ -48,8 +48,8 @@
}
],
extraData: ['usage'],
onFailure: function(err) {
if(err && err.status === 400) {
onFailure: function (err) {
if (err && err.status === 400) {
self.filtering.resetContext();
self.load();
}
Expand All @@ -74,22 +74,24 @@
});
};

self.updateColour = function(id, colour) {
TagSrv.updateTag(id, {colour: colour})
.then(function(/*response*/) {
self.updateColour = function (id, colour) {
TagSrv.updateTag(id, { colour: colour })
.then(function (/*response*/) {
NotificationSrv.success('Tag colour updated successfully');
TaxonomyCacheSrv.refreshFreeTags();
})
.catch(function(err) {
.catch(function (err) {
NotificationSrv.error('Tag list', err.data, err.status);
})
}

self.updateTag = function(id, value) {
TagSrv.updateTag(id, {predicate: value})
.then(function(/*response*/) {
self.updateTag = function (id, value) {
TagSrv.updateTag(id, { predicate: value })
.then(function (/*response*/) {
NotificationSrv.success('Tag value updated successfully');
TaxonomyCacheSrv.refreshFreeTags();
})
.catch(function(err) {
.catch(function (err) {
NotificationSrv.error('Tag list', err.data, err.status);
})
}
Expand Down Expand Up @@ -122,28 +124,28 @@
this.search();
};

this.filterBy = function(field, value) {
this.filterBy = function (field, value) {
self.filtering.clearFilters()
.then(function(){
.then(function () {
self.addFilterValue(field, value);
});
};

this.sortBy = function(sort) {
this.sortBy = function (sort) {
self.list.sort = sort;
self.list.update();
self.filtering.setSort(sort);
};

this.sortByField = function(field) {
this.sortByField = function (field) {
var context = this.filtering.context;
var currentSort = Array.isArray(context.sort) ? context.sort[0] : context.sort;
var sort = null;

if(currentSort.substr(1) !== field) {
if (currentSort.substr(1) !== field) {
sort = ['+' + field];
} else {
sort = [(currentSort === '+' + field) ? '-'+field : '+'+field];
sort = [(currentSort === '+' + field) ? '-' + field : '+' + field];
}

self.list.sort = sort;
Expand Down
15 changes: 9 additions & 6 deletions frontend/app/scripts/directives/tag-colour.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
(function() {
(function () {
'use strict';
angular.module('theHiveDirectives').directive('tagColour', function($timeout, TaxonomyCacheSrv) {
angular.module('theHiveDirectives').directive('tagColour', function ($timeout, TaxonomyCacheSrv, TagSrv) {
return {
restrict: 'A',
scope: {
tag: '='
},
link: function(scope, element/*, attrs*/) {
if(!scope.tag) {
link: function (scope, element/*, attrs*/) {
if (!scope.tag) {
return;
}

scope.bgColour = TaxonomyCacheSrv.getColour(scope.tag) || TaxonomyCacheSrv.getColour('_freetags_:' + scope.tag) || '#3c8dbc';
scope.bgColour = TaxonomyCacheSrv.getColour(scope.tag) ||
TaxonomyCacheSrv.getColour('_freetags_:' + scope.tag) ||
TagSrv.tagsDefaultColour ||
'#000000';

$timeout(function() {
$timeout(function () {
angular.element(element[0]).attr('style', 'background-color:' + scope.bgColour);
});
}
Expand Down
7 changes: 7 additions & 0 deletions frontend/app/scripts/services/api/TaxonomyCacheSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
});
};

this.refreshFreeTags = function () {
return TagSrv.getFreeTags()
.then(function (freeTags) {
self.cacheTagColors(freeTags);
});
}

this.all = function (reload) {
var deferred = $q.defer();

Expand Down

0 comments on commit df58be8

Please sign in to comment.