mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
select action childrens when selecting parent
This commit is contained in:
parent
424c9239b7
commit
c7e88b3924
@ -158,7 +158,6 @@ export default {
|
|||||||
this.results.hiddenField.value = '';
|
this.results.hiddenField.value = '';
|
||||||
|
|
||||||
console.log(this.actions.hiddenField, this.goals.hiddenField, this.results.hiddenField);
|
console.log(this.actions.hiddenField, this.goals.hiddenField, this.results.hiddenField);
|
||||||
// TODO choisir une action parente impliquera de retenir les actions "enfants".
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async getSocialActionsList() {
|
async getSocialActionsList() {
|
||||||
@ -171,14 +170,20 @@ export default {
|
|||||||
*/
|
*/
|
||||||
selectAction(value) {
|
selectAction(value) {
|
||||||
console.log('----'); console.log('select action', value.id);
|
console.log('----'); console.log('select action', value.id);
|
||||||
getGoalByAction(value.id).then(response => new Promise((resolve, reject) => {
|
let children = this.getChildrensFromParent(value);
|
||||||
this.addElementInData('goals', response.results);
|
this.addSelectedElement('actions', children);
|
||||||
resolve();
|
|
||||||
})).catch;
|
let parentAndChildren = [...[value], ...children];
|
||||||
getResultByAction(value.id).then(response => new Promise((resolve, reject) => {
|
parentAndChildren.forEach(elem => {
|
||||||
this.addElementInData('results', response.results);
|
getGoalByAction(elem.id).then(response => new Promise((resolve, reject) => {
|
||||||
resolve();
|
this.addElementInData('goals', response.results);
|
||||||
})).catch;
|
resolve();
|
||||||
|
})).catch;
|
||||||
|
getResultByAction(elem.id).then(response => new Promise((resolve, reject) => {
|
||||||
|
this.addElementInData('results', response.results);
|
||||||
|
resolve();
|
||||||
|
})).catch;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
unselectAction(value) {
|
unselectAction(value) {
|
||||||
@ -225,6 +230,21 @@ export default {
|
|||||||
console.log('----'); console.log('unselect result', value.id);
|
console.log('----'); console.log('unselect result', value.id);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Choose parent action will involve retaining the "children" actions.
|
||||||
|
* @param value
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
getChildrensFromParent(value) {
|
||||||
|
if (null === value.parent) {
|
||||||
|
let excludeParent = this.actions.options.filter(o => o.parent !== null);
|
||||||
|
let children = excludeParent.filter(o => o.parent.id === value.id);
|
||||||
|
console.log("get childrens", children.map(e => e.id));
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add response elements in data target
|
* Add response elements in data target
|
||||||
* @param target string -> 'actions', 'goals' or 'results'
|
* @param target string -> 'actions', 'goals' or 'results'
|
||||||
@ -260,21 +280,7 @@ export default {
|
|||||||
data.options = data.options.filter(e => e.id !== elem.id);
|
data.options = data.options.filter(e => e.id !== elem.id);
|
||||||
dump.push(elem.id);
|
dump.push(elem.id);
|
||||||
|
|
||||||
/// remove too from selected and from hiddenField
|
this.removeSelectedElement(target, elem);
|
||||||
let selected = data.value.some(e => e.id === elem.id);
|
|
||||||
if (selected) {
|
|
||||||
|
|
||||||
// remove from selected
|
|
||||||
data.value = data.value.filter(e => e.id !== elem.id);
|
|
||||||
console.log('remove ' + elem.id + ' from selected ' + target);
|
|
||||||
|
|
||||||
// remove from hiddenField
|
|
||||||
this.rebuildHiddenFieldValues(target);
|
|
||||||
|
|
||||||
// in any cases, remove should be recursive
|
|
||||||
this.unselectToNextField(target, elem);
|
|
||||||
}
|
|
||||||
///
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (dump.length > 0) {
|
if (dump.length > 0) {
|
||||||
@ -283,6 +289,52 @@ export default {
|
|||||||
return [ data.options, data.value ];
|
return [ data.options, data.value ];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param target
|
||||||
|
* @param elements
|
||||||
|
*/
|
||||||
|
addSelectedElement(target, elements) {
|
||||||
|
let data = this[target];
|
||||||
|
let dump = [];
|
||||||
|
elements.forEach(elem => {
|
||||||
|
let selected = data.value.some(e => e.id === elem.id);
|
||||||
|
if (!selected) {
|
||||||
|
|
||||||
|
data.value.push(elem);
|
||||||
|
dump.push(elem.id);
|
||||||
|
|
||||||
|
// add in hiddenField
|
||||||
|
this.rebuildHiddenFieldValues(target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (dump.length > 0) {
|
||||||
|
console.log('add ' + dump.length + ' selected elems in', target, dump);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove element from selected and from hiddenField
|
||||||
|
* @param target
|
||||||
|
* @param elem
|
||||||
|
*/
|
||||||
|
removeSelectedElement(target, elem) {
|
||||||
|
let data = this[target];
|
||||||
|
let selected = data.value.some(e => e.id === elem.id);
|
||||||
|
if (selected) {
|
||||||
|
|
||||||
|
// remove from selected
|
||||||
|
data.value = data.value.filter(e => e.id !== elem.id);
|
||||||
|
console.log('remove ' + elem.id + ' from selected ' + target);
|
||||||
|
|
||||||
|
// remove from hiddenField
|
||||||
|
this.rebuildHiddenFieldValues(target);
|
||||||
|
|
||||||
|
// in any cases, remove should be recursive
|
||||||
|
this.unselectToNextField(target, elem);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When unselect Action, it could remove elements in goals multiselect.
|
* When unselect Action, it could remove elements in goals multiselect.
|
||||||
* In that case, we have to unselect Goal to remove elements in results too.
|
* In that case, we have to unselect Goal to remove elements in results too.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user