reformula buscas
Deploy / Deploy (push) Successful in 1m44s Details

This commit is contained in:
JotaChina 2025-12-17 16:28:59 -03:00
parent 80d622986a
commit fdf3299333
1 changed files with 205 additions and 180 deletions

View File

@ -561,7 +561,7 @@ permalink: /projetos/
<script>
document.addEventListener('DOMContentLoaded', function () {
// --- 1. ELEMENTOS DOM ---
// --- 1. ELEMENTOS DOM E VARIÁVEIS GLOBAIS ---
const checkboxes = document.querySelectorAll('.filter-checkbox');
const searchInput = document.getElementById('search-input');
const clearInputBtn = document.querySelector('.js-clear-input');
@ -600,7 +600,148 @@ document.addEventListener('DOMContentLoaded', function () {
// Definição Inicial BPM (Do HTML)
let defMin = parseInt(inputMin.value), defMax = parseInt(inputMax.value);
// --- 2. LÓGICA DO SLIDER DE BPM (Dual) ---
// --- 2. FUNÇÕES DE FILTRAGEM (DEFINIDAS PRIMEIRO) ---
// Função Principal de Aplicação de Filtros
function applyGlobalFilters() {
let visibleCount = 0;
let minBpm = parseInt(inputMin.value);
let maxBpm = parseInt(inputMax.value);
if(minBpm > maxBpm) { let t = minBpm; minBpm = maxBpm; maxBpm = t; }
const allActiveTags = new Set([
...activeSidebar.instruments,
...activeSidebar.plugins,
...activeSidebar.samples,
...activeSidebar.bassline,
...activeSidebar.automation,
...activeSidebar.genres,
...activeSidebar.keys
].map(s => s.toLowerCase()));
const hasActiveTypeFilter = allActiveTags.size > 0 || (searchText.length > 2);
document.querySelectorAll('.project-item').forEach(item => {
const pName = item.getAttribute('data-name') || "";
let pBpm = parseInt(item.getAttribute('data-bpm'));
if(isNaN(pBpm)) pBpm = 0;
const pInsts = (item.getAttribute('data-instruments') || "").split(',');
const pPlugins = (item.getAttribute('data-plugins') || "").split(',');
const pSamples = (item.getAttribute('data-samples') || "").split(',');
const pBassline = (item.getAttribute('data-bassline') || "").split(',');
const pAutomation = (item.getAttribute('data-automation') || "").split(',');
// PATTERN SEARCH
const pPatternsStr = item.getAttribute('data-patterns') || "";
const pPatterns = pPatternsStr.split(',');
const pGenre = (item.getAttribute('data-genre') || "").toLowerCase();
const pSubs = (item.getAttribute('data-subgenres') || "").toLowerCase();
const pTagsIA = pGenre + "," + pSubs;
const pKey = item.getAttribute('data-key') || 'all';
const pStars = parseInt(item.getAttribute('data-stars') || 0);
const matchInst = activeSidebar.instruments.length === 0 || activeSidebar.instruments.some(f => pInsts.includes(f));
const matchPlugin = activeSidebar.plugins.length === 0 || activeSidebar.plugins.some(f => pPlugins.includes(f));
const matchSample = activeSidebar.samples.length === 0 || activeSidebar.samples.some(f => pSamples.includes(f));
const matchBassline = activeSidebar.bassline.length === 0 || activeSidebar.bassline.some(f => pBassline.includes(f));
const matchAuto = activeSidebar.automation.length === 0 || activeSidebar.automation.some(f => pAutomation.includes(f));
const matchKeys = activeSidebar.keys.length === 0 || activeSidebar.keys.includes(pKey);
const matchGenres = activeSidebar.genres.length === 0 || activeSidebar.genres.some(g => pTagsIA.includes(g.toLowerCase()));
const matchBpm = (pBpm >= minBpm && pBpm <= maxBpm);
const matchStars = (currentMinStars === 'all' || pStars === parseInt(currentMinStars));
const fullMeta = [pName, pBpm, pInsts, pPlugins, pTagsIA].join(' ').toLowerCase();
const matchText = searchText === "" || fullMeta.includes(searchText);
const matchPattern = activePatternChunks.length === 0 || activePatternChunks.every(chunk => pPatterns.includes(chunk));
if (matchInst && matchPlugin && matchSample && matchBassline && matchAuto && matchBpm && matchText && matchGenres && matchKeys && matchStars && matchPattern) {
item.style.display = 'block';
visibleCount++;
// 1. Reset Highlight States
const clickableTags = item.querySelectorAll('.clickable-tag');
clickableTags.forEach(t => t.classList.remove('is-matched-tag'));
const patternGrids = item.querySelectorAll('.pattern-mini-grid');
patternGrids.forEach(g => g.classList.remove('is-highlighted'));
// 2. Logic: Open correct details and Highlight Tags/Patterns
if(hasActiveTypeFilter || activePatternChunks.length > 0) {
item.querySelectorAll('details').forEach(d => d.open = false);
// Highlight Text Tags (Instruments, Plugins, etc)
clickableTags.forEach(tagEl => {
const tagVal = (tagEl.dataset.tagValue || "").trim().toLowerCase();
const isFilterMatch = allActiveTags.has(tagVal);
const isTextMatch = searchText.length > 2 && tagVal.includes(searchText);
if (isFilterMatch || isTextMatch) {
tagEl.classList.add('is-matched-tag');
const parentDetails = tagEl.closest('details');
if(parentDetails) parentDetails.open = true;
}
});
// Highlight Patterns
if (activePatternChunks.length > 0) {
let hasPatternMatch = false;
patternGrids.forEach(grid => {
const title = grid.getAttribute('title') || "";
const patVal = title.replace("Pattern: ", "").trim();
if (activePatternChunks.includes(patVal)) {
grid.classList.add('is-highlighted');
hasPatternMatch = true;
}
});
if (hasPatternMatch) {
if(patternGrids.length > 0) {
const parentDet = patternGrids[0].closest('details');
if(parentDet) parentDet.open = true;
}
}
}
} else {
// Default view: Open Instruments only
item.querySelectorAll('details').forEach(d => d.open = false);
const instDetail = item.querySelector('details:first-of-type');
if(instDetail) instDetail.open = true;
}
} else {
item.style.display = 'none';
}
});
countSpan.textContent = visibleCount;
countBar.classList.toggle('is-hidden', visibleCount >= document.querySelectorAll('.project-item').length);
noResults.classList.toggle('is-hidden', visibleCount > 0);
}
// Função de atualização do Sidebar
function updateActiveSidebar() {
activeSidebar = { instruments: [], plugins: [], samples: [], bassline: [], automation: [], keys: [], genres: [] };
document.querySelectorAll('.filter-checkbox').forEach(bx => {
if(bx.checked) {
activeSidebar[bx.dataset.category].push(bx.value);
if(bx.parentElement.classList.contains('tag')) bx.parentElement.classList.add('is-checked');
} else {
if(bx.parentElement.classList.contains('tag')) bx.parentElement.classList.remove('is-checked');
}
});
applyGlobalFilters();
}
// --- 3. LÓGICA DE UI E EVENT LISTENERS ---
// BPM Slider Logic
function updateSlider() {
let val1 = parseInt(sliderMin.value);
let val2 = parseInt(sliderMax.value);
@ -625,9 +766,9 @@ document.addEventListener('DOMContentLoaded', function () {
let val = parseInt(this.value); if(val < parseInt(inputMin.value)) val = parseInt(inputMin.value);
sliderMax.value = val; updateSlider();
});
fillSlider(defMin, defMax); // Init
fillSlider(defMin, defMax);
// --- 2.5 LÓGICA DO PATTERN SEARCH ---
// Pattern Search Logic
searchSteps.forEach(step => {
step.addEventListener('click', function() {
this.classList.toggle('is-active');
@ -645,7 +786,63 @@ document.addEventListener('DOMContentLoaded', function () {
activePatternChunks = rawChunks.filter(c => c !== "0000");
}
// --- 3. ENRIQUECIMENTO DOS CARDS COM JSON ---
// Checkboxes Init
checkboxes.forEach(cb => cb.addEventListener('change', updateActiveSidebar));
// Inputs de Busca
searchInput.addEventListener('input', (e) => { searchText = e.target.value.toLowerCase().trim(); applyGlobalFilters(); });
clearInputBtn.addEventListener('click', () => { searchInput.value = ""; searchText = ""; applyGlobalFilters(); });
if(starFilterSelect) starFilterSelect.addEventListener('change', (e) => { currentMinStars = e.target.value; applyGlobalFilters(); });
if(sortSelect) sortSelect.addEventListener('change', (e) => {
const crit = e.target.value;
const cols = Array.from(projectsContainer.children);
cols.sort((a, b) => {
const getVal = (el, k) => parseFloat(el.getAttribute(k) || 0);
if(crit === 'stars_desc') return getVal(b, 'data-stars') - getVal(a, 'data-stars');
if(crit === 'stars_asc') return getVal(a, 'data-stars') - getVal(b, 'data-stars');
if(crit === 'bpm_desc') return getVal(b, 'data-bpm-real') - getVal(a, 'data-bpm-real');
if(crit === 'intensity_desc') return getVal(b, 'data-intensity') - getVal(a, 'data-intensity');
if(crit === 'intensity_asc') return getVal(a, 'data-intensity') - getVal(b, 'data-intensity');
return a.getAttribute('data-title').localeCompare(b.getAttribute('data-title'));
});
cols.forEach(c => projectsContainer.appendChild(c));
});
// Botões Limpar Grupo
clearGroupBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault(); e.stopPropagation();
const target = btn.dataset.target;
if(target === 'bpm') {
sliderMin.value = sliderMin.min; sliderMax.value = sliderMax.max; updateSlider();
} else if (target === 'pattern') {
searchSteps.forEach(s => s.classList.remove('is-active'));
updatePatternChunks();
applyGlobalFilters();
} else {
document.querySelectorAll(`.filter-checkbox[data-category="${target}"]`).forEach(cb => {
cb.checked = false;
if(cb.parentElement.classList.contains('tag')) cb.parentElement.classList.remove('is-checked');
});
updateActiveSidebar();
}
});
});
resetBtn.addEventListener('click', () => {
document.querySelectorAll('.filter-checkbox').forEach(cb => { cb.checked = false; cb.parentElement.classList.remove('is-checked'); });
searchInput.value = ""; searchText = "";
searchSteps.forEach(s => s.classList.remove('is-active'));
updatePatternChunks();
sliderMin.value = sliderMin.min; sliderMax.value = sliderMax.max; updateSlider();
starFilterSelect.value = 'all'; currentMinStars = 'all'; sortSelect.value = 'default';
updateActiveSidebar();
});
// --- 4. ENRIQUECIMENTO DOS CARDS COM JSON (FETCH) ---
const JSON_URL = '/mmpSearch/src_mmpSearch/saida_analises/db_final_completo.json';
fetch(JSON_URL)
@ -654,7 +851,7 @@ document.addEventListener('DOMContentLoaded', function () {
enrichCards(data);
createGenreCheckboxes(data);
// Recalcula limites de BPM
// Recalcula limites de BPM com base no JSON
const bpms = data.map(i => parseFloat(i.analise_tecnica?.bpm || 0)).filter(b => b > 0);
if(bpms.length > 0) {
const maxData = Math.ceil(Math.max(...bpms));
@ -665,6 +862,7 @@ document.addEventListener('DOMContentLoaded', function () {
inputMin.max = maxData;
}
}
// Aplica filtros pela primeira vez APÓS carregar dados
applyGlobalFilters();
})
.catch(console.warn);
@ -782,180 +980,7 @@ document.addEventListener('DOMContentLoaded', function () {
});
}
function applyGlobalFilters() {
let visibleCount = 0;
let minBpm = parseInt(inputMin.value);
let maxBpm = parseInt(inputMax.value);
if(minBpm > maxBpm) { let t = minBpm; minBpm = maxBpm; maxBpm = t; }
const allActiveTags = new Set([
...activeSidebar.instruments,
...activeSidebar.plugins,
...activeSidebar.samples,
...activeSidebar.bassline,
...activeSidebar.automation,
...activeSidebar.genres,
...activeSidebar.keys
].map(s => s.toLowerCase()));
const hasActiveTypeFilter = allActiveTags.size > 0 || (searchText.length > 2);
document.querySelectorAll('.project-item').forEach(item => {
const pName = item.getAttribute('data-name') || "";
let pBpm = parseInt(item.getAttribute('data-bpm'));
if(isNaN(pBpm)) pBpm = 0;
const pInsts = (item.getAttribute('data-instruments') || "").split(',');
const pPlugins = (item.getAttribute('data-plugins') || "").split(',');
const pSamples = (item.getAttribute('data-samples') || "").split(',');
const pBassline = (item.getAttribute('data-bassline') || "").split(',');
const pAutomation = (item.getAttribute('data-automation') || "").split(',');
// PATTERN SEARCH
const pPatternsStr = item.getAttribute('data-patterns') || "";
const pPatterns = pPatternsStr.split(',');
const pGenre = (item.getAttribute('data-genre') || "").toLowerCase();
const pSubs = (item.getAttribute('data-subgenres') || "").toLowerCase();
const pTagsIA = pGenre + "," + pSubs;
const pKey = item.getAttribute('data-key') || 'all';
const pStars = parseInt(item.getAttribute('data-stars') || 0);
const matchInst = activeSidebar.instruments.length === 0 || activeSidebar.instruments.some(f => pInsts.includes(f));
const matchPlugin = activeSidebar.plugins.length === 0 || activeSidebar.plugins.some(f => pPlugins.includes(f));
const matchSample = activeSidebar.samples.length === 0 || activeSidebar.samples.some(f => pSamples.includes(f));
const matchBassline = activeSidebar.bassline.length === 0 || activeSidebar.bassline.some(f => pBassline.includes(f));
const matchAuto = activeSidebar.automation.length === 0 || activeSidebar.automation.some(f => pAutomation.includes(f));
const matchKeys = activeSidebar.keys.length === 0 || activeSidebar.keys.includes(pKey);
const matchGenres = activeSidebar.genres.length === 0 || activeSidebar.genres.some(g => pTagsIA.includes(g.toLowerCase()));
const matchBpm = (pBpm >= minBpm && pBpm <= maxBpm);
const matchStars = (currentMinStars === 'all' || pStars === parseInt(currentMinStars));
const fullMeta = [pName, pBpm, pInsts, pPlugins, pTagsIA].join(' ').toLowerCase();
const matchText = searchText === "" || fullMeta.includes(searchText);
const matchPattern = activePatternChunks.length === 0 || activePatternChunks.every(chunk => pPatterns.includes(chunk));
if (matchInst && matchPlugin && matchSample && matchBassline && matchAuto && matchBpm && matchText && matchGenres && matchKeys && matchStars && matchPattern) {
item.style.display = 'block';
visibleCount++;
// 1. Reset Highlight States
const clickableTags = item.querySelectorAll('.clickable-tag');
clickableTags.forEach(t => t.classList.remove('is-matched-tag'));
const patternGrids = item.querySelectorAll('.pattern-mini-grid');
patternGrids.forEach(g => g.classList.remove('is-highlighted'));
// 2. Logic: Open correct details and Highlight Tags/Patterns
if(hasActiveTypeFilter || activePatternChunks.length > 0) {
item.querySelectorAll('details').forEach(d => d.open = false);
// Highlight Text Tags (Instruments, Plugins, etc)
clickableTags.forEach(tagEl => {
const tagVal = (tagEl.dataset.tagValue || "").trim().toLowerCase();
const isFilterMatch = allActiveTags.has(tagVal);
const isTextMatch = searchText.length > 2 && tagVal.includes(searchText);
if (isFilterMatch || isTextMatch) {
tagEl.classList.add('is-matched-tag');
const parentDetails = tagEl.closest('details');
if(parentDetails) parentDetails.open = true;
}
});
// Highlight Patterns
if (activePatternChunks.length > 0) {
let hasPatternMatch = false;
patternGrids.forEach(grid => {
// title="Pattern: 1010" -> extract "1010"
const title = grid.getAttribute('title') || "";
const patVal = title.replace("Pattern: ", "").trim();
if (activePatternChunks.includes(patVal)) {
grid.classList.add('is-highlighted');
hasPatternMatch = true;
}
});
if (hasPatternMatch) {
// Find the Rhythm details block (closest to the grid)
if(patternGrids.length > 0) {
const parentDet = patternGrids[0].closest('details');
if(parentDet) parentDet.open = true;
}
}
}
} else {
// Default view: Open Instruments only
item.querySelectorAll('details').forEach(d => d.open = false);
const instDetail = item.querySelector('details:first-of-type');
if(instDetail) instDetail.open = true;
}
} else {
item.style.display = 'none';
}
});
countSpan.textContent = visibleCount;
countBar.classList.toggle('is-hidden', visibleCount >= document.querySelectorAll('.project-item').length);
noResults.classList.toggle('is-hidden', visibleCount > 0);
}
checkboxes.forEach(cb => cb.addEventListener('change', updateActiveSidebar));
searchInput.addEventListener('input', (e) => { searchText = e.target.value.toLowerCase().trim(); applyGlobalFilters(); });
clearInputBtn.addEventListener('click', () => { searchInput.value = ""; searchText = ""; applyGlobalFilters(); });
if(starFilterSelect) starFilterSelect.addEventListener('change', (e) => { currentMinStars = e.target.value; applyGlobalFilters(); });
if(sortSelect) sortSelect.addEventListener('change', (e) => {
const crit = e.target.value;
const cols = Array.from(projectsContainer.children);
cols.sort((a, b) => {
const getVal = (el, k) => parseFloat(el.getAttribute(k) || 0);
if(crit === 'stars_desc') return getVal(b, 'data-stars') - getVal(a, 'data-stars');
if(crit === 'stars_asc') return getVal(a, 'data-stars') - getVal(b, 'data-stars');
if(crit === 'bpm_desc') return getVal(b, 'data-bpm-real') - getVal(a, 'data-bpm-real');
if(crit === 'intensity_desc') return getVal(b, 'data-intensity') - getVal(a, 'data-intensity');
if(crit === 'intensity_asc') return getVal(a, 'data-intensity') - getVal(b, 'data-intensity');
return a.getAttribute('data-title').localeCompare(b.getAttribute('data-title'));
});
cols.forEach(c => projectsContainer.appendChild(c));
});
clearGroupBtns.forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault(); e.stopPropagation();
const target = btn.dataset.target;
if(target === 'bpm') {
sliderMin.value = sliderMin.min; sliderMax.value = sliderMax.max; updateSlider();
} else if (target === 'pattern') {
searchSteps.forEach(s => s.classList.remove('is-active'));
updatePatternChunks();
applyGlobalFilters();
} else {
document.querySelectorAll(`.filter-checkbox[data-category="${target}"]`).forEach(cb => {
cb.checked = false;
if(cb.parentElement.classList.contains('tag')) cb.parentElement.classList.remove('is-checked');
});
updateActiveSidebar();
}
});
});
resetBtn.addEventListener('click', () => {
document.querySelectorAll('.filter-checkbox').forEach(cb => { cb.checked = false; cb.parentElement.classList.remove('is-checked'); });
searchInput.value = ""; searchText = "";
searchSteps.forEach(s => s.classList.remove('is-active'));
updatePatternChunks();
sliderMin.value = sliderMin.min; sliderMax.value = sliderMax.max; updateSlider();
starFilterSelect.value = 'all'; currentMinStars = 'all'; sortSelect.value = 'default';
updateActiveSidebar();
});
// Modal
const modal = document.getElementById('preview-modal');
const iframe = document.getElementById('preview-iframe');
const modalTitle = document.getElementById('modal-title');