Save objective group via mutation

This commit is contained in:
Ramon Wenger 2018-11-20 18:48:48 +01:00
parent a1fd28b48e
commit a89c0d006b
1 changed files with 33 additions and 21 deletions

View File

@ -3,7 +3,7 @@
<template slot="header"> <template slot="header">
<h4 class="new-objective-group-wizard__heading">Lernziele: {{title}}</h4> <h4 class="new-objective-group-wizard__heading">Lernziele: {{title}}</h4>
</template> </template>
<objective-form <objective-form
:objective="objective" :objective="objective"
v-for="(objective, index) in objectives" v-for="(objective, index) in objectives"
@ -24,6 +24,9 @@
import ObjectiveForm from '@/components/objective-groups/ObjectiveForm'; import ObjectiveForm from '@/components/objective-groups/ObjectiveForm';
import AddContentElement from '@/components/AddContentElement'; import AddContentElement from '@/components/AddContentElement';
import NEW_OBJECTIVE_GROUP_MUTATION from '@/graphql/gql/mutations/addObjectiveGroup.gql';
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
export default { export default {
components: { components: {
AddContentElement, AddContentElement,
@ -44,36 +47,45 @@
addObjective() { addObjective() {
this.objectives.push({}); this.objectives.push({});
}, },
updateObjective(value) { updateObjective(text, index) {
console.log(value); this.objectives.splice(index, 1, {text});
}, },
saveObjectiveGroup() { saveObjectiveGroup() {
console.log('saving'); console.log('saving');
const objectiveGroup = {
title: this.$store.state.objectiveGroupType,
objectives: this.objectives,
module: this.$store.state.parentModule
};
this.$apollo.mutate({ this.$apollo.mutate({
mutation: NEW_OBJECTIVE_GROUP_MUTATION, mutation: NEW_OBJECTIVE_GROUP_MUTATION,
variables: { variables: {
input: { input: {
roomEntry: Object.assign({}, this.objectives, { objectiveGroup
room: this.room.id
})
} }
}, },
update: (store, {data: {addRoomEntry: {roomEntry}}}) => { // todo: make update work
try { // update: (store, {data: {addObjectiveGroup: {objectiveGroup}}}) => {
const query = ROOM_ENTRIES_QUERY; // const query = MODULE_DETAILS_QUERY;
const variables = {slug: this.room.slug}; // const variables = {slug: this.$route.params.slug};
const data = store.readQuery({query, variables}); // const data = store.readQuery({query, variables});
if (data.room && data.room.roomEntries) { // debugger;
data.room.roomEntries.edges.unshift({ // if (data.module && data.module.objectiveGroups) {
node: roomEntry, // data.module.objectiveGroups.edges.push({
__typename: 'RoomEntryNode' // node: objectiveGroup,
}); // __typename: 'ObjectiveGroupNode'
store.writeQuery({query, variables, data}); // });
} // store.writeQuery({query, variables, data});
} catch (e) { // }
// Query did not exist in the cache, and apollo throws a generic Error. Do nothing //
// }
refetchQueries: [{
query: MODULE_DETAILS_QUERY,
variables: {
slug: this.$route.params.slug
} }
} }]
}).then(() => { }).then(() => {
this.hideModal(); this.hideModal();
}); });