mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
vue activity: manage datas in store, not with data()
This commit is contained in:
@@ -4,28 +4,68 @@ import { createStore } from 'vuex';
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
//console.log('window.activity', window.activity);
|
||||
|
||||
const addIdToValue = (string, id) => {
|
||||
let array = string ? string.split(',') : [];
|
||||
array.push(id.toString());
|
||||
let str = array.join();
|
||||
return str;
|
||||
};
|
||||
|
||||
const removeIdFromValue = (string, id) => {
|
||||
let array = string.split(',');
|
||||
array = array.filter(el => el !== id.toString());
|
||||
let str = array.join();
|
||||
return str;
|
||||
};
|
||||
|
||||
const store = createStore({
|
||||
strict: debug,
|
||||
state: {
|
||||
activity: window.activity
|
||||
},
|
||||
getters: {
|
||||
activity: window.activity,
|
||||
socialIssuesOther: [],
|
||||
socialActionsList: [],
|
||||
},
|
||||
mutations: {
|
||||
|
||||
// SocialIssueAcc
|
||||
addSocialIssueInList(state, issue) {
|
||||
console.log('add list issue', issue.id);
|
||||
state.activity.accompanyingPeriod.socialIssues.push(issue);
|
||||
},
|
||||
addSocialIssueSelected(state, issue) {
|
||||
console.log('add selected issue', issue.id);
|
||||
state.activity.socialIssues.push(issue);
|
||||
},
|
||||
updateSocialIssuesSelected(state, issue) {
|
||||
console.log('update selected issues');
|
||||
state.activity.socialIssues = issue;
|
||||
},
|
||||
updateSocialIssuesOther(state, payload) {
|
||||
console.log('update other issues');
|
||||
state.socialIssuesOther = payload;
|
||||
},
|
||||
removeSocialIssueInOther(state, issue) {
|
||||
console.log('remove other issue', issue.id);
|
||||
state.socialIssuesOther = state.socialIssuesOther.filter(item => item !== issue);
|
||||
},
|
||||
resetSocialActionList(state) {
|
||||
console.log('reset actions list');
|
||||
state.socialActionsList = [];
|
||||
},
|
||||
addSocialActionInList(state, action) {
|
||||
console.log('add list action', action.id);
|
||||
state.socialActionsList.push(action);
|
||||
},
|
||||
addSocialActionSelected(state, action) {
|
||||
console.log('add selected action', action.id);
|
||||
state.activity.socialActions.push(action);
|
||||
},
|
||||
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;
|
||||
};
|
||||
if (list === 'issues') {
|
||||
state.activity.accompanyingPeriod.socialIssues = filterList(state.activity.accompanyingPeriod.socialIssues);
|
||||
}
|
||||
if (list === 'actions') {
|
||||
state.socialActionsList = filterList(state.socialActionsList);
|
||||
}
|
||||
},
|
||||
|
||||
// ConcernedGroups
|
||||
addPersonsInvolved(state, payload) {
|
||||
//console.log('### mutation addPersonsInvolved', payload.result.type);
|
||||
switch (payload.result.type) {
|
||||
@@ -58,6 +98,14 @@ const store = createStore({
|
||||
actions: {
|
||||
addPersonsInvolved({ commit }, payload) {
|
||||
//console.log('### action addPersonsInvolved', payload.result.type);
|
||||
|
||||
const addIdToValue = (string, id) => {
|
||||
let array = string ? string.split(',') : [];
|
||||
array.push(id.toString());
|
||||
let str = array.join();
|
||||
return str;
|
||||
};
|
||||
|
||||
switch (payload.result.type) {
|
||||
case 'person':
|
||||
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
||||
@@ -76,6 +124,14 @@ const store = createStore({
|
||||
},
|
||||
removePersonInvolved({ commit }, payload) {
|
||||
//console.log('### action removePersonInvolved', payload);
|
||||
|
||||
const removeIdFromValue = (string, id) => {
|
||||
let array = string.split(',');
|
||||
array = array.filter(el => el !== id.toString());
|
||||
let str = array.join();
|
||||
return str;
|
||||
};
|
||||
|
||||
switch (payload.type) {
|
||||
case 'person':
|
||||
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
||||
|
Reference in New Issue
Block a user