improve workflow decision form

This commit is contained in:
Julien Fastré 2022-02-01 10:02:33 +01:00
parent 50e722e637
commit a612d7dd9f
10 changed files with 250 additions and 74 deletions

View File

@ -271,7 +271,7 @@ class ActivityType
public function checkSocialActionsVisibility(ExecutionContextInterface $context, $payload)
{
if ($this->socialIssuesVisible !== $this->socialActionsVisible) {
if (!($this->socialIssuesVisible === 2 && $this->socialActionsVisible === 1)) {
if (!(2 === $this->socialIssuesVisible && 1 === $this->socialActionsVisible)) {
$context
->buildViolation('The socialActionsVisible value is not compatible with the socialIssuesVisible value')
->atPath('socialActionsVisible')

View File

@ -174,6 +174,20 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
return null;
}
public function getCurrentStepChained(): ?EntityWorkflowStep
{
$steps = $this->getStepsChained();
$currentStep = $this->getCurrentStep();
foreach ($steps as $step) {
if ($step === $currentStep) {
return $step;
}
}
return null;
}
public function getCurrentStepCreatedAt(): ?DateTimeInterface
{
if (null !== $previous = $this->getPreviousStepIfAny()) {

View File

@ -48,6 +48,8 @@ class WorkflowStepType extends AbstractType
$entityWorkflow = $options['entity_workflow'];
$handler = $this->entityWorkflowManager->getHandler($entityWorkflow);
$workflow = $this->registry->get($entityWorkflow, $entityWorkflow->getWorkflowName());
$place = $workflow->getMarking($entityWorkflow);
$placeMetadata = $workflow->getMetadataStore()->getPlaceMetadata(array_keys($place->getPlaces())[0]);
if (true === $options['transition']) {
if (null === $options['entity_workflow']) {
@ -68,40 +70,77 @@ class WorkflowStepType extends AbstractType
$transitions
);
if (array_key_exists('validationFilterInputLabels', $placeMetadata)) {
$inputLabels = $placeMetadata['validationFilterInputLabels'];
$builder->add('transitionFilter', ChoiceType::class, [
'multiple' => false,
'label' => 'workflow.My decision',
'choices' => [
'forward' => 'forward',
'backward' => 'backward',
'neutral' => 'neutral',
],
'choice_label' => function (string $key) use ($inputLabels) {
return $this->translatableStringHelper->localize($inputLabels[$key]);
},
'choice_attr' => static function (string $key) {
return [
$key => $key,
];
},
'mapped' => false,
'expanded' => true,
'data' => 'forward',
]);
}
$builder
->add('transition', ChoiceType::class, [
'label' => 'workflow.Transition to apply',
'label' => 'workflow.Next step',
'mapped' => false,
'multiple' => false,
'expanded' => true,
'choices' => $choices,
'choice_label' => function (Transition $transition) use ($workflow) {
$meta = $workflow->getMetadataStore()->getTransitionMetadata($transition);
$meta = $workflow->getMetadataStore()->getTransitionMetadata($transition);
if (array_key_exists('label', $meta)) {
return $this->translatableStringHelper->localize($meta['label']);
}
if (array_key_exists('label', $meta)) {
return $this->translatableStringHelper->localize($meta['label']);
}
return $transition->getName();
},
return $transition->getName();
},
'choice_attr' => static function (Transition $transition) use ($workflow) {
$toFinal = true;
$toFinal = true;
$isForward = 'neutral';
foreach ($transition->getTos() as $to) {
$meta = $workflow->getMetadataStore()->getPlaceMetadata($to);
$metadata = $workflow->getMetadataStore()->getTransitionMetadata($transition);
if (
if (array_key_exists('isForward', $metadata)) {
if ($metadata['isForward']) {
$isForward = 'forward';
} else {
$isForward = 'backward';
}
}
foreach ($transition->getTos() as $to) {
$meta = $workflow->getMetadataStore()->getPlaceMetadata($to);
if (
!array_key_exists('isFinal', $meta) || false === $meta['isFinal']
) {
$toFinal = false;
}
$toFinal = false;
}
}
return [
'data-is-transition' => 'data-is-transition',
'data-to-final' => $toFinal ? '1' : '0',
];
},
return [
'data-is-transition' => 'data-is-transition',
'data-to-final' => $toFinal ? '1' : '0',
'data-is-forward' => $isForward,
];
},
])
->add('future_dest_users', PickUserDynamicType::class, [
'label' => 'workflow.dest for next steps',

View File

@ -26,7 +26,9 @@ var ShowHide = function(options) {
container_content = [],
debug = 'debug' in options ? options.debug : false,
load_event = 'load_event' in options ? options.load_event : 'load',
id = 'uid' in options ? options.id : Math.random();
id = 'uid' in options ? options.id : Math.random(),
toggle_callback = 'toggle_callback' in options ? options.toggle_callback : null
;
var bootstrap = function(event) {
if (debug) {
@ -39,7 +41,6 @@ var ShowHide = function(options) {
contents.push(el);
}
container_content.push(contents);
// console.log('container content', container_content);
}
// attach the listener on each input
@ -96,9 +97,13 @@ var ShowHide = function(options) {
if (debug) {
console.log('force hide');
}
for (let contents of container_content.values()) {
for (let el of contents.values()) {
el.remove();
if (toggle_callback !== null) {
toggle_callback(container, 'hide');
} else {
for (let contents of container_content.values()) {
for (let el of contents.values()) {
el.remove();
}
}
}
is_shown = false;
@ -108,10 +113,14 @@ var ShowHide = function(options) {
if (debug) {
console.log('show');
}
for (let i of container_content.keys()) {
var contents = container_content[i];
for (let el of contents.values()) {
container[i].appendChild(el);
if (toggle_callback !== null) {
toggle_callback(container, 'show');
} else {
for (let i of container_content.keys()) {
var contents = container_content[i];
for (let el of contents.values()) {
container[i].appendChild(el);
}
}
}
is_shown = true;

View File

@ -2,29 +2,74 @@ import {ShowHide} from 'ChillMainAssets/lib/show_hide/show_hide.js';
window.addEventListener('DOMContentLoaded', function() {
let
finalizeAfterContainer = document.querySelector('#finalizeAfter'),
divTransitions = document.querySelector('#transitions'),
futureDestUsersContainer = document.querySelector('#futureDestUsers')
;
if (null === finalizeAfterContainer) {
return;
}
new ShowHide({
load_event: null,
froms: [finalizeAfterContainer],
container: [futureDestUsersContainer],
test: function(containers, arg2, arg3) {
for (let container of containers) {
for (let input of container.querySelectorAll('input')) {
if (!input.checked) {
return true;
} else {
return false;
if (null !== divTransitions) {
new ShowHide({
load_event: null,
froms: [divTransitions],
container: [futureDestUsersContainer],
test: function(divs, arg2, arg3) {
for (let div of divs) {
for (let input of div.querySelectorAll('input')) {
if (input.checked) {
if (input.dataset.toFinal === "1") {
return false;
} else {
return true;
}
}
}
}
}
},
})
return true;
},
});
}
let
transitionFilterContainer = document.querySelector('#transitionFilter'),
transitions = document.querySelector('#transitions')
;
if (null !== transitionFilterContainer) {
transitions.querySelectorAll('.form-check').forEach(function(row) {
const isForward = row.querySelector('input').dataset.isForward;
console.log(row);
console.log(isForward);
new ShowHide({
load_event: null,
froms: [transitionFilterContainer],
container: row,
test: function (containers) {
for (let container of containers) {
for (let input of container.querySelectorAll('input')) {
if (input.checked) {
return isForward === input.value;
}
}
}
},
toggle_callback: function (c, dir) {
for (let div of c) {
let input = div.querySelector('input');
if ('hide' === dir) {
input.checked = false;
input.disabled = true;
} else {
input.disabled = false;
}
}
},
});
});
}
});

View File

@ -3,7 +3,60 @@
{% if transition_form is not null %}
{{ form_start(transition_form) }}
{{ form_row(transition_form.transition) }}
{% set step = entity_workflow.currentStepChained %}
{% set labels = workflow_metadata(entity_workflow, 'label', step.currentStep) %}
{% set label = labels is null ? step.currentStep : labels|localize_translatable_string %}
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-sm-12">
{{ 'workflow.Current step'|trans }}&nbsp;:
<span class="badge bg-primary">{{ label }}</span>
</div>
</div>
{% if step.previous is not null %}
{% if step.previous.comment is not empty %}
<div class="row">
<div class="col-sm-12">
<blockquote class="chill-user-quote">
{{ step.previous.comment|chill_markdown_to_html }}
</blockquote>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-sm-12">
{{ 'By'|trans }}
{{ step.previous.transitionBy|chill_entity_render_box }},
{{ step.previous.transitionAt|format_datetime('short', 'short') }}
</div>
</div>
{% else %}
<div class="row">
<div class="col-sm-4">{{ 'workflow.Created by'|trans }}</div>
<div class="col-sm-8">{{ step.entityWorkflow.createdBy|chill_entity_render_box }}</div>
</div>
<div class="row">
<div class="col-sm-4">{{ 'Le'|trans }}</div>
<div class="col-sm-8">{{ step.entityWorkflow.createdAt|format_datetime('short', 'short') }}</div>
</div>
{% endif %}
</div>
</div>
<div id="transitionFilter">
{% if transition_form.transitionFilter is defined %}
{{ form_row(transition_form.transitionFilter) }}
{% endif %}
</div>
<div id="transitions">
{{ form_row(transition_form.transition) }}
</div>
{% if transition_form.freezeAfter is defined %}
{{ form_row(transition_form.freezeAfter) }}

View File

@ -69,6 +69,18 @@
</blockquote>
</div>
{% endif %}
{% if loop.last and step.destUser|length > 0 %}
<div class="item-row separator">
<div>
<p><b>{{ 'workflow.Users allowed to apply transition'|trans }}&nbsp;: </b></p>
<ul>
{% for u in step.destUser %}
<li>{{ u|chill_entity_render_box }}</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
</div>
{% endfor %}

View File

@ -370,7 +370,8 @@ Workflow history: Historique de la décision
workflow:
Created by: Créé par
Transition to apply: Ma décision
My decision: Ma décision
Next step: Prochaine étape
dest for next steps: Utilisateurs qui valideront la prochaine étape
Freeze: Geler
Freezed: Gelé
@ -392,6 +393,9 @@ workflow:
dest: Workflows en attente d'action
you subscribed to all steps: Vous recevrez une notification à chaque étape
you subscribed to final step: Vous recevrez une notification à l'étape finale
Current step: Étape actuelle
Comment on last change: Commentaire à la transition précédente
Users allowed to apply transition: Utilisateurs pouvant valider cette étape
Subscribe final: Recevoir une notification à l'étape finale
Subscribe all steps: Recevoir une notification à chaque étape

View File

@ -213,7 +213,7 @@ class AccompanyingPeriod implements
*
* @ORM\Column(type="date")
* @Groups({"read", "write", "docgen:read"})
* @Assert\LessThan(value= "today", groups={AccompanyingPeriod::STEP_CONFIRMED})
* @Assert\LessThan(value="today", groups={AccompanyingPeriod::STEP_CONFIRMED})
* @Assert\LessThan(propertyPath="closingDate", groups={AccompanyingPeriod::STEP_CONFIRMED})
*/
private ?DateTime $openingDate = null;

View File

@ -28,6 +28,11 @@ final class AccompanyingPeriodRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(AccompanyingPeriod::class);
}
public function countBy(array $criteria): int
{
return $this->repository->count($criteria);
}
public function countByRecentUserHistory(User $user, DateTimeImmutable $since): int
{
$qb = $this->buildQueryByRecentUserHistory($user, $since);
@ -35,11 +40,6 @@ final class AccompanyingPeriodRepository implements ObjectRepository
return $qb->select('count(a)')->getQuery()->getSingleScalarResult();
}
public function countBy(array $criteria): int
{
return $this->repository->count($criteria);
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);