Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #146

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions api/src/Gateways/PerguntaGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function __construct(Database $database)

public function getAll(array $ordenacao): array
{
$sql = "SELECT p.*,
$sql = "SELECT DISTINCT p.*,
u.id AS id_usuario,
u.nome_completo AS nome_usuario,
u.email AS email_usuario,
Expand All @@ -26,7 +26,7 @@ public function getAll(array $ordenacao): array
LEFT JOIN usuario ue ON pe.usuario_id = ue.id";

if (isset($ordenacao["MaisAlta"]) && $ordenacao["MaisAlta"]) {
$sql = "SELECT p.*,
$sql = "SELECT DISTINCT p.*,
u.id AS id_usuario,
u.nome_completo AS nome_usuario,
u.email AS email_usuario,
Expand All @@ -43,11 +43,12 @@ public function getAll(array $ordenacao): array
CASE
WHEN prioridade = 'Alta' THEN 1
WHEN prioridade = 'Normal' THEN 2
END;";
END
";
}

if (isset($ordenacao["MaisCurtidas"]) && $ordenacao["MaisCurtidas"]) {
$sql = "SELECT p.*,
$sql = "SELECT DISTINCT p.*,
u.id AS id_usuario,
u.nome_completo AS nome_usuario,
u.email AS email_usuario,
Expand Down
173 changes: 104 additions & 69 deletions sistema/curtidas/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,78 @@ const execute = async () => {
console.log(error);
}

tbody.innerHTML += perguntas
.map(
(pergunta) =>
`<tr>
<td>
<div id="id">
<span>${pergunta.id}</span>
</div>
</td>
<td>
<div id="colaborador">
<div class="avatar">
<img src="${pergunta.foto_usuario ?? '../../img/userFallback.jpg'}" />
</div>
<div class="nome">
<span>${pergunta.nome_usuario ?? 'Sem usuário'}</span>
</div>
</div>
</td>
<td>
<div id="pergunta">
${pergunta.pergunta}
</div>
</td>
<td>
<div id="curtidas"><span>${pergunta.curtidas}</span></div>
</td>
<td>
${
user.cargo === 'Administrador'
? `<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${pergunta.id} href="#"><i class="fas fa-trash-can"></i></button>
</div>`
: pergunta.criado_por === user.id
? `<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${pergunta.id} href="#"><i class="fas fa-trash-can"></i></button>
</div>`
: ''
}
</td>
</tr>
`,
)
.join('');

let botaoDeletar = document.querySelectorAll('.click');

botaoDeletar.forEach((botao) => {
botao.addEventListener('click', () => {
const id = botao.dataset.id;

Swal.fire({
title: 'Tem certezar que quer deletar a pergunta?',
showCancelButton: true,
confirmButtonText: 'Sim, confirmar!',
cancelButtonText: 'Não',
icon: 'question',
}).then(async (result) => {
if (result.isConfirmed) {
try {
await deletarPergunta(id);
window.location.reload();
} catch (error) {
toast(error.message, true);
}
}
});
});
});

//ordena as perguntas pra trazer as mais curtidas primeiro
curtidasIcon.addEventListener('click', () => {
const isClicked = curtidasIcon.getAttribute('isclicked') === 'true';
Expand All @@ -60,9 +132,10 @@ const execute = async () => {

tbody.innerHTML = '';

tbody.innerHTML += perguntas.map(
(pergunta) =>
`<tr>
tbody.innerHTML += perguntas
.map(
(pergunta) =>
`<tr>
<td>
<div id="id">
<span>${pergunta.id}</span>
Expand All @@ -87,87 +160,49 @@ const execute = async () => {
<div id="curtidas"><span>${pergunta.curtidas}</span></div>
</td>
<td>
<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${
pergunta.id
} href="#"><i class="fas fa-trash-can"></i></button>
</div>
</td>
</tr>
`,
);

curtidasIcon.setAttribute('isclicked', isClicked ? 'false' : 'true');
});

tbody.innerHTML += perguntas.map(
(pergunta) =>
`<tr>
<td>
<div id="id">
<span>${pergunta.id}</span>
</div>
</td>
<td>
<div id="colaborador">
<div class="avatar">
<img src="${pergunta.foto_usuario ?? '../../img/userFallback.jpg'}" />
</div>
<div class="nome">
<span>${pergunta.nome_usuario ?? 'Sem usuário'}</span>
</div>
</div>
</td>
<td>
<div id="pergunta">
${pergunta.pergunta}
</div>
</td>
<td>
<div id="curtidas"><span>${pergunta.curtidas}</span></div>
</td>
<td>
${
user.cargo === 'Administrador'
? `<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${pergunta.id} href="#"><i class="fas fa-trash-can"></i></button>
</div>`
: pergunta.criado_por === user.id
? `<div id="acao">
? `<div id="acao">
<a href="../../sistema/perguntas/editar/"><i class="fas fa-pencil"></i></a>
<button class='click' data-id=${pergunta.id} href="#"><i class="fas fa-trash-can"></i></button>
</div>`
: ''
: ''
}
</td>
</tr>
`,
);

//logica para deletar a pergunta
const botaoDeletar = document.querySelectorAll('.click');
</tr>
`,
)
.join('');

botaoDeletar.forEach((botao) => {
botao.addEventListener('click', () => {
const id = botao.dataset.id;
curtidasIcon.setAttribute('isclicked', isClicked ? 'false' : 'true');

Swal.fire({
title: 'Tem certezar que quer deletar a pergunta?',
showCancelButton: true,
confirmButtonText: 'Sim, confirmar!',
cancelButtonText: 'Não',
icon: 'question',
}).then(async (result) => {
if (result.isConfirmed) {
try {
await deletarPergunta(id);
window.location.reload();
} catch (error) {
toast(error.message, true);
botaoDeletar = document.querySelectorAll('.click');

botaoDeletar.forEach((botao) => {
botao.addEventListener('click', () => {
const id = botao.dataset.id;

Swal.fire({
title: 'Tem certezar que quer deletar a pergunta?',
showCancelButton: true,
confirmButtonText: 'Sim, confirmar!',
cancelButtonText: 'Não',
icon: 'question',
}).then(async (result) => {
if (result.isConfirmed) {
try {
await deletarPergunta(id);
window.location.reload();
} catch (error) {
toast(error.message, true);
}
}
}
});
});
});
});
Expand Down
10 changes: 6 additions & 4 deletions sistema/perguntas/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@ const execute = async () => {

suasPerguntasTbody.innerHTML = '';

suasPerguntasTbody.innerHTML += perguntasDoUsuario.map((pergunta) => {
const data = new Date(pergunta.criado_em);
suasPerguntasTbody.innerHTML += perguntasDoUsuario
.map((pergunta) => {
const data = new Date(pergunta.criado_em);

return `
return `
<tr>
<td>
<div id="id">
Expand Down Expand Up @@ -321,7 +322,8 @@ const execute = async () => {
</div>
</td>
</tr>`;
});
})
.join('');

const botaoDeletar = document.querySelectorAll('.deletar-pergunta');

Expand Down
Loading