fix
This commit is contained in:
@@ -20,7 +20,7 @@ const AI_ANALYZER_API_KEY = getEnv('AI_ANALYZER_API_KEY');
|
||||
const AI_ANALYZER_MODEL = getEnv('AI_ANALYZER_MODEL');
|
||||
|
||||
const rateLimitStore = new Map<string, { count: number; resetTime: number }>();
|
||||
const RATE_LIMIT_WINDOW = 60 * 1000; // 1 minute
|
||||
const RATE_LIMIT_WINDOW = 60 * 1000;
|
||||
const RATE_LIMIT_MAX = 5;
|
||||
|
||||
function sanitizeInput(input: string): string {
|
||||
|
||||
@@ -198,15 +198,12 @@ const phases = data.phases;
|
||||
<script define:vars={{ toolsData: data.tools, phases: data.phases }}>
|
||||
window.toolsData = toolsData;
|
||||
|
||||
// CONSOLIDATED: Approach selection - Pure navigation aid
|
||||
window.selectApproach = function(approach) {
|
||||
console.log(`Selected approach: ${approach}`);
|
||||
|
||||
// Clear any existing AI results
|
||||
const aiResults = document.getElementById('ai-results');
|
||||
if (aiResults) aiResults.style.display = 'none';
|
||||
|
||||
// Update visual selection state
|
||||
document.querySelectorAll('.approach-card').forEach(card => {
|
||||
card.classList.remove('selected');
|
||||
});
|
||||
@@ -214,14 +211,12 @@ const phases = data.phases;
|
||||
const selectedCard = document.querySelector(`.approach-card.${approach}`);
|
||||
if (selectedCard) selectedCard.classList.add('selected');
|
||||
|
||||
// Hide all approach sections first (ensures mutual exclusivity)
|
||||
const methodologySection = document.getElementById('methodology-section');
|
||||
const targetedSection = document.getElementById('targeted-section');
|
||||
|
||||
if (methodologySection) methodologySection.classList.remove('active');
|
||||
if (targetedSection) targetedSection.classList.remove('active');
|
||||
|
||||
// Show the selected approach section (navigation aid only)
|
||||
if (approach === 'methodology') {
|
||||
if (methodologySection) {
|
||||
methodologySection.classList.add('active');
|
||||
@@ -235,11 +230,9 @@ const phases = data.phases;
|
||||
}
|
||||
};
|
||||
|
||||
// CONSOLIDATED: Phase selection - Sets unified filter dropdown
|
||||
window.selectPhase = function(phase) {
|
||||
console.log(`Selected NIST phase: ${phase}`);
|
||||
|
||||
// Update visual selection of phase cards
|
||||
document.querySelectorAll('.phase-card').forEach(card => {
|
||||
card.classList.remove('active');
|
||||
});
|
||||
@@ -249,23 +242,19 @@ const phases = data.phases;
|
||||
selectedCard.classList.add('active');
|
||||
}
|
||||
|
||||
// CONSOLIDATED: Set the unified phase-select dropdown
|
||||
const phaseSelect = document.getElementById('phase-select');
|
||||
if (phaseSelect) {
|
||||
phaseSelect.value = phase;
|
||||
|
||||
// Trigger the change event to activate unified filtering
|
||||
const changeEvent = new Event('change', { bubbles: true });
|
||||
phaseSelect.dispatchEvent(changeEvent);
|
||||
}
|
||||
|
||||
// Switch to grid view to show filtered results
|
||||
const gridToggle = document.querySelector('.view-toggle[data-view="grid"]');
|
||||
if (gridToggle && !gridToggle.classList.contains('active')) {
|
||||
gridToggle.click();
|
||||
}
|
||||
|
||||
// Scroll to filtered results
|
||||
setTimeout(() => {
|
||||
window.scrollToElementById('tools-grid');
|
||||
}, 200);
|
||||
@@ -309,17 +298,14 @@ const phases = data.phases;
|
||||
const filtersSection = document.getElementById('filters-section');
|
||||
const noResults = document.getElementById('no-results');
|
||||
|
||||
// FIXED: Hide approach sections when switching to ANY view mode
|
||||
const methodologySection = document.getElementById('methodology-section');
|
||||
const targetedSection = document.getElementById('targeted-section');
|
||||
|
||||
// Hide all main content areas
|
||||
if (toolsGrid) toolsGrid.style.display = 'none';
|
||||
if (matrixContainer) matrixContainer.style.display = 'none';
|
||||
if (aiInterface) aiInterface.style.display = 'none';
|
||||
if (noResults) noResults.style.display = 'none';
|
||||
|
||||
// FIXED: Hide approach sections when switching to view modes
|
||||
if (methodologySection) methodologySection.classList.remove('active');
|
||||
if (targetedSection) targetedSection.classList.remove('active');
|
||||
|
||||
@@ -335,18 +321,14 @@ const phases = data.phases;
|
||||
case 'ai':
|
||||
if (aiInterface) aiInterface.style.display = 'block';
|
||||
|
||||
// FIXED: Show filters but hide everything except view controls
|
||||
if (filtersSection) {
|
||||
filtersSection.style.display = 'block';
|
||||
|
||||
// Hide all filter sections except the last one (view controls)
|
||||
const filterSections = filtersSection.querySelectorAll('.filter-section');
|
||||
filterSections.forEach((section, index) => {
|
||||
if (index === filterSections.length - 1) {
|
||||
// Keep view controls visible
|
||||
section.style.display = 'block';
|
||||
} else {
|
||||
// Hide other filter sections
|
||||
section.style.display = 'none';
|
||||
}
|
||||
});
|
||||
@@ -354,7 +336,6 @@ const phases = data.phases;
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXED: Reset filter sections visibility when not in AI view
|
||||
if (view !== 'ai' && filtersSection) {
|
||||
const filterSections = filtersSection.querySelectorAll('.filter-section');
|
||||
filterSections.forEach(section => {
|
||||
@@ -363,7 +344,6 @@ const phases = data.phases;
|
||||
}
|
||||
}
|
||||
|
||||
// Navigation functions for AI recommendations (unchanged)
|
||||
window.navigateToGrid = function(toolName) {
|
||||
console.log('Navigating to grid for tool:', toolName);
|
||||
|
||||
@@ -485,8 +465,6 @@ const phases = data.phases;
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// REPLACE the existing toolsFiltered event listener in index.astro with this enhanced version:
|
||||
|
||||
window.addEventListener('toolsFiltered', (event) => {
|
||||
const { tools: filtered, semanticSearch } = event.detail;
|
||||
const currentView = document.querySelector('.view-toggle.active')?.getAttribute('data-view');
|
||||
@@ -504,11 +482,9 @@ const phases = data.phases;
|
||||
if (semanticSearch && filtered.length > 0) {
|
||||
console.log('[SEMANTIC] Reordering tools by semantic similarity');
|
||||
|
||||
// FIXED: Create ordered array of cards based on semantic similarity
|
||||
const orderedCards = [];
|
||||
const remainingCards = [];
|
||||
|
||||
// First pass: collect cards in semantic order
|
||||
filtered.forEach(tool => {
|
||||
const toolName = tool.name.toLowerCase();
|
||||
const matchingCard = Array.from(allToolCards).find(card =>
|
||||
@@ -520,12 +496,10 @@ const phases = data.phases;
|
||||
orderedCards.push(matchingCard);
|
||||
visibleCount++;
|
||||
|
||||
// Add semantic indicators if available
|
||||
if (tool._semanticSimilarity) {
|
||||
matchingCard.setAttribute('data-semantic-similarity', tool._semanticSimilarity.toFixed(3));
|
||||
matchingCard.setAttribute('data-semantic-rank', tool._semanticRank || '');
|
||||
|
||||
// Visual indication of semantic ranking (subtle)
|
||||
const header = matchingCard.querySelector('.tool-card-header h3');
|
||||
if (header && tool._semanticRank <= 3) {
|
||||
const existingIndicator = header.querySelector('.semantic-rank-indicator');
|
||||
@@ -551,7 +525,6 @@ const phases = data.phases;
|
||||
}
|
||||
});
|
||||
|
||||
// Second pass: hide non-matching cards and collect them
|
||||
allToolCards.forEach(card => {
|
||||
const toolName = card.getAttribute('data-tool-name');
|
||||
if (!filteredNames.has(toolName)) {
|
||||
@@ -560,18 +533,15 @@ const phases = data.phases;
|
||||
}
|
||||
});
|
||||
|
||||
// Reorder DOM: semantic results first, then hidden cards
|
||||
const allCards = [...orderedCards, ...remainingCards];
|
||||
allCards.forEach(card => {
|
||||
toolsContainer.appendChild(card);
|
||||
});
|
||||
|
||||
} else {
|
||||
// FIXED: Standard filtering without semantic ordering
|
||||
allToolCards.forEach(card => {
|
||||
const toolName = card.getAttribute('data-tool-name');
|
||||
|
||||
// Clean up any semantic indicators
|
||||
card.removeAttribute('data-semantic-similarity');
|
||||
card.removeAttribute('data-semantic-rank');
|
||||
const semanticIndicator = card.querySelector('.semantic-rank-indicator');
|
||||
@@ -587,10 +557,8 @@ const phases = data.phases;
|
||||
}
|
||||
});
|
||||
|
||||
// Restore original order when not using semantic search
|
||||
if (!semanticSearch) {
|
||||
const originalOrder = Array.from(allToolCards).sort((a, b) => {
|
||||
// Get original indices from data attributes or DOM order
|
||||
const aIndex = Array.from(allToolCards).indexOf(a);
|
||||
const bIndex = Array.from(allToolCards).indexOf(b);
|
||||
return aIndex - bIndex;
|
||||
@@ -602,14 +570,12 @@ const phases = data.phases;
|
||||
}
|
||||
}
|
||||
|
||||
// Show/hide no results message
|
||||
if (visibleCount === 0) {
|
||||
noResults.style.display = 'block';
|
||||
} else {
|
||||
noResults.style.display = 'none';
|
||||
}
|
||||
|
||||
// Log semantic search info
|
||||
if (semanticSearch) {
|
||||
console.log(`[SEMANTIC] Displayed ${visibleCount} tools in semantic order`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user