Merge branch 'fix-prototypage-details' into deploy/quick-fixes

This commit is contained in:
Mathieu Jaumotte 2021-06-29 15:21:00 +02:00
commit 014170989e
4 changed files with 67 additions and 59 deletions

View File

@ -108,15 +108,14 @@ class Activity implements HasCenterInterface, HasScopeInterface
* @ORM\JoinTable(name="chill_activity_activity_chill_person_socialissue") * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialissue")
* @Groups({"read"}) * @Groups({"read"})
*/ */
private $socialIssues; private Collection $socialIssues;
/** /**
* @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction") * @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction")
* @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction") * @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction")
* @Groups({"read"}) * @Groups({"read"})
*/ */
private $socialActions; private Collection $socialActions;
/** /**
* @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType") * @ORM\ManyToOne(targetEntity="Chill\ActivityBundle\Entity\ActivityType")
@ -283,7 +282,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
return $this->socialIssues; return $this->socialIssues;
} }
public function addSocialIssue(SocialIssue $socialIssue): self public function addSocialIssue(?SocialIssue $socialIssue): self
{ {
if (!$this->socialIssues->contains($socialIssue)) { if (!$this->socialIssues->contains($socialIssue)) {
$this->socialIssues[] = $socialIssue; $this->socialIssues[] = $socialIssue;
@ -299,15 +298,12 @@ class Activity implements HasCenterInterface, HasScopeInterface
return $this; return $this;
} }
/**
* @return Collection|SocialAction[]
*/
public function getSocialActions(): Collection public function getSocialActions(): Collection
{ {
return $this->socialActions; return $this->socialActions;
} }
public function addSocialAction(SocialAction $socialAction): self public function addSocialAction(?SocialAction $socialAction): self
{ {
if (!$this->socialActions->contains($socialAction)) { if (!$this->socialActions->contains($socialAction)) {
$this->socialActions[] = $socialAction; $this->socialActions[] = $socialAction;

View File

@ -123,6 +123,9 @@ class ActivityType extends AbstractType
return implode(',', $socialIssueIds); return implode(',', $socialIssueIds);
}, },
function (?string $socialIssuesAsString): array { function (?string $socialIssuesAsString): array {
if (null === $socialIssuesAsString) {
return [];
}
return array_map( return array_map(
fn(string $id): ?SocialIssue => $this->om->getRepository(SocialIssue::class)->findOneBy(['id' => (int) $id]), fn(string $id): ?SocialIssue => $this->om->getRepository(SocialIssue::class)->findOneBy(['id' => (int) $id]),
explode(',', $socialIssuesAsString) explode(',', $socialIssuesAsString)
@ -144,6 +147,9 @@ class ActivityType extends AbstractType
return implode(',', $socialActionIds); return implode(',', $socialActionIds);
}, },
function (?string $socialActionsAsString): array { function (?string $socialActionsAsString): array {
if (null === $socialActionsAsString) {
return [];
}
return array_map( return array_map(
fn(string $id): ?SocialAction => $this->om->getRepository(SocialAction::class)->findOneBy(['id' => (int) $id]), fn(string $id): ?SocialAction => $this->om->getRepository(SocialAction::class)->findOneBy(['id' => (int) $id]),
explode(',', $socialActionsAsString) explode(',', $socialActionsAsString)

View File

@ -35,11 +35,6 @@
v-bind:options="socialIssuesOther" v-bind:options="socialIssuesOther"
v-model="value" v-model="value"
@select="addIssueInList"> @select="addIssueInList">
<template v-slot:selection="{ values, search, isOpen }"><!-- {{ values.length }} {{ isOpen }} -->
<span v-if="values.length > 0" class="multiselect__single"></span>
</template>
</VueMultiselect> </VueMultiselect>
</div> </div>
@ -57,7 +52,7 @@
</div> </div>
<check-social-action <check-social-action
v-if="socialIssuesSelected.length" v-if="socialIssuesSelected.length || socialActionsSelected.length"
v-for="action in socialActionsList" v-for="action in socialActionsList"
v-bind:key="action.id" v-bind:key="action.id"
v-bind:action="action" v-bind:action="action"
@ -69,7 +64,6 @@
{{ $t('activity.select_first_a_social_issue') }} {{ $t('activity.select_first_a_social_issue') }}
</span> </span>
</div> </div>
</div> </div>
@ -114,28 +108,38 @@ export default {
} }
}, },
mounted() { mounted() {
console.log('load others issues in multiselect'); /* Load others issues in multiselect
*/
this.issueIsLoading = true; this.issueIsLoading = true;
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);
/* Add in list the issues already associated (if not yet listed)
*/
this.socialIssuesSelected.forEach(issue => { this.socialIssuesSelected.forEach(issue => {
if (this.socialIssuesList.filter(i => i.id === issue.id).length !== 1) {
this.$store.commit('addIssueInList', issue); this.$store.commit('addIssueInList', issue);
}
}, this); }, this);
console.log(this.socialIssuesOther.length, this.socialIssuesOther); /* Remove from multiselect the issues that are not yet in checkbox list
*/
this.socialIssuesList.forEach(issue => { this.socialIssuesList.forEach(issue => {
this.$store.commit('removeIssueInOther', issue); this.$store.commit('removeIssueInOther', issue);
}, this); }, this);
console.log(this.socialIssuesOther.length); // grr !!!
// TODO décompter les issues initiales du multiselect
/* Filter issues
*/
this.$store.commit('filterList', 'issues'); this.$store.commit('filterList', 'issues');
/* Add in list the actions already associated (if not yet listed)
*/
this.socialActionsSelected.forEach(action => { this.socialActionsSelected.forEach(action => {
this.$store.commit('addActionInList', action); this.$store.commit('addActionInList', action);
}, this); }, this);
/* Filter issues
*/
this.$store.commit('filterList', 'actions'); this.$store.commit('filterList', 'actions');
this.issueIsLoading = false; this.issueIsLoading = false;
@ -148,7 +152,7 @@ export default {
remove it from multiselect, and add socialActions concerned remove it from multiselect, and add socialActions concerned
*/ */
addIssueInList(value) { addIssueInList(value) {
console.log('addIssueInList', value); //console.log('addIssueInList', value);
this.$store.commit('addIssueInList', value); this.$store.commit('addIssueInList', value);
this.$store.commit('removeIssueInOther', value); this.$store.commit('removeIssueInOther', value);
this.$store.dispatch('addIssueSelected', value); this.$store.dispatch('addIssueSelected', value);
@ -157,26 +161,23 @@ export default {
/* Update value for selected issues checkboxes /* Update value for selected issues checkboxes
*/ */
updateIssuesSelected(issues) { updateIssuesSelected(issues) {
console.log('updateIssuesSelected', issues); //console.log('updateIssuesSelected', issues);
this.$store.dispatch('updateIssuesSelected', issues); this.$store.dispatch('updateIssuesSelected', issues);
this.updateActionsList(); this.updateActionsList();
}, },
/* Update value for selected actions checkboxes /* Update value for selected actions checkboxes
*/ */
updateActionsSelected(actions) { updateActionsSelected(actions) {
console.log('updateActionsSelected', actions); //console.log('updateActionsSelected', actions);
this.$store.dispatch('updateActionsSelected', actions); this.$store.dispatch('updateActionsSelected', actions);
}, },
/* Add socialActions concerned: reset actions list, then loop on each issue selected /* Add socialActions concerned: after reset, loop on each issue selected
to get social actions concerned to get social actions concerned
*/ */
updateActionsList() { updateActionsList() {
console.log('updateActionsList'); //console.log('updateActionsList');
this.resetActionsList();
this.$store.commit('resetActionsList');
this.socialIssuesSelected.forEach(item => { this.socialIssuesSelected.forEach(item => {
console.log('for issue', item.id);
this.actionIsLoading = true; this.actionIsLoading = true;
getSocialActionByIssue(item.id) getSocialActionByIssue(item.id)
@ -192,6 +193,14 @@ export default {
resolve(); resolve();
})); }));
}, this); }, this);
},
/* Reset socialActions List: flush list and restore selected actions
*/
resetActionsList() {
this.$store.commit('resetActionsList');
this.socialActionsSelected.forEach(item => {
this.$store.commit('addActionInList', item);
}, this);
} }
} }
} }

View File

@ -29,47 +29,44 @@ const store = createStore({
// SocialIssueAcc // SocialIssueAcc
addIssueInList(state, issue) { addIssueInList(state, issue) {
console.log('add list issue', issue.id); //console.log('add issue list', issue.id);
state.activity.accompanyingPeriod.socialIssues.push(issue); state.activity.accompanyingPeriod.socialIssues.push(issue);
}, },
addIssueSelected(state, issue) { addIssueSelected(state, issue) {
console.log('add selected issue', issue.id); //console.log('add issue selected', issue.id);
state.activity.socialIssues.push(issue); state.activity.socialIssues.push(issue);
}, },
updateIssuesSelected(state, issues) { updateIssuesSelected(state, issues) {
console.log('update selected issues', issues); //console.log('update issues selected', issues);
state.activity.socialIssues = issues; state.activity.socialIssues = issues;
}, },
updateIssuesOther(state, payload) { updateIssuesOther(state, payload) {
console.log('update other issues'); //console.log('update issues other');
state.socialIssuesOther = payload; state.socialIssuesOther = payload;
}, },
removeIssueInOther(state, issue) { removeIssueInOther(state, issue) {
console.log('remove other issue', issue.id); //console.log('remove issue other', issue.id);
state.socialIssuesOther = state.socialIssuesOther.filter(item => item !== issue); state.socialIssuesOther = state.socialIssuesOther.filter(i => i.id !== issue.id);
}, },
resetActionsList(state) { resetActionsList(state) {
console.log('reset actions list'); //console.log('reset list actions');
state.socialActionsList = []; state.socialActionsList = [];
}, },
addActionInList(state, action) { addActionInList(state, action) {
console.log('add list action', action.id); //console.log('add action list', action.id);
state.socialActionsList.push(action); state.socialActionsList.push(action);
}, },
updateActionsSelected(state, actions) { updateActionsSelected(state, actions) {
console.log('update selected actions', actions); //console.log('update actions selected', actions);
state.activity.socialActions = actions; state.activity.socialActions = actions;
}, },
filterList(state, list) { filterList(state, list) {
const filterList = (list) => { const filterList = (list) => {
console.log('filter ' + list.length + ' items: uniq'); // grr !!! // remove duplicates entries
// TODO un filtrage qui enlève les doublons list = list.filter((value, index) => list.findIndex(array => array.id === value.id) === index);
//list = list.filter((v, i, a) => a.indexOf(v) === i); // alpha sort
let _list = [...new Set(list)]; list.sort((a,b) => (a.text > b.text) ? 1 : ((b.text > a.text) ? -1 : 0));
return list;
console.log('filter ' + list.length + ' items: sort', list);
_list.sort((a,b) => (a.text > b.text) ? 1 : ((b.text > a.text) ? -1 : 0));
return _list;
}; };
if (list === 'issues') { if (list === 'issues') {
state.activity.accompanyingPeriod.socialIssues = filterList(state.activity.accompanyingPeriod.socialIssues); state.activity.accompanyingPeriod.socialIssues = filterList(state.activity.accompanyingPeriod.socialIssues);