mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
vue activity: fix duplicates and add condition in initial loading
This commit is contained in:
parent
b705c5910f
commit
beca41774e
@ -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 = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="Chill\PersonBundle\Entity\SocialWork\SocialAction")
|
||||
* @ORM\JoinTable(name="chill_activity_activity_chill_person_socialaction")
|
||||
* @Groups({"read"})
|
||||
*/
|
||||
private $socialActions;
|
||||
|
||||
private ?Collection $socialActions = null;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
@ -307,7 +306,7 @@ class Activity implements HasCenterInterface, HasScopeInterface
|
||||
return $this->socialActions;
|
||||
}
|
||||
|
||||
public function addSocialAction(SocialAction $socialAction): self
|
||||
public function addSocialAction(?SocialAction $socialAction): self
|
||||
{
|
||||
if (!$this->socialActions->contains($socialAction)) {
|
||||
$this->socialActions[] = $socialAction;
|
||||
|
@ -120,24 +120,30 @@ export default {
|
||||
getSocialIssues().then(response => new Promise((resolve, reject) => {
|
||||
this.$store.commit('updateIssuesOther', response.results);
|
||||
|
||||
// ajoute dans la liste les issues déjà associées (si elles ne s'y trouvent pas déjà)
|
||||
this.socialIssuesSelected.forEach(issue => {
|
||||
this.$store.commit('addIssueInList', 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);
|
||||
// enlève du multiselect les issues qui sont dans la liste des checkbox
|
||||
this.socialIssuesList.forEach(issue => {
|
||||
this.$store.commit('removeIssueInOther', issue);
|
||||
}, this);
|
||||
console.log(this.socialIssuesOther.length); // grr !!!
|
||||
// TODO décompter les issues initiales du multiselect
|
||||
|
||||
// filtre les issues
|
||||
this.$store.commit('filterList', 'issues');
|
||||
|
||||
// ajoute dans la liste les actions déjà associées (si elles ne s'y trouvent pas déjà)
|
||||
this.socialActionsSelected.forEach(action => {
|
||||
this.$store.commit('addActionInList', action);
|
||||
}, this);
|
||||
|
||||
// filtre les actions
|
||||
this.$store.commit('filterList', 'actions');
|
||||
|
||||
|
||||
this.issueIsLoading = false;
|
||||
resolve();
|
||||
}));
|
||||
@ -175,22 +181,25 @@ export default {
|
||||
|
||||
this.$store.commit('resetActionsList');
|
||||
|
||||
// remettre les ActionsSelected dans ActionsList
|
||||
|
||||
this.socialIssuesSelected.forEach(item => {
|
||||
console.log('for issue', item.id);
|
||||
//console.log('for issue', item.id);
|
||||
|
||||
this.actionIsLoading = true;
|
||||
getSocialActionByIssue(item.id)
|
||||
.then(actions => new Promise((resolve, reject) => {
|
||||
|
||||
actions.results.forEach(action => {
|
||||
this.$store.commit('addActionInList', action);
|
||||
}, this);
|
||||
|
||||
this.$store.commit('filterList', 'actions');
|
||||
|
||||
this.actionIsLoading = false;
|
||||
resolve();
|
||||
.then(actions => new Promise((resolve, reject) => {
|
||||
|
||||
actions.results.forEach(action => {
|
||||
this.$store.commit('addActionInList', action);
|
||||
}, this);
|
||||
|
||||
this.$store.commit('filterList', 'actions');
|
||||
|
||||
this.actionIsLoading = false;
|
||||
resolve();
|
||||
}));
|
||||
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user