Skip to content

Commit a48792e

Browse files
authored
Merge pull request #11 from secultce/feat/config-options-for-publishing-opinions
Adicionada configuração para publicar manualmente os pareceres.
2 parents f40b995 + 4dcbf03 commit a48792e

File tree

6 files changed

+178
-40
lines changed

6 files changed

+178
-40
lines changed

Controllers/OpinionManagement.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function GET_opinions(): void
3535
* @var $registration \MapasCulturais\Entities\Registration
3636
*/
3737
$registration = $app->repo('Registration')->find($this->getData['id']);
38-
$opinions = [];
3938
if($registration->canUser('view')) {
4039
$opinions = new EvaluationList($registration);
4140
$this->json($opinions);
@@ -54,9 +53,18 @@ public function POST_publishOpinions(): void
5453

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

60-
// dump($opportunity->);
60+
61+
$opportunity->setMetadata('publishedOpinions', 'true');
62+
$error = $opportunity->save(true);
63+
if($error) {
64+
$this->errorJson(['error' => new \PDOException('Cannot save this data')], 500);
65+
return;
66+
}
67+
68+
$this->json(['success' => true]);
6169
}
6270
}

Plugin.php

+60-29
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
*/
1212
class Plugin extends \MapasCulturais\Plugin
1313
{
14-
1514
public function _init(): void
1615
{
1716
$app = (new App)->i();
18-
19-
$app->hook('template(<<registration|opportunity>>.<<single|view>>.head):begin', function () use ($app) {
17+
// Load assets in head
18+
$app->hook('template(<<registration|opportunity|panel>>.<<single|view|registrations|index>>.head):begin', function () use ($app) {
2019
$app->view->enqueueScript(
2120
'app',
2221
'swal2',
@@ -32,39 +31,29 @@ public function _init(): void
3231
'opinionManagement',
3332
'OpinionManagement/css/opinionManagement.css'
3433
);
35-
3634
$app->view->enqueueScript(
3735
'app',
3836
'opinion-management',
3937
'OpinionManagement/js/opinionManagement.js'
4038
);
4139
});
42-
$app->hook('template(panel.<<registrations|index>>.head):begin', function () use ($app) {
43-
$app->view->enqueueScript(
44-
'app',
45-
'swal2',
46-
'js/sweetalert2.all.min.js'
47-
);
48-
$app->view->enqueueStyle(
49-
'app',
50-
'swal2-theme-secultce',
51-
'css/swal2-secultce.min.css'
52-
);
53-
$app->view->enqueueStyle(
54-
'app',
55-
'opinionManagement',
56-
'OpinionManagement/css/opinionManagement.css'
57-
);
5840

59-
$app->view->enqueueScript(
60-
'app',
61-
'opinion-management',
62-
'OpinionManagement/js/opinionManagement.js'
63-
);
41+
$app->hook('template(opportunity.edit.registration-config):after', function () use ($app) {
42+
$opportunity = $this->controller->requestedEntity;
43+
/**
44+
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
45+
*/
46+
if($opportunity->evaluationMethodConfiguration->type != 'documentary') {
47+
return;
48+
}
49+
$this->part('OpinionManagement/selection-autopublish', ['opportunity' => $opportunity]);
6450
});
6551

6652
$app->hook('template(opportunity.single.registration-list-header):end', function() use($app) {
6753
$opportunity = $this->controller->requestedEntity;
54+
/**
55+
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
56+
*/
6857
if($opportunity->evaluationMethodConfiguration->type != 'documentary') {
6958
return;
7059
}
@@ -82,8 +71,12 @@ public function _init(): void
8271
});
8372
}
8473
});
74+
8575
$app->hook('template(opportunity.single.user-registration-table--registration--status):end', function ($registration, $opportunity) use ($app) {
86-
if($opportunity->evaluationMethodConfiguration->type != 'documentary' || !$opportunity->publishedRegistrations) {
76+
/**
77+
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
78+
*/
79+
if($opportunity->publishedOpinions != 'true') {
8780
return;
8881
}
8982

@@ -92,12 +85,28 @@ public function _init(): void
9285
}
9386
});
9487

88+
$app->hook('template(opportunity.single.opportunity-registrations--tables):begin', function () use ($app) {
89+
$opportunity = $this->controller->requestedEntity;
90+
/**
91+
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
92+
*/
93+
if($opportunity->evaluationMethodConfiguration->type != 'documentary'
94+
|| $opportunity->autopublishOpinions !== 'Não'
95+
|| $opportunity->publishedOpinions == 'true'
96+
) {
97+
return;
98+
}
99+
100+
$this->part('OpinionManagement/admin-btn-publish-opinions.php', ['opportunity' => $opportunity]);
101+
});
102+
95103
$app->hook('template(registration.view.header-fieldset):after', function() use($app) {
96104
$registration = $this->controller->requestedEntity;
97105
$opportunity = $registration->opportunity;
98106

99-
// http://localhost:8080/inscricao/612180872/
100-
107+
/**
108+
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
109+
*/
101110
if($opportunity->evaluationMethodConfiguration->type != 'documentary' || (!$opportunity->publishedRegistrations && !$opportunity->canUser('@control'))) {
102111
return;
103112
}
@@ -107,8 +116,10 @@ public function _init(): void
107116
}
108117
});
109118

110-
111119
$app->hook('template(panel.<<registrations|index>>.panel-registration):end', function ($registration) use ($app) {
120+
/**
121+
* @todo: Refatorar quando for mudar para publicar pareceres técnicos
122+
*/
112123
if(!$registration->opportunity->publishedRegistrations
113124
|| $registration->opportunity->evaluationMethodConfiguration->type != 'documentary'
114125
) return;
@@ -119,6 +130,11 @@ public function _init(): void
119130
'OpinionManagement/js/opinionManagement.js'
120131
);
121132
});
133+
134+
$app->hook('entity(Opportunity).publishRegistrations:before', function () {
135+
if($this->autopublishOpinions == 'Sim')
136+
$this->setMetadata('publishedOpinions', 'true');
137+
});
122138
}
123139

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

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

149+
$this->registerOpportunityMetadata('autopublishOpinions', [
150+
'type' => 'select',
151+
'default_value' => 'Não',
152+
'label' => \MapasCulturais\i::__('Publicar pareceres automaticamente'),
153+
'description' => \MapasCulturais\i::__('Indica se os pareceres devem ser publicados automaticamente'),
154+
'options' => ['Sim', 'Não'],
155+
'required' => true,
156+
]);
157+
$this->registerOpportunityMetadata('publishedOpinions', [
158+
'type' => 'select',
159+
'label' => \MapasCulturais\i::__('Pareceres publicados'),
160+
'default_value' => 'false',
161+
'options' => ['true', 'false'],
162+
'required' => true,
163+
]);
133164
}
134165
}

assets/OpinionManagement/css/opinionManagement.css

+10
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,13 @@ div:has(>.showOpinion) {
145145
text-align: start;
146146
margin-top: 8px;
147147
}
148+
149+
.opinions-section {
150+
display: flex;
151+
flex-wrap: wrap;
152+
justify-content: space-between;
153+
}
154+
155+
.opinions-section hr {
156+
width: 100%;
157+
}

assets/OpinionManagement/js/opinionManagement.js

+59-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const handleChkCollapseChange = target => {
66
}
77
}
88

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

70-
Swal.fire({
71-
title: "Oops...",
72-
text: "Aconteceu um problema!",
73-
footer: `<code style="font-size:11px; color:#c93">${message}</code>`,
74-
showConfirmButton: false,
75-
showCloseButton: true,
76-
})
69+
errorAlert(message)
70+
})
71+
}
72+
73+
const publishOpinions = target => {
74+
const opportunityId = target.getAttribute('data-id');
75+
76+
Swal.fire({
77+
title: "Essa ação é irreversível!",
78+
html: "Ao clicar em <strong>'Publicar'</strong> você está publicando os pareceres para a visualização dos proponentes. Isso não pode ser desfeito.",
79+
showConfirmButton: true,
80+
showCloseButton: false,
81+
showCancelButton: true,
82+
confirmButtonText: 'Publicar',
83+
cancelButtonText: 'Cancelar',
84+
})
85+
.then(result => {
86+
if(result.isConfirmed)
87+
fetch(MapasCulturais.baseURL + 'opinionManagement/publishOpinions', {
88+
method: 'POST',
89+
headers: {
90+
'Content-Type': 'application/x-www-form-urlencoded'
91+
},
92+
body: new URLSearchParams({
93+
id: opportunityId,
94+
}),
95+
})
96+
.then(response => {
97+
if(response.redirected) throw new Error('Guest')
98+
if (!response.ok) throw new Error(response.statusText)
99+
return response.json()
100+
})
101+
.then(response => {
102+
console.log(response)
103+
Swal.fire({
104+
title: "Pareceres publicados com sucesso!",
105+
text: "Os pareceres desta inscrição agora encontram-se publicados.",
106+
showConfirmButton: false,
107+
showCloseButton: true,
108+
})
109+
})
110+
.catch(error => {
111+
let { message } = error
112+
if(error.message === 'Forbidden') message = 'Você não tem permissão para acessar este recurso.'
113+
if(error.message === 'Guest') message = 'É necessário estar autenticado.'
114+
115+
errorAlert(message)
116+
})
77117
})
78-
}
118+
}
119+
120+
const errorAlert = message => {
121+
Swal.fire({
122+
title: "Oops...",
123+
text: "Aconteceu um problema!",
124+
footer: `<code style="font-size:11px; color:#c93">${message}</code>`,
125+
showConfirmButton: false,
126+
showCloseButton: true,
127+
})
128+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/** @var \MapasCulturais\Entities\Opportunity $opportunity */
3+
?>
4+
<?php $this->applyTemplateHook('opinions-section','before'); ?>
5+
<section class="opinions-section">
6+
<h3>Pareceres</h3>
7+
<div>
8+
<?php $this->applyTemplateHook('opinions-section.buttons','begin'); ?>
9+
<button
10+
class="btn btn-primary"
11+
onclick="publishOpinions(this)"
12+
data-id="<?= $opportunity->id ?>"
13+
><?= \MapasCulturais\i::__('Publicar Pareceres') ?></button>
14+
<?php $this->applyTemplateHook('opinions-section.buttons','end'); ?>
15+
</div>
16+
<hr>
17+
</section>
18+
<?php $this->applyTemplateHook('opinions-section','after'); ?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<style>
2+
#opinions-config:has(~ #evaluations-config[style="display: none;"]) {
3+
display: none;
4+
}
5+
</style>
6+
7+
<div id="opinions-config" class="registration-fieldset">
8+
<h4>Publicação de Pareceres</h4>
9+
<p>Deseja que os pareceres desta fase/oportunidade sejam publicados para os proponentes automaticamente ao publicar os resultados?</p>
10+
<span
11+
class="js-editable editable editable-click editable-unsaved"
12+
data-edit="autopublishOpinions"
13+
data-original-title="Publicar pareceres automaticamente"
14+
data-value="<?= /** @var \MapasCulturais\Entities\Opportunity $opportunity */
15+
$opportunity->getMetadata('autopublishOpinions') ?>"
16+
>
17+
<?= $opportunity->getMetadata('autopublishOpinions') ?>
18+
</span>
19+
<br><br>
20+
<em>Caso marque "Não" aparecerá um botão para publicar pareceres manualmente na aba de inscrições.</em>
21+
</div>

0 commit comments

Comments
 (0)