mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
add goals to work, and add results for each goal
This commit is contained in:
parent
5a4a0a3617
commit
ac4cf43753
@ -27,8 +27,7 @@
|
|||||||
<div><h3>Résultats</h3></div>
|
<div><h3>Résultats</h3></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- résultats sans objectifs -->
|
<!-- results which are not attached to an objective -->
|
||||||
|
|
||||||
<div v-if="hasResultsForAction">
|
<div v-if="hasResultsForAction">
|
||||||
<div>
|
<div>
|
||||||
{{ $t('results_without_objective') }}
|
{{ $t('results_without_objective') }}
|
||||||
@ -37,6 +36,38 @@
|
|||||||
<add-result :availableResults="resultsForAction" destination="action"></add-result>
|
<add-result :availableResults="resultsForAction" destination="action"></add-result>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- results which **are** attached to an objective -->
|
||||||
|
<div v-for="g in goalsPicked">
|
||||||
|
<div>
|
||||||
|
<span @click="removeGoal(g)">
|
||||||
|
<i class="fa fa-times"></i>
|
||||||
|
{{ g.title.fr }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<add-result destination="goal" :goal="g"></add-result>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- box to add goal -->
|
||||||
|
<div class="add_goal">
|
||||||
|
<div>
|
||||||
|
<div v-if="showAddObjective">
|
||||||
|
<ul>
|
||||||
|
<li v-for="g in availableForCheckGoal" @click="addGoal(g)">
|
||||||
|
<i class="fa fa-plus"></i>
|
||||||
|
{{ g.title.fr }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div @click="toggleAddObjective">
|
||||||
|
<i class="fa fa-plus"></i>
|
||||||
|
{{ $t('add_objective') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div><!-- empty for results --></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -106,12 +137,14 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
editor: ClassicEditor,
|
editor: ClassicEditor,
|
||||||
|
showAddObjective: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState([
|
...mapState([
|
||||||
'work',
|
'work',
|
||||||
'resultsForAction',
|
'resultsForAction',
|
||||||
|
'goalsPicked',
|
||||||
]),
|
]),
|
||||||
...mapGetters([
|
...mapGetters([
|
||||||
'hasResultsForAction',
|
'hasResultsForAction',
|
||||||
@ -142,6 +175,26 @@ export default {
|
|||||||
this.$store.mutate('setNote', note);
|
this.$store.mutate('setNote', note);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
availableForCheckGoal() {
|
||||||
|
let pickedIds = this.$store.state.goalsPicked.map(g => g.id);
|
||||||
|
console.log('pickeds goals id', pickedIds);
|
||||||
|
console.log(this.$store.state.goalsForAction);
|
||||||
|
|
||||||
|
return this.$store.state.goalsForAction.filter(g => !pickedIds.includes(g.id));
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
toggleAddObjective() {
|
||||||
|
this.showAddObjective = !this.showAddObjective;
|
||||||
|
},
|
||||||
|
addGoal(g) {
|
||||||
|
console.log('add Goal', g);
|
||||||
|
this.$store.commit('addGoal', g);
|
||||||
|
},
|
||||||
|
removeGoal(g) {
|
||||||
|
console.log('remove goal', g);
|
||||||
|
this.$store.commit('removeGoal', g);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="addResult">
|
<div class="addResult" v-if="hasResult">
|
||||||
<ul>
|
<ul>
|
||||||
<li v-for="r in pickedResults" @click="removeResult(r)">
|
<li v-for="r in pickedResults" @click="removeResult(r)">
|
||||||
<i class="fa fa-times"></i>
|
<i class="fa fa-times"></i>
|
||||||
@ -20,38 +20,62 @@
|
|||||||
{{ $t('add_a_result') }}
|
{{ $t('add_a_result') }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="noResult" v-if="!hasResult">
|
||||||
|
<div>
|
||||||
|
{{ $t('goal_has_ho_result') }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "AddResult",
|
name: "AddResult",
|
||||||
props: [ 'availableResults', 'destination' ],
|
props: [ 'destination', 'goal' ],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isExpanded: false,
|
isExpanded: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
hasResult() {
|
||||||
|
if (this.destination === 'action') {
|
||||||
|
return this.$store.state.resultsForAction.length > 0;
|
||||||
|
} else if (this.destination === 'goal') {
|
||||||
|
return this.$store.getters.resultsForGoal(this.goal).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw Error(`this.destination is not implemented: ${this.destination}`);
|
||||||
|
},
|
||||||
pickedResults() {
|
pickedResults() {
|
||||||
console.log('get checked');
|
console.log('get checked');
|
||||||
console.log('this.destination', this.destination);
|
console.log('this.destination', this.destination);
|
||||||
|
console.log('this.goal', this.goal);
|
||||||
if (this.destination === 'action') {
|
if (this.destination === 'action') {
|
||||||
return this.$store.state.resultsPicked;
|
return this.$store.state.resultsPicked;
|
||||||
|
} else if (this.destination === 'goal') {
|
||||||
|
return this.$store.getters.resultsPickedForGoal(this.goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Error(`this.destination is not implemented: ${this.destination}`);
|
throw Error(`this.destination is not implemented: ${this.destination}`);
|
||||||
},
|
},
|
||||||
availableForCheckResults() {
|
availableForCheckResults() {
|
||||||
console.log('availableForCheckResults');
|
console.log('availableForCheckResults');
|
||||||
|
console.log('this.destination', this.destination);
|
||||||
|
console.log('this.goal', this.goal);
|
||||||
if (this.destination === 'action') {
|
if (this.destination === 'action') {
|
||||||
let pickedIds = this.$store.state.resultsPicked.map(r => r.id);
|
let pickedIds = this.$store.state.resultsPicked.map(r => r.id);
|
||||||
console.log('picked ids', pickedIds);
|
console.log('picked ids', pickedIds);
|
||||||
|
|
||||||
return this.$store.state.resultsForAction.filter(r => !pickedIds.includes(r.id));
|
return this.$store.state.resultsForAction.filter(r => !pickedIds.includes(r.id));
|
||||||
|
} else if (this.destination === 'goal') {
|
||||||
|
console.log('results picked for goal', this.$store.getters.resultsPickedForGoal(this.goal));
|
||||||
|
let pickedIds = this.$store.getters.resultsPickedForGoal(this.goal).map(r => r.id);
|
||||||
|
|
||||||
|
return this.$store.getters.resultsForGoal(this.goal).filter(r => !pickedIds.includes(r.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('destination not implemented', this.destination);
|
throw Error(`this.destination is not implemented: ${this.destination}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -62,13 +86,23 @@ export default {
|
|||||||
console.log('addResult', r);
|
console.log('addResult', r);
|
||||||
if (this.destination === 'action') {
|
if (this.destination === 'action') {
|
||||||
this.$store.commit('addResultPicked', r);
|
this.$store.commit('addResultPicked', r);
|
||||||
|
return;
|
||||||
|
} else if (this.destination === 'goal') {
|
||||||
|
this.$store.commit('addResultForGoalPicked', { goal: this.goal, result: r });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
throw Error(`this.destination is not implemented: ${this.destination}`);
|
||||||
},
|
},
|
||||||
removeResult(r) {
|
removeResult(r) {
|
||||||
console.log('removeresult', r);
|
console.log('removeresult', r);
|
||||||
if (this.destination === 'action') {
|
if (this.destination === 'action') {
|
||||||
this.$store.commit('removeResultPicked', r);
|
this.$store.commit('removeResultPicked', r);
|
||||||
|
return;
|
||||||
|
} else if (this.destination === 'goal') {
|
||||||
|
this.$store.commit('removeResultForGoalPicked', { goal: this.goal, result: r });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
throw Error(`this.destination is not implemented: ${this.destination}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,16 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
hasResultsForAction(state) {
|
hasResultsForAction(state) {
|
||||||
return state.resultsForAction.length > 0;
|
return state.resultsForAction.length > 0;
|
||||||
|
},
|
||||||
|
resultsForGoal: (state) => (goal) => {
|
||||||
|
let founds = state.resultsForGoal.filter(r => r.goalId === goal.id);
|
||||||
|
|
||||||
|
return founds === undefined ? [] : founds;
|
||||||
|
},
|
||||||
|
resultsPickedForGoal: (state) => (goal) => {
|
||||||
|
let found = state.goalsPicked.find(g => g.id === goal.id);
|
||||||
|
|
||||||
|
return found === undefined ? [] : found.results;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
@ -43,7 +53,7 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
setResultsForGoal(state, { goal, results }) {
|
setResultsForGoal(state, { goal, results }) {
|
||||||
console.log('set results for goal', results);
|
console.log('set results for goal', results);
|
||||||
state.goalsForAction = goal;
|
state.goalsForAction.push(goal);
|
||||||
for (let i in results) {
|
for (let i in results) {
|
||||||
let r = results[i];
|
let r = results[i];
|
||||||
r.goalId = goal.id;
|
r.goalId = goal.id;
|
||||||
@ -57,6 +67,33 @@ const store = createStore({
|
|||||||
removeResultPicked(state, result) {
|
removeResultPicked(state, result) {
|
||||||
state.resultsPicked = state.resultsPicked.filter(r => r.id !== result.id);
|
state.resultsPicked = state.resultsPicked.filter(r => r.id !== result.id);
|
||||||
},
|
},
|
||||||
|
addGoal(state, goal) {
|
||||||
|
let g = goal;
|
||||||
|
// initialize results to empty array
|
||||||
|
g.results = []
|
||||||
|
state.goalsPicked.push(g);
|
||||||
|
},
|
||||||
|
removeGoal(state, goal) {
|
||||||
|
state.goalsPicked = state.goalsPicked.filter(g => g.id !== goal.id);
|
||||||
|
},
|
||||||
|
addResultForGoalPicked(state, { goal, result}) {
|
||||||
|
let found = state.goalsPicked.find(g => g.id === goal.id);
|
||||||
|
|
||||||
|
if (found === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
found.results.push(result);
|
||||||
|
},
|
||||||
|
removeResultForGoalPicked(state, { goal, result}) {
|
||||||
|
let found = state.goalsPicked.find(g => g.id === goal.id);
|
||||||
|
|
||||||
|
if (found === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
found.results = found.results.filter(r => r.id !== result.id);
|
||||||
|
},
|
||||||
addErrors(state, errors) {
|
addErrors(state, errors) {
|
||||||
console.log('handling errors', errors);
|
console.log('handling errors', errors);
|
||||||
for (let i in errors) {
|
for (let i in errors) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user