Skip to content

Commit

Permalink
Resolução de conflitos
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosViniciusG committed Jul 3, 2024
1 parent 3c1a6dc commit da11e40
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 165 deletions.
7 changes: 1 addition & 6 deletions lgbtq_connect/assets/js/funcionalidades.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,4 @@ function updateSelectValue(){
}
}

document.getElementById("meu_formulario").addEventListener("submit",updateSelectValue);

// Exporta as classes
module.exports = {
Pesquisador
};
document.getElementById("meu_formulario").addEventListener("submit",updateSelectValue);
338 changes: 193 additions & 145 deletions lgbtq_connect/includes/admin/admin_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class Tabela {
linha.innerHTML = `
<td id="formulario-${dados.id}-nome">${dados.nome}</td>
<td id="formulario-${dados.id}-email">${dados.email}</td>
<td id="formulario-${dados.id}-latitude">${dados.latitude}</td>
<td id="formulario-${dados.id}-longitude">${dados.longitude}</td>
<td id="formulario-${dados.id}-cidade">${dados.city}</td>
<td id="formulario-${dados.id}-rua">${dados.road}</td>
<td id="formulario-${dados.id}-servico">${dados.servico}</td>
<td id="formulario-${dados.id}-descricao">${descricao}</td>
<td id="formulario-${dados.id}-data_hora">${dataFormatada}</td>
Expand Down Expand Up @@ -178,23 +178,9 @@ function mostrarDescricaoCompleta(id) {
botao.innerText = 'Ver menos';
}
}
function destacarLinhaTabela(id) {
var tabela = document.getElementById("tabela");
var linha = document.getElementById(id);

// Loop para remover a linha-destacada de todas as linhas
for (var i = 0, row; (row = tabela.rows[i]); i++) {
row.classList.remove('linha-destacada');
}

linha.classList.add('linha-destacada'); // Adiciona a classe 'linha-destacada'
linha.scrollIntoView({ behavior: 'smooth' }); // Rola a página para a linha

// Remove a classe linha-destacada depois de um determinado tempo
setTimeout(function () {
linha.classList.remove('linha-destacada');
}, 2000);
}
function initMapAdmin() {
// Definindo o ícone personalizado no escopo global
const personalIcon = L.icon({
Expand All @@ -220,90 +206,54 @@ function initMapAdmin() {
});
});
}
function initSortButtons() {
// Adiciona um evento de clique aos botões de ordenação
var sortButtons = document.querySelectorAll('.sort-btn');

sortButtons.forEach(function(button) {
button.addEventListener('click', function() {
var table = button.closest('table');
var columnIndex = Array.from(button.parentNode.parentNode.children).indexOf(button.parentNode);
var order = button.getAttribute('data-order') || 'asc';

order = (order === 'asc') ? 'desc' : 'asc';
button.setAttribute('data-order', order);

// Atualiza o ícone do botão de ordenação
var icon = button.querySelector('.sort-icon');

// Remove e adiciona a classe do ícone com base na direção da ordenação
if (order === 'asc') {
icon.innerHTML = '&#9662;'; // Triângulo para baixo (ordem crescente)
} else {
icon.innerHTML = '&#9652;'; // Triângulo para cima (ordem decrescente)
}

// Obtém todas as linhas da tabela, exceto a primeira (cabeçalho)
var rows = Array.from(table.querySelectorAll('tbody > tr'));

// Determina o critério de ordenação com base na classe do botão
if (button.classList.contains('sort-by-date')) {
rows.sort(function(a, b) {
var aValue = new Date(a.children[columnIndex].textContent.trim().replace(/(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2}):(\d{2})/, '$3-$2-$1T$4:$5:$6'));
var bValue = new Date(b.children[columnIndex].textContent.trim().replace(/(\d{2})\/(\d{2})\/(\d{4}) (\d{2}):(\d{2}):(\d{2})/, '$3-$2-$1T$4:$5:$6'));
function initMapEdit(latitude, longitude, nome, servico, descricao) {
// Definindo o ícone personalizado no escopo global
const personalIcon = L.icon({
iconUrl: 'https://res.cloudinary.com/dxsx0emuu/image/upload/f_auto,q_auto/lc_marker',
iconSize: [20, 30], // tamanho do ícone
popupAnchor: [1, -10]
});

return (order === 'asc') ? aValue - bValue : bValue - aValue;
});
} else if (button.classList.contains('sort-by-email')) {
rows.sort(function(a, b) {
var aValue = a.children[columnIndex].textContent.trim().toLowerCase();
var bValue = b.children[columnIndex].textContent.trim().toLowerCase();
// Verifica se o mapa já foi inicializado e destrói se necessário
if (mapEdit !== undefined) {
mapEdit.remove();
}

return (order === 'asc') ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
});
} else {
// Caso padrão: ordenação por texto
rows.sort(function(a, b) {
var aValue = a.children[columnIndex].textContent.trim().toLowerCase();
var bValue = b.children[columnIndex].textContent.trim().toLowerCase();
mapEdit = L.map('mapa_formulario_edit', { doubleClickZoom: false }).setView([-15.8267, -47.9218], 13);

return (order === 'asc') ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
});
}
// Adiciona o provedor de mapa OpenStreetMap
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(mapEdit);

var popupConteudo = `
<div class="pop">
<h4><strong>${nome}</strong></h4>
<i>${servico}</i>
<div class="gradiente"></div>
<p><strong>${descricao}</strong></p>
</div>
`;

// Função para atualizar os inputs de latitude e longitude
function updateInputs(lat, lng) {
document.getElementById('editLatitude').value = lat;
document.getElementById('editLongitude').value = lng;
}

// Limpa o conteúdo da tabela antes de reordenar
while (table.querySelector('tbody').firstChild) {
table.querySelector('tbody').removeChild(table.querySelector('tbody').firstChild);
}
// Adiciona um marcador arrastável
var marker = L.marker(
[latitude, longitude],
{draggable: true, icon: personalIcon }
).addTo(mapEdit).bindPopup(popupConteudo);

// Reinsere as linhas ordenadas na tabela
rows.forEach(function(row) {
table.querySelector('tbody').appendChild(row);
});
});
marker.on('dragend', function (e) {
var newPosition = marker.getLatLng();
updateInputs(newPosition.lat, newPosition.lng);
});
}
// Limpa o conteúdo da tabela
function excluirLinhas(tabela)
{
while (tabela.querySelector('tbody').firstChild) {
tabela.querySelector('tbody').removeChild(tabela.querySelector('tbody').firstChild);
}
}

function adicionarZero(numero) {
return numero < 10 ? '0' + numero : numero;
}

function formatarDataHora(data) {
const dia = adicionarZero(data.getDate());
const mes = adicionarZero(data.getMonth() + 1); // Adiciona 1 porque os meses são indexados de 0 a 11
const ano = data.getFullYear();
const hora = adicionarZero(data.getHours());
const minutos = adicionarZero(data.getMinutes());
const segundos = adicionarZero(data.getSeconds());

return `${dia}/${mes}/${ano} ${hora}:${minutos}:${segundos}`;
document.getElementById('mapa_admin').style.display = "block";
}

function confirmarAcao(mensagem, formulario, acao) {
Expand Down Expand Up @@ -337,63 +287,161 @@ function confirmarAcao(mensagem, formulario, acao) {
}
};
}
function gerarLinhas(tabela, arr)
{
const STATUS_BOTOES = {
"Aprovado" : `
<button type="button" onclick="confirmarAcao('Tem certeza que quer negar a sugestão?', this.form, 'reprove')">Negar</button>
`,
"Negado" : `
<button type="button" onclick="confirmarAcao('Tem certeza que quer aprovar a sugestão?', this.form, 'approve')">Aprovar</button>
`,
"Pendente" : `
<button type="button" onclick="confirmarAcao('Tem certeza que quer aprovar a sugestão?', this.form, 'approve')">Aprovar</button>
<button type="button" onclick="confirmarAcao('Tem certeza que quer negar a sugestão?', this.form, 'reprove')">Negar</button>
`

function abrirModalEdicao(dados) {
const popup = document.getElementById("editPopup");
const modal = document.getElementById('editModal');

// Preenche os campos do formulário com os dados fornecidos
document.getElementById('editId').value = dados.id;
document.getElementById('editNome').value = dados.nome;
document.getElementById('editEmail').value = dados.email;
document.getElementById('editServico').value = dados.servico;
document.getElementById('editDescricao').value = dados.descricao;
document.getElementById('editLatitude').value = dados.latitude;
document.getElementById('editLongitude').value = dados.longitude;

initMapEdit(dados.latitude, dados.longitude, dados.nome, dados.servico, dados.descricao);

// Exibe o modal de edição
popup.style.display = "flex";
modal.style.display = "block";

// Atualiza o tamanho do mapa e define a visualização após um pequeno atraso para garantir que o modal tenha sido completamente exibido
setTimeout(function() {
mapEdit.invalidateSize();
mapEdit.setView([dados.latitude, dados.longitude], 13);
}, 200);

modal.scrollIntoView({ behavior: 'smooth' });

// Fecha o modal de edição quando o usuário clica fora do modal
window.onclick = function(event) {
if (event.target == popup) {
fecharEditor();
}
};
}

function fecharEditor() {
document.getElementById('editPopup').style.display = "none";
document.getElementById('editModal').style.display = "none";
document.getElementById('mapa_admin').style.display = "block";
document.getElementById('listaResultadosEdit').innerHTML = '';
document.getElementById('searchInputFormEdit').value = '';
}

function searchButtonClickedEdit() {
if (isSearching) {
return; // Se uma busca já estiver em andamento, saia da função
}
var tbody = tabela.querySelector('tbody');

arr.forEach(dados => {
var linha = document.createElement('tr');
linha.id = dados.id;
var descricao;
var data = new Date(dados.data_hora);
var dataFormatada = formatarDataHora(data);
if (dados.descricao.length > 10){
descricao = `
<span id="descricaoResumida_${dados.id}">${dados.descricao.substring(0, 10)}...</span>
<span id="descricaoCompleta_${dados.id}" style="display:none;">${dados.descricao}</span>
<button data-id="${dados.id}" onclick="mostrarDescricaoCompleta(${dados.id})">Ver mais</button>
`
isSearching = true; // Indica que uma busca está em andamento
var searchTerm = document.getElementById('searchInputFormEdit').value;
searchLocations(searchTerm);
}

function searchLocations(query) {
var resultados = [];
var apiUrl = 'https://nominatim.openstreetmap.org/search?format=json&q=' + encodeURIComponent(query);
fetch(apiUrl)
.then(response => response.json())
.then(data => {
data.forEach(location => {
resultados.push({
display_name: location.display_name,
lat: location.lat,
lon: location.lon
});
});
imprimirResultados(resultados);
isSearching = false; // Indica que a busca foi concluída
})
.catch(error => {
console.error('Erro ao buscar locais:', error);
isSearching = false; // Indica que a busca foi concluída mesmo com erro
});
}

function imprimirResultados(resultados) {
var listaResultadosOcultados = [];
var listaResultados = document.getElementById('listaResultadosEdit');

listaResultados.innerHTML = '';
var count = 0;
var div = document.createElement('div');
resultados.forEach(resultado => {
var divResultado = document.createElement('div');
divResultado.classList.add('celula_resultado');
divResultado.style.borderRadius = '3px';
divResultado.style.margin = '5px 5px 5px 0px';
divResultado.style.cursor = 'pointer';
divResultado.innerHTML = '<img src="https://i.imgur.com/4ZnmAxk.png" width="20px" height="20px">' + resultado.display_name;
divResultado.addEventListener('click', function () {
changeMapView(resultado.lat, resultado.lon);
});
count += 1;
if(count <= 5) {
div.appendChild(divResultado);
} else {
divResultado.style.display = 'none';
listaResultadosOcultados.push(divResultado);
div.appendChild(divResultado);
}
});

listaResultados.appendChild(div);

if (count > 5) {
// Adicionando botão "Ver Mais"
var verMaisButton = document.createElement('button');
verMaisButton.textContent = 'Ver Mais';
verMaisButton.setAttribute('type', 'button');
verMaisButton.setAttribute('class', 'ver');
verMaisButton.addEventListener('click', function() {
MostrarMaisResultados();
});

listaResultados.appendChild(verMaisButton);

// Adicionando botão "Ver Menos"
var verMenosButton = document.createElement('button');
verMenosButton.textContent = 'Ver Menos';
verMenosButton.setAttribute('type', 'button');
verMenosButton.setAttribute('class', 'ver');
verMenosButton.addEventListener('click', function() {
MostrarMenosResultados();
});
verMenosButton.style.display = 'none';

listaResultados.appendChild(verMenosButton);

// Função para mostrar mais resultados
function MostrarMaisResultados() {
listaResultadosOcultados.forEach(resultado => {
resultado.style.display = 'block';
});
verMaisButton.style.display = 'none';
verMenosButton.style.display = 'block';
}
else {
descricao = dados.descricao;

// Função para mostrar menos resultados
function MostrarMenosResultados() {
listaResultadosOcultados.forEach(resultado => {
resultado.style.display = 'none';
});
verMaisButton.style.display = 'block';
verMenosButton.style.display = 'none';
}

acoes = STATUS_BOTOES[dados.situacao];

linha.innerHTML = `
<td>${dados.nome}</td>
<td>${dados.email}</td>
<td>${dados.city}</td>
<td>${dados.road}</td>
<td>${dados.servico}</td>
<td>${descricao}</td>
<td>${dataFormatada}</td>
<td>${dados.situacao}</td>
<td>
<form method="post" action="">
<input type="hidden" name="id" value="${dados.id}">
<input type="hidden" name="action" value="">
${acoes}
<button type="button">Editar</button>
<button type="button" onclick="confirmarAcao('Tem certeza que quer excluir a sugestão?', this.form, 'exclude')">Excluir</button>
</td>
`;
tbody.appendChild(linha);
});
}
}

function changeMapView(lat, lng) {
if (mapEdit) {
mapEdit.setView([lat, lng], 13);
} else {
console.error("Mapa de edição não ativo");
}
}
}

function filtrar(elemento) {
let arr = [];
Expand Down
Loading

0 comments on commit da11e40

Please sign in to comment.