mirror of https://github.com/MISP/MISP
new: [UI] Show tag description if tag belongs to taxonomy
parent
8c15ea14a8
commit
09258f9bd6
|
@ -1108,8 +1108,12 @@ class TagsController extends AppController
|
|||
$conditions['OR'][] = array('LOWER(Tag.name) LIKE' => $t);
|
||||
}
|
||||
} else {
|
||||
foreach ($tag as $k => $t) {
|
||||
$conditions['OR'][] = array('Tag.name' => $t);
|
||||
foreach ($tag as $t) {
|
||||
if (is_numeric($t)) {
|
||||
$conditions['OR'][] = ['Tag.id' => $t];
|
||||
} else {
|
||||
$conditions['OR'][] = array('Tag.name' => $t);
|
||||
}
|
||||
}
|
||||
}
|
||||
$tags = $this->Tag->find('all', array(
|
||||
|
|
|
@ -867,8 +867,18 @@ class GalaxyCluster extends AppModel
|
|||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $user
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getCluster($name, $user)
|
||||
{
|
||||
$isGalaxyTag = strpos($name, 'misp-galaxy:') === 0;
|
||||
if (!$isGalaxyTag) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($this->__clusterCache[$name])) {
|
||||
return $this->__clusterCache[$name];
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
);
|
||||
if (!empty($tag['Tag']['id'])) {
|
||||
$span_tag = sprintf(
|
||||
'<a href="%s" style="%s" class="%s" title="%s">%s</a>',
|
||||
'<a href="%s" style="%s" class="%s" title="%s" data-tag-id="%s">%s</a>',
|
||||
sprintf(
|
||||
'%s%s%s',
|
||||
$baseurl,
|
||||
|
@ -86,6 +86,7 @@
|
|||
$aStyle,
|
||||
$aClass,
|
||||
$aText,
|
||||
h($tag['Tag']['id']),
|
||||
isset($aTextModified) ? $aTextModified : $aText
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -5483,3 +5483,101 @@ $('body').on('click', '.hex-value-convert', function() {
|
|||
.attr('aria-label', 'Switch to binary representation');
|
||||
}
|
||||
});
|
||||
|
||||
(function() {
|
||||
var tagDataCache = {};
|
||||
function fetchTagInfo(tagId, callback) {
|
||||
if (tagId in tagDataCache) {
|
||||
callback(tagDataCache[tagId]);
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
success: function (data) {
|
||||
data = $.parseJSON(data);
|
||||
var tagData;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var tag = data[i];
|
||||
if (tag.Tag.id == tagId) {
|
||||
tagData = data[i]
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tagData !== undefined) {
|
||||
callback(tagData);
|
||||
tagDataCache[tagId] = tagData;
|
||||
}
|
||||
},
|
||||
type: "get",
|
||||
url: baseurl + "/tags/search/" + tagId + "/1/1"
|
||||
})
|
||||
}
|
||||
|
||||
function constructTaxonomyInfo(tagData) {
|
||||
var predicateText = tagData.TaxonomyPredicate.expanded;
|
||||
if (tagData.TaxonomyPredicate.TaxonomyEntry) {
|
||||
predicateText += ": " + tagData.TaxonomyPredicate.TaxonomyEntry[0].expanded;
|
||||
}
|
||||
|
||||
var $predicate = $('<div/>').append(
|
||||
$('<h3/>').css("margin-top", "5px").text('Tag info'),
|
||||
$('<p/>').css("margin-bottom", "5px").text(predicateText)
|
||||
);
|
||||
if (tagData.TaxonomyPredicate.description) {
|
||||
$predicate.append($('<p/>').css("margin-bottom", "5px").append(
|
||||
$('<strong/>').text('Description: '),
|
||||
$('<span/>').text(tagData.TaxonomyPredicate.description),
|
||||
));
|
||||
}
|
||||
if (tagData.TaxonomyPredicate.TaxonomyEntry && tagData.TaxonomyPredicate.TaxonomyEntry[0].numerical_value) {
|
||||
$predicate.append($('<p/>').css("margin-bottom", "5px").append(
|
||||
$('<strong/>').text('Numerical value: '),
|
||||
$('<span/>').text(tagData.TaxonomyPredicate.TaxonomyEntry[0].numerical_value),
|
||||
));
|
||||
}
|
||||
var $meta = $('<div/>').append(
|
||||
$('<h3/>').text('Taxonomy: ' + tagData.Taxonomy.namespace.toUpperCase()),
|
||||
$('<p/>').css("margin-bottom", "5px").append(
|
||||
$('<span/>').text(tagData.Taxonomy.description),
|
||||
)
|
||||
)
|
||||
return $('<div/>').append($predicate, $meta)
|
||||
}
|
||||
|
||||
var popoverDebounce = null;
|
||||
$(document.body).on({
|
||||
mouseover: function() {
|
||||
var $tag = $(this);
|
||||
popoverDebounce = setTimeout(function() {
|
||||
popoverDebounce = null;
|
||||
var tagId = $tag.data('tag-id');
|
||||
|
||||
fetchTagInfo(tagId, function (tagData) {
|
||||
if (tagData.TaxonomyPredicate === undefined) {
|
||||
return;
|
||||
}
|
||||
// Check if user cursor is still on tag
|
||||
if ($(':hover').last()[0] !== $tag[0]) {
|
||||
return;
|
||||
}
|
||||
$tag.popover({
|
||||
html: true,
|
||||
container: 'body',
|
||||
placement: 'top',
|
||||
template: '<div class="popover"><div class="arrow"></div><div class="popover-content"></div></div>',
|
||||
content: function () {
|
||||
return constructTaxonomyInfo(tagData);
|
||||
}
|
||||
}).popover('show');
|
||||
});
|
||||
}, 200);
|
||||
},
|
||||
mouseout: function() {
|
||||
if (popoverDebounce) {
|
||||
clearTimeout(popoverDebounce);
|
||||
popoverDebounce = null;
|
||||
}
|
||||
$(this).popover('destroy');
|
||||
}
|
||||
}, 'a.tag[data-tag-id]');
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue