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