modifica arquivos estáticos
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -1,6 +1,3 @@
|
|||||||
.bg-light-gradient {
|
|
||||||
background: linear-gradient(to right, #f8f9fa, #e9ecef);
|
|
||||||
}
|
|
||||||
.search-card {
|
.search-card {
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
const API_BASE_URL = "http://109.199.98.226";
|
|
||||||
@ -1,242 +1,241 @@
|
|||||||
document.addEventListener('alpine:init', () => {
|
document.addEventListener('alpine:init', () => {
|
||||||
Alpine.data('searchApp', () => ({
|
Alpine.data('searchApp', () => ({
|
||||||
searchParams: {
|
searchParams: {
|
||||||
q: '',
|
q: '',
|
||||||
numero_diario: '',
|
numero_diario: '',
|
||||||
data_inicio: '',
|
data_inicio: '',
|
||||||
data_fim: '',
|
data_fim: '',
|
||||||
modo_busca: 'exata',
|
modo_busca: 'exata',
|
||||||
ordenar_por: 'data_asc',
|
ordenar_por: 'data_asc',
|
||||||
page: 1,
|
page: 1,
|
||||||
page_size: 10
|
page_size: 10
|
||||||
},
|
},
|
||||||
searchResults: null,
|
searchResults: null,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
hasSearched: false,
|
hasSearched: false,
|
||||||
error: null,
|
error: null,
|
||||||
showAdvanced: false,
|
showAdvanced: false,
|
||||||
expandedContents: {},
|
expandedContents: {},
|
||||||
suggestion: null,
|
suggestion: null,
|
||||||
ultimoTermoBuscado: '',
|
ultimoTermoBuscado: '',
|
||||||
|
|
||||||
get shouldShowSuggestion() {
|
get shouldShowSuggestion() {
|
||||||
if (!this.suggestion || !this.searchParams.q) return false;
|
if (!this.suggestion || !this.searchParams.q) return false;
|
||||||
|
|
||||||
// Função para remover acentos e converter para minúsculas
|
// Função para remover acentos e converter para minúsculas
|
||||||
const normalize = (text) => {
|
const normalize = (text) => {
|
||||||
return text.toLowerCase()
|
return text.toLowerCase()
|
||||||
.normalize('NFD')
|
.normalize('NFD')
|
||||||
.replace("/", " ")
|
.replace("/", " ")
|
||||||
.replace(/[^a-z0-9\s]/g, " ") // Substitui todos os outros símbolos por espaço
|
.replace(/[^a-z0-9\s]/g, " ") // Substitui todos os outros símbolos por espaço
|
||||||
.replace(/[\u0300-\u036f]/g, '');
|
.replace(/[\u0300-\u036f]/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const normalizedQuery = normalize(this.searchParams.q);
|
const normalizedQuery = normalize(this.searchParams.q);
|
||||||
const normalizedSuggestion = normalize(this.suggestion);
|
const normalizedSuggestion = normalize(this.suggestion);
|
||||||
|
|
||||||
// Só mostra a sugestão se for diferente do termo buscado (ignorando acentos e caixa)
|
// Só mostra a sugestão se for diferente do termo buscado (ignorando acentos e caixa)
|
||||||
return normalizedQuery !== normalizedSuggestion;
|
return normalizedQuery !== normalizedSuggestion;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Usa a sugestão como novo termo de busca
|
// Usa a sugestão como novo termo de busca
|
||||||
usesuggestion() {
|
usesuggestion() {
|
||||||
this.searchParams.q = this.suggestion;
|
this.searchParams.q = this.suggestion;
|
||||||
this.searchParams.page = 1;
|
this.searchParams.page = 1;
|
||||||
this.performSearch();
|
this.performSearch();
|
||||||
},
|
},
|
||||||
|
|
||||||
// Verifica se um diário tem uma melhor correspondência
|
// Verifica se um diário tem uma melhor correspondência
|
||||||
hasBestMatch(diario) {
|
hasBestMatch(diario) {
|
||||||
return diario.paginas && diario.paginas.length > 0;
|
return diario.paginas && diario.paginas.length > 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Muda a ordenação e faz uma nova busca
|
// Muda a ordenação e faz uma nova busca
|
||||||
changeOrder(order) {
|
changeOrder(order) {
|
||||||
if (this.searchParams.ordenar_por !== order) {
|
if (this.searchParams.ordenar_por !== order) {
|
||||||
this.searchParams.ordenar_por = order;
|
this.searchParams.ordenar_por = order;
|
||||||
this.searchParams.page = 1; // Volta para a primeira página
|
this.searchParams.page = 1; // Volta para a primeira página
|
||||||
this.performSearch();
|
this.performSearch();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Obter sugestão da API
|
// Obter sugestão da API
|
||||||
async getSuggestion(query) {
|
async getSuggestion(query) {
|
||||||
if (!query) return null;
|
if (!query) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = new URL('http://192.168.235.234/api/v1/diarios/sugestao');
|
const url = new URL(`${window.API_BASE_URL}/api/v1/diarios/sugestao`);
|
||||||
url.searchParams.append('q', query);
|
url.searchParams.append('q', query);
|
||||||
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data.sugestao;
|
return data.sugestao;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erro ao buscar sugestão:', error);
|
console.error('Erro ao buscar sugestão:', error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get totalPages() {
|
get totalPages() {
|
||||||
if (!this.searchResults) return 0;
|
if (!this.searchResults) return 0;
|
||||||
return Math.ceil(this.searchResults.total / this.searchResults.por_pagina);
|
return Math.ceil(this.searchResults.total / this.searchResults.por_pagina);
|
||||||
},
|
},
|
||||||
|
|
||||||
get paginationArray() {
|
get paginationArray() {
|
||||||
const pages = [];
|
const pages = [];
|
||||||
const currentPage = this.searchParams.page;
|
const currentPage = this.searchParams.page;
|
||||||
const totalPages = this.totalPages;
|
const totalPages = this.totalPages;
|
||||||
|
|
||||||
// Função auxiliar para adicionar páginas
|
// Função auxiliar para adicionar páginas
|
||||||
const addPage = (page) => {
|
const addPage = (page) => {
|
||||||
if (page >= 1 && page <= totalPages && !pages.includes(page)) {
|
if (page >= 1 && page <= totalPages && !pages.includes(page)) {
|
||||||
pages.push(page);
|
pages.push(page);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sempre mostrar primeira página, página atual, última página
|
// Sempre mostrar primeira página, página atual, última página
|
||||||
// e 1-2 páginas adjacentes à página atual
|
// e 1-2 páginas adjacentes à página atual
|
||||||
addPage(1);
|
addPage(1);
|
||||||
addPage(currentPage - 2);
|
addPage(currentPage - 2);
|
||||||
addPage(currentPage - 1);
|
addPage(currentPage - 1);
|
||||||
addPage(currentPage);
|
addPage(currentPage);
|
||||||
addPage(currentPage + 1);
|
addPage(currentPage + 1);
|
||||||
addPage(currentPage + 2);
|
addPage(currentPage + 2);
|
||||||
addPage(totalPages);
|
addPage(totalPages);
|
||||||
|
|
||||||
// Ordenar e adicionar separadores
|
// Ordenar e adicionar separadores
|
||||||
const result = pages.sort((a, b) => a - b);
|
const result = pages.sort((a, b) => a - b);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Retorna a melhor página (maior score) de um diário
|
// Retorna a melhor página (maior score) de um diário
|
||||||
getBestPage(paginas) {
|
getBestPage(paginas) {
|
||||||
if (!paginas || paginas.length === 0) return null;
|
if (!paginas || paginas.length === 0) return null;
|
||||||
|
|
||||||
// Ordena as páginas por score (se disponível) ou pelo número da página se não houver score
|
// Ordena as páginas por score (se disponível) ou pelo número da página se não houver score
|
||||||
const sortedPages = [...paginas].sort((a, b) => {
|
const sortedPages = [...paginas].sort((a, b) => {
|
||||||
if (a.score === undefined || b.score === undefined) return 0;
|
if (a.score === undefined || b.score === undefined) return 0;
|
||||||
if (a.score === undefined) return 1;
|
if (a.score === undefined) return 1;
|
||||||
if (b.score === undefined) return -1;
|
if (b.score === undefined) return -1;
|
||||||
return b.score - a.score;
|
return b.score - a.score;
|
||||||
});
|
});
|
||||||
|
|
||||||
return sortedPages[0];
|
return sortedPages[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Retorna todas as páginas exceto a melhor
|
// Retorna todas as páginas exceto a melhor
|
||||||
getOtherPages(paginas) {
|
getOtherPages(paginas) {
|
||||||
if (!paginas || paginas.length <= 1) return [];
|
if (!paginas || paginas.length <= 1) return [];
|
||||||
|
|
||||||
const bestPage = this.getBestPage(paginas);
|
const bestPage = this.getBestPage(paginas);
|
||||||
if (!bestPage) return paginas;
|
if (!bestPage) return paginas;
|
||||||
|
|
||||||
return paginas.filter(p => p.numero !== bestPage.numero)
|
return paginas.filter(p => p.numero !== bestPage.numero)
|
||||||
.sort((a, b) => a.numero - b.numero); // Ordena por número da página
|
.sort((a, b) => a.numero - b.numero); // Ordena por número da página
|
||||||
},
|
},
|
||||||
|
|
||||||
// Controla a exibição do conteúdo completo de uma página
|
// Controla a exibição do conteúdo completo de uma página
|
||||||
toggleFullContent(diarioIndex, paginaNumero) {
|
toggleFullContent(diarioIndex, paginaNumero) {
|
||||||
const key = `${diarioIndex}-${paginaNumero}`;
|
const key = `${diarioIndex}-${paginaNumero}`;
|
||||||
this.expandedContents[key] = !this.expandedContents[key];
|
this.expandedContents[key] = !this.expandedContents[key];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Verifica se um conteúdo está expandido
|
// Verifica se um conteúdo está expandido
|
||||||
isFullContentVisible(diarioIndex, paginaNumero) {
|
isFullContentVisible(diarioIndex, paginaNumero) {
|
||||||
const key = `${diarioIndex}-${paginaNumero}`;
|
const key = `${diarioIndex}-${paginaNumero}`;
|
||||||
return this.expandedContents[key] === true;
|
return this.expandedContents[key] === true;
|
||||||
},
|
},
|
||||||
|
|
||||||
async performSearch() {
|
async performSearch() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
this.error = null;
|
this.error = null;
|
||||||
this.hasSearched = true;
|
this.hasSearched = true;
|
||||||
this.expandedContents = {}; // Resetar estados expandidos
|
this.expandedContents = {}; // Resetar estados expandidos
|
||||||
this.suggestion = null; // Resetar a sugestão
|
this.suggestion = null; // Resetar a sugestão
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let suggestionPromise = null;
|
let suggestionPromise = null;
|
||||||
if (this.searchParams.q) {
|
if (this.searchParams.q) {
|
||||||
suggestionPromise = this.getSuggestion(this.searchParams.q);
|
suggestionPromise = this.getSuggestion(this.searchParams.q);
|
||||||
}
|
}
|
||||||
if (this.searchParams.q !== this.ultimoTermoBuscado) {
|
if (this.searchParams.q !== this.ultimoTermoBuscado) {
|
||||||
this.searchParams.page = 1;
|
this.searchParams.page = 1;
|
||||||
}
|
}
|
||||||
this.ultimoTermoBuscado = this.searchParams.q;
|
this.ultimoTermoBuscado = this.searchParams.q;
|
||||||
// Usando agora o endpoint busca
|
// Usando agora o endpoint busca
|
||||||
const url = new URL('http://192.168.235.234/api/v1/diarios/busca');
|
const url = new URL(`${window.API_BASE_URL}/api/v1/diarios/busca`);
|
||||||
|
// Adicionar parâmetros à URL
|
||||||
|
Object.entries(this.searchParams).forEach(([key, value]) => {
|
||||||
|
if (value !== '' && value !== null) {
|
||||||
|
url.searchParams.append(key, value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Adicionar parâmetros à URL
|
const response = await fetch(url);
|
||||||
Object.entries(this.searchParams).forEach(([key, value]) => {
|
|
||||||
if (value !== '' && value !== null) {
|
|
||||||
url.searchParams.append(key, value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await fetch(url);
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => null);
|
||||||
|
throw new Error(errorData?.message || `Erro HTTP: ${response.status}`);
|
||||||
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
this.searchResults = await response.json();
|
||||||
const errorData = await response.json().catch(() => null);
|
|
||||||
throw new Error(errorData?.message || `Erro HTTP: ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.searchResults = await response.json();
|
// Processar os resultados para garantir que as páginas tenham score
|
||||||
|
if (this.searchResults && this.searchResults.resultados) {
|
||||||
|
this.searchResults.resultados.forEach(diario => {
|
||||||
|
if (diario.paginas) {
|
||||||
|
// Atribuir scores padrão se não existirem
|
||||||
|
diario.paginas.forEach((pagina, index) => {
|
||||||
|
if (pagina.score === undefined || pagina.score === null) {
|
||||||
|
pagina.score = diario.paginas.length - index; // Score inversamente proporcional ao índice
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Processar os resultados para garantir que as páginas tenham score
|
if (suggestionPromise) {
|
||||||
if (this.searchResults && this.searchResults.resultados) {
|
this.suggestion = await suggestionPromise;
|
||||||
this.searchResults.resultados.forEach(diario => {
|
}
|
||||||
if (diario.paginas) {
|
} catch (error) {
|
||||||
// Atribuir scores padrão se não existirem
|
console.error('Erro na busca:', error);
|
||||||
diario.paginas.forEach((pagina, index) => {
|
this.error = `Erro ao buscar diários: ${error.message}`;
|
||||||
if (pagina.score === undefined || pagina.score === null) {
|
} finally {
|
||||||
pagina.score = diario.paginas.length - index; // Score inversamente proporcional ao índice
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (suggestionPromise) {
|
formatDate(dateString) {
|
||||||
this.suggestion = await suggestionPromise;
|
const options = { day: '2-digit', month: '2-digit', year: 'numeric' };
|
||||||
}
|
return new Date(dateString + 'T00:00:00').toLocaleDateString('pt-BR', options);
|
||||||
} catch (error) {
|
},
|
||||||
console.error('Erro na busca:', error);
|
goToPage(page) {
|
||||||
this.error = `Erro ao buscar diários: ${error.message}`;
|
if (page < 1 || page > this.totalPages) return;
|
||||||
} finally {
|
this.searchParams.page = page;
|
||||||
this.isLoading = false;
|
this.performSearch();
|
||||||
}
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
},
|
},
|
||||||
|
|
||||||
formatDate(dateString) {
|
resetSearch() {
|
||||||
const options = { day: '2-digit', month: '2-digit', year: 'numeric' };
|
this.searchParams = {
|
||||||
return new Date(dateString + 'T00:00:00').toLocaleDateString('pt-BR', options);
|
q: '',
|
||||||
},
|
numero_diario: '',
|
||||||
goToPage(page) {
|
data_inicio: '',
|
||||||
if (page < 1 || page > this.totalPages) return;
|
data_fim: '',
|
||||||
this.searchParams.page = page;
|
modo_busca: 'exata',
|
||||||
this.performSearch();
|
ordenar_por: 'relevancia',
|
||||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
page: 1,
|
||||||
},
|
page_size: 10
|
||||||
|
};
|
||||||
resetSearch() {
|
this.searchResults = null;
|
||||||
this.searchParams = {
|
this.hasSearched = false;
|
||||||
q: '',
|
this.error = null;
|
||||||
numero_diario: '',
|
this.expandedContents = {};
|
||||||
data_inicio: '',
|
}
|
||||||
data_fim: '',
|
|
||||||
modo_busca: 'exata',
|
|
||||||
ordenar_por: 'relevancia',
|
|
||||||
page: 1,
|
|
||||||
page_size: 10
|
|
||||||
};
|
|
||||||
this.searchResults = null;
|
|
||||||
this.hasSearched = false;
|
|
||||||
this.error = null;
|
|
||||||
this.expandedContents = {};
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user