Skip to content

Commit

Permalink
#1869 Improve the way default tag colour is taken into account
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Mar 26, 2021
1 parent 5eb03de commit 8779cdc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 47 deletions.
26 changes: 15 additions & 11 deletions frontend/app/scripts/directives/tag-item.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
(function () {
'use strict';
angular.module('theHiveDirectives').directive('tagItem', function(TaxonomyCacheSrv) {
angular.module('theHiveDirectives').directive('tagItem', function (TaxonomyCacheSrv, TagSrv) {
return {
restrict: 'E',
replace: true,
Expand All @@ -9,15 +9,16 @@
colour: '='
},
templateUrl: 'views/directives/tag-item.html',
link: function(scope/*, element, attrs*/) {
if(!scope.value) {
link: function (scope/*, element, attrs*/) {
if (!scope.value) {
return;
}
if(_.isString(scope.value)) {
if (_.isString(scope.value)) {
scope.tag = scope.value;
scope.bgColor = scope.colour ||
TaxonomyCacheSrv.getColour(scope.value) ||
TaxonomyCacheSrv.getColour('_freetags_:' + scope.value) ||
TagSrv.tagsDefaultColour ||
'#000000';
} else {
scope.tag = _.without([
Expand All @@ -26,22 +27,25 @@
scope.value.predicate,
scope.value.value ? ("=\"" + scope.value.value + "\"") : null
], null).join('');
scope.bgColor = scope.value.colour || scope.colour || '#000000';
scope.bgColor = scope.value.colour ||
scope.colour ||
TagSrv.tagsDefaultColour ||
'#000000';
}

scope.$watch('colour', function(value) {
if(!value) {
scope.$watch('colour', function (value) {
if (!value) {
return;
}
scope.bgColor = value;
});

scope.$watch('value', function(value) {
if(!value) {
scope.$watch('value', function (value) {
if (!value) {
return;
}

if(_.isString(value)) {
if (_.isString(value)) {
scope.tag = value;
} else {
scope.tag = _.without([
Expand Down
6 changes: 6 additions & 0 deletions frontend/app/scripts/services/api/TagSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
angular.module('theHiveServices')
.service('TagSrv', function (QuerySrv, $q, VersionSrv, $http) {

var self = this;

this.tagsDefaultColour = '#000000';

this.getFreeTags = function () {
var defer = $q.defer();

VersionSrv.get()
.then(function (appConfig) {
var defaultColour = appConfig.config.freeTagDefaultColour;

self.tagsDefaultColour = defaultColour;

return QuerySrv.query('v1', [
{ _name: 'listTag' },
{ _name: 'freetags' },
Expand Down
42 changes: 21 additions & 21 deletions frontend/app/scripts/services/api/TaxonomyCacheSrv.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
(function() {
(function () {
'use strict';
angular.module('theHiveServices')
.service('TaxonomyCacheSrv', function($http, $q, $filter, $uibModal, TagSrv, QuerySrv) {
.service('TaxonomyCacheSrv', function ($http, $q, $filter, $uibModal, VersionSrv, TagSrv, QuerySrv) {
var self = this;

this.cache = null;
this.tagsCache = null;

this.list = function() {
this.list = function () {
return QuerySrv.call('v1', [
{ _name: 'listTaxonomy' }
], {
name:'list-taxonomies'
name: 'list-taxonomies'
}, {
name: 'filter',
_field: 'enabled',
_value: true
});
};

this.clearCache = function() {
this.clearCache = function () {
self.cache = null;
self.tagsCache = null;
};

this.getCache = function(name) {
this.getCache = function (name) {
return self.cache[name];
};

this.getColour = function(tag) {
this.getColour = function (tag) {
return self.tagsCache[tag];
};

this.cacheTagColors = function(tags) {
this.cacheTagColors = function (tags) {
var fn = $filter('tagValue');

_.each(tags, function(tag) {
_.each(tags, function (tag) {
var name = fn(tag);

if(!_.isEmpty(name)) {
self.tagsCache[name] = tag.colour;
if (!_.isEmpty(name)) {
self.tagsCache[name] = tag.colour;
}
});
};

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

if (self.cache === null || reload === true) {
self.list()
.then(function(response) {
.then(function (response) {
self.cache = {};
self.tagsCache = {};

_.each(response, function(taxonomy) {
_.each(response, function (taxonomy) {
self.cache[taxonomy.namespace] = taxonomy;

self.cacheTagColors(taxonomy.tags);
});
})
.then(function() {
.then(function () {
return TagSrv.getFreeTags();
})
.then(function(freeTags) {
.then(function (freeTags) {
self.cacheTagColors(freeTags);

deferred.resolve(self.cache);
Expand All @@ -74,7 +74,7 @@
return deferred.promise;
};

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

var modalInstance = $uibModal.open({
Expand All @@ -84,18 +84,18 @@
templateUrl: 'views/partials/misc/taxonomy-selection.modal.html',
size: 'lg',
resolve: {
taxonomies: function() {
taxonomies: function () {
return self.all();
}
}
});

modalInstance.result
.then(function(selectedTags) {
.then(function (selectedTags) {
var filterFn = $filter('tagValue'),
tags = [];

_.each(selectedTags, function(tag) {
_.each(selectedTags, function (tag) {
tags.push({
text: filterFn(tag)
});
Expand All @@ -104,7 +104,7 @@
//$scope.tags = $scope.tags.concat(tags);
defer.resolve(tags);
})
.catch(function(err) {
.catch(function (err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Tag selection', err.data, err.status);
}
Expand Down
7 changes: 3 additions & 4 deletions frontend/app/views/partials/admin/taxonomy/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ <h3 class="modal-title">{{::$modal.taxonomy.namespace}} taxonomy</h3>
<tbody>
<tr ng-repeat="tag in $modal.taxonomy.tags">
<td>
<span class="label">
<tag value="tag"></tag>
</span>
<tag-item class="label-lg" value="tag"></tag-item>
</td>
<td>{{::tag.predicate}}</td>
<td>{{::tag.value || '-'}}</td>
<td>{{::tag.colour}}</td>
<td>
<span ng-if="::tag.description" uib-tooltip="{{::tag.description}}" tooltip-placement="left">
<span ng-if="::tag.description" uib-tooltip="{{::tag.description}}"
tooltip-placement="left">
<i class="fa fa-question-circle"></i>
</span>
</td>
Expand Down
30 changes: 19 additions & 11 deletions frontend/app/views/partials/misc/taxonomy-selection.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ <h3 class="modal-title">Select tags from library</h3>
<div ng-if="$modal.formData.selectedTags.length > 0">
<div class="empty-message">
<div class="tags-list flexwrap">
<tag-item ng-repeat="tag in $modal.formData.selectedTags track by $index"
value="tag" class="clickable" ng-click="$modal.selectTag(tag)"></tag-item>
<tag-item ng-repeat="tag in $modal.formData.selectedTags track by $index" value="tag"
class="clickable" ng-click="$modal.selectTag(tag)"></tag-item>
</div>
</div>
<p class="help-block">Click on a tag to unselect it</p>
Expand All @@ -32,9 +32,11 @@ <h3 class="modal-title">Select tags from library</h3>
<div class="list-group">
<a href class="list-group-item" ng-repeat="taxonomy in $modal.taxonomies"
ng-click="$modal.selectTaxonomy(taxonomy)" class="clearfix">
<span class="badge" uib-tooltip="{{taxonomy.description}}" tooltip-placement="left" tooltip-append-to-body="true"><i class="fa fa-question"></i></span>
<span class="badge" uib-tooltip="{{taxonomy.description}}" tooltip-placement="left"
tooltip-append-to-body="true"><i class="fa fa-question"></i></span>
<span>{{taxonomy.namespace}} </span>
<small class="pull-right mr-m"><em class="text-muted">({{taxonomy.tags.length || 0}} tags)</em></small>
<small class="pull-right mr-m"><em class="text-muted">({{taxonomy.tags.length || 0}}
tags)</em></small>
</a>
</div>
</div>
Expand All @@ -44,38 +46,44 @@ <h3 class="modal-title">Select tags from library</h3>
<label>
Choose tags from taxonomy: {{$modal.formData.selectedTaxonomy.namespace}}
</label>
<a class="pull-right" href ng-click="$modal.formData.selectedTaxonomy = undefined">Show all taxonomies</a>
<a class="pull-right" href ng-click="$modal.formData.selectedTaxonomy = undefined">Show all
taxonomies</a>
</div>

<div class="row mb-xxs">
<div class="col-sm-12">
<div class="has-feedback">
<input type="text" ng-model="$modal.search" class="form-control" placeholder="Filter tags" autofocus>
<input type="text" ng-model="$modal.search" class="form-control" placeholder="Filter tags"
autofocus>
<span class="glyphicon glyphicon-search form-control-feedback"></span>
</div>
</div>
</div>

<div style="height: 300px; max-height: 300px; overflow-y: scroll;">
<div class="list-group">
<a href class="list-group-item" ng-repeat="tag in $modal.formData.selectedTaxonomy.tags | filter:$modal.search"
<a href class="list-group-item"
ng-repeat="tag in $modal.formData.selectedTaxonomy.tags | filter:$modal.search"
ng-click="$modal.selectTag(tag)">
<span class="mr-xs" ng-class="{'text-primary': !!tag.selected, 'text-disabled': !!!tag.selected}">
<span class="mr-xs"
ng-class="{'text-primary': !!tag.selected, 'text-disabled': !!!tag.selected}">
<i class="fa fa-check"></i>
</span>

<span class="badge" ng-if="::tag.description" uib-tooltip="{{::tag.description}}" tooltip-placement="left" tooltip-append-to-body="true">
<span class="badge" ng-if="::tag.description" uib-tooltip="{{::tag.description}}"
tooltip-placement="left" tooltip-append-to-body="true">
<i class="fa fa-question"></i>
</span>

<tag value="tag"></tag>
<tag-item value="tag"></tag-item>
</a>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default pull-left" type="button" ng-click="$modal.cancel()">Cancel</button>
<button class="btn btn-primary pull-right" type="submit" ng-disabled="$modal.formData.selectedTags === 0">Add Selected tags</button>
<button class="btn btn-primary pull-right" type="submit" ng-disabled="$modal.formData.selectedTags === 0">Add
Selected tags</button>
</div>
</form>

0 comments on commit 8779cdc

Please sign in to comment.