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

feat: implementa modelos publicos #491

Merged
merged 3 commits into from
Sep 24, 2024
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
31 changes: 26 additions & 5 deletions src/core/Traits/EntityManagerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$this->requireAuthentication();
$this->entityOpportunity = $this->requestedEntity;

$app->disableAccessControl();

Check warning on line 39 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L39

Added line #L39 was not covered by tests
$this->entityOpportunityModel = $this->generateOpportunity();

$this->generateEvaluationMethods();
Expand All @@ -45,6 +46,8 @@

$this->entityOpportunityModel->save(true);

$app->enableAccessControl();

Check warning on line 49 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L49

Added line #L49 was not covered by tests

$this->json($this->entityOpportunityModel);
}

Expand Down Expand Up @@ -82,6 +85,21 @@
echo json_encode($dataModels);
}

function POST_modelpublic(){
$app = App::i();

Check warning on line 89 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L88-L89

Added lines #L88 - L89 were not covered by tests

$this->requireAuthentication();
$this->entityOpportunity = $this->requestedEntity;

Check warning on line 92 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L91-L92

Added lines #L91 - L92 were not covered by tests

$isModelPublic = $this->postData['isModelPublic'];

Check warning on line 94 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L94

Added line #L94 was not covered by tests

$this->entityOpportunity->setMetadata('isModelPublic', $isModelPublic);
$this->entityOpportunity->saveTerms();
$this->entityOpportunity->save(true);

Check warning on line 98 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L96-L98

Added lines #L96 - L98 were not covered by tests

$this->json($isModelPublic);

Check warning on line 100 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L100

Added line #L100 was not covered by tests
}

private function generateModel()
{
$app = App::i();
Expand Down Expand Up @@ -113,18 +131,19 @@
private function generateOpportunity()
{
$app = App::i();

$postData = $this->postData;

$name = $postData['name'];

$this->entityOpportunityModel = clone $this->entityOpportunity;

$this->entityOpportunityModel->name = $name;
$this->entityOpportunityModel->status = Entity::STATUS_DRAFT;
$this->entityOpportunityModel->owner = $app->user->profile;

Check warning on line 141 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L141

Added line #L141 was not covered by tests
$app->em->persist($this->entityOpportunityModel);
$app->em->flush();



// necessário adicionar as categorias, proponetes e ranges após salvar devido a trigger public.fn_propagate_opportunity_insert
$this->entityOpportunityModel->registrationCategories = $this->entityOpportunity->registrationCategories;
$this->entityOpportunityModel->registrationProponentTypes = $this->entityOpportunity->registrationProponentTypes;
Expand Down Expand Up @@ -158,14 +177,15 @@
private function generatePhases() : void
{
$app = App::i();

$phases = $app->repo('Opportunity')->findBy([
'parent' => $this->entityOpportunity
]);
foreach ($phases as $phase) {

if (!$phase->getMetadata('isLastPhase')) {
$newPhase = clone $phase;
$newPhase->setParent($this->entityOpportunityModel);
$newPhase->owner = $app->user->profile;

Check warning on line 188 in src/core/Traits/EntityManagerModel.php

View check run for this annotation

Codecov / codecov/patch

src/core/Traits/EntityManagerModel.php#L188

Added line #L188 was not covered by tests

foreach ($phase->getMetadata() as $metadataKey => $metadataValue) {
if (!is_null($metadataValue) && $metadataValue != '') {
Expand All @@ -192,6 +212,7 @@
}
}
}


if ($phase->getMetadata('isLastPhase')) {
$publishDate = $phase->getPublishTimestamp();
Expand All @@ -209,7 +230,7 @@
$phase->save(true);
}
}
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ app.component('opportunity-create-based-model', {

methods: {
async save() {
this.__processing = this.text('Gerando oportunidade baseado no modelo...');

const api = new API(this.entity.__objectType);

let objt = this.formData;
Expand All @@ -40,9 +38,13 @@ app.component('opportunity-create-based-model', {
}

await api.POST(`/opportunity/generateopportunity/${objt.entityId}`, objt).then(response => response.json().then(dataReturn => {
this.messages.success(this.text('Oportunidade gerada com sucesso'));
this.messages.success(this.text('Aguarde, estamos gerando a oportunidade baseada no modelo.'));

this.sendSuccess = true;
window.location.href = `/gestao-de-oportunidade/${dataReturn.id}/#info`;

setTimeout(() => {
window.location.href = `/gestao-de-oportunidade/${dataReturn.id}/#info`;
}, "5000");
}));
},
validade(objt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

return [
'Todos os campos são obrigatorio' => i::__('Todos os campos são obrigatorio'),
'Oportunidade gerada com sucesso' => i::__('Oportunidade gerada com sucesso'),
'Gerando oportunidade baseado no modelo...' => i::__('Gerando oportunidade baseado no modelo...'),
'Oportunidade gerada com sucesso, você será redirecionado...' => i::__('Oportunidade gerada com sucesso, você será redirecionado...'),
'Aguarde, estamos gerando a oportunidade baseada no modelo.' => i::__('Aguarde, estamos gerando a oportunidade baseada no modelo.'),

Check warning on line 8 in src/modules/Entities/components/opportunity-create-based-model/texts.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Entities/components/opportunity-create-based-model/texts.php#L7-L8

Added lines #L7 - L8 were not covered by tests
];
62 changes: 46 additions & 16 deletions src/modules/Panel/components/panel--entity-models-card/script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
app.component('panel--entity-models-card', {
template: $TEMPLATES['panel--entity-models-card'],
emits: ['deleted'],

setup() {
const messages = useMessages();
const text = Utils.getTexts('panel--entity-models-card')
return { text, messages }
},
props: {
class: {
type: [String, Array, Object],
Expand All @@ -17,32 +21,58 @@ app.component('panel--entity-models-card', {
default: true
}
},
data() {
fetch('/opportunity/findOpportunitiesModels')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
this.models = data;
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
data() {
const api = new API(this.entity.__objectType);
const response = api.GET('/opportunity/findOpportunitiesModels');
response.then((r) => r.json().then((r) => {
this.models = r;
}));

let isModelPublic = this.entity.isModelPublic == 1 ? true : false;

return {
models: [],
isModelPublic,
models: []
}
},

watch: {
'isModelPublic'(_new,_old){
if(_new != _old){
this.isActive(_new);
}
},
},
methods: {
isActive(active) {
this.entity.isModelPublic = active ? 1 : 0;
this.modelPublic();
},
async modelPublic(){
const api = new API(this.entity.__objectType);
let objt = {
isModelPublic: this.entity.isModelPublic
};

await api.POST(`/opportunity/modelpublic/${this.entity.id}`, objt).then(res => {
this.messages.success(this.text('Modelo atualizado com sucesso'));
});
}
},
computed: {
classes() {
return this.class;
},
leftButtons() {
return 'delete';
},
showModel() {
let showModel = false;
if (this.entity.owner._id == $MAPAS.user.profile._id || this.entity.isModelPublic) {
showModel = true;
}

return showModel;
},
}
})
35 changes: 23 additions & 12 deletions src/modules/Panel/components/panel--entity-models-card/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

');
?>
<article class="panel__row panel-entity-card" :class="{classes, 'col-6': entity.isModel == 1}">
<header class="panel-entity-card__header">
<article class="panel__row panel-entity-models-card col-6" v-if="showModel">
<header class="panel-entity-models-card__header">

Check warning on line 19 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L18-L19

Added lines #L18 - L19 were not covered by tests
<div class="left">
<slot name="picture" :entity="entity">
<mc-avatar :entity="entity" size="medium"></mc-avatar>
</slot>
<div class="panel-entity-card__header--info">
<div class="panel-entity-models-card__header--info">

Check warning on line 24 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L24

Added line #L24 was not covered by tests
<slot name="title" :entity="entity">
<a :href="entity.singleUrl" class="panel-entity-card__header--info-link">
<a :href="entity.singleUrl" class="panel-entity-models-card__header--info-link">

Check warning on line 26 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L26

Added line #L26 was not covered by tests
<mc-title tag="h2" :shortLength="100" :longLength="110">
{{ entity.name }}
</mc-title>
Expand All @@ -32,19 +32,19 @@
</div>
</div>
<div class="right">
<div class="panel-entity-card__header-actions">
<div class="panel-entity-models-card__header-actions">

Check warning on line 35 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L35

Added line #L35 was not covered by tests
<slot name="header-actions" :entity="entity">
{{ entity.isModelPublic == 0 ? 'MEU MODELO' : 'MODELO PÚBLICO' }}
</slot>
</div>
</div>
</header>
<main class="panel-entity-card__main">
<main class="panel-entity-models-card__main">

Check warning on line 42 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L42

Added line #L42 was not covered by tests
<span class="card-info"></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>
<p>{{ model.descricao.substring(0, 150) }}</p>

Check warning on line 47 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L47

Added line #L47 was not covered by tests
<mc-icon name="project" class="icon-model"></mc-icon>
<strong><?=i::__('Tipo de Oportunidade: ')?></strong>{{ entity.type.name }}
<br>
Expand All @@ -56,14 +56,25 @@
<br>
<mc-icon name="agent" class="icon-model"></mc-icon>
<strong><?=i::__('Tipo de agente: ')?></strong> {{ model.tipoAgente }}
<br><br>
<?php if($app->user->is('admin')): ?>
<div v-if="entity.currentUserPermissions?.modify">
<label class="switch" >
<input type="checkbox" v-model="isModelPublic" />
<span class="slider round"></span>
</label>
<span class="switch-text"><?= i::__("Modelo público") ?></span>

Check warning on line 66 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L60-L66

Added lines #L60 - L66 were not covered by tests
</div>
<br><br>
<?php endif; ?>
</span>
</div>
</div>
</main>
<footer class="panel-entity-card__footer">
<div class="panel-entity-card__footer-actions">
<footer class="panel-entity-models-card__footer">
<div class="panel-entity-models-card__footer-actions">

Check warning on line 75 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L74-L75

Added lines #L74 - L75 were not covered by tests
<slot name="footer-actions">
<div class="panel-entity-card__footer-actions left">
<div class="panel-entity-models-card__footer-actions left">

Check warning on line 77 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L77

Added line #L77 was not covered by tests
<slot name="entity-actions-left" :entity="entity">
<panel--entity-actions
:entity="entity"
Expand All @@ -73,11 +84,11 @@
></panel--entity-actions>
</slot>
</div>
<div class="panel-entity-card__footer-actions right">
<div class="panel-entity-models-card__footer-actions right">

Check warning on line 87 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L87

Added line #L87 was not covered by tests
<slot name="entity-actions-center" >
</slot>
<slot name="entity-actions-right" >
<div v-if="entity.currentUserPermissions?.modify && entity.status != -2 && entity.__objectType == 'opportunity' && entity.isModel == 1">
<div v-if="showModel && entity.status != -2 && entity.__objectType == 'opportunity' && entity.isModel == 1">

Check warning on line 91 in src/modules/Panel/components/panel--entity-models-card/template.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/template.php#L91

Added line #L91 was not covered by tests
<opportunity-create-based-model :entity="entity" classes="col-12"></opportunity-create-based-model>
</div>
</slot>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

use MapasCulturais\i;

return [
'Modelo atualizado com sucesso' => i::__('Modelo atualizado com sucesso'),
];

Check warning on line 7 in src/modules/Panel/components/panel--entity-models-card/texts.php

View check run for this annotation

Codecov / codecov/patch

src/modules/Panel/components/panel--entity-models-card/texts.php#L5-L7

Added lines #L5 - L7 were not covered by tests
10 changes: 2 additions & 8 deletions src/modules/Panel/components/panel--entity-tabs/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ app.component('panel--entity-tabs', {

if (this.user) {
query.user = `EQ(${this.user})`
queryGetModel.user = `EQ(${this.user})`
// queryGetModel.user = `EQ(${this.user})`
}

return {
Expand All @@ -42,10 +42,6 @@ app.component('panel--entity-tabs', {
showPrivateKey: false,
}
},
computed: {

},

props: {
type: String,
user: {
Expand All @@ -54,17 +50,15 @@ app.component('panel--entity-tabs', {
},
select: {
type: String,
default: 'id,status,name,type,createTimestamp,terms,files.avatar,currentUserPermissions,isModel,isModelPublic'
default: 'id,status,name,type,createTimestamp,terms,files.avatar,currentUserPermissions,isModel,isModelPublic,owner'
},
tabs: {
type: String,
default: "publish,draft,granted,mymodels,trash,archived"
},

},

methods: {

showTab(status) {
const tabs = this.tabs.split(',');

Expand Down
Loading
Loading