mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-09-17 15:27:43 +02:00
116 lines
4.1 KiB
JavaScript
116 lines
4.1 KiB
JavaScript
var vulnerabilitySearchWrapper = document.querySelector("#vulnerability-search-input");
|
|
var vulnerabilityInputBox = vulnerabilitySearchWrapper.querySelector("input");
|
|
var vulnerabilitySuggBox = vulnerabilitySearchWrapper.querySelector(".autocom-box");
|
|
var vulnerability_filter_icon = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-filter"><polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"></polygon></svg>`;
|
|
|
|
var vulnerability_col_suggestions = [
|
|
'name',
|
|
"severity",
|
|
"tags",
|
|
"status",
|
|
"description"
|
|
];
|
|
|
|
var vulnerability_condition_suggestions = [
|
|
"=",
|
|
"!"
|
|
];
|
|
|
|
var vulnerability_joiner = [
|
|
"&",
|
|
"|"
|
|
];
|
|
|
|
var vulnerability_suggestion_selector = vulnerability_col_suggestions;
|
|
|
|
vulnerabilityInputBox.onclick = (event) => {
|
|
emptyArray = vulnerability_suggestion_selector.filter((data)=>{
|
|
return data.toLocaleLowerCase();
|
|
});
|
|
badge_color = "warning";
|
|
emptyArray = emptyArray.map((data)=>{
|
|
switch (data) {
|
|
case "=":
|
|
title = `Filters vulnerability <span class="badge badge-success">Equals</span> Some Value`;
|
|
break;
|
|
case "!":
|
|
title = `Filters vulnerability <span class="badge badge-danger">Not Equals</span> Some Value`;
|
|
break;
|
|
case ">":
|
|
title = `Filters vulnerability <span class="badge badge-dark">Greater than</span> Some Value`;
|
|
break;
|
|
case "<":
|
|
title = `Filters vulnerability <span class="badge badge-dark">Less than</span> Some Value`;
|
|
break;
|
|
case "&":
|
|
title = `<span class="badge badge-danger">& and</span> Match vulnerability if <span class="badge badge-danger">all args</span> are true`;
|
|
break;
|
|
case "|":
|
|
title = `<span class="badge badge-warning">| or</span> Match vulnerability if <span class="badge badge-warning">either of one</span> is true`;
|
|
break;
|
|
default:
|
|
badge_color = "info";
|
|
title = `Filter vulnerability that contains <span class="badge badge-dark">${data}</span>`;
|
|
}
|
|
return data = `<li id="dropdown-li" class="text-dark"><div class="row"><div class="col-6" id="filter_name"><span class="text-${badge_color}">${vulnerability_filter_icon}</span>${data}</div><div class="col-6 text-dark" id="filter_name"> ${title}</span></div></div></li>`;
|
|
});
|
|
|
|
vulnerabilitySearchWrapper.classList.add("active");
|
|
vulnerability_showSuggestions(emptyArray);
|
|
let allList = vulnerabilitySuggBox.querySelectorAll("li");
|
|
for (let i = 0; i < allList.length; i++) {
|
|
allList[i].setAttribute("onclick", "vulnerability_select(this)");
|
|
}
|
|
}
|
|
|
|
function vulnerability_showSuggestions(list){
|
|
let listData;
|
|
listData = list.join('');
|
|
vulnerabilitySuggBox.innerHTML = listData;
|
|
}
|
|
|
|
function vulnerability_select(element){
|
|
let selectData = element.textContent.split(" ")[0];
|
|
vulnerabilityInputBox.value = $('#vulnerability-search').val() + selectData;
|
|
$("#vulnerability-search").change();
|
|
}
|
|
|
|
|
|
$('#vulnerability-search').on("change paste keyup", function(event) {
|
|
if (event.which == 13 || event.which == 27) {
|
|
vulnerabilitySearchWrapper.classList.remove("active");
|
|
return;
|
|
}
|
|
if ($(this).val().length == 0) {
|
|
vulnerability_suggestion_selector = vulnerability_col_suggestions;
|
|
}
|
|
cond_split_val = $(this).val().split(new RegExp('[=><!&|]', 'g'));
|
|
|
|
last_obj = cond_split_val.slice(-1)[0];
|
|
|
|
if (vulnerability_col_suggestions.indexOf(last_obj) > -1) {
|
|
vulnerability_suggestion_selector = vulnerability_condition_suggestions;
|
|
}
|
|
|
|
else if (["=", "!", ">", "<"].indexOf($(this).val().slice(-1)) > -1) {
|
|
vulnerability_suggestion_selector = vulnerability_joiner;
|
|
}
|
|
|
|
|
|
else if (["&", "|"].indexOf($(this).val().slice(-1)) > -1) {
|
|
vulnerability_suggestion_selector = vulnerability_col_suggestions;
|
|
}
|
|
|
|
document.getElementById("vulnerability-search").click();
|
|
});
|
|
|
|
|
|
|
|
|
|
$(document).on('click', function (e) {
|
|
// console.log($(e.target).attr('id'));
|
|
if ($(e.target).attr('id') != 'vulnerability-search' && $(e.target).attr('id') != 'filter_name') {
|
|
vulnerabilitySearchWrapper.classList.remove("active");
|
|
}
|
|
});
|