Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/OWASP-BLT/BLT
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnieBLT committed Jan 24, 2025
2 parents c501ef8 + 8dc96e6 commit 6ef56c5
Show file tree
Hide file tree
Showing 4 changed files with 794 additions and 127 deletions.
73 changes: 62 additions & 11 deletions website/templates/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,19 @@
action="{% url 'search' %}"
method="get">
<i class="lg:!flex hidden fa fa-search absolute left-4 text-[#9CA3AF] z-10 my-auto"></i>
<input type="hidden" name="type" id="filter-type" value="organizations">
<!-- Search Input -->
<input type="text"
name="query"
id="query-input"
placeholder="Search"
class="text-xl lg:text-base lg:ps-9 lg:scale-[1.4] w-[70px] lg:w-auto h-16 placeholder-[#9CA3AF] bg-[#EDEDED] outline-none p-5 font-semibold rounded-l-2xl">
<div class="relative">
<!-- Dropdown Button -->
<button id="organizations-btn"
type="button"
class="flex items-center text-xl lg:text-base h-16 bg-[#ededed] p-5 font-semibold text-[#9CA3AF] outline-none rounded-r-2xl">
<i id="selected-icon" class="fa fa-building mr-2"></i>
<i id="selected-icon" class="fas fa-building mr-2"></i>
<span id="selected-filter">{% trans "Organizations" %}</span>
<i class="fa fa-chevron-down ml-2"></i>
</button>
Expand All @@ -177,11 +179,31 @@
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
<i class="fas fa-box mr-2"></i> {% trans "Projects" %}
</a>
<a href="#"
data-value="repos"
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
<i class="fas fa-folder mr-2"></i> {% trans "Repos" %}
</a>
<a href="#"
data-value="users"
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
<i class="fas fa-user-friends mr-2"></i> {% trans "Users" %}
</a>
<a href="#"
data-value="issues"
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
<i class="fas fa-exclamation-circle mr-2"></i> {% trans "Issues" %}
</a>
<a href="#"
data-value="domains"
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
<i class="fas fa-globe mr-2"></i> {% trans "Domains" %}
</a>
<a href="#"
data-value="labels"
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
<i class="fas fa-tag mr-2"></i> {% trans "Labels" %}
</a>
<a href="#"
data-value="tags"
class="filter-option flex items-center px-3 py-2 hover:bg-gray-100 text-sm">
Expand Down Expand Up @@ -345,17 +367,45 @@ <h3 class="text-xl font-extrabold">Chat with BLT Bot</h3>
<!--Script for Dropdown button-->
<script>
document.addEventListener("DOMContentLoaded", function () {

const organizationsBtn = document.getElementById("organizations-btn");
const organizationsDropdown = document.getElementById("organizations-dropdown");
const queryInput = document.getElementById("query-input");

// Function to get URL parameters
function getUrlParameter(name) {
const params = new URLSearchParams(window.location.search);
return params.get(name);
}

// Set initial values from URL parameters if they exist
const savedQuery = getUrlParameter('query');
const savedType = getUrlParameter('type');

if (savedQuery) {
queryInput.value = savedQuery;
}

if (savedType) {
// Find the matching filter option
const matchingOption = document.querySelector(`.filter-option[data-value="${savedType}"]`);
if (matchingOption) {
const iconElement = matchingOption.querySelector('i');
const textContent = matchingOption.textContent.trim();

// Update the button display
document.getElementById('selected-icon').className = iconElement.className + ' mr-2';
document.getElementById('selected-filter').textContent = textContent;
document.getElementById('filter-type').value = savedType;
}
}

if (organizationsBtn && organizationsDropdown) {
organizationsBtn.addEventListener("click", function (e) {
e.preventDefault();
e.stopPropagation();

const isHidden = organizationsDropdown.classList.toggle('hidden');

if (!isHidden) {
const btnRect = organizationsBtn.getBoundingClientRect();
Object.assign(organizationsDropdown.style, {
Expand All @@ -365,10 +415,11 @@ <h3 class="text-xl font-extrabold">Chat with BLT Bot</h3>
minWidth: `${btnRect.width}px`,
display: 'block',
});
} else{
} else {
organizationsDropdown.style.display = 'none';
}
});

// Close dropdown when clicking outside
document.addEventListener("click", function (e) {
if (!organizationsBtn.contains(e.target) && !organizationsDropdown.contains(e.target)) {
Expand All @@ -379,18 +430,18 @@ <h3 class="text-xl font-extrabold">Chat with BLT Bot</h3>
} else {
console.error('Required elements not found!');
}

document.querySelectorAll('.filter-option').forEach(option => {
option.addEventListener('click', function(e) {
option.addEventListener('click', function (e) {
e.preventDefault();
const iconElement = this.querySelector('i');
const textContent = this.textContent.trim();

const selectedIcon = document.getElementById('selected-icon');
const selectedFilter = document.getElementById('selected-filter');
const filterValue = this.getAttribute('data-value');

document.getElementById('selected-icon').className = iconElement.className + ' mr-2';
document.getElementById('selected-filter').textContent = textContent;
document.getElementById('filter-type').value = filterValue;

selectedIcon.className = iconElement.className + ' mr-2';
selectedFilter.textContent = textContent;

organizationsDropdown.classList.add('hidden');
organizationsDropdown.style.display = 'none';
});
Expand Down
Loading

0 comments on commit 6ef56c5

Please sign in to comment.