various improvements

This commit is contained in:
2021-12-04 01:13:55 +01:00
parent 6c1a946608
commit 063ceb2c53
17 changed files with 163 additions and 69 deletions

View File

@@ -23,12 +23,12 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext
*/
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void;
public function getFormData(DocGeneratorTemplate $template, $entity): array;
/**
* has form.
*
* @param mixed $entity
*/
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
public function getFormData(DocGeneratorTemplate $template, $entity): array;
}

View File

@@ -59,4 +59,23 @@ class AdminDocGeneratorTemplateController extends CRUDController
return $entity;
}
function generateTemplateParameter(string $action, $entity, Request $request, array $defaultTemplateParameters = [])
{
switch ($action) {
case 'new':
$context = $this->contextManager->getContextByKey($request->get('context'));
break;
case 'edit':
$context = $this->contextManager->getContextByDocGeneratorTemplate($entity);
break;
default:
return parent::generateTemplateParameter($action, $entity, $request, $defaultTemplateParameters); // TODO: Change the autogenerated stub
}
return array_merge(
$defaultTemplateParameters,
['context' => $context]
);
}
}

View File

@@ -113,10 +113,11 @@ final class DocGeneratorTemplateController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$contextGenerationData = $form->getData();
} elseif (!$form->isSubmitted() || ($form->isSubmitted() && !$form->isValid())) {
$template = '@ChillDocGenerator/Generator/basic_form.html.twig';
$templateOptions = ['entity' => $entity, 'form' => $form->createView(), 'template' => $template];
$templatePath = '@ChillDocGenerator/Generator/basic_form.html.twig';
$templateOptions = ['entity' => $entity, 'form' => $form->createView(),
'template' => $template, 'context' => $context];
return $this->render($template, $templateOptions);
return $this->render($templatePath, $templateOptions);
}
}

View File

@@ -1,21 +1,39 @@
<template>
<template v-if="templates.length > 0">
<slot name="title">
<h2>{{ $t('Generate document from template')}}</h2>
</slot>
<select class="form-select form-select-sm" v-model="template">
<option disabled value="">{{ $t('evaluation_choose_a_template') }}</option>
<template v-for="t in templates">
<option v-bind:value="t.id">{{ t.name.fr }}</option>
</template>
</select>
<button v-if="canGenerate" class="btn btn-update btn-sm change-icon" type="button" @click="generateDocument"><i class="fa fa-fw fa-cog"></i></button>
<button v-else class="btn btn-update btn-sm change-icon" type="button" disabled ><i class="fa fa-fw fa-cog"></i></button>
<div>
<template v-if="templates.length > 0">
<slot name="title">
<h2>{{ $t('generate_document')}}</h2>
</slot>
<div v-if="hasDescription">
<p>{{ getDescription }}</p>
</div>
</template>
<div class="container">
<div class="row">
<div class="col-md-4">
<slot name="label">
<label>{{ $t('select_a_template') }}</label>
</slot>
</div>
<div class="col-md-8">
<div class="input-group mb-3">
<select class="form-select" v-model="template">
<option disabled selected value="">{{ $t('choose_a_template') }}</option>
<template v-for="t in templates">
<option v-bind:value="t.id">{{ t.name.fr }}</option>
</template>
</select>
<button v-if="canGenerate" class="btn btn-update btn-sm change-icon" type="button" @click="generateDocument"><i class="fa fa-fw fa-cog"></i></button>
<button v-else class="btn btn-update btn-sm change-icon" type="button" disabled ><i class="fa fa-fw fa-cog"></i></button>
</div>
</div>
</div>
<div class="row" v-if="hasDescription">
<div class="col-md-8 align-self-end">
<p>{{ getDescription }}</p>
</div>
</div>
</div>
</template>
</div>
</template>
@@ -106,6 +124,15 @@ export default {
window.location.assign(url);
},
},
i18n: {
messages: {
fr: {
generate_document: 'Générer un document',
select_a_template: 'Choisir un gabarit',
choose_a_template: 'Choisir',
}
}
}
}
</script>

View File

@@ -1,11 +1,15 @@
{% extends '@ChillDocGenerator/Admin/layout.html.twig' %}
{% block title %}
{% include('@ChillMain/CRUD/_edit_title.html.twig') %}
{% endblock %}
{% block title 'docgen.Edit template'|trans %}
{% block layout_wvm_content %}
{% embed '@ChillMain/CRUD/_edit_content.html.twig' %}
{% block crud_content_header %}
<h1>{{ 'docgen.Edit template'|trans }}</h1>
<h2>{{ 'docgen.With context %name%'|trans({'%name%': context.name|trans }) }}</h2>
{% endblock crud_content_header %}
{% block content_form_actions_view %}{% endblock %}
{% block content_form_actions_save_and_show %}{% endblock %}
{% endembed %}

View File

@@ -1,12 +1,17 @@
{% extends '@ChillDocGenerator/Admin/layout.html.twig' %}
{% block title %}
{% include('@ChillMain/CRUD/_new_title.html.twig') %}
{% endblock %}
{% block title 'docgen.New template'|trans %}
{% block layout_wvm_content %}
{% embed '@ChillMain/CRUD/_new_content.html.twig' %}
{% block crud_content_header %}
<h1>{{ 'docgen.New template'|trans }}</h1>
<h2>{{ 'docgen.With context %name%'|trans({'%name%': context.name|trans }) }}</h2>
{% endblock crud_content_header %}
{% block content_form_actions_save_and_show %}{% endblock %}
{% endembed %}
{% endblock %}

View File

@@ -1,10 +1,11 @@
{% extends 'ChillMainBundle::layout.html.twig' %}
{% block title 'Generate document'|trans %}
{% block title 'docgen.Generate a document'|trans %}
{% block content %}
<div class="col-md-10 col-xxl">
<h1>{{ block('title') }}</h1>
<h2>{{ template.name|localize_translatable_string }}</h2>
{{ form_start(form, { 'attr': { 'id': 'generate_doc_form' }}) }}
{{ form(form) }}
@@ -12,8 +13,8 @@
<ul class="record_actions sticky-form-buttons">
<li>
<button type="submit" class="btn btn-edit" form="generate_doc_form">
<i class="fa fa-cog"></i> {{ 'Generate'|trans }}
<button type="submit" class="btn btn-edit change-icon" form="generate_doc_form">
<i class="fa fa-cog"></i> {{ 'docgen.Generate'|trans }}
</button>
</li>
</ul>

View File

@@ -99,7 +99,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
}
$type = $reflection->getProperty($attribute->getName())->getType();
} elseif ($reflection->hasMethod($method = 'get'.ucfirst($attribute->getName()))) {
} elseif ($reflection->hasMethod($method = 'get' . ucfirst($attribute->getName()))) {
if (!$reflection->getMethod($method)->hasReturnType()) {
throw new \LogicException(sprintf(
'Could not determine how the content is determined for the attribute %s. Add a return type on the method',
@@ -108,7 +108,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
}
$type = $reflection->getMethod($method)->getReturnType();
} elseif ($reflection->hasMethod($method = 'is'.ucfirst($attribute->getName()))) {
} elseif ($reflection->hasMethod($method = 'is' . ucfirst($attribute->getName()))) {
if (!$reflection->getMethod($method)->hasReturnType()) {
throw new \LogicException(sprintf(
'Could not determine how the content is determined for the attribute %s. Add a return type on the method',
@@ -168,12 +168,14 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
switch ($type) {
case 'array':
return [];
case 'bool':
case 'double':
case 'float':
case 'int':
case 'resource':
return null;
case 'string':
return '';

View File

@@ -0,0 +1,3 @@
docgen:
Generate a document: Génerer un document
Generate: Génerer