[activity] handle case when there is no action associated to selected

issues
This commit is contained in:
Julien Fastré 2021-11-29 22:43:14 +01:00
parent 55b9242690
commit 7b0c7988df
4 changed files with 41 additions and 14 deletions

View File

@ -50,19 +50,26 @@
<i class="chill-green fa fa-circle-o-notch fa-spin fa-lg"></i> <i class="chill-green fa fa-circle-o-notch fa-spin fa-lg"></i>
</div> </div>
<check-social-action <span v-else-if="socialIssuesSelected.length === 0" class="inline-choice chill-no-data-statement mt-3">
v-if="socialIssuesSelected.length || socialActionsSelected.length"
v-for="action in socialActionsList"
v-bind:key="action.id"
v-bind:action="action"
v-bind:selection="socialActionsSelected"
@updateSelected="updateActionsSelected">
</check-social-action>
<span v-else class="inline-choice chill-no-data-statement mt-3">
{{ $t('activity.select_first_a_social_issue') }} {{ $t('activity.select_first_a_social_issue') }}
</span> </span>
<template v-else-if="socialActionsList.length > 0">
<check-social-action
v-if="socialIssuesSelected.length || socialActionsSelected.length"
v-for="action in socialActionsList"
v-bind:key="action.id"
v-bind:action="action"
v-bind:selection="socialActionsSelected"
@updateSelected="updateActionsSelected">
</check-social-action>
</template>
<span v-else-if="actionAreLoaded && socialActionsList.length === 0" class="inline-choice chill-no-data-statement mt-3">
{{ $t('activity.social_action_list_empty') }}
</span>
</div> </div>
</div> </div>
@ -85,7 +92,8 @@ export default {
data() { data() {
return { return {
issueIsLoading: false, issueIsLoading: false,
actionIsLoading: false actionIsLoading: false,
actionAreLoaded: false,
} }
}, },
computed: { computed: {
@ -109,6 +117,7 @@ export default {
/* Load others issues in multiselect /* Load others issues in multiselect
*/ */
this.issueIsLoading = true; this.issueIsLoading = true;
this.actionAreLoaded = false;
getSocialIssues().then(response => new Promise((resolve, reject) => { getSocialIssues().then(response => new Promise((resolve, reject) => {
this.$store.commit('updateIssuesOther', response.results); this.$store.commit('updateIssuesOther', response.results);
@ -141,6 +150,7 @@ export default {
this.$store.commit('filterList', 'actions'); this.$store.commit('filterList', 'actions');
this.issueIsLoading = false; this.issueIsLoading = false;
this.actionAreLoaded = true;
resolve(); resolve();
})); }));
}, },

View File

@ -9,6 +9,7 @@ const activityMessages = {
choose_other_social_issue: "Ajouter une autre problématique sociale...", choose_other_social_issue: "Ajouter une autre problématique sociale...",
social_actions: "Actions d'accompagnement", social_actions: "Actions d'accompagnement",
select_first_a_social_issue: "Sélectionnez d'abord une problématique sociale", select_first_a_social_issue: "Sélectionnez d'abord une problématique sociale",
social_action_list_empty: "Aucune action sociale disponible",
// //
add_persons: "Ajouter des personnes concernées", add_persons: "Ajouter des personnes concernées",

View File

@ -10,10 +10,12 @@
namespace Chill\ActivityBundle\Validator\Constraints; namespace Chill\ActivityBundle\Validator\Constraints;
use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Entity\Activity;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException; use Symfony\Component\Validator\Exception\UnexpectedValueException;
use function array_merge;
class ActivityValidityValidator extends ConstraintValidator class ActivityValidityValidator extends ConstraintValidator
{ {
@ -118,9 +120,19 @@ class ActivityValidityValidator extends ConstraintValidator
} }
if ($activity->getActivityType()->getSocialActionsVisible() === 2 && $activity->getSocialActions()->count() === 0) { if ($activity->getActivityType()->getSocialActionsVisible() === 2 && $activity->getSocialActions()->count() === 0) {
$this->context // check if a social action may be added
->buildViolation($constraint->socialActionsMessage) $actions = [];
->addViolation();
foreach ($activity->getSocialIssues() as $socialIssue) {
/** @var SocialIssue $socialIssue */
$actions = array_merge($actions, $socialIssue->getRecursiveSocialActions()->toArray());
}
if (0 < count($actions)) {
$this->context
->buildViolation($constraint->socialActionsMessage)
->addViolation();
}
} }
} }
} }

View File

@ -103,6 +103,10 @@ class Paginator implements PaginatorInterface
public function countPages() public function countPages()
{ {
if (0 === $this->itemPerPage) {
return 1;
}
$nb = floor($this->totalItems / $this->itemPerPage); $nb = floor($this->totalItems / $this->itemPerPage);
if ($this->totalItems % $this->itemPerPage > 0) { if ($this->totalItems % $this->itemPerPage > 0) {