Skip to content

Commit

Permalink
Merge pull request #11 from secultce/feat/config-options-for-publishi…
Browse files Browse the repository at this point in the history
…ng-opinions

Adicionada configuração para publicar manualmente os pareceres.
  • Loading branch information
Junior-Shyko authored and ronnyjohnti committed Mar 13, 2024
2 parents f40b995 + 4dcbf03 commit 3916a23
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 40 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Todas as mudanças relevantes serão documentadas nesse arquivo.

O formato é baseado no [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0), e esse projeto adere ao [Semantic Versionning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2024-03-13
### Adicionado
- Agora o administrador pode selecionar se quer fazer publicação dos pareceres de forma automática ou manual;
- Adicionando botão para administrador publicar os pareceres (somente quando estiver configurado como publicação manual).

## [1.0.0] - 2024-02-27
### Adicionado
- O administrador da oportunidade consegue ver a lista de pareceres na aba de inscrições da oportunidade.
Expand Down
12 changes: 10 additions & 2 deletions Controllers/OpinionManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function GET_opinions(): void
* @var $registration \MapasCulturais\Entities\Registration
*/
$registration = $app->repo('Registration')->find($this->getData['id']);
$opinions = [];
if($registration->canUser('view')) {
$opinions = new EvaluationList($registration);
$this->json($opinions);
Expand All @@ -54,9 +53,18 @@ public function POST_publishOpinions(): void

$opportunity = $app->repo('Opportunity')->find($this->postData['id']);
if(!$opportunity->isUserAdmin($app->user)) {
$this->errorJson(['permission-denied'], 403);
return;
}

// dump($opportunity->);

$opportunity->setMetadata('publishedOpinions', 'true');
$error = $opportunity->save(true);
if($error) {
$this->errorJson(['error' => new \PDOException('Cannot save this data')], 500);
return;
}

$this->json(['success' => true]);
}
}
89 changes: 60 additions & 29 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
*/
class Plugin extends \MapasCulturais\Plugin
{

public function _init(): void
{
$app = (new App)->i();

$app->hook('template(<<registration|opportunity>>.<<single|view>>.head):begin', function () use ($app) {
// Load assets in head
$app->hook('template(<<registration|opportunity|panel>>.<<single|view|registrations|index>>.head):begin', function () use ($app) {
$app->view->enqueueScript(
'app',
'swal2',
Expand All @@ -32,39 +31,29 @@ public function _init(): void
'opinionManagement',
'OpinionManagement/css/opinionManagement.css'
);

$app->view->enqueueScript(
'app',
'opinion-management',
'OpinionManagement/js/opinionManagement.js'
);
});
$app->hook('template(panel.<<registrations|index>>.head):begin', function () use ($app) {
$app->view->enqueueScript(
'app',
'swal2',
'js/sweetalert2.all.min.js'
);
$app->view->enqueueStyle(
'app',
'swal2-theme-secultce',
'css/swal2-secultce.min.css'
);
$app->view->enqueueStyle(
'app',
'opinionManagement',
'OpinionManagement/css/opinionManagement.css'
);

$app->view->enqueueScript(
'app',
'opinion-management',
'OpinionManagement/js/opinionManagement.js'
);
$app->hook('template(opportunity.edit.registration-config):after', function () use ($app) {
$opportunity = $this->controller->requestedEntity;
/**
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
*/
if($opportunity->evaluationMethodConfiguration->type != 'documentary') {
return;
}
$this->part('OpinionManagement/selection-autopublish', ['opportunity' => $opportunity]);
});

$app->hook('template(opportunity.single.registration-list-header):end', function() use($app) {
$opportunity = $this->controller->requestedEntity;
/**
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
*/
if($opportunity->evaluationMethodConfiguration->type != 'documentary') {
return;
}
Expand All @@ -82,8 +71,12 @@ public function _init(): void
});
}
});

$app->hook('template(opportunity.single.user-registration-table--registration--status):end', function ($registration, $opportunity) use ($app) {
if($opportunity->evaluationMethodConfiguration->type != 'documentary' || !$opportunity->publishedRegistrations) {
/**
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
*/
if($opportunity->publishedOpinions != 'true') {
return;
}

Expand All @@ -92,12 +85,28 @@ public function _init(): void
}
});

$app->hook('template(opportunity.single.opportunity-registrations--tables):begin', function () use ($app) {
$opportunity = $this->controller->requestedEntity;
/**
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
*/
if($opportunity->evaluationMethodConfiguration->type != 'documentary'
|| $opportunity->autopublishOpinions !== 'Não'
|| $opportunity->publishedOpinions == 'true'
) {
return;
}

$this->part('OpinionManagement/admin-btn-publish-opinions.php', ['opportunity' => $opportunity]);
});

$app->hook('template(registration.view.header-fieldset):after', function() use($app) {
$registration = $this->controller->requestedEntity;
$opportunity = $registration->opportunity;

// http://localhost:8080/inscricao/612180872/

/**
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
*/
if($opportunity->evaluationMethodConfiguration->type != 'documentary' || (!$opportunity->publishedRegistrations && !$opportunity->canUser('@control'))) {
return;
}
Expand All @@ -107,8 +116,10 @@ public function _init(): void
}
});


$app->hook('template(panel.<<registrations|index>>.panel-registration):end', function ($registration) use ($app) {
/**
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
*/
if(!$registration->opportunity->publishedRegistrations
|| $registration->opportunity->evaluationMethodConfiguration->type != 'documentary'
) return;
Expand All @@ -119,6 +130,11 @@ public function _init(): void
'OpinionManagement/js/opinionManagement.js'
);
});

$app->hook('entity(Opportunity).publishRegistrations:before', function () {
if($this->autopublishOpinions == 'Sim')
$this->setMetadata('publishedOpinions', 'true');
});
}

/**
Expand All @@ -130,5 +146,20 @@ public function register(): void

$app->registerController('opinionManagement', OpinionManagement::class);

$this->registerOpportunityMetadata('autopublishOpinions', [
'type' => 'select',
'default_value' => 'Não',
'label' => \MapasCulturais\i::__('Publicar pareceres automaticamente'),
'description' => \MapasCulturais\i::__('Indica se os pareceres devem ser publicados automaticamente'),
'options' => ['Sim', 'Não'],
'required' => true,
]);
$this->registerOpportunityMetadata('publishedOpinions', [
'type' => 'select',
'label' => \MapasCulturais\i::__('Pareceres publicados'),
'default_value' => 'false',
'options' => ['true', 'false'],
'required' => true,
]);
}
}
10 changes: 10 additions & 0 deletions assets/OpinionManagement/css/opinionManagement.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,13 @@ div:has(>.showOpinion) {
text-align: start;
margin-top: 8px;
}

.opinions-section {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}

.opinions-section hr {
width: 100%;
}
68 changes: 59 additions & 9 deletions assets/OpinionManagement/js/opinionManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const handleChkCollapseChange = target => {
}
}


const opinionHtml = opinion => {
let htmlParsed = '<div class="opinion">'
htmlParsed += `<div class="evaluation-title">
Expand Down Expand Up @@ -67,12 +66,63 @@ const showOpinions = registrationId => {
if(error.message === 'Forbidden') message = 'Você não tem permissão para acessar este recurso.'
if(error.message === 'Guest') message = 'É necessário estar autenticado.'

Swal.fire({
title: "Oops...",
text: "Aconteceu um problema!",
footer: `<code style="font-size:11px; color:#c93">${message}</code>`,
showConfirmButton: false,
showCloseButton: true,
})
errorAlert(message)
})
}

const publishOpinions = target => {
const opportunityId = target.getAttribute('data-id');

Swal.fire({
title: "Essa ação é irreversível!",
html: "Ao clicar em <strong>'Publicar'</strong> você está publicando os pareceres para a visualização dos proponentes. Isso não pode ser desfeito.",
showConfirmButton: true,
showCloseButton: false,
showCancelButton: true,
confirmButtonText: 'Publicar',
cancelButtonText: 'Cancelar',
})
.then(result => {
if(result.isConfirmed)
fetch(MapasCulturais.baseURL + 'opinionManagement/publishOpinions', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
id: opportunityId,
}),
})
.then(response => {
if(response.redirected) throw new Error('Guest')
if (!response.ok) throw new Error(response.statusText)
return response.json()
})
.then(response => {
console.log(response)
Swal.fire({
title: "Pareceres publicados com sucesso!",
text: "Os pareceres desta inscrição agora encontram-se publicados.",
showConfirmButton: false,
showCloseButton: true,
})
})
.catch(error => {
let { message } = error
if(error.message === 'Forbidden') message = 'Você não tem permissão para acessar este recurso.'
if(error.message === 'Guest') message = 'É necessário estar autenticado.'

errorAlert(message)
})
})
}
}

const errorAlert = message => {
Swal.fire({
title: "Oops...",
text: "Aconteceu um problema!",
footer: `<code style="font-size:11px; color:#c93">${message}</code>`,
showConfirmButton: false,
showCloseButton: true,
})
}
18 changes: 18 additions & 0 deletions layouts/parts/OpinionManagement/admin-btn-publish-opinions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/** @var \MapasCulturais\Entities\Opportunity $opportunity */
?>
<?php $this->applyTemplateHook('opinions-section','before'); ?>
<section class="opinions-section">
<h3>Pareceres</h3>
<div>
<?php $this->applyTemplateHook('opinions-section.buttons','begin'); ?>
<button
class="btn btn-primary"
onclick="publishOpinions(this)"
data-id="<?= $opportunity->id ?>"
><?= \MapasCulturais\i::__('Publicar Pareceres') ?></button>
<?php $this->applyTemplateHook('opinions-section.buttons','end'); ?>
</div>
<hr>
</section>
<?php $this->applyTemplateHook('opinions-section','after'); ?>
21 changes: 21 additions & 0 deletions layouts/parts/OpinionManagement/selection-autopublish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<style>
#opinions-config:has(~ #evaluations-config[style="display: none;"]) {
display: none;
}
</style>

<div id="opinions-config" class="registration-fieldset">
<h4>Publicação de Pareceres</h4>
<p>Deseja que os pareceres desta fase/oportunidade sejam publicados para os proponentes automaticamente ao publicar os resultados?</p>
<span
class="js-editable editable editable-click editable-unsaved"
data-edit="autopublishOpinions"
data-original-title="Publicar pareceres automaticamente"
data-value="<?= /** @var \MapasCulturais\Entities\Opportunity $opportunity */
$opportunity->getMetadata('autopublishOpinions') ?>"
>
<?= $opportunity->getMetadata('autopublishOpinions') ?>
</span>
<br><br>
<em>Caso marque "Não" aparecerá um botão para publicar pareceres manualmente na aba de inscrições.</em>
</div>

0 comments on commit 3916a23

Please sign in to comment.