mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
App.vue: improve logs to understand algo
This commit is contained in:
parent
b2e83892a7
commit
424c9239b7
@ -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,9 @@ 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);
|
||||||
|
// TODO choisir une action parente impliquera de retenir les actions "enfants".
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async getSocialActionsList() {
|
async getSocialActionsList() {
|
||||||
@ -165,29 +170,25 @@ 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) => {
|
getGoalByAction(value.id).then(response => new Promise((resolve, reject) => {
|
||||||
//console.log('fetch Goals', response);
|
|
||||||
this.addElementInData('goals', response.results);
|
this.addElementInData('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.addElementInData('results', response.results);
|
this.addElementInData('results', response.results);
|
||||||
resolve();
|
resolve();
|
||||||
})).catch;
|
})).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 +198,33 @@ 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);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 +232,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 +253,48 @@ 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
|
/// remove too from selected and from hiddenField
|
||||||
let selected = data.value.some(e => e.id === elem.id);
|
let selected = data.value.some(e => e.id === elem.id);
|
||||||
if (selected) {
|
if (selected) {
|
||||||
|
|
||||||
// remove from selected
|
// remove from selected
|
||||||
data.value = data.value.filter(e => e.id !== elem.id);
|
data.value = data.value.filter(e => e.id !== elem.id);
|
||||||
|
console.log('remove ' + elem.id + ' from selected ' + target);
|
||||||
|
|
||||||
// remove from hiddenField
|
// remove from hiddenField
|
||||||
this.rebuildHiddenFieldValues(target);
|
this.rebuildHiddenFieldValues(target);
|
||||||
// remove should be recursive; here it works but is not fine
|
|
||||||
if (target === 'goals') { // <==== TODO improve loop
|
// in any cases, remove should be recursive
|
||||||
this.unselectGoal(elem);
|
this.unselectToNextField(target, elem);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
///
|
///
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return data.options;
|
if (dump.length > 0) {
|
||||||
|
console.log('remove ' + dump.length + ' elems from ' + target + ' options', dump);
|
||||||
|
}
|
||||||
|
return [ data.options, data.value ];
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 +303,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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user