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

View File

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

View File

@ -35,11 +35,6 @@
v-bind:options="socialIssuesOther"
v-model="value"
@select="addIssueInList">
<template v-slot:selection="{ values, search, isOpen }"><!-- {{ values.length }} {{ isOpen }} -->
<span v-if="values.length > 0" class="multiselect__single"></span>
</template>
</VueMultiselect>
</div>
@ -57,7 +52,7 @@
</div>
<check-social-action
v-if="socialIssuesSelected.length"
v-if="socialIssuesSelected.length || socialActionsSelected.length"
v-for="action in socialActionsList"
v-bind:key="action.id"
v-bind:action="action"
@ -69,7 +64,6 @@
{{ $t('activity.select_first_a_social_issue') }}
</span>
</div>
</div>
@ -114,28 +108,38 @@ export default {
}
},
mounted() {
console.log('load others issues in multiselect');
/* Load others issues in multiselect
*/
this.issueIsLoading = true;
getSocialIssues().then(response => new Promise((resolve, reject) => {
this.$store.commit('updateIssuesOther', response.results);
/* Add in list the issues already associated (if not yet listed)
*/
this.socialIssuesSelected.forEach(issue => {
if (this.socialIssuesList.filter(i => i.id === issue.id).length !== 1) {
this.$store.commit('addIssueInList', issue);
}
}, 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.$store.commit('removeIssueInOther', issue);
}, this);
console.log(this.socialIssuesOther.length); // grr !!!
// TODO décompter les issues initiales du multiselect
/* Filter issues
*/
this.$store.commit('filterList', 'issues');
/* Add in list the actions already associated (if not yet listed)
*/
this.socialActionsSelected.forEach(action => {
this.$store.commit('addActionInList', action);
}, this);
/* Filter issues
*/
this.$store.commit('filterList', 'actions');
this.issueIsLoading = false;
@ -148,7 +152,7 @@ export default {
remove it from multiselect, and add socialActions concerned
*/
addIssueInList(value) {
console.log('addIssueInList', value);
//console.log('addIssueInList', value);
this.$store.commit('addIssueInList', value);
this.$store.commit('removeIssueInOther', value);
this.$store.dispatch('addIssueSelected', value);
@ -157,26 +161,23 @@ export default {
/* Update value for selected issues checkboxes
*/
updateIssuesSelected(issues) {
console.log('updateIssuesSelected', issues);
//console.log('updateIssuesSelected', issues);
this.$store.dispatch('updateIssuesSelected', issues);
this.updateActionsList();
},
/* Update value for selected actions checkboxes
*/
updateActionsSelected(actions) {
console.log('updateActionsSelected', actions);
//console.log('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
*/
updateActionsList() {
console.log('updateActionsList');
this.$store.commit('resetActionsList');
//console.log('updateActionsList');
this.resetActionsList();
this.socialIssuesSelected.forEach(item => {
console.log('for issue', item.id);
this.actionIsLoading = true;
getSocialActionByIssue(item.id)
@ -192,6 +193,14 @@ export default {
resolve();
}));
}, 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
addIssueInList(state, issue) {
console.log('add list issue', issue.id);
//console.log('add issue list', issue.id);
state.activity.accompanyingPeriod.socialIssues.push(issue);
},
addIssueSelected(state, issue) {
console.log('add selected issue', issue.id);
//console.log('add issue selected', issue.id);
state.activity.socialIssues.push(issue);
},
updateIssuesSelected(state, issues) {
console.log('update selected issues', issues);
//console.log('update issues selected', issues);
state.activity.socialIssues = issues;
},
updateIssuesOther(state, payload) {
console.log('update other issues');
//console.log('update issues other');
state.socialIssuesOther = payload;
},
removeIssueInOther(state, issue) {
console.log('remove other issue', issue.id);
state.socialIssuesOther = state.socialIssuesOther.filter(item => item !== issue);
//console.log('remove issue other', issue.id);
state.socialIssuesOther = state.socialIssuesOther.filter(i => i.id !== issue.id);
},
resetActionsList(state) {
console.log('reset actions list');
//console.log('reset list actions');
state.socialActionsList = [];
},
addActionInList(state, action) {
console.log('add list action', action.id);
//console.log('add action list', action.id);
state.socialActionsList.push(action);
},
updateActionsSelected(state, actions) {
console.log('update selected actions', actions);
//console.log('update actions selected', actions);
state.activity.socialActions = actions;
},
filterList(state, list) {
const filterList = (list) => {
console.log('filter ' + list.length + ' items: uniq'); // grr !!!
// TODO un filtrage qui enlève les doublons
//list = list.filter((v, i, a) => a.indexOf(v) === i);
let _list = [...new Set(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;
// remove duplicates entries
list = list.filter((value, index) => list.findIndex(array => array.id === value.id) === index);
// alpha sort
list.sort((a,b) => (a.text > b.text) ? 1 : ((b.text > a.text) ? -1 : 0));
return list;
};
if (list === 'issues') {
state.activity.accompanyingPeriod.socialIssues = filterList(state.activity.accompanyingPeriod.socialIssues);