Skip to content

Commit

Permalink
Merge pull request #485 from RedeMapas/feature/develop-gestao-modelo
Browse files Browse the repository at this point in the history
Feature/develop gestao modelo
  • Loading branch information
lpirola authored Sep 6, 2024
2 parents 085ecf7 + 6ea8588 commit 44b21d1
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/conf/opportunity-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ function compareNamesOpportunity ($item1, $item2) {
'label' => \MapasCulturais\i::__('É modelo?'),
'default_value' => 0
),
'isModelOfficial' => array(
'isModelPublic' => array(
'type' => 'integer',
'label' => \MapasCulturais\i::__('É modelo oficial?'),
'label' => \MapasCulturais\i::__('É modelo público?'),
),

),
Expand Down
58 changes: 48 additions & 10 deletions src/core/Traits/EntityManagerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use MapasCulturais\App;
use MapasCulturais\Entities\ProjectOpportunity;
use MapasCulturais\Entity;
use MapasCulturais\Definitions\Metadata AS DefinitionMetadata;

trait EntityManagerModel {

Expand Down Expand Up @@ -50,6 +49,33 @@ function ALL_generateopportunity(){
$this->json($this->opportunityModel);
}

function GET_findOpportunitiesModels()
{
$app = App::i();
$dataModels = [];

$opportunities = $app->repo('Opportunity')->findAll();
foreach ($opportunities as $opp) {
if ($opp->isModel) {
$phases = $opp->phases;

$lastPhase = array_pop($phases);

$days = !is_null($opp->registrationFrom) && !is_null($lastPhase->publishTimestamp) ? $lastPhase->publishTimestamp->diff($opp->registrationFrom)->days . " Dia(s)" : 'N/A';
$tipoAgente = $opp->registrationProponentTypes ? implode(', ', $opp->registrationProponentTypes) : 'N/A';
$dataModels[] = [
'id' => $opp->id,
'numeroFases' => count($opp->phases),
'descricao' => $opp->shortDescription,
'tempoEstimado' => $days,
'tipoAgente' => $tipoAgente
];
}
}

echo json_encode($dataModels);
}

private function generateModel() : ProjectOpportunity
{
$app = App::i();
Expand All @@ -61,14 +87,21 @@ private function generateModel() : ProjectOpportunity

$this->opportunityModel = clone $this->opportunity;

$this->opportunityModel->setName($name);
$this->opportunityModel->setStatus(-1);
$this->opportunityModel->setShortDescription($description);
$this->opportunityModel->registrationCategories = [];
$this->opportunityModel->name = $name;
$this->opportunityModel->status = -1;
$this->opportunityModel->shortDescription = $description;
$app->em->persist($this->opportunityModel);
$app->em->flush();

// necessário adicionar as categorias, proponetes e ranges após salvar devido a trigger public.fn_propagate_opportunity_insert
$this->opportunityModel->registrationCategories = $this->opportunity->registrationCategories;
$this->opportunityModel->registrationProponentTypes = $this->opportunity->registrationProponentTypes;
$this->opportunityModel->registrationRanges = $this->opportunity->registrationRanges;
$this->opportunityModel->save(true);

return $this->opportunityModel;


}

private function generateOpportunity() : ProjectOpportunity
Expand All @@ -81,12 +114,17 @@ private function generateOpportunity() : ProjectOpportunity

$this->opportunityModel = clone $this->opportunity;

$this->opportunityModel->setName($name);
$this->opportunityModel->setStatus(0);
$this->opportunityModel->registrationCategories = [];
$this->opportunityModel->name = $name;
$this->opportunityModel->status = Entity::STATUS_DRAFT;
$app->em->persist($this->opportunityModel);
$app->em->flush();

// necessário adicionar as categorias, proponetes e ranges após salvar devido a trigger public.fn_propagate_opportunity_insert
$this->opportunityModel->registrationCategories = $this->opportunity->registrationCategories;
$this->opportunityModel->registrationProponentTypes = $this->opportunity->registrationProponentTypes;
$this->opportunityModel->registrationRanges = $this->opportunity->registrationRanges;
$this->opportunityModel->save(true);

return $this->opportunityModel;
}

Expand Down Expand Up @@ -169,7 +207,7 @@ private function generatePhases() : void
}


private function generateMetadata($isModel = 1, $isModelOfficial = 0) : void
private function generateMetadata($isModel = 1, $isModelPublic = 0) : void
{
foreach ($this->opportunity->getMetadata() as $metadataKey => $metadataValue) {
if (!is_null($metadataValue) && $metadataValue != '') {
Expand All @@ -178,7 +216,7 @@ private function generateMetadata($isModel = 1, $isModelOfficial = 0) : void
}

$this->opportunityModel->setMetadata('isModel', $isModel);
$this->opportunityModel->setMetadata('isModelOfficial', $isModelOfficial);
$this->opportunityModel->setMetadata('isModelPublic', $isModelPublic);

$this->opportunityModel->saveTerms();
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/Traits/EntityOpportunityDuplicator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ private function cloneOpportunity() : ProjectOpportunity
$name = $this->opportunity->name;
$this->newOpportunity->name = "$name - [Cópia][$now]";
$this->newOpportunity->status = Entity::STATUS_DRAFT;
$this->newOpportunity->registrationCategories = [];
$app->em->persist($this->newOpportunity);
$app->em->flush();

$this->newOpportunity->registrationCategories = $this->opportunity->registrationCategories;
$this->newOpportunity->registrationProponentTypes = $this->opportunity->registrationProponentTypes;
$this->newOpportunity->registrationRanges = $this->opportunity->registrationRanges;
$this->newOpportunity->save(true);

return $this->newOpportunity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
entity-field
");
?>
<div class="grid-12 col-12">
<div>
<mc-modal title="<?= i::__('Título do edital') ?>">
<template #default>
<div>
Expand All @@ -28,7 +28,7 @@
</template>

<template #button="modal">
<button type="button" @click="modal.open();" class="button button--icon button--sm"><?= i::__('Usar modelo') ?></button>
<button type="button" @click="modal.open();" class="button button--primary button--icon"><?= i::__('Usar modelo') ?></button>
</template>
</mc-modal>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<p>Para salvar um modelo, preencha os campos abaixo.</p><br>
<div>
<div class="field">
<label><?= i::__('Nome do modelo') ?></label>
<label><?= i::__('Nome do modelo') ?><span class="required">*</span></label>
<input type="text" v-model="formData.name">
</div><br>

<div class="field">
<label><?= i::__('Breve descrição do modelo') ?></label>
<label><?= i::__('Breve descrição do modelo') ?><span class="required">*</span></label>
<textarea placeholder="Breve descrição" v-model="formData.description"></textarea>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/Opportunities/views/panel/opportunities.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
create-opportunity
mc-icon
panel--entity-card
panel--entity-tabs-copy
panel--entity-tabs
');
?>

Expand All @@ -31,5 +31,5 @@
</div>
</header>

<panel--entity-tabs-copy type="opportunity"></panel--entity-tabs-copy>
<panel--entity-tabs type="opportunity"></panel--entity-tabs>
</div>
4 changes: 2 additions & 2 deletions src/modules/Panel/components/panel--entity-tabs/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ app.component('panel--entity-tabs', {
},

created() {
fetch('/api/findOpportunitiesModels')
fetch('/opportunity/findOpportunitiesModels')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
Expand Down Expand Up @@ -72,7 +72,7 @@ app.component('panel--entity-tabs', {
},
select: {
type: String,
default: 'id,status,name,type,createTimestamp,terms,files.avatar,currentUserPermissions,isModel'
default: 'id,status,name,type,createTimestamp,terms,files.avatar,currentUserPermissions,isModel,isModelPublic'
},
tabs: {
type: String,
Expand Down
12 changes: 8 additions & 4 deletions src/modules/Panel/components/panel--entity-tabs/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
mc-tabs
panel--entity-card
registration-card
opportunity-create-based-model
');

$tabs = $tabs ?? [
Expand Down Expand Up @@ -95,11 +96,10 @@
</template>
<template #subtitle="{ entity }">
<slot name="card-content" :entity="entity">
<span v-if="entity.type && entity.isModel != null">
<span class="card-info">MEU MODELO</span>
<span v-if="entity.type && entity.isModel == 1">
<span class="card-info">{{ entity.isModelPublic == 0 ? 'MEU MODELO' : 'MODELO PÚBLICO' }}</span>
<div class="card-desc">
<div v-for="model in models" :key="model.id">

<span v-if="model.id == entity.id">
<p>{{ model.descricao }}</p>
<mc-icon name="project" class="icon-model"></mc-icon>
Expand Down Expand Up @@ -129,7 +129,11 @@
<slot name="entity-actions-center" :entity="entity"></slot>
</template>
<template #entity-actions-right>
<slot name="entity-actions-right" :entity="entity"></slot>
<slot name="entity-actions-right" :entity="entity">
<div v-if="entity.currentUserPermissions?.modify && entity.status != -2 && entity.__objectType == 'opportunity' && entity.isModel == 1">
<opportunity-create-based-model :entity="entity" classes="col-12"></opportunity-create-based-model>
</div>
</slot>
</template>
</panel--entity-card>
</slot>
Expand Down

0 comments on commit 44b21d1

Please sign in to comment.