Merge branch '__SocialWorkTypeFilter' into 111_exports_suite

This commit is contained in:
Mathieu Jaumotte 2022-09-14 14:58:35 +02:00
commit f07847e985

View File

@ -54,6 +54,8 @@
<VueMultiselect <VueMultiselect
v-model="result" v-model="result"
:options="results.options" :options="results.options"
@select="selectResult"
@remove="unselectResult"
:multiple="true" :multiple="true"
:close-on-select="false" :close-on-select="false"
:placeholder="$t('result.placeholder')" :placeholder="$t('result.placeholder')"
@ -154,6 +156,8 @@ export default {
this.actions.hiddenField.value = ''; this.actions.hiddenField.value = '';
this.goals.hiddenField.value = ''; this.goals.hiddenField.value = '';
this.results.hiddenField.value = ''; this.results.hiddenField.value = '';
console.log(this.actions.hiddenField, this.goals.hiddenField, this.results.hiddenField);
}, },
methods: { methods: {
async getSocialActionsList() { async getSocialActionsList() {
@ -165,29 +169,31 @@ export default {
* @param value * @param value
*/ */
selectAction(value) { selectAction(value) {
console.log('selectAction', value); console.log('----'); console.log('select action', value.id);
getGoalByAction(value.id).then(response => new Promise((resolve, reject) => { let children = this.getChildrensFromParent(value);
//console.log('fetch Goals', response); this.addSelectedElement('actions', children);
this.addElementInData('goals', response.results);
resolve(); let parentAndChildren = [...[value], ...children];
})).catch; parentAndChildren.forEach(elem => {
getResultByAction(value.id).then(response => new Promise((resolve, reject) => { getGoalByAction(elem.id).then(response => new Promise((resolve, reject) => {
//console.log('fetch Results', response); this.addElementInData('goals', response.results);
this.addElementInData('results', response.results); resolve();
resolve(); })).catch;
})).catch; getResultByAction(elem.id).then(response => new Promise((resolve, reject) => {
this.addElementInData('results', response.results);
resolve();
})).catch;
});
}, },
unselectAction(value) { unselectAction(value) {
console.log('unselectAction', value); console.log('----'); console.log('unselect action', value.id);
getGoalByAction(value.id).then(response => new Promise((resolve, reject) => { getGoalByAction(value.id).then(response => new Promise((resolve, reject) => {
//console.log('fetch Goals', response); [ this.goals.options, this.goals.value ] = this.removeElementInData('goals', response.results);
this.goals.options = this.removeElementInData('goals', response.results);
resolve(); resolve();
})).catch; })).catch;
getResultByAction(value.id).then(response => new Promise((resolve, reject) => { getResultByAction(value.id).then(response => new Promise((resolve, reject) => {
//console.log('fetch Results', response); [ this.results.options, this.results.value ] = this.removeElementInData('results', response.results);
this.results.options = this.removeElementInData('results', response.results);
resolve(); resolve();
})).catch; })).catch;
}, },
@ -197,23 +203,48 @@ export default {
* @param value * @param value
*/ */
selectGoal(value) { selectGoal(value) {
console.log('selectGoal', value); console.log('----'); console.log('select goal', value.id);
getResultByGoal(value.id).then(response => new Promise((resolve, reject) => { getResultByGoal(value.id).then(response => new Promise((resolve, reject) => {
//console.log('fetch Results', response);
this.addElementInData('results', response.results); this.addElementInData('results', response.results);
resolve(); resolve();
})).catch; })).catch;
}, },
unselectGoal(value) { unselectGoal(value) {
console.log('unselectGoal', value); console.log('----'); console.log('unselect goal', value.id);
getResultByGoal(value.id).then(response => new Promise((resolve, reject) => { getResultByGoal(value.id).then(response => new Promise((resolve, reject) => {
//console.log('fetch Results', response); [ this.results.options, this.results.value ] = this.removeElementInData('results', response.results);
this.results.options = this.removeElementInData('results', response.results);
resolve(); resolve();
})).catch; })).catch;
}, },
/**
* Select/unselect in Result Multiselect
* @param value
*/
selectResult(value) {
console.log('----'); console.log('select result', value.id);
},
unselectResult(value) {
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'
@ -221,13 +252,17 @@ export default {
*/ */
addElementInData(target, response) { addElementInData(target, response) {
let data = this[target]; let data = this[target];
let dump = [];
response.forEach(elem => { response.forEach(elem => {
let found = data.options.some(e => e.id === elem.id); let found = data.options.some(e => e.id === elem.id);
if (!found) { if (!found) {
console.log('push elem in', target, elem.id);
data.options.push(elem); data.options.push(elem);
dump.push(elem.id);
} }
}) })
if (dump.length > 0) {
console.log('push ' + dump.length + ' elems in', target, dump);
}
}, },
/** /**
@ -238,28 +273,80 @@ export default {
*/ */
removeElementInData(target, response) { removeElementInData(target, response) {
let data = this[target]; let data = this[target];
let dump = [];
response.forEach(elem => { response.forEach(elem => {
let found = data.options.some(e => e.id === elem.id); let found = data.options.some(e => e.id === elem.id);
if (found) { if (found) {
console.log('remove elem from', target, elem.id);
data.options = data.options.filter(e => e.id !== elem.id); data.options = data.options.filter(e => e.id !== 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);
// remove from hiddenField
this.rebuildHiddenFieldValues(target);
// remove should be recursive; here it works but is not fine
if (target === 'goals') { // <==== TODO improve loop
this.unselectGoal(elem);
}
}
///
} }
}) })
return data.options; if (dump.length > 0) {
console.log('remove ' + dump.length + ' elems from ' + target + ' options', dump);
}
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.
* In that case, we have to unselect Goal to remove elements in results too.
* @param target
* @param elem
*/
unselectToNextField(target, elem) {
if (target === 'goals') {
console.log('!!!! target is goal: unselect goal', elem.id);
this.unselectGoal(elem);
console.log('!!!! done');
}
}, },
/** /**
@ -268,10 +355,12 @@ export default {
*/ */
rebuildHiddenFieldValues(target) { rebuildHiddenFieldValues(target) {
let data = this[target]; let data = this[target];
console.log('rebuild hiddenFields ' + target + ' values :');
data.hiddenField.value = ''; // reset data.hiddenField.value = ''; // reset
data.value.forEach(elem => { data.value.forEach(elem => {
data.hiddenField.value = this.addIdToValue(data.hiddenField.value, elem.id); data.hiddenField.value = this.addIdToValue(data.hiddenField.value, elem.id);
}) })
console.log(data.hiddenField);
}, },
addIdToValue(string, id) { addIdToValue(string, id) {