Skip to content

Commit

Permalink
Merge branch 'mapasculturais:develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
lpirola authored May 23, 2024
2 parents e17426a + 238eea8 commit 3d2ae0e
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 77 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ e este projeto adere ao [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- resolve aplicar filtros para pesquisa de eventos
- Faz as abas `com permissão` das entidades do painel listarem também as entidades em rascunho

## [7.3.58] - 2024-05-22
### Correções
- Remove webmanifest para evitar erros no carregamento atravez do safari

## [7.3.57] - 2024-05-17
### Melhorias
- Não solicita o campo País em ambientes com a configuração statesAndCitiesCountryCode definida como BR
Expand Down
11 changes: 8 additions & 3 deletions src/core/Controllers/Opportunity.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,15 @@ function apiFindRegistrations($opportunity, $query_data) {
// $phase é a fase que foi informada no parâmetro @opportunity
if($phase->equals($opportunity)) {
if($phase->publishedRegistrations && !$phase->canUser('viewEvaluations') && !$phase->canUser('@control')){
// usuários com permissão na oportunidade podem ver inscrições em rascunho
// usuários sem permissão só podem ver inscrições não pendentes (selecionadas, suplentes, não selecionadas e inválidas [status > 1])
$filter_status = $phase->canUser('@control') ?
API::GTE(Registration::STATUS_DRAFT) : API::GT(Registration::STATUS_SENT);

if(isset($data['status'])){
$current_phase_query_params['status'] = API::AND(API::IN([10,8]), $data['status']);
$current_phase_query_params['status'] = API::AND($filter_status, $data['status']);
} else {
$current_phase_query_params['status'] = API::IN([10,8]);
$current_phase_query_params['status'] = $filter_status;
}
} else if(isset($data['status'])) {
$current_phase_query_params['status'] = $data['status'];
Expand Down Expand Up @@ -488,7 +493,7 @@ function apiFindRegistrations($opportunity, $query_data) {
$current_phase_query_params['@select'] = implode(',', $current_phase_query_select);

$current_phase_query = new ApiQuery(Registration::class, $current_phase_query_params);
if(isset($previous_phase_query)) {
if(isset($previous_phase_query) && !$phase->isLastPhase) {
$current_phase_query->addFilterByApiQuery($previous_phase_query, 'number', 'number');
}
$previous_phase_query = $current_phase_query;
Expand Down
75 changes: 44 additions & 31 deletions src/core/Entities/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ static function getValidations() {
$app = App::i();
$validations = [
'owner' => [
'required' => \MapasCulturais\i::__("O agente responsável é obrigatório."),
'$this->validateOwnerLimit()' => \MapasCulturais\i::__('Foi excedido o limite de inscrições para este agente responsável.'),
'required' => i::__("O agente responsável é obrigatório."),
'$this->validateOwnerLimit()' => i::__('Foi excedido o limite de inscrições para este agente responsável.'),
]
];

Expand Down Expand Up @@ -984,6 +984,35 @@ function cleanMaskedRegistrationFields(){
$app->enableAccessControl();
}

/**
* Verifica se um campo deve ser exibido com base nas categorias,
* faixas e tipos de proponente definidos na configuração do campo.
*
* @param RegistrationFieldConfiguration|RegistrationFileConfiguration $field O campo a ser verificado.
* @return bool Verdadeiro se o campo deve ser exibido, falso caso contrário.
*/
function isFieldVisisble(RegistrationFieldConfiguration|RegistrationFileConfiguration $field): bool {
$opportunity = $this->opportunity;

$use_category = (bool) $opportunity->registrationCategories;
$use_range = (bool) $opportunity->registrationRanges;
$use_proponent_types = (bool) $opportunity->registrationProponentTypes;

if ($use_category && count($field->categories) > 0 && !in_array($this->category, $field->categories)) {
return false;
}

if ($use_range && count($field->registrationRanges) > 0 && !in_array($this->range, $field->registrationRanges)) {
return false;
}

if ($use_proponent_types && count($field->proponentTypes) > 0 && !in_array($this->proponentType, $field->proponentTypes)) {
return false;
}

return true;
}

function getValidationErrors() {
if($this->isNew()) {
return parent::getValidationErrors();
Expand All @@ -1008,15 +1037,15 @@ function getSendValidationErrors(string $field_prefix = 'field_', $file_prefix =
$use_proponent_types = (bool) $opportunity->registrationProponentTypes;

if($use_range && !$this->range) {
$errorsResult['range'] = [\MapasCulturais\i::__('Faixa é um campo obrigatório.')];
$errorsResult['range'] = [i::__('Faixa é um campo obrigatório.')];
}

if($use_proponent_types && !$this->proponentType) {
$errorsResult['proponentType'] = [\MapasCulturais\i::__('Tipo de proponente é um campo obrigatório.')];
$errorsResult['proponentType'] = [i::__('Tipo de proponente é um campo obrigatório.')];
}

if($use_category && !$this->category){
$errorsResult['category'] = [\MapasCulturais\i::__('Categoria é um campo obrigatório.')];
$errorsResult['category'] = [i::__('Categoria é um campo obrigatório.')];
}

$definitionsWithAgents = $this->_getDefinitionsWithAgents();
Expand All @@ -1029,17 +1058,17 @@ function getSendValidationErrors(string $field_prefix = 'field_', $file_prefix =

if($def->use === 'required'){
if(!$def->agent){
$errors[] = sprintf(\MapasCulturais\i::__('O agente "%s" é obrigatório.'), $def->label);
$errors[] = sprintf(i::__('O agente "%s" é obrigatório.'), $def->label);
}
}

if($def->agent){
if($def->relationStatus < 0){
$errors[] = sprintf(\MapasCulturais\i::__('O agente %s ainda não confirmou sua participação neste projeto.'), $def->agent->name);
$errors[] = sprintf(i::__('O agente %s ainda não confirmou sua participação neste projeto.'), $def->agent->name);
}else{
if($def->agent->type->id !== $def->type){
$typeDescription = $app->getRegisteredEntityTypeById($def->agent, $def->type)->name;
$errors[] = sprintf(\MapasCulturais\i::__('Este agente deve ser do tipo "%s".'), $typeDescription);
$errors[] = sprintf(i::__('Este agente deve ser do tipo "%s".'), $typeDescription);
}
}
}
Expand All @@ -1059,29 +1088,21 @@ function getSendValidationErrors(string $field_prefix = 'field_', $file_prefix =
if(isset($isSpaceRelationRequired)){
if($isSpaceRelationRequired === 'required'){
if($spaceDefined === null) {
$errorsResult['space'] = [\MapasCulturais\i::__('O espaço é obrigatório')];
$errorsResult['space'] = [i::__('O espaço é obrigatório')];
}
}
if($isSpaceRelationRequired === 'required' || $isSpaceRelationRequired === 'optional'){
//Espaço não autorizado
if( $spaceDefined && $spaceDefined->status < 0){
$errorsResult['space'] = [\MapasCulturais\i::__('O espaço vinculado a esta inscrição aguarda autorização do responsável')];
$errorsResult['space'] = [i::__('O espaço vinculado a esta inscrição aguarda autorização do responsável')];
}
}
}

// validate attachments
foreach($opportunity->registrationFileConfigurations as $rfc){

if($use_category && count($rfc->categories) > 0 && !in_array($this->category, $rfc->categories)){
continue;
}

if ($use_range && count($rfc->registrationRanges) > 0 && !in_array($this->range, $rfc->registrationRanges)) {
continue;
}

if ($use_proponent_types && count($rfc->proponentTypes) > 0 && !in_array($this->proponentType, $rfc->proponentTypes)) {
if(!$this->isFieldVisisble($rfc)){
continue;
}

Expand All @@ -1095,7 +1116,7 @@ function getSendValidationErrors(string $field_prefix = 'field_', $file_prefix =
$errors = [];
if($field_required){
if(!isset($this->files[$rfc->fileGroupName])){
$errors[] = \MapasCulturais\i::__('O arquivo é obrigatório.');
$errors[] = i::__('O arquivo é obrigatório.');
}
}
if($errors){
Expand All @@ -1106,15 +1127,7 @@ function getSendValidationErrors(string $field_prefix = 'field_', $file_prefix =
// validate fields
foreach ($opportunity->registrationFieldConfigurations as $field) {

if ($use_category && count($field->categories) > 0 && !in_array($this->category, $field->categories)) {
continue;
}

if ($use_range && count($field->registrationRanges) > 0 && !in_array($this->range, $field->registrationRanges)) {
continue;
}

if ($use_proponent_types && count($field->proponentTypes) > 0 && !in_array($this->proponentType, $field->proponentTypes)) {
if (!$this->isFieldVisisble($field)) {
continue;
}

Expand Down Expand Up @@ -1154,7 +1167,7 @@ function getSendValidationErrors(string $field_prefix = 'field_', $file_prefix =

if ($empty) {
if($field_required) {
$errors[] = \MapasCulturais\i::__('O campo é obrigatório.');
$errors[] = i::__('O campo é obrigatório.');
}
} else {

Expand Down Expand Up @@ -1183,7 +1196,7 @@ function getSendValidationErrors(string $field_prefix = 'field_', $file_prefix =
// @TODO: validar o campo projectName

if($opportunity->projectName == 2 && !$this->projectName){
$errorsResult['projectName'] = [\MapasCulturais\i::__('O nome do projeto é obrigatório.')];
$errorsResult['projectName'] = [i::__('O nome do projeto é obrigatório.')];
}

$app->applyHookBoundTo($this, "entity($this->getHookClassPath()).sendValidationErrors", [&$errorsResult]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,37 @@ app.component('opportunity-registrations-table', {
}

const sortOptions = [
{ value: `status DESC,${consolidatedResultOrder} DESC`, label: 'por status descendente' },
{ value: `status ASC,${consolidatedResultOrder} ASC`, label: 'por status ascendente' },
{ value: `${consolidatedResultOrder} DESC`, label: 'resultado das avaliações' },
{ value: 'createTimestamp ASC', label: 'mais antigas primeiro' },
{ value: 'createTimestamp DESC', label: 'mais recentes primeiro' },
{ value: 'sentTimestamp ASC', label: 'enviadas a mais tempo primeiro' },
{ value: 'sentTimestamp DESC', label: 'enviadas a menos tempo primeiro' },
];

if(hadTechnicalEvaluationPhase) {
order = 'score DESC';
if(this.phase.isLastPhase) {
order = `status DESC,score DESC`;
sortOptions.splice(0, 0, {value: 'score DESC', label: 'pontuação final'});
}
sortOptions.splice(0, 0, { value: `status ASC,score ASC`, label: 'por status ascendente' });
sortOptions.splice(0, 0, { value: `status DESC,score DESC`, label: 'por status descendente' });

if(isAffirmativePoliciesActive) {
avaliableFields.push({
title: __('concorrendo por cota', 'opportunity-registrations-table'),
fieldName: 'eligible',
fieldType: 'boolean'
});
} else {
sortOptions.splice(0, 0, { value: `${consolidatedResultOrder} DESC`, label: 'resultado das avaliações' });
sortOptions.splice(0, 0, { value: `status ASC,${consolidatedResultOrder} ASC`, label: 'por status ascendente' });
sortOptions.splice(0, 0, { value: `status DESC,${consolidatedResultOrder} DESC`, label: 'por status descendente' });

visible += ',eligible';
order = '@quota';
sortOptions.splice(0, 0, {value: '@quota', label: 'classificação final'});
}
if(hadTechnicalEvaluationPhase) {
order = 'score DESC';
sortOptions.splice(0, 0, {value: 'score DESC', label: 'pontuação final'});
}

if(isAffirmativePoliciesActive) {
avaliableFields.push({
title: __('concorrendo por cota', 'opportunity-registrations-table'),
fieldName: 'eligible',
fieldType: 'boolean'
});

if(this.phase.isLastPhase) {
order = `status DESC,score DESC`;
visible += ',eligible';
order = '@quota';
sortOptions.splice(0, 0, {value: '@quota', label: 'classificação final'});
}
}

return {
Expand Down
22 changes: 11 additions & 11 deletions src/modules/OpportunityPhases/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use MapasCulturais\Entities\Registration;
use MapasCulturais\Exceptions;
use MapasCulturais\i;
use PHPUnit\Util\Annotation\Registry;

class Module extends \MapasCulturais\Module{

Expand Down Expand Up @@ -991,16 +990,13 @@ function _init () {
Registration::STATUS_INVALID => [i::__('Inválida'), i::__('Inválida em "{PHASE_NAME}"')],
];

if ($registration->opportunity->equals($previous_phase)) {
$label = $labels[$registration->status][0];
} else {
$opp_phase = $registration->opportunity;
$phase = $opp_phase->evaluationMethodConfiguration ?: $opp_phase;
$label = $labels[$registration->status][1];
$label = str_replace('{PHASE_NAME}', $phase->name, $label);
}

$opp_phase = $registration->opportunity;
$phase = $opp_phase->evaluationMethodConfiguration ?: $opp_phase;
$label = $labels[$registration->status][1];
$label = str_replace('{PHASE_NAME}', $phase->name, $label);

$current_phase_registration->consolidatedResult = $label;
$current_phase_registration->score = $registration->score;

$methods = [
Registration::STATUS_DRAFT => 'setStatusToInvalid',
Expand All @@ -1013,7 +1009,6 @@ function _init () {

$method = $methods[$registration->status];

$app->log->debug("$current_phase_registration->number ======= >>>>>>>> $method");
$current_phase_registration->$method();

$new_registrations[] = $current_phase_registration->number;
Expand Down Expand Up @@ -1497,6 +1492,11 @@ function register () {
'default'=> true,
]);

$this->registerOpportunityMetadata("registrationsOutdated", [
'label'=> "Indica que as inscrições da fase não estão atualizadas",
'type' => 'bool',
'default'=> false,
]);
}


Expand Down
4 changes: 4 additions & 0 deletions src/modules/RegistrationFieldTypes/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public function _init()
$fields = $opportunity->getRegistrationFieldConfigurations();

foreach($fields as $field) {
if(!$this->isFieldVisisble($field)) {
continue;
}

if($field->fieldType == 'agent-owner-field') {
$entity = $this->owner;

Expand Down
11 changes: 0 additions & 11 deletions src/themes/BaseV2/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ function _init()
$this->enqueueStyle('app-v2', 'main', 'css/theme-BaseV2.css');
$this->assetManager->publishFolder('fonts');

// Manifest do five icon
$app->hook('GET(site.webmanifest)', function() use ($app) {
/** @var \MapasCulturais\Controller $this */
$this->json([
'icons' => [
[ 'src' => $app->view->asset('img/favicon-192x192.png', false), 'type' => 'image/png', 'sizes' => '192x192' ],
[ 'src' => $app->view->asset('img/favicon-512x512.png', false), 'type' => 'image/png', 'sizes' => '512x512' ],
],
]);
});

$app->hook('template(<<*>>.head):end', function () {
echo "<script>
document.addEventListener('DOMContentLoaded', (e) => {
Expand Down
1 change: 0 additions & 1 deletion src/themes/BaseV2/layouts/parts/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<link rel="profile" href="//gmpg.org/xfn/11" />
<link rel="icon" href="<?= $this->asset($app->config['favicon.svg'],false)?>" type="image/svg+xml">
<link rel="apple-touch-icon" href="<?= $this->asset($app->config['favicon.180'],false)?>">
<link rel="manifest" href="<?=$app->createUrl('site', 'webmanifest')?>">

<?php $this->printStyles('vendor-v2'); ?>
<?php $this->printStyles('app-v2'); ?>
Expand Down

0 comments on commit 3d2ae0e

Please sign in to comment.